Ron has been doing really good work over in v3. The problem is that the work got...
[coreboot.git] / targets / buildtarget
1 #!/bin/sh
2 PYTHON=python
3 # Target build script
4
5 if [ $# -lt 1 ]; then
6         echo "usage: buildtarget target [path-to-coreboot]"
7         exit 1
8 fi
9
10 if [ $# -gt 1 ]; then
11         lbpath=$2
12 else
13         lbpath=`pwd`
14         lbpath=`dirname $lbpath`
15 fi
16
17 target_dir=$lbpath/targets
18 config_lb=$1
19 config_dir=$lbpath/util/newconfig
20 yapps2_py=$config_dir/yapps2.py
21 config_g=$config_dir/config.g
22
23 if [ ! -d $target_dir ]; then
24         echo "Target directory not found"
25         exit 1
26 fi
27
28 cd $target_dir
29
30 if [ ! -f $config_lb ]; then
31         config_lb=$1/Config.lb
32 fi
33 if [ ! -f $config_lb ]; then
34         echo "No target config file found"
35         echo "Tried both $1 and $config_lb"
36         exit 1
37 fi
38
39 build_dir=`dirname $config_lb`/`sed -n -e 's/^target \(.*\)$/\1/p' $config_lb`
40 echo "build_dir=$build_dir"
41 config_py=$build_dir/config.py
42
43 if [ ! -d $build_dir ] ; then
44         mkdir -p $build_dir
45 fi
46 if [ ! -f $config_py ]; then
47         echo "No coreboot config script found. Rebuilding it.."
48         $PYTHON $yapps2_py $config_g $config_py
49 fi
50
51 # make sure config.py is up-to-date
52
53 export PYTHONPATH=$config_dir
54 $PYTHON $config_py $config_lb $lbpath
55
56 # now start checking for distro-specific breakage. 
57 ## This check is for the no stack protector mess.
58 EXTRA_CFLAGS=
59
60 if [ -z "$CC" ]; then
61        CC=gcc
62 fi
63
64 $CC -fno-stack-protector -S -xc /dev/null -o .$$.tmp 2>/dev/null
65
66 if [ $? -eq 0 ]; then
67        EXTRA_CFLAGS=-fno-stack-protector
68 fi
69
70 rm -rf .$$.tmp
71
72 # The linker output fd depends on the gcc version.
73 #  1) 'ld-2.15 --help' and 'gcc-4.0 -Wl,--help' use STDOUT.
74 #  2) 'gcc-3.3 --help' and 'gcc-3.4 -Wl,--help' use STDERR.
75 # Thus older versions of GCC (presumably 3.x) implement a redirection of
76 # output to stderr. Re-redirect stderr to stdout to work always.
77 if $CC -Wl,--help 2>&1 | grep -q build-id; then
78         EXTRA_LFLAGS="$EXTRA_LFLAGS -Wl,--build-id=none"
79 fi
80
81 for i in $build_dir/Makefile.settings $build_dir/*/Makefile.settings
82 do
83         echo DISTRO_CFLAGS+=$EXTRA_CFLAGS >>$i
84         echo DISTRO_LFLAGS+=$EXTRA_LFLAGS >>$i
85 done
86
87 exit $?