| |
1 #!/bin/sh |
| |
2 |
| |
3 |
| |
4 # some utility functions |
| |
5 isplatform() |
| |
6 { |
| |
7 for p in $PLATFORM |
| |
8 do |
| |
9 if [ "$p" = "$1" ]; then |
| |
10 return 0 |
| |
11 fi |
| |
12 done |
| |
13 return 1 |
| |
14 } |
| |
15 notisplatform() |
| |
16 { |
| |
17 for p in $PLATFORM |
| |
18 do |
| |
19 if [ "$p" = "$1" ]; then |
| |
20 return 1 |
| |
21 fi |
| |
22 done |
| |
23 return 0 |
| |
24 } |
| |
25 istoolchain() |
| |
26 { |
| |
27 for t in $TOOLCHAIN |
| |
28 do |
| |
29 if [ "$t" = "$1" ]; then |
| |
30 return 0 |
| |
31 fi |
| |
32 done |
| |
33 return 1 |
| |
34 } |
| |
35 notistoolchain() |
| |
36 { |
| |
37 for t in $TOOLCHAIN |
| |
38 do |
| |
39 if [ "$t" = "$1" ]; then |
| |
40 return 1 |
| |
41 fi |
| |
42 done |
| |
43 return 0 |
| |
44 } |
| |
45 |
| |
46 # clean abort |
| |
47 abort_configure() |
| |
48 { |
| |
49 rm -Rf "$TEMP_DIR" |
| |
50 exit 1 |
| |
51 } |
| |
52 |
| |
53 # Test for availability of pkg-config |
| |
54 PKG_CONFIG=`command -v pkg-config` |
| |
55 : ${PKG_CONFIG:="false"} |
| |
56 |
| |
57 # Simple uname based platform detection |
| |
58 # $PLATFORM is used for platform dependent dependency selection |
| |
59 OS=`uname -s` |
| |
60 OS_VERSION=`uname -r` |
| |
61 printf "detect platform... " |
| |
62 if [ "$OS" = "SunOS" ]; then |
| |
63 PLATFORM="solaris sunos unix svr4" |
| |
64 elif [ "$OS" = "Linux" ]; then |
| |
65 PLATFORM="linux unix" |
| |
66 elif [ "$OS" = "FreeBSD" ]; then |
| |
67 PLATFORM="freebsd bsd unix" |
| |
68 elif [ "$OS" = "OpenBSD" ]; then |
| |
69 PLATFORM="openbsd bsd unix" |
| |
70 elif [ "$OS" = "NetBSD" ]; then |
| |
71 PLATFORM="netbsd bsd unix" |
| |
72 elif [ "$OS" = "Darwin" ]; then |
| |
73 PLATFORM="macos osx bsd unix" |
| |
74 elif echo "$OS" | grep -i "MINGW" > /dev/null; then |
| |
75 PLATFORM="windows mingw" |
| |
76 fi |
| |
77 : ${PLATFORM:="unix"} |
| |
78 |
| |
79 PLATFORM_NAME=`echo "$PLATFORM" | cut -f1 -d' ' -` |
| |
80 echo "$PLATFORM_NAME" |
| |
81 |
| |
82 |
| |
83 # help text |
| |
84 printhelp() |
| |
85 { |
| |
86 echo "Usage: $0 [OPTIONS]..." |
| |
87 cat << __EOF__ |
| |
88 Installation directories: |
| |
89 --prefix=PREFIX path prefix for architecture-independent files |
| |
90 [$prefix] |
| |
91 --exec-prefix=EPREFIX path prefix for architecture-dependent files |
| |
92 [PREFIX] |
| |
93 |
| |
94 --bindir=DIR user executables [EPREFIX/bin] |
| |
95 --sbindir=DIR system admin executables [EPREFIX/sbin] |
| |
96 --libexecdir=DIR program executables [EPREFIX/libexec] |
| |
97 --sysconfdir=DIR system configuration files [PREFIX/etc] |
| |
98 --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com] |
| |
99 --localstatedir=DIR modifiable single-machine data [PREFIX/var] |
| |
100 --runstatedir=DIR run-time variable data [LOCALSTATEDIR/run] |
| |
101 --libdir=DIR object code libraries [EPREFIX/lib] |
| |
102 --includedir=DIR C header files [PREFIX/include] |
| |
103 --datarootdir=DIR read-only arch.-independent data root [PREFIX/share] |
| |
104 --datadir=DIR read-only architecture-independent data [DATAROOTDIR] |
| |
105 --infodir=DIR info documentation [DATAROOTDIR/info] |
| |
106 --mandir=DIR man documentation [DATAROOTDIR/man] |
| |
107 --localedir=DIR locale-dependent data [DATAROOTDIR/locale] |
| |
108 |
| |
109 Build Types: |
| |
110 --debug add extra compile flags for debug builds |
| |
111 --release add extra compile flags for release builds |
| |
112 |
| |
113 __EOF__ |
| |
114 } |
| |
115 |
| |
116 # create temporary directory |
| |
117 TEMP_DIR=".tmp-`uname -n`" |
| |
118 rm -Rf "$TEMP_DIR" |
| |
119 if mkdir -p "$TEMP_DIR"; then |
| |
120 : |
| |
121 else |
| |
122 echo "Cannot create tmp dir $TEMP_DIR" |
| |
123 echo "Abort" |
| |
124 exit 1 |
| |
125 fi |
| |
126 touch "$TEMP_DIR/options" |
| |
127 touch "$TEMP_DIR/features" |
| |
128 |
| |
129 # define standard variables |
| |
130 # also define standard prefix (this is where we will search for config.site) |
| |
131 prefix=/usr |
| |
132 exec_prefix= |
| |
133 bindir= |
| |
134 sbindir= |
| |
135 libdir= |
| |
136 libexecdir= |
| |
137 datarootdir= |
| |
138 datadir= |
| |
139 sysconfdir= |
| |
140 sharedstatedir= |
| |
141 localstatedir= |
| |
142 runstatedir= |
| |
143 includedir= |
| |
144 infodir= |
| |
145 localedir= |
| |
146 mandir= |
| |
147 |
| |
148 # custom variables |
| |
149 |
| |
150 # features |
| |
151 |
| |
152 # |
| |
153 # parse arguments |
| |
154 # |
| |
155 BUILD_TYPE="default" |
| |
156 for ARG in "$@" |
| |
157 do |
| |
158 case "$ARG" in |
| |
159 "--prefix="*) prefix=${ARG#--prefix=} ;; |
| |
160 "--exec-prefix="*) exec_prefix=${ARG#--exec-prefix=} ;; |
| |
161 "--bindir="*) bindir=${ARG#----bindir=} ;; |
| |
162 "--sbindir="*) sbindir=${ARG#--sbindir=} ;; |
| |
163 "--libdir="*) libdir=${ARG#--libdir=} ;; |
| |
164 "--libexecdir="*) libexecdir=${ARG#--libexecdir=} ;; |
| |
165 "--datarootdir="*) datarootdir=${ARG#--datarootdir=} ;; |
| |
166 "--datadir="*) datadir=${ARG#--datadir=} ;; |
| |
167 "--sysconfdir="*) sysconfdir=${ARG#--sysconfdir=} ;; |
| |
168 "--sharedstatedir="*) sharedstatedir=${ARG#--sharedstatedir=} ;; |
| |
169 "--localstatedir="*) localstatedir=${ARG#--localstatedir=} ;; |
| |
170 "--includedir="*) includedir=${ARG#--includedir=} ;; |
| |
171 "--infodir="*) infodir=${ARG#--infodir=} ;; |
| |
172 "--mandir"*) mandir=${ARG#--mandir} ;; |
| |
173 "--localedir"*) localedir=${ARG#--localedir} ;; |
| |
174 "--help"*) printhelp; abort_configure ;; |
| |
175 "--debug") BUILD_TYPE="debug" ;; |
| |
176 "--release") BUILD_TYPE="release" ;; |
| |
177 "-"*) echo "unknown option: $ARG"; abort_configure ;; |
| |
178 esac |
| |
179 done |
| |
180 |
| |
181 |
| |
182 |
| |
183 # set defaults for dir variables |
| |
184 : ${exec_prefix:="$prefix"} |
| |
185 : ${bindir:='${exec_prefix}/bin'} |
| |
186 : ${sbindir:='${exec_prefix}/sbin'} |
| |
187 : ${libdir:='${exec_prefix}/lib'} |
| |
188 : ${libexecdir:='${exec_prefix}/libexec'} |
| |
189 : ${datarootdir:='${prefix}/share'} |
| |
190 : ${datadir:='${datarootdir}'} |
| |
191 : ${sysconfdir:='${prefix}/etc'} |
| |
192 : ${sharedstatedir:='${prefix}/com'} |
| |
193 : ${localstatedir:='${prefix}/var'} |
| |
194 : ${runstatedir:='${localstatedir}/run'} |
| |
195 : ${includedir:='${prefix}/include'} |
| |
196 : ${infodir:='${datarootdir}/info'} |
| |
197 : ${mandir:='${datarootdir}/man'} |
| |
198 : ${localedir:='${datarootdir}/locale'} |
| |
199 |
| |
200 # check if a config.site exists and load it |
| |
201 if [ -n "$CONFIG_SITE" ]; then |
| |
202 # CONFIG_SITE may contain space separated file names |
| |
203 for cs in $CONFIG_SITE; do |
| |
204 printf "loading defaults from $cs... " |
| |
205 . "$cs" |
| |
206 echo ok |
| |
207 done |
| |
208 elif [ -f "$prefix/share/config.site" ]; then |
| |
209 printf "loading site defaults... " |
| |
210 . "$prefix/share/config.site" |
| |
211 echo ok |
| |
212 elif [ -f "$prefix/etc/config.site" ]; then |
| |
213 printf "loading site defaults... " |
| |
214 . "$prefix/etc/config.site" |
| |
215 echo ok |
| |
216 fi |
| |
217 |
| |
218 |
| |
219 # generate vars.mk |
| |
220 cat > "$TEMP_DIR/vars.mk" << __EOF__ |
| |
221 prefix=$prefix |
| |
222 exec_prefix=$exec_prefix |
| |
223 bindir=$bindir |
| |
224 sbindir=$sbindir |
| |
225 libdir=$libdir |
| |
226 libexecdir=$libexecdir |
| |
227 datarootdir=$datarootdir |
| |
228 datadir=$datadir |
| |
229 sysconfdir=$sysconfdir |
| |
230 sharedstatedir=$sharedstatedir |
| |
231 localstatedir=$localstatedir |
| |
232 runstatedir=$runstatedir |
| |
233 includedir=$includedir |
| |
234 infodir=$infodir |
| |
235 mandir=$mandir |
| |
236 localedir=$localedir |
| |
237 __EOF__ |
| |
238 |
| |
239 # toolchain detection utilities |
| |
240 . make/toolchain.sh |
| |
241 |
| |
242 # |
| |
243 # DEPENDENCIES |
| |
244 # |
| |
245 |
| |
246 # check languages |
| |
247 lang_c= |
| |
248 lang_cpp= |
| |
249 if detect_cpp_compiler ; then |
| |
250 lang_cpp=1 |
| |
251 fi |
| |
252 |
| |
253 # create buffer for make variables required by dependencies |
| |
254 echo > "$TEMP_DIR/make.mk" |
| |
255 |
| |
256 test_pkg_config() |
| |
257 { |
| |
258 if "$PKG_CONFIG" --exists "$1" ; then : |
| |
259 else return 1 ; fi |
| |
260 if [ -z "$2" ] || "$PKG_CONFIG" --atleast-version="$2" "$1" ; then : |
| |
261 else return 1 ; fi |
| |
262 if [ -z "$3" ] || "$PKG_CONFIG" --exact-version="$3" "$1" ; then : |
| |
263 else return 1 ; fi |
| |
264 if [ -z "$4" ] || "$PKG_CONFIG" --max-version="$4" "$1" ; then : |
| |
265 else return 1 ; fi |
| |
266 return 0 |
| |
267 } |
| |
268 |
| |
269 print_check_msg() |
| |
270 { |
| |
271 if [ -z "$1" ]; then |
| |
272 shift |
| |
273 printf "$@" |
| |
274 fi |
| |
275 } |
| |
276 |
| |
277 |
| |
278 # start collecting dependency information |
| |
279 echo > "$TEMP_DIR/flags.mk" |
| |
280 |
| |
281 DEPENDENCIES_FAILED= |
| |
282 ERROR=0 |
| |
283 # unnamed dependencies |
| |
284 TEMP_CFLAGS="$CFLAGS" |
| |
285 TEMP_CXXFLAGS="$CXXFLAGS" |
| |
286 TEMP_LDFLAGS="$LDFLAGS" |
| |
287 while true |
| |
288 do |
| |
289 while true |
| |
290 do |
| |
291 if [ -z "$lang_cpp" ] ; then |
| |
292 ERROR=1 |
| |
293 break |
| |
294 fi |
| |
295 |
| |
296 break |
| |
297 done |
| |
298 break |
| |
299 done |
| |
300 |
| |
301 # add general dependency flags to flags.mk |
| |
302 echo "# general flags" >> "$TEMP_DIR/flags.mk" |
| |
303 if [ -n "${TEMP_CFLAGS}" ] && [ -n "$lang_c" ]; then |
| |
304 echo "CFLAGS += $TEMP_CFLAGS" >> "$TEMP_DIR/flags.mk" |
| |
305 fi |
| |
306 if [ -n "${TEMP_CXXFLAGS}" ] && [ -n "$lang_cpp" ]; then |
| |
307 echo "CXXFLAGS += $TEMP_CXXFLAGS" >> "$TEMP_DIR/flags.mk" |
| |
308 fi |
| |
309 if [ -n "${TEMP_LDFLAGS}" ]; then |
| |
310 echo "LDFLAGS += $TEMP_LDFLAGS" >> "$TEMP_DIR/flags.mk" |
| |
311 fi |
| |
312 |
| |
313 # |
| |
314 # OPTION VALUES |
| |
315 # |
| |
316 |
| |
317 # |
| |
318 # TARGETS |
| |
319 # |
| |
320 |
| |
321 echo >> "$TEMP_DIR/flags.mk" |
| |
322 echo "configuring target: default" |
| |
323 echo "# flags for target default" >> "$TEMP_DIR/flags.mk" |
| |
324 TEMP_CFLAGS= |
| |
325 TEMP_CXXFLAGS= |
| |
326 TEMP_LDFLAGS= |
| |
327 |
| |
328 |
| |
329 # Features |
| |
330 |
| |
331 |
| |
332 if [ -n "${TEMP_CFLAGS}" ] && [ -n "$lang_c" ]; then |
| |
333 echo "CFLAGS += $TEMP_CFLAGS" >> "$TEMP_DIR/flags.mk" |
| |
334 fi |
| |
335 if [ -n "${TEMP_CXXFLAGS}" ] && [ -n "$lang_cpp" ]; then |
| |
336 echo "CXXFLAGS += $TEMP_CXXFLAGS" >> "$TEMP_DIR/flags.mk" |
| |
337 fi |
| |
338 if [ "$BUILD_TYPE" = "debug" ]; then |
| |
339 if [ -n "$lang_c" ]; then |
| |
340 echo 'CFLAGS += ${DEBUG_CC_FLAGS}' >> "$TEMP_DIR/flags.mk" |
| |
341 fi |
| |
342 if [ -n "$lang_cpp" ]; then |
| |
343 echo 'CXXFLAGS += ${DEBUG_CXX_FLAGS}' >> "$TEMP_DIR/flags.mk" |
| |
344 fi |
| |
345 fi |
| |
346 if [ "$BUILD_TYPE" = "release" ]; then |
| |
347 if [ -n "$lang_c" ]; then |
| |
348 echo 'CFLAGS += ${RELEASE_CC_FLAGS}' >> "$TEMP_DIR/flags.mk" |
| |
349 fi |
| |
350 if [ -n "$lang_cpp" ]; then |
| |
351 echo 'CXXFLAGS += ${RELEASE_CXX_FLAGS}' >> "$TEMP_DIR/flags.mk" |
| |
352 fi |
| |
353 fi |
| |
354 if [ -n "${TEMP_LDFLAGS}" ]; then |
| |
355 echo "LDFLAGS += $TEMP_LDFLAGS" >> "$TEMP_DIR/flags.mk" |
| |
356 fi |
| |
357 |
| |
358 |
| |
359 # final result |
| |
360 if [ $ERROR -ne 0 ]; then |
| |
361 echo |
| |
362 echo "Error: Unresolved dependencies" |
| |
363 echo "$DEPENDENCIES_FAILED" |
| |
364 abort_configure |
| |
365 fi |
| |
366 |
| |
367 echo "configure finished" |
| |
368 echo |
| |
369 echo "Build Config:" |
| |
370 echo " PREFIX: $prefix" |
| |
371 echo " TOOLCHAIN: $TOOLCHAIN_NAME" |
| |
372 echo |
| |
373 |
| |
374 # generate the config.mk file |
| |
375 cat > "$TEMP_DIR/config.mk" << __EOF__ |
| |
376 # |
| |
377 # config.mk generated by configure |
| |
378 # |
| |
379 |
| |
380 __EOF__ |
| |
381 write_toolchain_defaults "$TEMP_DIR/toolchain.mk" |
| |
382 cat "$TEMP_DIR/vars.mk" "$TEMP_DIR/toolchain.mk" "$TEMP_DIR/flags.mk" "$TEMP_DIR/make.mk" > config.mk |
| |
383 rm -Rf "$TEMP_DIR" |