UNIXworkcode

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