Thu, 23 Nov 2023 23:41:40 +0100
fix incorrect documentation of cxBufferEof()
1 #!/bin/sh
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"
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=
35 # custom variables
36 src_dir=`pwd`
37 DOXYGEN=`command -v doxygen`
38 PANDOC=`command -v pandoc`
39 CMAKE=`command -v cmake`
41 # features
43 # clean abort
44 abort_configure()
45 {
46 rm -Rf "$TEMP_DIR"
47 exit 1
48 }
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]
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]
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)
82 __EOF__
83 }
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
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'}
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
153 # Test for availability of pkg-config
154 PKG_CONFIG=`command -v pkg-config`
155 : ${PKG_CONFIG:="false"}
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"}
179 PLATFORM_NAME=`echo "$PLATFORM" | cut -f1 -d' ' -`
180 echo "$PLATFORM_NAME"
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 }
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__
228 # toolchain detection utilities
229 . make/toolchain.sh
231 #
232 # DEPENDENCIES
233 #
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
245 # create buffer for make variables required by dependencies
246 echo > "$TEMP_DIR/make.mk"
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 }
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
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
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
314 __EOF__
315 echo yes
316 return 1
317 done
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
335 __EOF__
336 echo yes
337 return 1
338 done
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
356 __EOF__
357 echo yes
358 return 1
359 done
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=/bin/mkdir -p
373 RMFILE=/bin/rm -f
374 RMDIR=/bin/rm -f -R
375 COPYFILE=/bin/cp -f
376 COPYALL=/bin/cp -f -R
377 SYMLINK=/bin/ln -s
379 __EOF__
380 echo yes
381 return 1
382 done
384 echo no
385 return 0
386 }
387 dependency_error_cmake()
388 {
389 printf "checking for cmake... "
390 # dependency cmake
391 while true
392 do
393 if test -n "$CMAKE" > /dev/null ; then
394 :
395 else
396 break
397 fi
398 echo yes
399 return 1
400 done
402 echo no
403 return 0
404 }
405 dependency_error_doxygen()
406 {
407 printf "checking for doxygen... "
408 # dependency doxygen
409 while true
410 do
411 if test -n "$DOXYGEN" > /dev/null ; then
412 :
413 else
414 break
415 fi
416 echo yes
417 return 1
418 done
420 echo no
421 return 0
422 }
427 # start collecting dependency information
428 echo > "$TEMP_DIR/flags.mk"
430 DEPENDENCIES_FAILED=
431 ERROR=0
432 # unnamed dependencies
433 TEMP_CFLAGS=
434 TEMP_CXXFLAGS=
435 TEMP_LDFLAGS=
436 while true
437 do
438 while true
439 do
441 cat >> "$TEMP_DIR/make.mk" << __EOF__
442 # library version
443 VERSION=3.0.1
444 LIBVERSION=4.0.0
445 LIBVERSION_MAJOR=4
447 # build directory structure !! do not change or override !!
448 build_dir=${src_dir}/build
449 docs_dir=${src_dir}/build/docs
450 dist_dir=${src_dir}/dist
452 __EOF__
453 break
454 done
455 break
456 done
458 # add general dependency flags to flags.mk
459 echo "# general flags" >> "$TEMP_DIR/flags.mk"
460 if [ -n "${TEMP_CFLAGS}" -a -n "$lang_c" ]; then
461 echo "CFLAGS += $TEMP_CFLAGS" >> "$TEMP_DIR/flags.mk"
462 fi
463 if [ -n "${TEMP_CXXFLAGS}" -a -n "$lang_cpp" ]; then
464 echo "CXXFLAGS += $TEMP_CXXFLAGS" >> "$TEMP_DIR/flags.mk"
465 fi
466 if [ -n "${TEMP_LDFLAGS}" ]; then
467 echo "LDFLAGS += $TEMP_LDFLAGS" >> "$TEMP_DIR/flags.mk"
468 fi
470 #
471 # OPTION VALUES
472 #
473 checkopt_with_tests_yes()
474 {
475 VERR=0
476 if dependency_error_cpp ; then
477 VERR=1
478 fi
479 if dependency_error_cmake ; then
480 VERR=1
481 fi
482 if [ $VERR -ne 0 ]; then
483 return 1
484 fi
485 cat >> "$TEMP_DIR/make.mk" << __EOF__
486 WITH_TESTS=yes
488 __EOF__
489 return 0
490 }
491 checkopt_with_tests_no()
492 {
493 VERR=0
494 if [ $VERR -ne 0 ]; then
495 return 1
496 fi
497 return 0
498 }
499 checkopt_with_docs_all()
500 {
501 VERR=0
502 if dependency_error_pandoc ; then
503 VERR=1
504 fi
505 if dependency_error_doxygen ; then
506 VERR=1
507 fi
508 if [ $VERR -ne 0 ]; then
509 return 1
510 fi
511 cat >> "$TEMP_DIR/make.mk" << __EOF__
512 # Documentation
513 WITH_DOCS_API=yes
514 WITH_DOCS_HTML=yes
516 __EOF__
517 return 0
518 }
519 checkopt_with_docs_html()
520 {
521 VERR=0
522 if dependency_error_pandoc ; then
523 VERR=1
524 fi
525 if [ $VERR -ne 0 ]; then
526 return 1
527 fi
528 cat >> "$TEMP_DIR/make.mk" << __EOF__
529 # Documentation
530 WITH_DOCS_HTML=yes
532 __EOF__
533 return 0
534 }
535 checkopt_with_docs_api()
536 {
537 VERR=0
538 if dependency_error_doxygen ; then
539 VERR=1
540 fi
541 if [ $VERR -ne 0 ]; then
542 return 1
543 fi
544 cat >> "$TEMP_DIR/make.mk" << __EOF__
545 # Documentation
546 WITH_DOCS_API=yes
548 __EOF__
549 return 0
550 }
551 checkopt_with_docs_none()
552 {
553 VERR=0
554 if [ $VERR -ne 0 ]; then
555 return 1
556 fi
557 return 0
558 }
560 #
561 # TARGETS
562 #
564 echo >> "$TEMP_DIR/flags.mk"
565 echo "configuring global target"
566 echo "# flags for unnamed target" >> "$TEMP_DIR/flags.mk"
567 TEMP_CFLAGS=
568 TEMP_CXXFLAGS=
569 TEMP_LDFLAGS=
571 if dependency_error_c; then
572 DEPENDENCIES_FAILED="$DEPENDENCIES_FAILED c "
573 ERROR=1
574 fi
575 if dependency_error_file_tools; then
576 DEPENDENCIES_FAILED="$DEPENDENCIES_FAILED file_tools "
577 ERROR=1
578 fi
580 # Features
582 # Option: --with-tests
583 if [ -z "$OPT_WITH_TESTS" ]; then
584 echo "auto-detecting option 'with-tests'"
585 SAVED_ERROR="$ERROR"
586 SAVED_DEPENDENCIES_FAILED="$DEPENDENCIES_FAILED"
587 ERROR=1
588 while true
589 do
590 if checkopt_with_tests_yes ; then
591 echo " with-tests: yes" >> "$TEMP_DIR/options"
592 ERROR=0
593 break
594 fi
595 if checkopt_with_tests_no ; then
596 echo " with-tests: no" >> "$TEMP_DIR/options"
597 ERROR=0
598 break
599 fi
600 break
601 done
602 if [ $ERROR -ne 0 ]; then
603 SAVED_ERROR=1
604 SAVED_DEPENDENCIES_FAILED="option 'with-tests' $SAVED_DEPENDENCIES_FAILED"
605 fi
606 ERROR="$SAVED_ERROR"
607 DEPENDENCIES_FAILED="$SAVED_DEPENDENCIES_FAILED"
608 else
609 echo "checking option with-tests = $OPT_WITH_TESTS"
610 if false; then
611 false
612 elif [ "$OPT_WITH_TESTS" = "yes" ]; then
613 echo " with-tests: $OPT_WITH_TESTS" >> $TEMP_DIR/options
614 if checkopt_with_tests_yes ; then
615 :
616 else
617 ERROR=1
618 DEPENDENCIES_FAILED="option 'with-tests' $DEPENDENCIES_FAILED"
619 fi
620 elif [ "$OPT_WITH_TESTS" = "no" ]; then
621 echo " with-tests: $OPT_WITH_TESTS" >> $TEMP_DIR/options
622 if checkopt_with_tests_no ; then
623 :
624 else
625 ERROR=1
626 DEPENDENCIES_FAILED="option 'with-tests' $DEPENDENCIES_FAILED"
627 fi
628 fi
629 fi
630 # Option: --with-docs
631 if [ -z "$OPT_WITH_DOCS" ]; then
632 echo "auto-detecting option 'with-docs'"
633 SAVED_ERROR="$ERROR"
634 SAVED_DEPENDENCIES_FAILED="$DEPENDENCIES_FAILED"
635 ERROR=1
636 while true
637 do
638 if checkopt_with_docs_all ; then
639 echo " with-docs: all" >> "$TEMP_DIR/options"
640 ERROR=0
641 break
642 fi
643 if checkopt_with_docs_html ; then
644 echo " with-docs: html" >> "$TEMP_DIR/options"
645 ERROR=0
646 break
647 fi
648 if checkopt_with_docs_api ; then
649 echo " with-docs: api" >> "$TEMP_DIR/options"
650 ERROR=0
651 break
652 fi
653 if checkopt_with_docs_none ; then
654 echo " with-docs: none" >> "$TEMP_DIR/options"
655 ERROR=0
656 break
657 fi
658 break
659 done
660 if [ $ERROR -ne 0 ]; then
661 SAVED_ERROR=1
662 SAVED_DEPENDENCIES_FAILED="option 'with-docs' $SAVED_DEPENDENCIES_FAILED"
663 fi
664 ERROR="$SAVED_ERROR"
665 DEPENDENCIES_FAILED="$SAVED_DEPENDENCIES_FAILED"
666 else
667 echo "checking option with-docs = $OPT_WITH_DOCS"
668 if false; then
669 false
670 elif [ "$OPT_WITH_DOCS" = "all" ]; then
671 echo " with-docs: $OPT_WITH_DOCS" >> $TEMP_DIR/options
672 if checkopt_with_docs_all ; then
673 :
674 else
675 ERROR=1
676 DEPENDENCIES_FAILED="option 'with-docs' $DEPENDENCIES_FAILED"
677 fi
678 elif [ "$OPT_WITH_DOCS" = "html" ]; then
679 echo " with-docs: $OPT_WITH_DOCS" >> $TEMP_DIR/options
680 if checkopt_with_docs_html ; then
681 :
682 else
683 ERROR=1
684 DEPENDENCIES_FAILED="option 'with-docs' $DEPENDENCIES_FAILED"
685 fi
686 elif [ "$OPT_WITH_DOCS" = "api" ]; then
687 echo " with-docs: $OPT_WITH_DOCS" >> $TEMP_DIR/options
688 if checkopt_with_docs_api ; then
689 :
690 else
691 ERROR=1
692 DEPENDENCIES_FAILED="option 'with-docs' $DEPENDENCIES_FAILED"
693 fi
694 elif [ "$OPT_WITH_DOCS" = "none" ]; then
695 echo " with-docs: $OPT_WITH_DOCS" >> $TEMP_DIR/options
696 if checkopt_with_docs_none ; then
697 :
698 else
699 ERROR=1
700 DEPENDENCIES_FAILED="option 'with-docs' $DEPENDENCIES_FAILED"
701 fi
702 fi
703 fi
705 if [ -n "${TEMP_CFLAGS}" -a -n "$lang_c" ]; then
706 echo "CFLAGS += $TEMP_CFLAGS" >> "$TEMP_DIR/flags.mk"
707 fi
708 if [ -n "${TEMP_CXXFLAGS}" -a -n "$lang_cpp" ]; then
709 echo "CXXFLAGS += $TEMP_CXXFLAGS" >> "$TEMP_DIR/flags.mk"
710 fi
711 if [ "$BUILD_TYPE" = "debug" ]; then
712 if [ -n "$lang_c" ]; then
713 echo 'CFLAGS += ${DEBUG_CC_FLAGS}' >> "$TEMP_DIR/flags.mk"
714 fi
715 if [ -n "$lang_cpp" ]; then
716 echo 'CXXFLAGS += ${DEBUG_CXX_FLAGS}' >> "$TEMP_DIR/flags.mk"
717 fi
718 fi
719 if [ "$BUILD_TYPE" = "release" ]; then
720 if [ -n "$lang_c" ]; then
721 echo 'CFLAGS += ${RELEASE_CC_FLAGS}' >> "$TEMP_DIR/flags.mk"
722 fi
723 if [ -n "$lang_cpp" ]; then
724 echo 'CXXFLAGS += ${RELEASE_CXX_FLAGS}' >> "$TEMP_DIR/flags.mk"
725 fi
726 fi
727 if [ -n "${TEMP_LDFLAGS}" ]; then
728 echo "LDFLAGS += $TEMP_LDFLAGS" >> "$TEMP_DIR/flags.mk"
729 fi
732 # final result
733 if [ $ERROR -ne 0 ]; then
734 echo
735 echo "Error: Unresolved dependencies"
736 echo "$DEPENDENCIES_FAILED"
737 abort_configure
738 fi
740 echo "configure finished"
741 echo
742 echo "Build Config:"
743 echo " PREFIX: $prefix"
744 echo " TOOLCHAIN: $TOOLCHAIN_NAME"
745 echo "Options:"
746 cat "$TEMP_DIR/options"
747 echo
749 # generate the config.mk file
750 cat > "$TEMP_DIR/config.mk" << __EOF__
751 #
752 # config.mk generated by configure
753 #
755 __EOF__
756 write_toolchain_defaults "$TEMP_DIR/toolchain.mk"
757 cat "$TEMP_DIR/vars.mk" "$TEMP_DIR/toolchain.mk" "$TEMP_DIR/flags.mk" "$TEMP_DIR/make.mk" > config.mk
758 rm -Rf "$TEMP_DIR"