make/configure.vm

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

mercurial