add eibdvis
[bcusdk.git] / build / build.dev.in
blob08e21757721f9a79422e42ad21e604dbd488e34b
1 #!/bin/bash
2 # BCU SDK bcu development enviroment
3 # Copyright (C) 2005-2007 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@/bcugen3
21 EMBED=@BINDIR@/embedprogid
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 2005-2007 Martin Koegler <mkoegler@auto.tuwien.ac.at>
38 creates a bcu image using the configuration in the config file
40 Usage: $progname [options] config_file
41 Options:
42 -Ixxx adds xxx to the include path
43 -ixxx stores image as xxx (default:config_file.load)
44 -Dxxx uses xxx as temorary directory and keep temporary files there
45 (warning: all content can be lost)
47 END
48 exit 1
51 function error()
53 if [ $keep != 1 ]; then
54 rm -r $TMP
56 exit 1
59 INC=
60 keep=0
61 TMP=
62 OUT=
63 IN=
65 while [ $# != 0 ]
67 value="`echo x\"$1\" | sed -e 's/^x-.//'`"
68 case "$1" in
69 -D*) keep=1; TMP="$value" ;;
70 -I*) INC="$INC $1" ;;
71 -i*) OUT="$value" ;;
73 -*) echo "$progname: unknown option $1"
74 usage;;
75 *) break;;
76 esac
77 shift
78 done
80 if [ $# != 1 ]; then
81 echo "$progname: expect config.file"
82 usage
85 IN="$1"
87 if [ ! -f "$IN" ]; then
88 echo "$progname: $IN not found"
89 exit 1
92 if [ "x$OUT" == "x" ]; then
93 OUT="$IN.load"
96 if [ "x$TMP" == "x" ]; then
97 TMP=`mktemp -u bcusdk.XXXXXXXXXX`||exit 1
98 mkdir $TMP
99 elif [ ! -e "$TMP" ]; then
100 mkdir $TMP
103 if [ ! -d $TMP ]; then
104 echo "can not create directory $TMP"
105 exit 1
108 TMP=`(cd $TMP; pwd)`
110 if [ $keep != 1 ]; then
111 trap "rm -r $TMP; exit 1" 1 2 3 5 10 13 15
114 $BCUGEN "$IN" "$TMP/c.h" "$TMP/c.i" "$TMP/p1.s" "$TMP/p.var" || error
116 VAR=`cat "$TMP/p.var"`
118 if [ ! -f "$LIB/lib$VAR.a" ]; then
119 echo "unknown variant $VAR"
120 error
123 $TGCC -E $INC -I. -o "$TMP/c.inc" -x c "$TMP/c.i" || error
125 echo "#include \"c.h\"">"$TMP/c.c"
126 echo "#include \"c.inc\"">>"$TMP/c.c"
128 $TGCC -c -O3 -Os -Wall -Winline -gstabs -I$SINC -o "$TMP/c.o" "$TMP/c.c" || error
129 $TAS -I$SINC -o "$TMP/p1.o" "$TMP/p1.s" || error
131 $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
132 $TLD -Map "$TMP/load.map" -T $LD/genload.link -o "$TMP/load" "$TMP/elf" || error
135 cp "$TMP/load" "$OUT" || error
137 if [ $keep != 1 ]; then
138 rm -r "$TMP"
140 echo "Done"
141 exit 0