configure (14499B)
1 #!/bin/sh 2 3 cd `dirname "$0"` 4 . package/info 5 6 usage () { 7 cat <<EOF 8 Usage: $0 [OPTION]... [TARGET] 9 10 Defaults for the options are specified in brackets. 11 12 System types: 13 --target=TARGET configure to run on target TARGET [detected] 14 --host=TARGET same as --target 15 16 Installation directories: 17 --prefix=PREFIX main installation prefix [/] 18 --exec-prefix=EPREFIX installation prefix for executable files [PREFIX] 19 20 Fine tuning of the installation directories: 21 --dynlibdir=DIR shared library files [PREFIX/lib] 22 --bindir=BINDIR user executables [EPREFIX/bin] 23 --libexecdir=DIR package-scoped executables [EPREFIX/libexec] 24 --libdir=DIR static library files [PREFIX/lib/$package] 25 --includedir=DIR C header files [PREFIX/include] 26 27 If no --prefix option is given, by default libdir (but not dynlibdir) will be 28 /usr/lib/$package, and includedir will be /usr/include. 29 30 Dependencies: 31 --with-sysdeps=DIR use sysdeps in DIR [PREFIX/lib/skalibs/sysdeps] 32 --with-include=DIR add DIR to the list of searched directories for headers 33 --with-lib=DIR add DIR to the list of searched directories for static libraries 34 --with-dynlib=DIR add DIR to the list of searched directories for shared libraries 35 36 If no --prefix option is given, by default sysdeps will be fetched from 37 /usr/lib/skalibs/sysdeps. 38 39 Optional features: 40 --enable-shared build shared libraries [disabled] 41 --disable-static do not build static libraries [enabled] 42 --disable-allstatic do not prefer linking against static libraries [enabled] 43 --enable-static-libc make entirely static binaries [disabled] 44 --disable-all-pic don't build executables or static libs as PIC [enabled] 45 --enable-slashpackage[=ROOT] assume /package installation at ROOT [disabled] 46 --enable-absolute-paths do not rely on PATH to access this package's binaries, 47 hardcode absolute BINDIR/foobar paths instead [disabled] 48 --enable-nsss use the nsss library for user information [disabled] 49 --disable-execline don't use the execline library [enabled] 50 51 EOF 52 exit 0 53 } 54 55 # Helper functions 56 57 # If your system does not have printf, you can comment this, but it is 58 # generally not a good idea to use echo. 59 # See http://www.etalabs.net/sh_tricks.html 60 echo () { 61 IFS=" " 62 printf %s\\n "$*" 63 } 64 65 quote () { 66 tr '\n' ' ' <<EOF | grep '^[-[:alnum:]_=,./:]* $' >/dev/null 2>&1 && { echo "$1" ; return 0 ; } 67 $1 68 EOF 69 echo "$1" | sed -e "s/'/'\\\\''/g" -e "1s/^/'/" -e "\$s/\$/'/" -e "s#^'\([-[:alnum:]_,./:]*\)=\(.*\)\$#\1='\2#" -e "s|\*/|* /|g" 70 } 71 72 fail () { 73 echo "$*" 74 exit 1 75 } 76 77 fnmatch () { 78 eval "case \"\$2\" in $1) return 0 ;; *) return 1 ;; esac" 79 } 80 81 cmdexists () { 82 type "$1" >/dev/null 2>&1 83 } 84 85 trycc () { 86 test -z "$CC_AUTO" && cmdexists "$1" && CC_AUTO="$*" 87 } 88 89 stripdir () { 90 while eval "fnmatch '*/' \"\${$1}\"" ; do 91 eval "$1=\${$1%/}" 92 done 93 } 94 95 tryflag () { 96 echo "Checking whether compiler accepts $2 ..." 97 echo "typedef int x;" > "$tmpc" 98 if $CC_AUTO $CPPFLAGS_AUTO $CPPFLAGS $CPPFLAGS_POST $CFLAGS_AUTO $CFLAGS $CFLAGS_POST "$2" -c -o "$tmpo" "$tmpc" >/dev/null 2>&1 ; then 99 echo " ... yes" 100 eval "$1=\"\${$1} \$2\"" 101 eval "$1=\${$1# }" 102 return 0 103 else 104 echo " ... no" 105 return 1 106 fi 107 } 108 109 tryldflag () { 110 echo "Checking whether linker accepts $2 ..." 111 echo "typedef int x;" > "$tmpc" 112 if $CC_AUTO $CFLAGS_AUTO $CFLAGS $CFLAGS_POST $LDFLAGS_AUTO $LDFLAGS $LDFLAGS_POST -nostdlib "$2" -o "$tmpe" "$tmpc" >/dev/null 2>&1 ; then 113 echo " ... yes" 114 eval "$1=\"\${$1} \$2\"" 115 eval "$1=\${$1# }" 116 return 0 117 else 118 echo " ... no" 119 return 1 120 fi 121 } 122 123 124 # Actual script 125 126 CC_AUTO= 127 CPPFLAGS_AUTO="-D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700 -iquote src/include-local -Isrc/include" 128 CPPFLAGS_POST="$CPPFLAGS" 129 CPPFLAGS= 130 CFLAGS_AUTO="-pipe -Wall" 131 CFLAGS_POST="$CFLAGS" 132 CFLAGS=-O2 133 LDFLAGS_AUTO= 134 LDFLAGS_POST="$LDFLAGS" 135 LDFLAGS= 136 LDFLAGS_NOSHARED= 137 LDFLAGS_SHARED=-shared 138 prefix= 139 exec_prefix='$prefix' 140 dynlibdir='$prefix/lib' 141 libexecdir='$exec_prefix/libexec' 142 bindir='$exec_prefix/bin' 143 libdir='$prefix/lib/$package' 144 includedir='$prefix/include' 145 sysdeps='$prefix/lib/skalibs/sysdeps' 146 manualsysdeps=false 147 shared=false 148 static=true 149 allpic=true 150 slashpackage=false 151 abspath=false 152 usensss=false 153 useexecline=true 154 sproot= 155 home= 156 exthome= 157 allstatic=true 158 evenmorestatic=false 159 addincpath='' 160 addlibspath='' 161 addlibdpath='' 162 vpaths='' 163 vpathd='' 164 build= 165 166 for arg ; do 167 case "$arg" in 168 --help) usage ;; 169 --prefix=*) prefix=${arg#*=} ;; 170 --exec-prefix=*) exec_prefix=${arg#*=} ;; 171 --dynlibdir=*) dynlibdir=${arg#*=} ;; 172 --libexecdir=*) libexecdir=${arg#*=} ;; 173 --bindir=*) bindir=${arg#*=} ;; 174 --libdir=*) libdir=${arg#*=} ;; 175 --includedir=*) includedir=${arg#*=} ;; 176 --with-sysdeps=*) sysdeps=${arg#*=} manualsysdeps=true ;; 177 --with-include=*) var=${arg#*=} ; stripdir var ; addincpath="$addincpath -I$var" ;; 178 --with-lib=*) var=${arg#*=} ; stripdir var ; addlibspath="$addlibspath -L$var" ; vpaths="$vpaths $var" ;; 179 --with-dynlib=*) var=${arg#*=} ; stripdir var ; addlibdpath="$addlibdpath -L$var" ; vpathd="$vpathd $var" ;; 180 --enable-shared|--enable-shared=yes) shared=true ;; 181 --disable-shared|--enable-shared=no) shared=false ;; 182 --enable-static|--enable-static=yes) static=true ;; 183 --disable-static|--enable-static=no) static=false ;; 184 --enable-allstatic|--enable-allstatic=yes) allstatic=true ;; 185 --disable-allstatic|--enable-allstatic=no) allstatic=false ; evenmorestatic=false ;; 186 --enable-static-libc|--enable-static-libc=yes) allstatic=true ; evenmorestatic=true ;; 187 --disable-static-libc|--enable-static-libc=no) evenmorestatic=false ;; 188 --enable-all-pic|--enable-all-pic=yes) allpic=true ;; 189 --disable-all-pic|--enable-all-pic=no) allpic=false ;; 190 --enable-slashpackage=*) sproot=${arg#*=} ; slashpackage=true ; ;; 191 --enable-slashpackage) sproot= ; slashpackage=true ;; 192 --disable-slashpackage) sproot= ; slashpackage=false ;; 193 --enable-absolute-paths|--enable-absolute-paths=yes) abspath=true ;; 194 --disable-absolute-paths|--enable-absolute-paths=no) abspath=false ;; 195 --enable-nsss|--enable-nsss=yes) usensss=true ;; 196 --disable-nsss|--enable-nsss=no) usensss=false ;; 197 --enable-execline|--enable-execline=yes) useexecline=true ;; 198 --disable-execline|--enable-execline=no) useexecline=false ;; 199 --enable-*|--disable-*|--with-*|--without-*|--*dir=*) ;; 200 --host=*|--target=*) target=${arg#*=} ;; 201 --build=*) build=${arg#*=} ;; 202 -* ) echo "$0: unknown option $arg" ;; 203 *=*) eval "${arg%%=*}=\${arg#*=}" ;; 204 *) target=$arg ;; 205 esac 206 done 207 208 # Add /usr in the default default case 209 if test -z "$prefix" ; then 210 if test "$libdir" = '$prefix/lib/$package' ; then 211 libdir=/usr/lib/$package 212 fi 213 if test "$includedir" = '$prefix/include' ; then 214 includedir=/usr/include 215 fi 216 if test "$sysdeps" = '$prefix/lib/skalibs/sysdeps' ; then 217 sysdeps=/usr/lib/skalibs/sysdeps 218 fi 219 fi 220 221 # Expand installation directories 222 stripdir prefix 223 for i in exec_prefix dynlibdir libexecdir bindir libdir includedir sysdeps sproot ; do 224 eval tmp=\${$i} 225 eval $i=$tmp 226 stripdir $i 227 done 228 229 # Get usable temp filenames 230 i=0 231 set -C 232 while : ; do 233 i=$(($i+1)) 234 tmpc="./tmp-configure-$$-$PPID-$i.c" 235 tmpo="./tmp-configure-$$-$PPID-$i.o" 236 tmpe="./tmp-configure-$$-$PPID-$i.tmp" 237 2>|/dev/null > "$tmpc" && break 238 2>|/dev/null > "$tmpo" && break 239 2>|/dev/null > "$tmpe" && break 240 test "$i" -gt 50 && fail "$0: cannot create temporary files" 241 done 242 set +C 243 trap 'rm -f "$tmpc" "$tmpo" "$tmpe"' EXIT ABRT INT QUIT TERM HUP 244 245 # Set slashpackage values 246 if $slashpackage ; then 247 home=${sproot}/package/${category}/${package}-${version} 248 exthome=${sproot}/package/${category}/${package} 249 if $manualsysdeps ; then 250 : 251 else 252 sysdeps=${DESTDIR}${sproot}/package/prog/skalibs/sysdeps 253 fi 254 extbinprefix=${exthome}/command 255 dynlibdir=${home}/library.so 256 bindir=${home}/command 257 libdir=${home}/library 258 libexecdir=$bindir 259 includedir=${home}/include 260 while read dep condvar ; do 261 if test -n "$condvar" ; then 262 eval "cond=$condvar" 263 else 264 cond=true 265 fi 266 if $cond ; then 267 addincpath="$addincpath -I${DESTDIR}${sproot}${dep}/include" 268 vpaths="$vpaths ${DESTDIR}${sproot}${dep}/library" 269 addlibspath="$addlibspath -L${DESTDIR}${sproot}${dep}/library" 270 vpathd="$vpathd ${DESTDIR}${sproot}${dep}/library.so" 271 addlibdpath="$addlibdpath -L${DESTDIR}${sproot}${dep}/library.so" 272 fi 273 done < package/deps-build 274 fi 275 276 # Find a C compiler to use 277 if test -n "$target" && test x${build} != x${target} ; then 278 cross=${target}- 279 else 280 cross= 281 fi 282 echo "Checking for C compiler..." 283 trycc ${CC} 284 if test -n "$CC_AUTO" ; then 285 b=`basename "$CC"` 286 adjust_cross=false 287 if test "$b" != "$CC" ; then 288 adjust_cross=true 289 echo "$0: warning: compiler $CC is declared with its own path. If it's not accessible via PATH, you will need to pass AR, RANLIB and STRIP make variables to the make invocation." 1>&2 290 fi 291 if test -n "$cross" ; then 292 if test "$b" = "${b##$cross}" ; then 293 echo "$0: warning: compiler $CC is declared as a cross-compiler for target $target but does not start with prefix ${cross}" 1>&2 294 elif $adjust_cross ; then 295 cross=`dirname "$CC"`/"$cross" 296 fi 297 fi 298 fi 299 trycc ${cross}gcc 300 trycc ${cross}clang 301 trycc ${cross}cc 302 test -n "$CC_AUTO" || { echo "$0: cannot find a C compiler" ; exit 1 ; } 303 echo " ... $CC_AUTO" 304 echo "Checking whether C compiler works... " 305 echo "typedef int x;" > "$tmpc" 306 if $CC_AUTO $CPPFLAGS_AUTO $CPPFLAGS $CPPFLAGS_POST $CFLAGS_AUTO $CFLAGS $CFLAGS_POST -c -o "$tmpo" "$tmpc" 2>"$tmpe" ; then 307 echo " ... yes" 308 else 309 echo " ... no. Compiler output follows:" 310 cat < "$tmpe" 311 exit 1 312 fi 313 314 echo "Checking target system type..." 315 if test -z "$target" ; then 316 if test -n "$build" ; then 317 target=$build ; 318 else 319 target=$($CC_AUTO -dumpmachine 2>/dev/null) || target=unknown 320 fi 321 fi 322 echo " ... $target" 323 if test ! -d $sysdeps || test ! -f $sysdeps/target ; then 324 echo "$0: error: $sysdeps is not a valid sysdeps directory" 325 exit 1 326 fi 327 if [ "x$target" != "x$(cat $sysdeps/target)" ] ; then 328 echo "$0: error: target $target does not match the contents of $sysdeps/target" 329 exit 1 330 fi 331 332 spawn_lib=$(cat $sysdeps/spawn.lib) 333 socket_lib=$(cat $sysdeps/socket.lib) 334 sysclock_lib=$(cat $sysdeps/sysclock.lib) 335 timer_lib=$(cat $sysdeps/timer.lib) 336 util_lib=$(cat $sysdeps/util.lib) 337 338 if $allpic ; then 339 tryflag CPPFLAGS_AUTO -fPIC 340 fi 341 tryflag CFLAGS_AUTO -std=c99 342 tryflag CFLAGS -fomit-frame-pointer 343 tryflag CFLAGS_AUTO -fno-exceptions 344 tryflag CFLAGS_AUTO -fno-unwind-tables 345 tryflag CFLAGS_AUTO -fno-asynchronous-unwind-tables 346 tryflag CPPFLAGS_AUTO -Werror=implicit-function-declaration 347 tryflag CPPFLAGS_AUTO -Werror=implicit-int 348 tryflag CPPFLAGS_AUTO -Werror=pointer-sign 349 tryflag CPPFLAGS_AUTO -Werror=pointer-arith 350 tryflag CFLAGS_AUTO -ffunction-sections 351 tryflag CFLAGS_AUTO -fdata-sections 352 353 tryldflag LDFLAGS_AUTO -Wl,--sort-section=alignment 354 tryldflag LDFLAGS_AUTO -Wl,--sort-common 355 356 CPPFLAGS_AUTO="${CPPFLAGS_AUTO}${addincpath}" 357 358 if $evenmorestatic ; then 359 LDFLAGS_NOSHARED=-static 360 fi 361 362 if $shared ; then 363 tryldflag LDFLAGS -Wl,--hash-style=both 364 fi 365 366 LDFLAGS_SHARED="${LDFLAGS_SHARED}${addlibdpath}" 367 368 if test -z "$vpaths" ; then 369 while read dep ; do 370 base=$(basename $dep) ; 371 vpaths="$vpaths /usr/lib/$base" 372 addlibspath="$addlibspath -L/usr/lib/$base" 373 done < package/deps-build 374 fi 375 376 if $allstatic ; then 377 LDFLAGS_NOSHARED="${LDFLAGS_NOSHARED}${addlibspath}" 378 tryldflag LDFLAGS_NOSHARED -Wl,--gc-sections 379 else 380 LDFLAGS_NOSHARED="${LDFLAGS_NOSHARED}${addlibdpath}" 381 fi 382 383 echo "Creating config.mak..." 384 cmdline=$(quote "$0") 385 for i ; do cmdline="$cmdline $(quote "$i")" ; done 386 exec 3>&1 1>config.mak 387 cat << EOF 388 # This file was generated by: 389 # $cmdline 390 # Any changes made here will be lost if configure is re-run. 391 392 target := $target 393 package := $package 394 prefix := $prefix 395 exec_prefix := $exec_prefix 396 dynlibdir := $dynlibdir 397 libexecdir := $libexecdir 398 bindir := $bindir 399 libdir := $libdir 400 includedir := $includedir 401 sysdeps := $sysdeps 402 slashpackage := $slashpackage 403 sproot := $sproot 404 version := $version 405 home := $home 406 exthome := $exthome 407 SPAWN_LIB := ${spawn_lib} 408 SOCKET_LIB := ${socket_lib} 409 SYSCLOCK_LIB := ${sysclock_lib} 410 TIMER_LIB := ${timer_lib} 411 UTIL_LIB := ${util_lib} 412 413 CC := $CC_AUTO 414 CPPFLAGS_AUTO := $CPPFLAGS_AUTO 415 CPPFLAGS := $CPPFLAGS $CPPFLAGS_POST 416 CFLAGS_AUTO := $CFLAGS_AUTO 417 CFLAGS := $CFLAGS $CFLAGS_POST 418 LDFLAGS_AUTO := $LDFLAGS_AUTO 419 LDFLAGS := $LDFLAGS $LDFLAGS_POST 420 LDFLAGS_SHARED := $LDFLAGS_SHARED 421 LDFLAGS_NOSHARED := $LDFLAGS_NOSHARED 422 CROSS_COMPILE := $cross 423 424 vpath lib%.a$vpaths 425 vpath lib%.so$vpathd 426 EOF 427 if $allstatic ; then 428 echo ".LIBPATTERNS := lib%.a" 429 echo "DO_ALLSTATIC := 1" 430 else 431 echo ".LIBPATTERNS := lib%.so" 432 fi 433 if $static ; then 434 echo "DO_STATIC := 1" 435 else 436 echo "DO_STATIC :=" 437 fi 438 if $shared ; then 439 echo "DO_SHARED := 1" 440 else 441 echo "DO_SHARED :=" 442 fi 443 if $allpic ; then 444 echo "STATIC_LIBS_ARE_PIC := 1" 445 else 446 echo "STATIC_LIBS_ARE_PIC :=" 447 fi 448 if $usensss ; then 449 echo "LIBNSSS := -lnsss" 450 echo "MAYBEPTHREAD_LIB := -lpthread" 451 else 452 echo "LIBNSSS :=" 453 echo "MAYBEPTHREAD_LIB :=" 454 fi 455 if $useexecline ; then 456 echo "EXECLINE_LIB := -lexecline" 457 else 458 echo "EXECLINE_LIB :=" 459 fi 460 461 exec 1>&3 3>&- 462 echo " ... done." 463 464 echo "Creating src/include/${package}/config.h..." 465 mkdir -p -m 0755 src/include/${package} 466 exec 3>&1 1> src/include/${package}/config.h 467 cat <<EOF 468 /* ISC license. */ 469 470 /* Generated by: $cmdline */ 471 472 #ifndef ${package_macro_name}_CONFIG_H 473 #define ${package_macro_name}_CONFIG_H 474 475 #define ${package_macro_name}_VERSION "$version" 476 EOF 477 if $slashpackage ; then 478 echo "#define ${package_macro_name}_BINPREFIX \"$bindir/\"" 479 echo "#define ${package_macro_name}_EXTBINPREFIX \"$extbinprefix/\"" 480 elif $abspath ; then 481 echo "#define ${package_macro_name}_BINPREFIX \"$bindir/\"" 482 echo "#define ${package_macro_name}_EXTBINPREFIX \"$bindir/\"" 483 else 484 echo "#define ${package_macro_name}_BINPREFIX \"\"" 485 echo "#define ${package_macro_name}_EXTBINPREFIX \"\"" 486 fi 487 echo "#define ${package_macro_name}_LIBEXECPREFIX \"$libexecdir/\"" 488 echo 489 echo "#undef ${package_macro_name}_USE_EXECLINE" 490 if $useexecline ; then 491 echo "#define ${package_macro_name}_USE_EXECLINE" 492 fi 493 echo 494 echo "#endif" 495 exec 1>&3 3>&- 496 echo " ... done."