Jordan Crouse | c3e728f | 2008-04-09 23:05:59 +0000 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | ## This file is part of the libpayload project. |
| 3 | ## |
| 4 | ## Copyright (C) 2008 Advanced Micro Devices, Inc. |
| 5 | ## |
| 6 | ## Redistribution and use in source and binary forms, with or without |
| 7 | ## modification, are permitted provided that the following conditions |
| 8 | ## are met: |
| 9 | ## 1. Redistributions of source code must retain the above copyright |
| 10 | ## notice, this list of conditions and the following disclaimer. |
| 11 | ## 2. Redistributions in binary form must reproduce the above copyright |
| 12 | ## notice, this list of conditions and the following disclaimer in the |
| 13 | ## documentation and/or other materials provided with the distribution. |
| 14 | ## 3. The name of the author may not be used to endorse or promote products |
| 15 | ## derived from this software without specific prior written permission. |
| 16 | ## |
| 17 | ## THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
| 18 | ## ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 19 | ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 20 | ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
| 21 | ## FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 22 | ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 23 | ## OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 24 | ## HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 25 | ## LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 26 | ## OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 27 | ## SUCH DAMAGE. |
| 28 | |
| 29 | # GCC wrapper for libpayload |
Vadim Bendebury | c253717 | 2014-05-19 15:43:47 -0700 | [diff] [blame] | 30 | if [ "${V}" = "1" ]; then |
Marc Jones | bb9490a | 2012-11-30 16:22:51 -0700 | [diff] [blame] | 31 | DEBUGME=1 |
| 32 | else |
| 33 | DEBUGME=0 |
| 34 | fi |
| 35 | |
| 36 | if [ $DEBUGME -eq 1 ]; then |
| 37 | echo "CC = $CC" |
| 38 | fi |
| 39 | |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 40 | # let's not recurse. |
Ronald G. Minnich | b575d67 | 2009-02-15 23:32:57 +0000 | [diff] [blame] | 41 | # This is a hack, I know, but it makes sure that really simple user errors |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 42 | # don't fork-bomb your machine. |
Patrick Georgi | a4a022c | 2011-02-14 19:24:37 +0000 | [diff] [blame] | 43 | if [ -n "$CC" ]; then |
Marc Jones | bb9490a | 2012-11-30 16:22:51 -0700 | [diff] [blame] | 44 | b=`basename "$CC"` |
Ronald G. Minnich | b575d67 | 2009-02-15 23:32:57 +0000 | [diff] [blame] | 45 | if [ "$b" = "lpgcc" ]; then |
| 46 | CC="" |
| 47 | fi |
Patrick Georgi | a4a022c | 2011-02-14 19:24:37 +0000 | [diff] [blame] | 48 | fi |
Ronald G. Minnich | b575d67 | 2009-02-15 23:32:57 +0000 | [diff] [blame] | 49 | |
Stefan Reinauer | c359124 | 2008-08-07 15:22:01 +0000 | [diff] [blame] | 50 | if [ "$CC" != "" ]; then |
| 51 | DEFAULT_CC=$CC |
| 52 | else |
Jordan Crouse | c3e728f | 2008-04-09 23:05:59 +0000 | [diff] [blame] | 53 | DEFAULT_CC=gcc |
Stefan Reinauer | c359124 | 2008-08-07 15:22:01 +0000 | [diff] [blame] | 54 | fi |
Jordan Crouse | c3e728f | 2008-04-09 23:05:59 +0000 | [diff] [blame] | 55 | |
| 56 | BASE=`dirname $0` |
| 57 | |
| 58 | # This will set the _LIBDIR and _INCDIR variables used below |
| 59 | . $BASE/lp.functions |
| 60 | |
Stefan Reinauer | 5429e26 | 2009-05-26 18:01:53 +0000 | [diff] [blame] | 61 | # include libpayload config |
Patrick Georgi | cb76136 | 2013-02-21 14:33:25 +0100 | [diff] [blame] | 62 | if [ -f $BASE/../libpayload.config ]; then |
| 63 | . $BASE/../libpayload.config |
| 64 | elif [ -f $BASE/../.config ]; then |
| 65 | . $BASE/../.config |
| 66 | else |
| 67 | echo "Can't find config" |
| 68 | exit 1 |
| 69 | fi |
Stefan Reinauer | 5429e26 | 2009-05-26 18:01:53 +0000 | [diff] [blame] | 70 | |
Gabe Black | 51edd54 | 2013-09-30 23:00:33 -0700 | [diff] [blame] | 71 | if [ "$CONFIG_LP_ARCH_ARM" = "y" ]; then |
| 72 | _ARCHINCDIR=$_INCDIR/arm |
| 73 | _ARCHLIBDIR=$_LIBDIR/arm |
Patrick Georgi | cb76136 | 2013-02-21 14:33:25 +0100 | [diff] [blame] | 74 | _ARCHEXTRA="" |
Gabe Black | 51edd54 | 2013-09-30 23:00:33 -0700 | [diff] [blame] | 75 | _ARCH=arm |
Patrick Georgi | cb76136 | 2013-02-21 14:33:25 +0100 | [diff] [blame] | 76 | fi |
Furquan Shaikh | 8c8c377 | 2014-02-19 11:35:30 -0800 | [diff] [blame] | 77 | if [ "$CONFIG_LP_ARCH_ARM64" = "y" ]; then |
| 78 | _ARCHINCDIR=$_INCDIR/arm64 |
| 79 | _ARCHLIBDIR=$_LIBDIR/arm64 |
| 80 | _ARCHEXTRA="" |
| 81 | _ARCH=arm64 |
| 82 | fi |
Ionela Voinescu | ce22c02 | 2014-09-24 17:05:33 +0100 | [diff] [blame] | 83 | if [ "$CONFIG_LP_ARCH_MIPS" = "y" ]; then |
| 84 | _ARCHINCDIR=$_INCDIR/mips |
| 85 | _ARCHLIBDIR=$_LIBDIR/mips |
| 86 | _ARCHEXTRA="" |
| 87 | _ARCH=mips |
| 88 | fi |
Gabe Black | 1ee2c6d | 2013-08-09 04:27:35 -0700 | [diff] [blame] | 89 | if [ "$CONFIG_LP_ARCH_X86" = "y" ]; then |
Patrick Georgi | cb76136 | 2013-02-21 14:33:25 +0100 | [diff] [blame] | 90 | _ARCHINCDIR=$_INCDIR/x86 |
| 91 | _ARCHLIBDIR=$_LIBDIR/x86 |
| 92 | _ARCHEXTRA="-m32 " |
| 93 | _ARCH=x86 |
| 94 | fi |
| 95 | |
| 96 | if [ -f $_LIBDIR/libpayload.ldscript ]; then |
| 97 | _LDDIR=$_LIBDIR |
| 98 | elif [ -f $BASE/../arch/$_ARCH/libpayload.ldscript ]; then |
| 99 | _LDDIR=$BASE/../arch/$_ARCH |
| 100 | fi |
| 101 | _LDSCRIPT="-Wl,-T,$_LDDIR/libpayload.ldscript" |
Ulf Jordan | 6818a32 | 2009-02-10 21:12:35 +0000 | [diff] [blame] | 102 | |
Jordan Crouse | c3e728f | 2008-04-09 23:05:59 +0000 | [diff] [blame] | 103 | trygccoption() { |
Patrick Georgi | 82867d3 | 2012-09-26 15:26:05 +0200 | [diff] [blame] | 104 | $DEFAULT_CC $1 -S -xc /dev/null -o /dev/null &> /dev/null |
| 105 | return $? |
Jordan Crouse | c3e728f | 2008-04-09 23:05:59 +0000 | [diff] [blame] | 106 | } |
| 107 | |
Jordan Crouse | c3e728f | 2008-04-09 23:05:59 +0000 | [diff] [blame] | 108 | DOLINK=1 |
| 109 | |
| 110 | # This variable will contain the command line that the user wants to |
| 111 | # pass to gas |
| 112 | |
| 113 | CMDLINE= |
| 114 | |
| 115 | # Process various flags that would change our behavior |
| 116 | |
| 117 | while [ $# -gt 0 ]; do |
| 118 | case $1 in |
| 119 | -m32|-fno-stack-protector) |
| 120 | shift |
| 121 | continue |
| 122 | ;; |
| 123 | -m64) |
| 124 | error "Invalid option --64 - only 32 bit architectures are supported" |
| 125 | ;; |
| 126 | -c) |
| 127 | DOLINK=0 |
| 128 | ;; |
| 129 | -debug-wrapper) |
| 130 | DEBUGME=1 |
| 131 | shift |
| 132 | continue |
| 133 | ;; |
Ulf Jordan | 6818a32 | 2009-02-10 21:12:35 +0000 | [diff] [blame] | 134 | -Wl,-T,*) |
| 135 | _LDSCRIPT="$1" |
| 136 | shift |
| 137 | continue |
| 138 | ;; |
Jordan Crouse | c3e728f | 2008-04-09 23:05:59 +0000 | [diff] [blame] | 139 | *) |
| 140 | ;; |
| 141 | esac |
| 142 | |
| 143 | CMDLINE="$CMDLINE $1" |
| 144 | shift |
| 145 | done |
| 146 | |
Patrick Georgi | cb76136 | 2013-02-21 14:33:25 +0100 | [diff] [blame] | 147 | _CFLAGS="$_ARCHEXTRA -nostdinc -nostdlib -I$BASE/../build -I$_INCDIR -I$_ARCHINCDIR -D__LIBPAYLOAD__=1" |
Jordan Crouse | c3e728f | 2008-04-09 23:05:59 +0000 | [diff] [blame] | 148 | |
Gabe Black | 1ee2c6d | 2013-08-09 04:27:35 -0700 | [diff] [blame] | 149 | if [ "$CONFIG_LP_PDCURSES" = y ]; then |
Vladimir Serbinenko | 571bec7 | 2014-01-15 22:04:12 +0100 | [diff] [blame] | 150 | _CFLAGS="$_CFLAGS -I$BASE/../curses/PDCurses-3.4" |
| 151 | fi |
| 152 | |
Gabe Black | 1ee2c6d | 2013-08-09 04:27:35 -0700 | [diff] [blame] | 153 | if [ "$CONFIG_LP_TINYCURSES" = y ]; then |
Vladimir Serbinenko | 571bec7 | 2014-01-15 22:04:12 +0100 | [diff] [blame] | 154 | _CFLAGS="$_CFLAGS -I$BASE/../curses" |
| 155 | fi |
| 156 | |
Jordan Crouse | c3e728f | 2008-04-09 23:05:59 +0000 | [diff] [blame] | 157 | # Check for the -fno-stack-protector silliness |
| 158 | |
| 159 | trygccoption -fno-stack-protector |
| 160 | [ $? -eq 0 ] && _CFLAGS="$_CFLAGS -fno-stack-protector" |
| 161 | |
Paul Kocialkowski | f1b7afb | 2015-08-10 11:00:39 +0200 | [diff] [blame] | 162 | _CFLAGS="$_CFLAGS -include $BASE/../include/kconfig.h -I`$DEFAULT_CC $_ARCHEXTRA -print-search-dirs | head -n 1 | cut -d' ' -f2`include" |
Jordan Crouse | c3e728f | 2008-04-09 23:05:59 +0000 | [diff] [blame] | 163 | |
Patrick Georgi | cb76136 | 2013-02-21 14:33:25 +0100 | [diff] [blame] | 164 | _LDFLAGS="-L$BASE/../lib -L$_LIBDIR $_LDSCRIPT -static" |
Jordan Crouse | c3e728f | 2008-04-09 23:05:59 +0000 | [diff] [blame] | 165 | |
| 166 | if [ $DOLINK -eq 0 ]; then |
| 167 | if [ $DEBUGME -eq 1 ]; then |
Paul Kocialkowski | 7572e66 | 2015-08-03 14:08:40 +0200 | [diff] [blame] | 168 | echo "$DEFAULT_CC $CMDLINE $_CFLAGS" |
Jordan Crouse | c3e728f | 2008-04-09 23:05:59 +0000 | [diff] [blame] | 169 | fi |
| 170 | |
Paul Kocialkowski | 7572e66 | 2015-08-03 14:08:40 +0200 | [diff] [blame] | 171 | $DEFAULT_CC $CMDLINE $_CFLAGS |
Jordan Crouse | c3e728f | 2008-04-09 23:05:59 +0000 | [diff] [blame] | 172 | else |
Vadim Bendebury | 562d71f | 2014-11-27 18:49:33 -0800 | [diff] [blame] | 173 | if [ -z "${CONFIG_LP_ARCH_MIPS}" ]; then |
| 174 | _LIBGCC=`$DEFAULT_CC $_ARCHEXTRA -print-libgcc-file-name` |
| 175 | fi |
Patrick Georgi | cb76136 | 2013-02-21 14:33:25 +0100 | [diff] [blame] | 176 | if [ -f $_ARCHLIBDIR/head.o ]; then |
| 177 | HEAD_O=$_ARCHLIBDIR/head.o |
| 178 | elif [ -f $BASE/../build/head.o ]; then |
| 179 | HEAD_O=$BASE/../build/head.o |
| 180 | else |
| 181 | echo "Could not find head.o" |
| 182 | exit 1 |
| 183 | fi |
Julius Werner | 4bfa29e | 2015-08-20 14:36:34 -0700 | [diff] [blame] | 184 | |
| 185 | if grep -q ARM64_A53_ERRATUM_843419=y $BASE/../libpayload.config && |
| 186 | grep -q fix-cortex-a53-843419 $BASE/../libpayload.xcompile; then |
| 187 | _LDFLAGS+=" -Wl,--fix-cortex-a53-843419" |
| 188 | fi |
| 189 | |
Jordan Crouse | c3e728f | 2008-04-09 23:05:59 +0000 | [diff] [blame] | 190 | if [ $DEBUGME -eq 1 ]; then |
Paul Kocialkowski | 7572e66 | 2015-08-03 14:08:40 +0200 | [diff] [blame] | 191 | echo "$DEFAULT_CC $_LDFLAGS $HEAD_O $CMDLINE $_CFLAGS -lpayload $_LIBGCC" |
Jordan Crouse | c3e728f | 2008-04-09 23:05:59 +0000 | [diff] [blame] | 192 | fi |
| 193 | |
Stefan Reinauer | 7208f6e | 2010-03-25 18:54:43 +0000 | [diff] [blame] | 194 | # Note: $_ARCHLIBDIR/head.o must be the first object being linked, because it |
Robert Millan | 39ebf2f | 2008-11-11 23:36:12 +0000 | [diff] [blame] | 195 | # contains a Multiboot header. The Multiboot standard requires this |
| 196 | # header to be placed below 0x2000 in the resulting image. See: |
| 197 | # http://www.gnu.org/software/grub/manual/multiboot/html_node/OS-image-format.html |
| 198 | |
Paul Kocialkowski | 7572e66 | 2015-08-03 14:08:40 +0200 | [diff] [blame] | 199 | $DEFAULT_CC $_LDFLAGS $HEAD_O $CMDLINE $_CFLAGS -lpayload $_LIBGCC |
Jordan Crouse | c3e728f | 2008-04-09 23:05:59 +0000 | [diff] [blame] | 200 | fi |