Add missing header file for struct timeval
[bcusdk.git] / build / build.img.in
blobb12c445358f4f3d9348c293156e2c6a2e4ef5b02
1 #!/bin/bash
2 # BCU SDK bcu development enviroment
3 # Copyright (C) 2005-2008 Martin Koegler <mkoegler@auto.tuwien.ac.at>
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 version="@VERSION@"
20 BCUGEN=@BINDIR@/bcugen2
21 EXTRACT=@BINDIR@/extractprogid
22 LIB=@LIBDIR@
23 SINC=@INCDIR@
24 LD=@LDDIR@
25 TGCC=@TGCC@
26 TLD=@TLD@
27 TAR=@TAR@
28 TAS=@TAS@
30 set -e
32 progname="`basename \"$0\"`"
34 usage()
36 cat >&2 <<END
37 $progname $version Copyright (C) 2005-2008 Martin Koegler <mkoegler@auto.tuwien.ac.at>
38 creates a bcu image
40 Usage: $progname [options] config_desc
41 Options:
42 -Dxx uses xxx as temorary directory and keep temporary files there
43 (warning: all content can be lost)
44 -cxxx uses xxx as program id
45 -ixxx stores image as xxx (default:config_desc.load)
47 END
48 exit 1
51 function error()
53 if [ $keep != 1 ]; then
54 rm -r $TMP
56 exit 1
59 CONF=
60 keep=0
61 TMP=
62 OUT=
64 while [ $# != 0 ]
66 value="`echo x\"$1\" | sed -e 's/^x-.//'`"
67 case "$1" in
68 -D*) keep=1; TMP="$value" ;;
69 -c*) CONF="$value" ;;
70 -i*) OUT="$value" ;;
72 -*) echo "$progname: unknown option $1"
73 usage;;
74 *) break;;
75 esac
76 shift
77 done
79 if [ $# != 1 ]; then
80 echo "$progname: expect config_desc"
81 usage
84 IN="$1"
86 if [ ! -f "$IN" ]; then
87 echo "$progname: $IN not found"
88 exit 1
91 if [ "x$OUT" == "x" ]; then
92 OUT="$IN.load"
95 if [ "x$TMP" == "x" ]; then
96 TMP=`mktemp -u bcusdk.XXXXXXXXXX`||exit 1
97 mkdir $TMP
98 elif [ ! -e "$TMP" ]; then
99 mkdir $TMP
102 if [ ! -d $TMP ]; then
103 echo "can not create directory $TMP"
104 exit 1
107 TMP=`(cd $TMP; pwd)`
109 if [ $keep != 1 ]; then
110 trap "rm -r $TMP; exit 1" 1 2 3 5 10 13 15
113 if [ "x$CONF" == "x" ]; then
114 $EXTRACT "$IN" "$TMP/cf" || error
116 else
117 cp "$CONF" "$TMP/cf" || error
120 pushd "$TMP" >/dev/null || error
121 $TAR x cf bcusdk-version || error
123 if [ "x`cat bcusdk-version`" == "x0.0.0" ]; then
124 $TAR x cf config || error
125 $TAR x cf c.inc || error
126 else
127 echo "Unsupported Formatversion: `cat bcusdk-version`"
128 error
131 popd >/dev/null || error
133 $BCUGEN "$TMP/config" "$IN" "$TMP/c.h" "$TMP/p1.s" "$TMP/p.var" || error
135 VAR=`cat "$TMP/p.var"`
137 if [ ! -f "$LIB/lib$VAR.a" ]; then
138 echo "unknown variant $VAR"
139 error
142 echo "#include \"c.h\"">"$TMP/c.c"
143 echo "#include \"c.inc\"">>"$TMP/c.c"
145 $TGCC -c -O3 -Os -Wall -Winline -gstabs -I$SINC -o "$TMP/c.o" "$TMP/c.c" || error
146 $TAS -I$SINC -o "$TMP/p1.o" "$TMP/p1.s" || error
148 $TLD -Map "$TMP/elf.map" -N -T "$LD/$VAR.link" --move-sections --relax -o "$TMP/elf" "$TMP/c.o" "$TMP/p1.o" -\( -lc -lm `$TGCC -print-libgcc-file-name` "$LIB/lib$VAR.a" -\) || error
149 $TLD -Map "$TMP/load.map" -T $LD/genload.link -o "$TMP/load" "$TMP/elf" || error
152 cp "$TMP/load" "$OUT" || error
154 if [ $keep != 1 ]; then
155 rm -r "$TMP"
157 echo "Done"
158 exit 0