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