configure

changeset 753
24dc84788dee
child 754
4bc7d966c9db
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 src_dir=`pwd`
37 DOXYGEN=`command -v doxygen`
38 PANDOC=`command -v pandoc`
39 CMAKE=`command -v cmake`
40
41 # features
42
43 # clean abort
44 abort_configure()
45 {
46 rm -Rf "$TEMP_DIR"
47 exit 1
48 }
49
50 # help text
51 printhelp()
52 {
53 echo "Usage: $0 [OPTIONS]..."
54 cat << __EOF__
55 Installation directories:
56 --prefix=PREFIX path prefix for architecture-independent files
57 [/usr]
58 --exec-prefix=EPREFIX path prefix for architecture-dependent files
59 [PREFIX]
60
61 --bindir=DIR user executables [EPREFIX/bin]
62 --sbindir=DIR system admin executables [EPREFIX/sbin]
63 --libexecdir=DIR program executables [EPREFIX/libexec]
64 --sysconfdir=DIR system configuration files [PREFIX/etc]
65 --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com]
66 --localstatedir=DIR modifiable single-machine data [PREFIX/var]
67 --runstatedir=DIR run-time variable data [LOCALSTATEDIR/run]
68 --libdir=DIR object code libraries [EPREFIX/lib]
69 --includedir=DIR C header files [PREFIX/include]
70 --datarootdir=DIR read-only arch.-independent data root [PREFIX/share]
71 --datadir=DIR read-only architecture-independent data [DATAROOTDIR]
72 --infodir=DIR info documentation [DATAROOTDIR/info]
73 --mandir=DIR man documentation [DATAROOTDIR/man]
74 --localedir=DIR locale-dependent data [DATAROOTDIR/locale]
75
76 Options:
77 --debug add extra compile flags for debug builds
78 --release add extra compile flags for release builds
79 --with-tests=(yes|no)
80 --with-docs=(all|html|api|none)
81
82 __EOF__
83 }
84
85 #
86 # parse arguments
87 #
88 BUILD_TYPE="default"
89 for ARG in "$@"
90 do
91 case "$ARG" in
92 "--prefix="*) prefix=${ARG#--prefix=} ;;
93 "--exec-prefix="*) exec_prefix=${ARG#--exec-prefix=} ;;
94 "--bindir="*) bindir=${ARG#----bindir=} ;;
95 "--sbindir="*) sbindir=${ARG#--sbindir=} ;;
96 "--libdir="*) libdir=${ARG#--libdir=} ;;
97 "--libexecdir="*) libexecdir=${ARG#--libexecdir=} ;;
98 "--datarootdir="*) datarootdir=${ARG#--datarootdir=} ;;
99 "--datadir="*) datadir=${ARG#--datadir=} ;;
100 "--sysconfdir="*) sysconfdir=${ARG#--sysconfdir=} ;;
101 "--sharedstatedir="*) sharedstatedir=${ARG#--sharedstatedir=} ;;
102 "--localstatedir="*) localstatedir=${ARG#--localstatedir=} ;;
103 "--includedir="*) includedir=${ARG#--includedir=} ;;
104 "--infodir="*) infodir=${ARG#--infodir=} ;;
105 "--mandir"*) mandir=${ARG#--mandir} ;;
106 "--localedir"*) localedir=${ARG#--localedir} ;;
107 "--help"*) printhelp; abort_configure ;;
108 "--debug") BUILD_TYPE="debug" ;;
109 "--release") BUILD_TYPE="release" ;;
110 "--with-tests="*) OPT_WITH_TESTS=${ARG#--with-tests=} ;;
111 "--with-docs="*) OPT_WITH_DOCS=${ARG#--with-docs=} ;;
112 "-"*) echo "unknown option: $ARG"; abort_configure ;;
113 esac
114 done
115
116
117
118 # set defaults for dir variables
119 : ${exec_prefix:="$prefix"}
120 : ${bindir:='${exec_prefix}/bin'}
121 : ${sbindir:='${exec_prefix}/sbin'}
122 : ${libdir:='${exec_prefix}/lib'}
123 : ${libexecdir:='${exec_prefix}/libexec'}
124 : ${datarootdir:='${prefix}/share'}
125 : ${datadir:='${datarootdir}'}
126 : ${sysconfdir:='${prefix}/etc'}
127 : ${sharedstatedir:='${prefix}/com'}
128 : ${localstatedir:='${prefix}/var'}
129 : ${runstatedir:='${localstatedir}/run'}
130 : ${includedir:='${prefix}/include'}
131 : ${infodir:='${datarootdir}/info'}
132 : ${mandir:='${datarootdir}/man'}
133 : ${localedir:='${datarootdir}/locale'}
134
135 # check if a config.site exists and load it
136 if [ -n "$CONFIG_SITE" ]; then
137 # CONFIG_SITE may contain space separated file names
138 for cs in $CONFIG_SITE; do
139 printf "loading defaults from $cs... "
140 . "$cs"
141 echo ok
142 done
143 elif [ -f "$prefix/share/config.site" ]; then
144 printf "loading site defaults... "
145 . "$prefix/share/config.site"
146 echo ok
147 elif [ -f "$prefix/etc/config.site" ]; then
148 printf "loading site defaults... "
149 . "$prefix/etc/config.site"
150 echo ok
151 fi
152
153 # Test for availability of pkg-config
154 PKG_CONFIG=`command -v pkg-config`
155 : ${PKG_CONFIG:="false"}
156
157 # Simple uname based platform detection
158 # $PLATFORM is used for platform dependent dependency selection
159 OS=`uname -s`
160 OS_VERSION=`uname -r`
161 printf "detect platform... "
162 if [ "$OS" = "SunOS" ]; then
163 PLATFORM="solaris sunos unix svr4"
164 fi
165 if [ "$OS" = "Linux" ]; then
166 PLATFORM="linux unix"
167 fi
168 if [ "$OS" = "FreeBSD" ]; then
169 PLATFORM="freebsd bsd unix"
170 fi
171 if [ "$OS" = "Darwin" ]; then
172 PLATFORM="macos osx bsd unix"
173 fi
174 if echo "$OS" | grep -i "MINGW" > /dev/null; then
175 PLATFORM="windows mingw"
176 fi
177 : ${PLATFORM:="unix"}
178
179 PLATFORM_NAME=`echo "$PLATFORM" | cut -f1 -d' ' -`
180 echo "$PLATFORM_NAME"
181
182 isplatform()
183 {
184 for p in $PLATFORM
185 do
186 if [ "$p" = "$1" ]; then
187 return 0
188 fi
189 done
190 return 1
191 }
192 notisplatform()
193 {
194 for p in $PLATFORM
195 do
196 if [ "$p" = "$1" ]; then
197 return 1
198 fi
199 done
200 return 0
201 }
202
203
204 # generate vars.mk
205 cat > "$TEMP_DIR/vars.mk" << __EOF__
206 prefix="$prefix"
207 exec_prefix="$exec_prefix"
208 bindir="$bindir"
209 sbindir="$sbindir"
210 libdir="$libdir"
211 libexecdir="$libexecdir"
212 datarootdir="$datarootdir"
213 datadir="$datadir"
214 sysconfdir="$sysconfdir"
215 sharedstatedir="$sharedstatedir"
216 localstatedir="$localstatedir"
217 runstatedir="$runstatedir"
218 includedir="$includedir"
219 infodir="$infodir"
220 mandir="$mandir"
221 localedir="$localedir"
222 src_dir="$src_dir"
223 DOXYGEN="$DOXYGEN"
224 PANDOC="$PANDOC"
225 CMAKE="$CMAKE"
226 __EOF__
227
228 # toolchain detection utilities
229 . make/toolchain.sh
230
231 #
232 # DEPENDENCIES
233 #
234
235 # check languages
236 lang_c=
237 lang_cpp=
238 if detect_cpp_compiler ; then
239 lang_cpp=1
240 fi
241 if detect_c_compiler ; then
242 lang_c=1
243 fi
244
245 # create buffer for make variables required by dependencies
246 echo > "$TEMP_DIR/make.mk"
247
248 test_pkg_config()
249 {
250 if "$PKG_CONFIG" --exists "$1" ; then :
251 else return 1 ; fi
252 if [ -z "$2" ] || "$PKG_CONFIG" --atleast-version="$2" "$1" ; then :
253 else return 1 ; fi
254 if [ -z "$3" ] || "$PKG_CONFIG" --exact-version="$3" "$1" ; then :
255 else return 1 ; fi
256 if [ -z "$4" ] || "$PKG_CONFIG" --max-version="$4" "$1" ; then :
257 else return 1 ; fi
258 return 0
259 }
260
261 dependency_error_pandoc()
262 {
263 printf "checking for pandoc... "
264 # dependency pandoc
265 while true
266 do
267 if test -n "$PANDOC" > /dev/null ; then
268 :
269 else
270 break
271 fi
272 echo yes
273 return 1
274 done
275
276 echo no
277 return 0
278 }
279 dependency_error_cpp()
280 {
281 printf "checking for cpp... "
282 # dependency cpp
283 while true
284 do
285 if [ -z "$lang_cpp" ] ; then
286 break
287 fi
288 echo yes
289 return 1
290 done
291
292 echo no
293 return 0
294 }
295 dependency_error_c()
296 {
297 printf "checking for c... "
298 # dependency c platform="mingw"
299 while true
300 do
301 if notisplatform "mingw"; then
302 break
303 fi
304 if [ -z "$lang_c" ] ; then
305 break
306 fi
307 cat >> $TEMP_DIR/make.mk << __EOF__
308 # Dependency: c
309 AR=ar
310 ARFLAGS=r
311 STLIB_EXT=.lib
312 SHLIB_EXT=.dll
313
314 __EOF__
315 echo yes
316 return 1
317 done
318
319 # dependency c platform="macos"
320 while true
321 do
322 if notisplatform "macos"; then
323 break
324 fi
325 if [ -z "$lang_c" ] ; then
326 break
327 fi
328 cat >> $TEMP_DIR/make.mk << __EOF__
329 # Dependency: c
330 AR=ar
331 ARFLAGS=r
332 STLIB_EXT=.a
333 SHLIB_EXT=.dylib
334
335 __EOF__
336 echo yes
337 return 1
338 done
339
340 # dependency c platform="unix"
341 while true
342 do
343 if notisplatform "unix"; then
344 break
345 fi
346 if [ -z "$lang_c" ] ; then
347 break
348 fi
349 cat >> $TEMP_DIR/make.mk << __EOF__
350 # Dependency: c
351 AR=ar
352 ARFLAGS=r
353 STLIB_EXT=.a
354 SHLIB_EXT=.so
355
356 __EOF__
357 echo yes
358 return 1
359 done
360
361 echo no
362 return 0
363 }
364 dependency_error_file_tools()
365 {
366 printf "checking for file-tools... "
367 # dependency file-tools
368 while true
369 do
370 cat >> $TEMP_DIR/make.mk << __EOF__
371 # Dependency: file-tools
372 MKDIR=mkdir -p
373 RMDIR=rm -f -R
374 COPYFILE=cp
375 COPYALL=cp -R
376
377 __EOF__
378 echo yes
379 return 1
380 done
381
382 echo no
383 return 0
384 }
385 dependency_error_cmake()
386 {
387 printf "checking for cmake... "
388 # dependency cmake
389 while true
390 do
391 if test -n "$CMAKE" > /dev/null ; then
392 :
393 else
394 break
395 fi
396 echo yes
397 return 1
398 done
399
400 echo no
401 return 0
402 }
403 dependency_error_doxygen()
404 {
405 printf "checking for doxygen... "
406 # dependency doxygen
407 while true
408 do
409 if test -n "$DOXYGEN" > /dev/null ; then
410 :
411 else
412 break
413 fi
414 echo yes
415 return 1
416 done
417
418 echo no
419 return 0
420 }
421
422
423
424
425 # start collecting dependency information
426 echo > "$TEMP_DIR/flags.mk"
427
428 DEPENDENCIES_FAILED=
429 ERROR=0
430 # unnamed dependencies
431 TEMP_CFLAGS=
432 TEMP_CXXFLAGS=
433 TEMP_LDFLAGS=
434 while true
435 do
436 while true
437 do
438
439 cat >> "$TEMP_DIR/make.mk" << __EOF__
440 # library version
441 VERSION="3.0.0"
442
443 # build directory structure !! do not change or override !!
444 BUILD_DIR=${src_dir}/build
445 DOCS_DIR=${src_dir}/build/docs
446 DIST_DIR=${src_dir}/dist
447
448 __EOF__
449 break
450 done
451 break
452 done
453
454 # add general dependency flags to flags.mk
455 echo "# general flags" >> "$TEMP_DIR/flags.mk"
456 if [ -n "${TEMP_CFLAGS}" -a -n "$lang_c" ]; then
457 echo "CFLAGS += $TEMP_CFLAGS" >> "$TEMP_DIR/flags.mk"
458 fi
459 if [ -n "${TEMP_CXXFLAGS}" -a -n "$lang_cpp" ]; then
460 echo "CXXFLAGS += $TEMP_CXXFLAGS" >> "$TEMP_DIR/flags.mk"
461 fi
462 if [ -n "${TEMP_LDFLAGS}" ]; then
463 echo "LDFLAGS += $TEMP_LDFLAGS" >> "$TEMP_DIR/flags.mk"
464 fi
465
466 #
467 # OPTION VALUES
468 #
469 checkopt_with_tests_yes()
470 {
471 VERR=0
472 if dependency_error_cpp ; then
473 VERR=1
474 fi
475 if dependency_error_cmake ; then
476 VERR=1
477 fi
478 if [ $VERR -ne 0 ]; then
479 return 1
480 fi
481 cat >> "$TEMP_DIR/make.mk" << __EOF__
482 WITH_TESTS=yes
483
484 __EOF__
485 return 0
486 }
487 checkopt_with_tests_no()
488 {
489 VERR=0
490 if [ $VERR -ne 0 ]; then
491 return 1
492 fi
493 return 0
494 }
495 checkopt_with_docs_all()
496 {
497 VERR=0
498 if dependency_error_pandoc ; then
499 VERR=1
500 fi
501 if dependency_error_doxygen ; then
502 VERR=1
503 fi
504 if [ $VERR -ne 0 ]; then
505 return 1
506 fi
507 cat >> "$TEMP_DIR/make.mk" << __EOF__
508 # Documentation
509 WITH_DOCS_API=yes
510 WITH_DOCS_HTML=yes
511
512 __EOF__
513 return 0
514 }
515 checkopt_with_docs_html()
516 {
517 VERR=0
518 if dependency_error_pandoc ; then
519 VERR=1
520 fi
521 if [ $VERR -ne 0 ]; then
522 return 1
523 fi
524 cat >> "$TEMP_DIR/make.mk" << __EOF__
525 # Documentation
526 WITH_DOCS_HTML=yes
527
528 __EOF__
529 return 0
530 }
531 checkopt_with_docs_api()
532 {
533 VERR=0
534 if dependency_error_doxygen ; then
535 VERR=1
536 fi
537 if [ $VERR -ne 0 ]; then
538 return 1
539 fi
540 cat >> "$TEMP_DIR/make.mk" << __EOF__
541 # Documentation
542 WITH_DOCS_API=yes
543
544 __EOF__
545 return 0
546 }
547 checkopt_with_docs_none()
548 {
549 VERR=0
550 if [ $VERR -ne 0 ]; then
551 return 1
552 fi
553 return 0
554 }
555
556 #
557 # TARGETS
558 #
559
560 echo >> "$TEMP_DIR/flags.mk"
561 echo "configuring global target"
562 echo "# flags for unnamed target" >> "$TEMP_DIR/flags.mk"
563 TEMP_CFLAGS=
564 TEMP_CXXFLAGS=
565 TEMP_LDFLAGS=
566
567 if dependency_error_c; then
568 DEPENDENCIES_FAILED="$DEPENDENCIES_FAILED c "
569 ERROR=1
570 fi
571 if dependency_error_file_tools; then
572 DEPENDENCIES_FAILED="$DEPENDENCIES_FAILED file_tools "
573 ERROR=1
574 fi
575
576 # Features
577
578 # Option: --with-tests
579 if [ -z "$OPT_WITH_TESTS" ]; then
580 echo "auto-detecting option 'with-tests'"
581 SAVED_ERROR="$ERROR"
582 SAVED_DEPENDENCIES_FAILED="$DEPENDENCIES_FAILED"
583 ERROR=1
584 while true
585 do
586 if checkopt_with_tests_yes ; then
587 echo " with-tests: yes" >> "$TEMP_DIR/options"
588 ERROR=0
589 break
590 fi
591 if checkopt_with_tests_no ; then
592 echo " with-tests: no" >> "$TEMP_DIR/options"
593 ERROR=0
594 break
595 fi
596 break
597 done
598 if [ $ERROR -ne 0 ]; then
599 SAVED_ERROR=1
600 SAVED_DEPENDENCIES_FAILED="option 'with-tests' $SAVED_DEPENDENCIES_FAILED"
601 fi
602 ERROR="$SAVED_ERROR"
603 DEPENDENCIES_FAILED="$SAVED_DEPENDENCIES_FAILED"
604 else
605 echo "checking option with-tests = $OPT_WITH_TESTS"
606 if false; then
607 false
608 elif [ "$OPT_WITH_TESTS" = "yes" ]; then
609 echo " with-tests: $OPT_WITH_TESTS" >> $TEMP_DIR/options
610 if checkopt_with_tests_yes ; then
611 :
612 else
613 ERROR=1
614 DEPENDENCIES_FAILED="option 'with-tests' $DEPENDENCIES_FAILED"
615 fi
616 elif [ "$OPT_WITH_TESTS" = "no" ]; then
617 echo " with-tests: $OPT_WITH_TESTS" >> $TEMP_DIR/options
618 if checkopt_with_tests_no ; then
619 :
620 else
621 ERROR=1
622 DEPENDENCIES_FAILED="option 'with-tests' $DEPENDENCIES_FAILED"
623 fi
624 fi
625 fi
626 # Option: --with-docs
627 if [ -z "$OPT_WITH_DOCS" ]; then
628 echo "auto-detecting option 'with-docs'"
629 SAVED_ERROR="$ERROR"
630 SAVED_DEPENDENCIES_FAILED="$DEPENDENCIES_FAILED"
631 ERROR=1
632 while true
633 do
634 if checkopt_with_docs_all ; then
635 echo " with-docs: all" >> "$TEMP_DIR/options"
636 ERROR=0
637 break
638 fi
639 if checkopt_with_docs_html ; then
640 echo " with-docs: html" >> "$TEMP_DIR/options"
641 ERROR=0
642 break
643 fi
644 if checkopt_with_docs_api ; then
645 echo " with-docs: api" >> "$TEMP_DIR/options"
646 ERROR=0
647 break
648 fi
649 if checkopt_with_docs_none ; then
650 echo " with-docs: none" >> "$TEMP_DIR/options"
651 ERROR=0
652 break
653 fi
654 break
655 done
656 if [ $ERROR -ne 0 ]; then
657 SAVED_ERROR=1
658 SAVED_DEPENDENCIES_FAILED="option 'with-docs' $SAVED_DEPENDENCIES_FAILED"
659 fi
660 ERROR="$SAVED_ERROR"
661 DEPENDENCIES_FAILED="$SAVED_DEPENDENCIES_FAILED"
662 else
663 echo "checking option with-docs = $OPT_WITH_DOCS"
664 if false; then
665 false
666 elif [ "$OPT_WITH_DOCS" = "all" ]; then
667 echo " with-docs: $OPT_WITH_DOCS" >> $TEMP_DIR/options
668 if checkopt_with_docs_all ; then
669 :
670 else
671 ERROR=1
672 DEPENDENCIES_FAILED="option 'with-docs' $DEPENDENCIES_FAILED"
673 fi
674 elif [ "$OPT_WITH_DOCS" = "html" ]; then
675 echo " with-docs: $OPT_WITH_DOCS" >> $TEMP_DIR/options
676 if checkopt_with_docs_html ; then
677 :
678 else
679 ERROR=1
680 DEPENDENCIES_FAILED="option 'with-docs' $DEPENDENCIES_FAILED"
681 fi
682 elif [ "$OPT_WITH_DOCS" = "api" ]; then
683 echo " with-docs: $OPT_WITH_DOCS" >> $TEMP_DIR/options
684 if checkopt_with_docs_api ; then
685 :
686 else
687 ERROR=1
688 DEPENDENCIES_FAILED="option 'with-docs' $DEPENDENCIES_FAILED"
689 fi
690 elif [ "$OPT_WITH_DOCS" = "none" ]; then
691 echo " with-docs: $OPT_WITH_DOCS" >> $TEMP_DIR/options
692 if checkopt_with_docs_none ; then
693 :
694 else
695 ERROR=1
696 DEPENDENCIES_FAILED="option 'with-docs' $DEPENDENCIES_FAILED"
697 fi
698 fi
699 fi
700
701 if [ -n "${TEMP_CFLAGS}" -a -n "$lang_c" ]; then
702 echo "CFLAGS += $TEMP_CFLAGS" >> "$TEMP_DIR/flags.mk"
703 fi
704 if [ -n "${TEMP_CXXFLAGS}" -a -n "$lang_cpp" ]; then
705 echo "CXXFLAGS += $TEMP_CXXFLAGS" >> "$TEMP_DIR/flags.mk"
706 fi
707 if [ "$BUILD_TYPE" = "debug" ]; then
708 if [ -n "$lang_c" ]; then
709 echo 'CFLAGS += ${DEBUG_CC_FLAGS}' >> "$TEMP_DIR/flags.mk"
710 fi
711 if [ -n "$lang_cpp" ]; then
712 echo 'CXXFLAGS += ${DEBUG_CXX_FLAGS}' >> "$TEMP_DIR/flags.mk"
713 fi
714 fi
715 if [ "$BUILD_TYPE" = "release" ]; then
716 if [ -n "$lang_c" ]; then
717 echo 'CFLAGS += ${RELEASE_CC_FLAGS}' >> "$TEMP_DIR/flags.mk"
718 fi
719 if [ -n "$lang_cpp" ]; then
720 echo 'CXXFLAGS += ${RELEASE_CXX_FLAGS}' >> "$TEMP_DIR/flags.mk"
721 fi
722 fi
723 if [ -n "${TEMP_LDFLAGS}" ]; then
724 echo "LDFLAGS += $TEMP_LDFLAGS" >> "$TEMP_DIR/flags.mk"
725 fi
726
727
728 # final result
729 if [ $ERROR -ne 0 ]; then
730 echo
731 echo "Error: Unresolved dependencies"
732 echo "$DEPENDENCIES_FAILED"
733 abort_configure
734 fi
735
736 echo "configure finished"
737 echo
738 echo "Build Config:"
739 echo " PREFIX: $prefix"
740 echo " TOOLCHAIN: $TOOLCHAIN_NAME"
741 echo "Options:"
742 cat "$TEMP_DIR/options"
743 echo
744
745 # generate the config.mk file
746 cat > "$TEMP_DIR/config.mk" << __EOF__
747 #
748 # config.mk generated by configure
749 #
750
751 __EOF__
752 write_toolchain_defaults "$TEMP_DIR/toolchain.mk"
753 cat "$TEMP_DIR/vars.mk" "$TEMP_DIR/toolchain.mk" "$TEMP_DIR/flags.mk" "$TEMP_DIR/make.mk" > config.mk
754 rm -Rf "$TEMP_DIR"
755
756

mercurial