- Update abuild.sh so it will rebuild successfull builds
[coreboot.git] / util / abuild / abuild.sh
1 #!/bin/bash
2 #
3 #  LinuxBIOS autobuild
4 #
5 #  This script builds LinuxBIOS images for all available targets.
6 #
7 #  (C) 2004 by Stefan Reinauer <stepan@openbios.org>
8 #
9 #  This file is subject to the terms and conditions of the GNU General
10 #  Public License. See the file COPYING in the main directory of this
11 #  archive for more details.
12 #     
13
14 LBROOT=$1
15
16 # /path/to/freebios2/
17 if [ -z "$LBROOT" ] ; then
18         LBROOT=$( cd ../..; pwd )
19 fi
20
21
22 # Where shall we place all the build trees?
23 TARGET=$( pwd )/linuxbios-builds
24
25 # path to payload. Should be more generic
26 PAYLOAD=/dev/null
27
28 # Lines of error context to be printed in FAILURE case
29 CONTEXT=5
30
31 # One might want to adjust these in case of cross compiling
32 MAKE="make"
33 PYTHON=python
34
35 ARCH=`uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ \
36         -e s/arm.*/arm/ -e s/sa110/arm/ -e s/x86_64/amd64/ \
37         -e "s/Power Macintosh/ppc/"`
38
39 function vendors
40 {
41         # make this a function so we can easily select
42         # without breaking readability
43         ls -1 $LBROOT/src/mainboard | grep -v CVS
44 }
45
46 function mainboards
47 {
48         # make this a function so we can easily select
49         # without breaking readability
50         
51         VENDOR=$1
52         
53         ls -1 $LBROOT/src/mainboard/$VENDOR | grep -v CVS 
54 }
55
56 function architecture
57 {
58         VENDOR=$1
59         MAINBOARD=$2
60         cat $LBROOT/src/mainboard/$VENDOR/$MAINBOARD/Config.lb | \
61                 grep ^arch | cut -f 2 -d\ 
62 }
63
64 function create_config
65 {
66         VENDOR=$1
67         MAINBOARD=$2
68         echo -n "  Creating config file..."
69         mkdir -p $TARGET
70         ( cat << EOF
71 # This will make a target directory of ./VENDOR_MAINBOARD
72
73 target VENDOR_MAINBOARD
74 mainboard VENDOR/MAINBOARD
75
76 romimage "normal"
77         option USE_FALLBACK_IMAGE=0
78         option ROM_IMAGE_SIZE=0x13000
79         option LINUXBIOS_EXTRA_VERSION=".0-normal"
80         payload PAYLOAD
81 end
82
83 romimage "fallback" 
84         option USE_FALLBACK_IMAGE=1
85         option ROM_IMAGE_SIZE=0x13000
86         option LINUXBIOS_EXTRA_VERSION=".0-fallback"
87         payload PAYLOAD
88 end
89
90 buildrom ./VENDOR_MAINBOARD.rom ROM_SIZE "normal" "fallback"
91 EOF
92         ) | sed -e s,VENDOR,$VENDOR,g \
93                 -e s,MAINBOARD,$MAINBOARD,g \
94                 -e s,PAYLOAD,$PAYLOAD,g \
95                 > $TARGET/Config-${VENDOR}_${MAINBOARD}.lb
96         echo " ok"
97 }
98
99 function create_builddir
100 {       
101         VENDOR=$1
102         MAINBOARD=$2
103         
104         echo -n "  Creating builddir..."
105
106         target_dir=$TARGET
107         config_dir=$LBROOT/util/newconfig
108         yapps2_py=$config_dir/yapps2.py
109         config_g=$config_dir/config.g
110         config_lb=Config-${VENDOR}_${MAINBOARD}.lb
111
112         cd $target_dir
113
114         build_dir=${VENDOR}_${MAINBOARD}
115         config_py=$build_dir/config.py
116
117         if [ ! -d $build_dir ] ; then
118                 mkdir -p $build_dir
119         fi
120         if [ ! -f $config_py ]; then
121                 $PYTHON $yapps2_py $config_g $config_py &> $build_dir/py.log
122         fi
123
124         # make sure config.py is up-to-date
125
126         export PYTHONPATH=$config_dir
127         $PYTHON $config_py $config_lb $LBROOT &> $build_dir/config.log
128         if [ $? -eq 0 ]; then
129                 echo "ok"
130         else
131                 echo "FAILED! Log excerpt:"
132                 tail -n $CONTEXT $build_dir/config.log
133                 return 1
134         fi
135 }
136
137 function create_buildenv
138 {
139         VENDOR=$1
140         MAINBOARD=$2
141         create_config $VENDOR $MAINBOARD
142         create_builddir $VENDOR $MAINBOARD
143 }
144
145 function compile_target
146 {       
147         VENDOR=$1
148         MAINBOARD=$2
149
150         echo -n "  Compiling image .."
151         CURR=$( pwd )
152         cd $TARGET/${VENDOR}_${MAINBOARD}
153         eval $MAKE &> make.log
154         if [ $? -eq 0 ]; then
155                 echo "ok" > compile.status
156                 echo "ok."
157                 cd $CURR
158                 return 0
159         else
160                 echo "FAILED! Log excerpt:"
161                 tail -n $CONTEXT make.log
162                 cd $CURR
163                 return 1
164         fi
165 }
166
167 function built_successfully
168 {
169         CURR=`pwd`
170         cd $TARGET/${VENDOR}_${MAINBOARD}
171         status="fail"
172         if [ -r compile.status ] ; then
173                 status=`cat compile.status`
174         fi
175         cd $CURR
176         [ "$status" == "ok" ]
177 }
178 function build_target
179 {
180         VENDOR=$1
181         MAINBOARD=$2
182         TARCH=$( architecture $VENDOR $MAINBOARD )
183         
184         echo -n "Processing mainboard/$VENDOR/$MAINBOARD"
185         if [ "$ARCH" == "$TARCH" ]; then
186                 echo " ($TARCH: ok)"
187                 if ! built_successfully $VENDOR $MAINBOARD  ; then
188                         create_buildenv $VENDOR $MAINBOARD
189                         if [ $? -eq 0 ]; then
190                                 compile_target $VENDOR $MAINBOARD
191                         fi
192                 else
193                         echo " ( mainboard/$VENDOR/$MAINBOARD previously ok )"
194                 fi
195
196         else
197                 # cross compiling not supported yet.
198                 echo " ($TARCH: skipped, we're $ARCH)"
199         fi
200         echo
201 }
202
203 for VENDOR in $( vendors ); do
204   for MAINBOARD in $( mainboards $VENDOR ); do
205         build_target $VENDOR $MAINBOARD
206   done
207 done
208