FreeCalypso > hg > fc-magnetite
comparison configure.sh @ 62:9c16635ee5d2
configure.sh: putting it all together
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 01 Oct 2016 02:48:53 +0000 |
parents | |
children | bb53b2e2d548 |
comparison
equal
deleted
inserted
replaced
61:dba3f097489e | 62:9c16635ee5d2 |
---|---|
1 #!/bin/sh | |
2 | |
3 set -e | |
4 | |
5 if [ ! -f configure.sh ] | |
6 then | |
7 echo "This script needs to be run from the top of the source tree" 1>&2 | |
8 exit 1 | |
9 fi | |
10 | |
11 if [ ! -f helpers/makeline ] | |
12 then | |
13 echo "Please run make in the helpers directory first" 1>&2 | |
14 exit 1 | |
15 fi | |
16 | |
17 # start looking at our invokation line | |
18 | |
19 if [ "$1" == --clean ] | |
20 then | |
21 clean_flag=1 | |
22 shift | |
23 else | |
24 clean_flag=0 | |
25 fi | |
26 | |
27 if [ $# -lt 2 ] | |
28 then | |
29 echo "usage: $0 [--clean] target config [vars]" 1>&2 | |
30 exit 1 | |
31 fi | |
32 | |
33 TARGET="$1" | |
34 CONFIG="$2" | |
35 | |
36 if [ ! -f "targets/$TARGET.conf" -o ! -f "targets/$TARGET.h" ] | |
37 then | |
38 echo "Error: target $TARGET not known" 1>&2 | |
39 exit 1 | |
40 fi | |
41 | |
42 if [ ! -f "configs/$CONFIG" ] | |
43 then | |
44 echo "Error: configuration $CONFIG not known" 1>&2 | |
45 exit 1 | |
46 fi | |
47 | |
48 . "targets/$TARGET.conf" | |
49 | |
50 BUILD_DIR="build-$TARGET-$CONFIG" | |
51 USE_STR2IND=0 | |
52 | |
53 # allow the user to override these defaults | |
54 | |
55 shift | |
56 shift | |
57 while [ $# != 0 ] | |
58 do | |
59 eval "$1" | |
60 shift | |
61 done | |
62 | |
63 echo "Building configuration $CONFIG for target $TARGET in $BUILD_DIR" | |
64 | |
65 if [ "$clean_flag" = 1 ] | |
66 then | |
67 rm -rf $BUILD_DIR | |
68 fi | |
69 mkdir -p $BUILD_DIR | |
70 | |
71 : > $BUILD_DIR/lcfgen | |
72 | |
73 # shell functions to be used in the configuration recipe | |
74 | |
75 build_lib() { | |
76 if [ $# -lt 1 -o $# -gt 2 ] | |
77 then | |
78 echo "Error: build_lib takes 1 or 2 arguments" 1>&2 | |
79 exit 1 | |
80 fi | |
81 scripts/mk-component.sh "$1" "$2" | |
82 SUBDIR="$SUBDIR $1" | |
83 current_lib=$1/$1.lib | |
84 LIBS="$LIBS $current_lib" | |
85 } | |
86 | |
87 blob_lib() { | |
88 if [ $# != 1 ] | |
89 then | |
90 echo "Error: blob_lib takes 1 argument" 1>&2 | |
91 exit 1 | |
92 fi | |
93 current_lib="../$1" | |
94 LIBS="$LIBS $current_lib" | |
95 } | |
96 | |
97 lib_link_magic() { | |
98 if [ $# != 1 ] | |
99 then | |
100 echo "Error: lib_link_magic takes 1 argument" 1>&2 | |
101 exit 1 | |
102 fi | |
103 if [ -z "$current_lib" ] | |
104 then | |
105 echo "Error: lib_link_magic called before build_lib or blob_lib" 1>&2 | |
106 exit 1 | |
107 fi | |
108 SPECIAL_LINK_LIBS="$SPECIAL_LINK_LIBS $current_lib" | |
109 echo "$1" >> $BUILD_DIR/lcfgen | |
110 } | |
111 | |
112 # invoke the configuration recipe | |
113 | |
114 export BUILD_DIR TARGET USE_STR2IND | |
115 | |
116 SUBDIR= | |
117 LIBS= | |
118 SPECIAL_LINK_LIBS= | |
119 current_lib= | |
120 | |
121 . "configs/$CONFIG" | |
122 | |
123 # str2ind magic | |
124 | |
125 if [ -z "$str2ind_blobs_used" ] | |
126 then | |
127 echo "Error: configs/$CONFIG must set str2ind_blobs_used" 1>&2 | |
128 exit 1 | |
129 fi | |
130 | |
131 if [ "$str2ind_blobs_used" = 1 ] | |
132 then | |
133 cp blobs/str2ind.tab $BUILD_DIR | |
134 fi | |
135 | |
136 if [ "$str2ind_blobs_used" = 0 -a "$USE_STR2IND" = 0 ] | |
137 then | |
138 echo 'char *str2ind_version = "&0";' > $BUILD_DIR/str2ind.c | |
139 fi | |
140 | |
141 # generate the top level Makefile! | |
142 | |
143 helpers/makeline def SUBDIR $SUBDIR > $BUILD_DIR/Makefile | |
144 echo >> $BUILD_DIR/Makefile | |
145 helpers/makeline def LIBS $LIBS >> $BUILD_DIR/Makefile | |
146 echo >> $BUILD_DIR/Makefile | |
147 helpers/makeline def SPECIAL_LINK_LIBS $SPECIAL_LINK_LIBS >> $BUILD_DIR/Makefile | |
148 echo >> $BUILD_DIR/Makefile | |
149 helpers/makeline def LINK_SCRIPT_SRC ../$LINK_SCRIPT_SRC >> $BUILD_DIR/Makefile | |
150 echo >> $BUILD_DIR/Makefile | |
151 | |
152 cat makefile-frags/first-part >> $BUILD_DIR/Makefile | |
153 | |
154 if [ "$USE_STR2IND" = 1 ] | |
155 then | |
156 cat makefile-frags/str2ind-tab-depend >> $BUILD_DIR/Makefile | |
157 fi | |
158 | |
159 if [ "$str2ind_blobs_used" = 1 -o "$USE_STR2IND" = 1 ] | |
160 then | |
161 cat makefile-frags/str2ind-c-gen >> $BUILD_DIR/Makefile | |
162 fi | |
163 | |
164 cat makefile-frags/link-steps >> $BUILD_DIR/Makefile | |
165 | |
166 cat makefile-frags/clean-always >> $BUILD_DIR/Makefile | |
167 if [ "$str2ind_blobs_used" = 0 ] | |
168 then | |
169 echo ' rm -f str2ind.tab str2ind.log' >> $BUILD_DIR/Makefile | |
170 fi | |
171 if [ "$str2ind_blobs_used" = 1 -o "$USE_STR2IND" = 1 ] | |
172 then | |
173 echo ' rm -f str2ind.c' >> $BUILD_DIR/Makefile | |
174 fi | |
175 echo >> $BUILD_DIR/Makefile | |
176 echo 'FRC:' >> $BUILD_DIR/Makefile | |
177 | |
178 # All done! | |
179 | |
180 echo "Run make in $BUILD_DIR to compile the firmware" |