blob: a555bcbc48a69eb8fea79ad0ca57b138fdda10f3 [file] [log] [blame]
Jordan Crousec3e728f2008-04-09 23:05:59 +00001#!/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
Marc Jonesbb9490a2012-11-30 16:22:51 -070030if [ -z "${V}" ] && [ "${V}" = 1 ]; then
31 DEBUGME=1
32else
33 DEBUGME=0
34fi
35
36if [ $DEBUGME -eq 1 ]; then
37 echo "CC = $CC"
38fi
39
Stefan Reinauer14e22772010-04-27 06:56:47 +000040# let's not recurse.
Ronald G. Minnichb575d672009-02-15 23:32:57 +000041# This is a hack, I know, but it makes sure that really simple user errors
Stefan Reinauer14e22772010-04-27 06:56:47 +000042# don't fork-bomb your machine.
Patrick Georgia4a022c2011-02-14 19:24:37 +000043if [ -n "$CC" ]; then
Marc Jonesbb9490a2012-11-30 16:22:51 -070044b=`basename "$CC"`
Ronald G. Minnichb575d672009-02-15 23:32:57 +000045if [ "$b" = "lpgcc" ]; then
46CC=""
47fi
Patrick Georgia4a022c2011-02-14 19:24:37 +000048fi
Ronald G. Minnichb575d672009-02-15 23:32:57 +000049
Stefan Reinauerc3591242008-08-07 15:22:01 +000050if [ "$CC" != "" ]; then
51DEFAULT_CC=$CC
52else
Jordan Crousec3e728f2008-04-09 23:05:59 +000053DEFAULT_CC=gcc
Stefan Reinauerc3591242008-08-07 15:22:01 +000054fi
Jordan Crousec3e728f2008-04-09 23:05:59 +000055
56BASE=`dirname $0`
57
58# This will set the _LIBDIR and _INCDIR variables used below
59. $BASE/lp.functions
60
Stefan Reinauer5429e262009-05-26 18:01:53 +000061# include libpayload config
Patrick Georgicb761362013-02-21 14:33:25 +010062if [ -f $BASE/../libpayload.config ]; then
63 . $BASE/../libpayload.config
64elif [ -f $BASE/../.config ]; then
65 . $BASE/../.config
66else
67 echo "Can't find config"
68 exit 1
69fi
Stefan Reinauer5429e262009-05-26 18:01:53 +000070
Gabe Black51edd542013-09-30 23:00:33 -070071if [ "$CONFIG_LP_ARCH_ARM" = "y" ]; then
72 _ARCHINCDIR=$_INCDIR/arm
73 _ARCHLIBDIR=$_LIBDIR/arm
Patrick Georgicb761362013-02-21 14:33:25 +010074 _ARCHEXTRA=""
Gabe Black51edd542013-09-30 23:00:33 -070075 _ARCH=arm
Patrick Georgicb761362013-02-21 14:33:25 +010076fi
77
Gabe Black1ee2c6d2013-08-09 04:27:35 -070078if [ "$CONFIG_LP_ARCH_X86" = "y" ]; then
Patrick Georgicb761362013-02-21 14:33:25 +010079 _ARCHINCDIR=$_INCDIR/x86
80 _ARCHLIBDIR=$_LIBDIR/x86
81 _ARCHEXTRA="-m32 "
82 _ARCH=x86
83fi
84
85if [ -f $_LIBDIR/libpayload.ldscript ]; then
86 _LDDIR=$_LIBDIR
87elif [ -f $BASE/../arch/$_ARCH/libpayload.ldscript ]; then
88 _LDDIR=$BASE/../arch/$_ARCH
89fi
90_LDSCRIPT="-Wl,-T,$_LDDIR/libpayload.ldscript"
Ulf Jordan6818a322009-02-10 21:12:35 +000091
Jordan Crousec3e728f2008-04-09 23:05:59 +000092trygccoption() {
Patrick Georgi82867d32012-09-26 15:26:05 +020093 $DEFAULT_CC $1 -S -xc /dev/null -o /dev/null &> /dev/null
94 return $?
Jordan Crousec3e728f2008-04-09 23:05:59 +000095}
96
Jordan Crousec3e728f2008-04-09 23:05:59 +000097DOLINK=1
98
99# This variable will contain the command line that the user wants to
100# pass to gas
101
102CMDLINE=
103
104# Process various flags that would change our behavior
105
106while [ $# -gt 0 ]; do
107 case $1 in
108 -m32|-fno-stack-protector)
109 shift
110 continue
111 ;;
112 -m64)
113 error "Invalid option --64 - only 32 bit architectures are supported"
114 ;;
115 -c)
116 DOLINK=0
117 ;;
118 -debug-wrapper)
119 DEBUGME=1
120 shift
121 continue
122 ;;
Ulf Jordan6818a322009-02-10 21:12:35 +0000123 -Wl,-T,*)
124 _LDSCRIPT="$1"
125 shift
126 continue
127 ;;
Jordan Crousec3e728f2008-04-09 23:05:59 +0000128 *)
129 ;;
130 esac
131
132 CMDLINE="$CMDLINE $1"
133 shift
134done
135
Patrick Georgicb761362013-02-21 14:33:25 +0100136_CFLAGS="$_ARCHEXTRA -nostdinc -nostdlib -I$BASE/../build -I$_INCDIR -I$_ARCHINCDIR -D__LIBPAYLOAD__=1"
Jordan Crousec3e728f2008-04-09 23:05:59 +0000137
Gabe Black1ee2c6d2013-08-09 04:27:35 -0700138if [ "$CONFIG_LP_PDCURSES" = y ]; then
Vladimir Serbinenko571bec72014-01-15 22:04:12 +0100139 _CFLAGS="$_CFLAGS -I$BASE/../curses/PDCurses-3.4"
140fi
141
Gabe Black1ee2c6d2013-08-09 04:27:35 -0700142if [ "$CONFIG_LP_TINYCURSES" = y ]; then
Vladimir Serbinenko571bec72014-01-15 22:04:12 +0100143 _CFLAGS="$_CFLAGS -I$BASE/../curses"
144fi
145
Jordan Crousec3e728f2008-04-09 23:05:59 +0000146# Check for the -fno-stack-protector silliness
147
148trygccoption -fno-stack-protector
149[ $? -eq 0 ] && _CFLAGS="$_CFLAGS -fno-stack-protector"
150
Ronald G. Minnich1a29c1e2013-02-14 15:26:09 -0800151_CFLAGS="$_CFLAGS -I`$DEFAULT_CC $_ARCHEXTRA -print-search-dirs | head -n 1 | cut -d' ' -f2`include"
Jordan Crousec3e728f2008-04-09 23:05:59 +0000152
Patrick Georgicb761362013-02-21 14:33:25 +0100153_LDFLAGS="-L$BASE/../lib -L$_LIBDIR $_LDSCRIPT -static"
Jordan Crousec3e728f2008-04-09 23:05:59 +0000154
155if [ $DOLINK -eq 0 ]; then
156 if [ $DEBUGME -eq 1 ]; then
157 echo "$DEFAULT_CC $_CFLAGS $CMDLINE"
158 fi
159
160 $DEFAULT_CC $_CFLAGS $CMDLINE
161else
Ronald G. Minnich1a29c1e2013-02-14 15:26:09 -0800162 _LIBGCC=`$DEFAULT_CC $_ARCHEXTRA -print-libgcc-file-name`
Patrick Georgicb761362013-02-21 14:33:25 +0100163 if [ -f $_ARCHLIBDIR/head.o ]; then
164 HEAD_O=$_ARCHLIBDIR/head.o
165 elif [ -f $BASE/../build/head.o ]; then
166 HEAD_O=$BASE/../build/head.o
167 else
168 echo "Could not find head.o"
169 exit 1
170 fi
Jordan Crousec3e728f2008-04-09 23:05:59 +0000171 if [ $DEBUGME -eq 1 ]; then
Patrick Georgicb761362013-02-21 14:33:25 +0100172 echo "$DEFAULT_CC $_CFLAGS $_LDFLAGS $HEAD_O $CMDLINE -lpayload $_LIBGCC"
Jordan Crousec3e728f2008-04-09 23:05:59 +0000173 fi
174
Stefan Reinauer7208f6e2010-03-25 18:54:43 +0000175 # Note: $_ARCHLIBDIR/head.o must be the first object being linked, because it
Robert Millan39ebf2f2008-11-11 23:36:12 +0000176 # contains a Multiboot header. The Multiboot standard requires this
177 # header to be placed below 0x2000 in the resulting image. See:
178 # http://www.gnu.org/software/grub/manual/multiboot/html_node/OS-image-format.html
179
Patrick Georgicb761362013-02-21 14:33:25 +0100180 $DEFAULT_CC $_CFLAGS $_LDFLAGS $HEAD_O $CMDLINE -lpayload $_LIBGCC
Jordan Crousec3e728f2008-04-09 23:05:59 +0000181fi