make/configure.vm

changeset 68
ae763178ee1e
child 74
ed9a5ffd1f13
equal deleted inserted replaced
67:767fe7a007f7 68:ae763178ee1e
1 #!/bin/sh
2
3 # create temporary directory
4 TEMP_DIR=".tmp-`uname -n`"
5 rm -Rf "$TEMP_DIR"
6 if mkdir -p "$TEMP_DIR"; then
7 :
8 else
9 echo "Cannot create tmp dir $TEMP_DIR"
10 echo "Abort"
11 exit 1
12 fi
13 touch "$TEMP_DIR/options"
14 touch "$TEMP_DIR/features"
15
16 # define standard variables
17 PREFIX=/usr
18 EPREFIX=
19 BINDIR=
20 SBINDIR=
21 LIBDIR=
22 LIBEXECDIR=
23 DATADIR=
24 SYSCONFDIR=
25 SHAREDSTATEDIR=
26 LOCALSTATEDIR=
27 INCLUDEDIR=
28 INFODIR=
29 MANDIR=
30
31 # custom variables
32 #foreach( $var in $vars )
33 #if( $var.exec )
34 ${var.varName}=`${var.value}`
35 #else
36 ${var.varName}=${var.value}
37 #end
38 #end
39
40 # features
41 #foreach( $feature in $features )
42 #if( ${feature.isDefault()} )
43 ${feature.getVarName()}=auto
44 #end
45 #end
46
47 # clean abort
48 abort_configure()
49 {
50 rm -Rf "$TEMP_DIR"
51 exit 1
52 }
53
54 # help text
55 printhelp()
56 {
57 echo "Usage: $0 [OPTIONS]..."
58 cat << __EOF__
59 Installation directories:
60 --prefix=PREFIX path prefix for architecture-independent files
61 [/usr]
62 --exec-prefix=EPREFIX path prefix for architecture-dependent files
63 [PREFIX]
64
65 --bindir=DIR user executables [EPREFIX/bin]
66 --sbindir=DIR system admin executables [EPREFIX/sbin]
67 --libexecdir=DIR program executables [EPREFIX/libexec]
68 --sysconfdir=DIR system configuration files [PREFIX/etc]
69 --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com]
70 --localstatedir=DIR modifiable single-machine data [PREFIX/var]
71 --libdir=DIR object code libraries [EPREFIX/lib]
72 --includedir=DIR C header files [PREFIX/include]
73 --datarootdir=DIR read-only arch.-independent data root [PREFIX/share]
74 --datadir=DIR read-only architecture-independent data [DATAROOTDIR]
75 --infodir=DIR info documentation [DATAROOTDIR/info]
76 --mandir=DIR man documentation [DATAROOTDIR/man]
77
78 #if( $options.size() > 0 )
79 Options:
80 --debug add extra compile flags for debug builds
81 --release add extra compile flags for release builds
82 #foreach( $opt in $options )
83 --${opt.getArgument()}=${opt.getValuesString()}
84 #end
85
86 #end
87 #if( $features.size() > 0 )
88 Optional Features:
89 #foreach( $feature in $features )
90 #if( $feature.default )
91 --disable-${feature.arg}
92 #else
93 --enable-${feature.arg}
94 #end
95 #end
96
97 #end
98 __EOF__
99 }
100
101 #
102 # parse arguments
103 #
104 BUILD_TYPE="default"
105 #set( $D = '$' )
106 for ARG in "$@"
107 do
108 case "$ARG" in
109 "--prefix="*) PREFIX=${D}{ARG#--prefix=} ;;
110 "--exec-prefix="*) EPREFIX=${D}{ARG#--exec-prefix=} ;;
111 "--bindir="*) BINDIR=${D}{ARG#----bindir=} ;;
112 "--sbindir="*) SBINDIR=${D}{ARG#--sbindir=} ;;
113 "--libdir="*) LIBDIR=${D}{ARG#--libdir=} ;;
114 "--libexecdir="*) LIBEXECDIR=${D}{ARG#--libexecdir=} ;;
115 "--datadir="*) DATADIR=${D}{ARG#--datadir=} ;;
116 "--sysconfdir="*) SYSCONFDIR=${D}{ARG#--sysconfdir=} ;;
117 "--sharedstatedir="*) SHAREDSTATEDIR=${D}{ARG#--sharedstatedir=} ;;
118 "--localstatedir="*) LOCALSTATEDIR=${D}{ARG#--localstatedir=} ;;
119 "--includedir="*) INCLUDEDIR=${D}{ARG#--includedir=} ;;
120 "--infodir="*) INFODIR=${D}{ARG#--infodir=} ;;
121 "--mandir"*) MANDIR=${D}{ARG#--mandir} ;;
122 "--help"*) printhelp; abort_configure ;;
123 "--debug") BUILD_TYPE="debug" ;;
124 "--release") BUILD_TYPE="release" ;;
125 #foreach( $opt in $options )
126 "--${opt.getArgument()}="*) ${opt.getVarName()}=${D}{ARG#--${opt.getArgument()}=} ;;
127 #end
128 #foreach( $feature in $features )
129 "--enable-${feature.arg}") ${feature.getVarName()}=on ;;
130 "--disable-${feature.arg}") unset ${feature.getVarName()} ;;
131 #end
132 "-"*) echo "unknown option: $ARG"; abort_configure ;;
133 esac
134 done
135
136 ## Begin unparsed content. **
137 #[[
138 # set dir variables
139 : ${EPREFIX:="$PREFIX"}
140 : ${BINDIR:="$EPREFIX/bin"}
141 : ${SBINDIR:="$EPREFIX/sbin"}
142 : ${LIBDIR:="$EPREFIX/lib"}
143 : ${LIBEXECDIR:="$EPREFIX/libexec"}
144 : ${DATADIR:="$PREFIX/share"}
145 : ${SYSCONFDIR:="$PREFIX/etc"}
146 : ${SHAREDSTATEDIR:="$PREFIX/com"}
147 : ${LOCALSTATEDIR:="$PREFIX/var"}
148 : ${INCLUDEDIR:="$PREFIX/include"}
149 : ${INFODIR:="$PREFIX/info"}
150 : ${MANDIR:="$PREFIX/man"}
151
152 # Test for availability of pkg-config
153 PKG_CONFIG=`command -v pkg-config`
154 : ${PKG_CONFIG:="false"}
155
156 # Simple uname based platform detection
157 # $PLATFORM is used for platform dependent dependency selection
158 OS=`uname -s`
159 OS_VERSION=`uname -r`
160 printf "detect platform... "
161 if [ "$OS" = "SunOS" ]; then
162 PLATFORM="solaris sunos unix svr4"
163 fi
164 if [ "$OS" = "Linux" ]; then
165 PLATFORM="linux unix"
166 fi
167 if [ "$OS" = "FreeBSD" ]; then
168 PLATFORM="freebsd bsd unix"
169 fi
170 if [ "$OS" = "Darwin" ]; then
171 PLATFORM="macos osx bsd unix"
172 fi
173 if echo "$OS" | grep -i "MINGW" > /dev/null; then
174 PLATFORM="windows mingw"
175 fi
176 : ${PLATFORM:="unix"}
177
178 PLATFORM_NAME=`echo "$PLATFORM" | cut -f1 -d' ' -`
179 echo "$PLATFORM_NAME"
180
181 isplatform()
182 {
183 for p in $PLATFORM
184 do
185 if [ "$p" = "$1" ]; then
186 return 0
187 fi
188 done
189 return 1
190 }
191 notisplatform()
192 {
193 for p in $PLATFORM
194 do
195 if [ "$p" = "$1" ]; then
196 return 1
197 fi
198 done
199 return 0
200 }
201 ]]#
202 ## End of unparsed content **
203
204 # generate vars.mk
205 cat > "$TEMP_DIR/vars.mk" << __EOF__
206 PREFIX=$PREFIX
207 EPREFIX=$EPREFIX
208 BINDIR=$BINDIR
209 SBINDIR=$SBINDIR
210 LIBDIR=$LIBDIR
211 LIBEXECDIR=$LIBEXECDIR
212 DATADIR=$DATADIR
213 SYSCONFDIR=$SYSCONFDIR
214 SHAREDSTATEDIR=$SHAREDSTATEDIR
215 LOCALSTATEDIR=$LOCALSTATEDIR
216 INCLUDEDIR=$INCLUDEDIR
217 INFODIR=$INFODIR
218 MANDIR=$MANDIR
219 #foreach( $var in $vars )
220 ${var.varName}=$${var.varName}
221 #end
222 __EOF__
223 sort -u -o "$TEMP_DIR/vars.mk" "$TEMP_DIR/vars.mk"
224
225
226 # toolchain detection utilities
227 . make/toolchain.sh
228
229 #
230 # DEPENDENCIES
231 #
232
233 # check languages
234 lang_c=
235 lang_cpp=
236 #foreach( $lang in $languages )
237 if detect_${lang}_compiler ; then
238 lang_${lang}=1
239 fi
240 #end
241
242 # create buffer for make variables required by dependencies
243 echo > "$TEMP_DIR/make.mk"
244
245 test_pkg_config()
246 {
247 if "$PKG_CONFIG" --exists "$1" ; then :
248 else return 1 ; fi
249 if [ -z "$2" ] || "$PKG_CONFIG" --atleast-version="$2" "$1" ; then :
250 else return 1 ; fi
251 if [ -z "$3" ] || "$PKG_CONFIG" --exact-version="$3" "$1" ; then :
252 else return 1 ; fi
253 if [ -z "$4" ] || "$PKG_CONFIG" --max-version="$4" "$1" ; then :
254 else return 1 ; fi
255 return 0
256 }
257
258 #foreach( $dependency in $namedDependencies )
259 dependency_error_${dependency.name}()
260 {
261 printf "checking for ${dependency.name}... "
262 #foreach( $sub in $dependency.getSubdependencies() )
263 # dependency $sub.getFullName()
264 while true
265 do
266 #if( $sub.platform )
267 if notisplatform "${sub.platform}"; then
268 break
269 fi
270 #end
271 #foreach( $np in $sub.getNotList() )
272 if isplatform "${np}"; then
273 break
274 fi
275 #end
276 #foreach( $lang in $sub.lang )
277 if [ -z "$lang_${lang}" ] ; then
278 break
279 fi
280 #end
281 #if( $sub.pkgconfig.size() > 0 )
282 if [ -z "$PKG_CONFIG" ]; then
283 break
284 fi
285 #end
286 #foreach( $test in $sub.tests )
287 if $test > /dev/null ; then
288 :
289 else
290 break
291 fi
292 #end
293 #foreach( $pkg in $sub.pkgconfig )
294 if test_pkg_config "$pkg.name" "$pkg.atleast" "$pkg.exact" "$pkg.max" ; then
295 TEMP_CFLAGS="$TEMP_CFLAGS `"$PKG_CONFIG" --cflags $pkg.name`"
296 TEMP_LDFLAGS="$TEMP_LDFLAGS `"$PKG_CONFIG" --libs $pkg.name`"
297 else
298 break
299 fi
300 #end
301 #foreach( $flags in $sub.flags )
302 #if( $flags.exec )
303 if tmp_flags=`$flags.value` ; then
304 TEMP_$flags.varName="$TEMP_$flags.varName $tmp_flags"
305 else
306 break
307 fi
308 #else
309 TEMP_$flags.varName="$TEMP_$flags.varName $flags.value"
310 #end
311 #end
312 #if ( $sub.make.length() > 0 )
313 cat >> $TEMP_DIR/make.mk << __EOF__
314 # Dependency: $dependency.name
315 $sub.make
316 __EOF__
317 #end
318 echo yes
319 return 1
320 done
321
322 #end
323 echo no
324 return 0
325 }
326 #end
327
328
329
330
331 # start collecting dependency information
332 echo > "$TEMP_DIR/flags.mk"
333
334 DEPENDENCIES_FAILED=
335 ERROR=0
336 #if( $dependencies.size() > 0 )
337 # unnamed dependencies
338 TEMP_CFLAGS=
339 TEMP_CXXFLAGS=
340 TEMP_LDFLAGS=
341 #foreach( $dependency in $dependencies )
342 while true
343 do
344 #if( $dependency.platform )
345 if notisplatform "${dependency.platform}"; then
346 break
347 fi
348 #end
349 #foreach( $np in $dependency.getNotList() )
350 if isplatform "${np}"; then
351 break
352 fi
353 #end
354 while true
355 do
356 #foreach( $lang in $dependency.lang )
357 if [ -z "$lang_${lang}" ] ; then
358 ERROR=1
359 break
360 fi
361 #end
362 #if( $dependency.pkgconfig.size() > 0 )
363 if [ -z "$PKG_CONFIG" ]; then
364 ERROR=1
365 break
366 fi
367 #end
368 #foreach( $pkg in $dependency.pkgconfig )
369 printf "checking for pkg-config package $pkg.name... "
370 if test_pkg_config "$pkg.name" "$pkg.atleast" "$pkg.exact" "$pkg.max" ; then
371 echo yes
372 TEMP_CFLAGS="$TEMP_CFLAGS `"$PKG_CONFIG" --cflags $pkg.name`"
373 TEMP_LDFLAGS="$TEMP_LDFLAGS `"$PKG_CONFIG" --libs $pkg.name`"
374 else
375 echo no
376 ERROR=1
377 break
378 fi
379 #end
380
381 #foreach( $flags in $dependency.flags )
382 #if( $flags.exec )
383 $flags.value > /dev/null
384 if tmp_flags=`$flags.value` ; then
385 TEMP_$flags.varName="$TEMP_$flags.varName $tmp_flags"
386 else
387 ERROR=1
388 break
389 fi
390 #else
391 TEMP_$flags.varName="$TEMP_$flags.varName $flags.value"
392 #end
393 #end
394 #if ( $dependency.make.length() > 0 )
395 cat >> "$TEMP_DIR/make.mk" << __EOF__
396 $dependency.make
397 __EOF__
398 #end
399 break
400 done
401 break
402 done
403 #end
404
405 # add general dependency flags to flags.mk
406 echo "# general flags" >> "$TEMP_DIR/flags.mk"
407 if [ -n "${TEMP_CFLAGS}" ]; then
408 echo "CFLAGS += $TEMP_CFLAGS" >> "$TEMP_DIR/flags.mk"
409 fi
410 if [ -n "${TEMP_CXXFLAGS}" ]; then
411 echo "CXXFLAGS += $TEMP_CXXFLAGS" >> "$TEMP_DIR/flags.mk"
412 fi
413 if [ -n "${TEMP_LDFLAGS}" ]; then
414 echo "LDFLAGS += $TEMP_LDFLAGS" >> "$TEMP_DIR/flags.mk"
415 fi
416 #end
417
418 #
419 # OPTION VALUES
420 #
421 #foreach( $opt in $options )
422 #foreach( $val in $opt.values )
423 ${val.func}()
424 {
425 VERR=0
426 #foreach( $dep in $val.dependencies )
427 if dependency_error_$dep ; then
428 VERR=1
429 fi
430 #end
431 if [ $VERR -ne 0 ]; then
432 return 1
433 fi
434 #foreach( $def in $val.defines )
435 TEMP_CFLAGS="$TEMP_CFLAGS ${def.toFlags()}"
436 TEMP_CXXFLAGS="$TEMP_CXXFLAGS ${def.toFlags()}"
437 #end
438 #if( $val.hasMake() )
439 cat >> "$TEMP_DIR/make.mk" << __EOF__
440 $val.make
441 __EOF__
442 #end
443 return 0
444 }
445 #end
446 #end
447
448 #
449 # TARGETS
450 #
451
452 #foreach( $target in $targets )
453 echo >> "$TEMP_DIR/flags.mk"
454 #if ( $target.name )
455 # Target: $target.name
456 echo "# flags for target $target.name" >> "$TEMP_DIR/flags.mk"
457 #else
458 # Target
459 echo "# flags for unnamed target" >> "$TEMP_DIR/flags.mk"
460 #end
461 TEMP_CFLAGS=
462 TEMP_CXXFLAGS=
463 TEMP_LDFLAGS=
464
465 #foreach( $dependency in $target.dependencies )
466 if dependency_error_$dependency; then
467 DEPENDENCIES_FAILED="$DEPENDENCIES_FAILED ${dependency} "
468 ERROR=1
469 fi
470 #end
471
472 # Features
473 #foreach( $feature in $target.features )
474 if [ -n "$${feature.getVarName()}" ]; then
475 #foreach( $dependency in $feature.dependencies )
476 # check dependency
477 if dependency_error_$dependency ; then
478 # "auto" features can fail and are just disabled in this case
479 if [ "$${feature.getVarName()}" = "auto" ]; then
480 DISABLE_${feature.getVarName()}=1
481 else
482 DEPENDENCIES_FAILED="$DEPENDENCIES_FAILED ${dependency} "
483 ERROR=1
484 fi
485 fi
486 #end
487 if [ -n "$DISABLE_${feature.getVarName()}" ]; then
488 unset ${feature.getVarName()}
489 fi
490 fi
491 #end
492
493 #foreach( $opt in $target.options )
494 # Option: --${opt.argument}
495 if [ -z ${D}${opt.getVarName()} ]; then
496 SAVED_ERROR="$ERROR"
497 SAVED_DEPENDENCIES_FAILED="$DEPENDENCIES_FAILED"
498 ERROR=1
499 while true
500 do
501 #foreach( $optdef in $opt.defaults )
502 #if( $optdef.platform )
503 if isplatform "$optdef.platform"; then
504 #end
505 if $optdef.func ; then
506 echo " ${opt.argument}: ${optdef.valueName}" >> "$TEMP_DIR/options"
507 ERROR=0
508 break
509 fi
510 #if( $optdef.platform )
511 fi
512 #end
513 #end
514 break
515 done
516 if [ $ERROR -ne 0 ]; then
517 SAVED_ERROR=1
518 fi
519 ERROR="$SAVED_ERROR"
520 DEPENDENCIES_FAILED="$SAVED_DEPENDENCIES_FAILED"
521 else
522 if false; then
523 false
524 #foreach( $optval in $opt.values )
525 elif [ "${D}${opt.getVarName()}" = "${optval.value}" ]; then
526 echo " ${opt.argument}: ${D}${opt.getVarName()}" >> $TEMP_DIR/options
527 if $optval.func ; then
528 :
529 else
530 ERROR=1
531 fi
532 #end
533 fi
534 fi
535 #end
536
537 if [ -n "${TEMP_CFLAGS}" ]; then
538 echo "${target.getCFlags()} += $TEMP_CFLAGS" >> "$TEMP_DIR/flags.mk"
539 fi
540 if [ -n "${TEMP_CXXFLAGS}" ]; then
541 echo "${target.getCXXFlags()} += $TEMP_CXXFLAGS" >> "$TEMP_DIR/flags.mk"
542 fi
543 if [ "$BUILD_TYPE" = "debug" ]; then
544 echo '${target.getCFlags()} += ${DEBUG_CC_FLAGS}' >> "$TEMP_DIR/flags.mk"
545 echo '${target.getCXXFlags()} += ${DEBUG_CXX_FLAGS}' >> "$TEMP_DIR/flags.mk"
546 fi
547 if [ "$BUILD_TYPE" = "release" ]; then
548 echo '${target.getCFlags()} += ${RELEASE_CC_FLAGS}' >> "$TEMP_DIR/flags.mk"
549 echo '${target.getCXXFlags()} += ${RELEASE_CXX_FLAGS}' >> "$TEMP_DIR/flags.mk"
550 fi
551 if [ -n "${TEMP_LDFLAGS}" ]; then
552 echo "${target.getLDFlags()} += $TEMP_LDFLAGS" >> "$TEMP_DIR/flags.mk"
553 fi
554
555 #end
556
557 # final result
558 if [ $ERROR -ne 0 ]; then
559 echo
560 echo "Error: Unresolved dependencies"
561 echo "$DEPENDENCIES_FAILED"
562 abort_configure
563 fi
564
565 echo "configure finished"
566 echo
567 echo "Build Config:"
568 echo " PREFIX: $PREFIX"
569 echo " TOOLCHAIN: $TOOLCHAIN_NAME"
570 #if ( $options.size() > 0 )
571 echo "Options:"
572 cat "$TEMP_DIR/options"
573 #end
574 #if ( $features.size() > 0 )
575 echo "Features:"
576 #foreach( $feature in $features )
577 if [ -n "$${feature.getVarName()}" ]; then
578 echo " $feature.name: on"
579 else
580 echo " $feature.name: off"
581 fi
582 #end
583 #end
584 echo
585
586 # generate the config.mk file
587 cat > "$TEMP_DIR/config.mk" << __EOF__
588 #
589 # config.mk generated by configure
590 #
591
592 __EOF__
593 write_toolchain_defaults "$TEMP_DIR/toolchain.mk"
594 cat "$TEMP_DIR/vars.mk" "$TEMP_DIR/toolchain.mk" "$TEMP_DIR/flags.mk" "$TEMP_DIR/make.mk" > config.mk
595 rm -Rf "$TEMP_DIR"
596
597

mercurial