1 #!/bin/sh 2 srcversion='$MirOS: src/bin/mksh/Build.sh,v 1.459 2010/08/24 15:46:06 tg Exp $' 3 #- 4 # Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 5 # Thorsten Glaser <tg (at] mirbsd.org> 6 # 7 # Provided that these terms and disclaimer and all copyright notices 8 # are retained or reproduced in an accompanying document, permission 9 # is granted to deal in this work without restriction, including un- 10 # limited rights to use, publicly perform, distribute, sell, modify, 11 # merge, give away, or sublicence. 12 # 13 # This work is provided "AS IS" and WITHOUT WARRANTY of any kind, to 14 # the utmost extent permitted by applicable law, neither express nor 15 # implied; without malicious intent or gross negligence. In no event 16 # may a licensor, author or contributor be held liable for indirect, 17 # direct, other damage, loss, or other issues arising in any way out 18 # of dealing in the work, even if advised of the possibility of such 19 # damage or existence of a defect, except proven that it results out 20 # of said person's immediate fault when using the work as intended. 21 #- 22 # People analysing the output must whitelist conftest.c for any kind 23 # of compiler warning checks (mirtoconf is by design not quiet). 24 # 25 # Environment used: CC CFLAGS CPPFLAGS LDFLAGS LIBS NOWARN NROFF 26 # TARGET_OS TARGET_OSREV 27 # Feature selectors: USE_PRINTF_BUILTIN 28 # CPPFLAGS recognised: MKSH_ASSUME_UTF8 MKSH_BINSHREDUCED MKSH_CLS_STRING 29 # MKSH_CONSERVATIVE_FDS MKSH_MIDNIGHTBSD01ASH_COMPAT 30 # MKSH_NOPWNAM MKSH_NO_LIMITS MKSH_SMALL MKSH_S_NOVI 31 # MKSH_UNEMPLOYED MKSH_DEFAULT_EXECSHELL MKSHRC_PATH 32 # MKSH_DEFAULT_TMPDIR MKSH_CLRTOEOL_STRING MKSH_A4PB 33 34 LC_ALL=C 35 export LC_ALL 36 37 v() { 38 $e "$*" 39 eval "$@" 40 } 41 42 vv() { 43 _c=$1 44 shift 45 $e "\$ $*" 2>&1 46 eval "$@" >vv.out 2>&1 47 sed "s^${_c} " <vv.out 48 } 49 50 vq() { 51 eval "$@" 52 } 53 54 rmf() { 55 for _f in "$@"; do 56 case ${_f} in 57 mksh.1) ;; 58 *) rm -f "${_f}" ;; 59 esac 60 done 61 } 62 63 if test -d /usr/xpg4/bin/. >/dev/null 2>&1; then 64 # Solaris: some of the tools have weird behaviour, use portable ones 65 PATH=/usr/xpg4/bin:$PATH 66 export PATH 67 fi 68 69 if test -n "${ZSH_VERSION+x}" && (emulate sh) >/dev/null 2>&1; then 70 emulate sh 71 NULLCMD=: 72 fi 73 74 allu=QWERTYUIOPASDFGHJKLZXCVBNM 75 alll=qwertyuiopasdfghjklzxcvbnm 76 alln=0123456789 77 alls=______________________________________________________________ 78 nl=' 79 ' 80 tcfn=no 81 bi= 82 ui= 83 ao= 84 fx= 85 me=`basename "$0"` 86 orig_CFLAGS=$CFLAGS 87 phase=x 88 oldish_ed=stdout-ed,no-stderr-ed 89 90 if test -t 1; then 91 bi='[1m' 92 ui='[4m' 93 ao='[0m' 94 fi 95 96 upper() { 97 echo :"$@" | sed 's/^://' | tr $alll $allu 98 } 99 100 # clean up after ac_testrun() 101 ac_testdone() { 102 eval HAVE_$fu=$fv 103 fr=no 104 test 0 = $fv || fr=yes 105 $e "$bi==> $fd...$ao $ui$fr$ao$fx" 106 fx= 107 } 108 109 # ac_cache label: sets f, fu, fv?=0 110 ac_cache() { 111 f=$1 112 fu=`upper $f` 113 eval fv=\$HAVE_$fu 114 case $fv in 115 0|1) 116 fx=' (cached)' 117 return 0 118 ;; 119 esac 120 fv=0 121 return 1 122 } 123 124 # ac_testinit label [!] checkif[!]0 [setlabelifcheckis[!]0] useroutput 125 # returns 1 if value was cached/implied, 0 otherwise: call ac_testdone 126 ac_testinit() { 127 if ac_cache $1; then 128 test x"$2" = x"!" && shift 129 test x"$2" = x"" || shift 130 fd=${3-$f} 131 ac_testdone 132 return 1 133 fi 134 fc=0 135 if test x"$2" = x""; then 136 ft=1 137 else 138 if test x"$2" = x"!"; then 139 fc=1 140 shift 141 fi 142 eval ft=\$HAVE_`upper $2` 143 shift 144 fi 145 fd=${3-$f} 146 if test $fc = "$ft"; then 147 fv=$2 148 fx=' (implied)' 149 ac_testdone 150 return 1 151 fi 152 $e ... $fd 153 return 0 154 } 155 156 # pipe .c | ac_test[n] [!] label [!] checkif[!]0 [setlabelifcheckis[!]0] useroutput 157 ac_testn() { 158 if test x"$1" = x"!"; then 159 fr=1 160 shift 161 else 162 fr=0 163 fi 164 ac_testinit "$@" || return 165 cat >conftest.c 166 vv ']' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN conftest.c $LIBS $ccpr" 167 test $tcfn = no && test -f a.out && tcfn=a.out 168 test $tcfn = no && test -f a.exe && tcfn=a.exe 169 test $tcfn = no && test -f conftest && tcfn=conftest 170 if test -f $tcfn; then 171 test 1 = $fr || fv=1 172 else 173 test 0 = $fr || fv=1 174 fi 175 vscan= 176 if test $phase = u; then 177 test $ct = gcc && vscan='unrecogni[sz]ed' 178 test $ct = hpcc && vscan='unsupported' 179 test $ct = pcc && vscan='unsupported' 180 test $ct = sunpro && vscan='-e ignored -e turned.off' 181 fi 182 test -n "$vscan" && grep $vscan vv.out >/dev/null 2>&1 && fv=$fr 183 rmf conftest.c conftest.o ${tcfn}* vv.out 184 ac_testdone 185 } 186 187 # ac_ifcpp cppexpr [!] label [!] checkif[!]0 [setlabelifcheckis[!]0] useroutput 188 ac_ifcpp() { 189 expr=$1; shift 190 ac_testn "$@" <<-EOF 191 int main(void) { return ( 192 #$expr 193 0 194 #else 195 /* force a failure: expr is false */ 196 thiswillneverbedefinedIhope() 197 #endif 198 ); } 199 EOF 200 test x"$1" = x"!" && shift 201 f=$1 202 fu=`upper $f` 203 eval fv=\$HAVE_$fu 204 test x"$fv" = x"1" 205 } 206 207 ac_cppflags() { 208 test x"$1" = x"" || fu=$1 209 fv=$2 210 test x"$2" = x"" && eval fv=\$HAVE_$fu 211 CPPFLAGS="$CPPFLAGS -DHAVE_$fu=$fv" 212 } 213 214 ac_test() { 215 ac_testn "$@" 216 ac_cppflags 217 } 218 219 # ac_flags [-] add varname flags [text] 220 ac_flags() { 221 if test x"$1" = x"-"; then 222 shift 223 hf=1 224 else 225 hf=0 226 fi 227 fa=$1 228 vn=$2 229 f=$3 230 ft=$4 231 test x"$ft" = x"" && ft="if $f can be used" 232 save_CFLAGS=$CFLAGS 233 CFLAGS="$CFLAGS $f" 234 if test 1 = $hf; then 235 ac_testn can_$vn '' "$ft" 236 else 237 ac_testn can_$vn '' "$ft" <<-'EOF' 238 /* evil apo'stroph in comment test */ 239 int main(void) { return (0); } 240 EOF 241 fi 242 eval fv=\$HAVE_CAN_`upper $vn` 243 test 11 = $fa$fv || CFLAGS=$save_CFLAGS 244 } 245 246 # ac_header [!] header [prereq ...] 247 ac_header() { 248 if test x"$1" = x"!"; then 249 na=1 250 shift 251 else 252 na=0 253 fi 254 hf=$1; shift 255 hv=`echo "$hf" | tr -d '\012\015' | tr -c $alll$allu$alln $alls` 256 for i 257 do 258 echo "#include <$i>" >>x 259 done 260 echo "#include <$hf>" >>x 261 echo 'int main(void) { return (0); }' >>x 262 ac_testn "$hv" "" "<$hf>" <x 263 rmf x 264 test 1 = $na || ac_cppflags 265 } 266 267 addsrcs() { 268 if test x"$1" = x"!"; then 269 fr=0 270 shift 271 else 272 fr=1 273 fi 274 eval i=\$$1 275 test $fr = "$i" && case " $SRCS " in 276 *\ $2\ *) ;; 277 *) SRCS="$SRCS $2" ;; 278 esac 279 } 280 281 282 if test -d mksh || test -d mksh.exe; then 283 echo "$me: Error: ./mksh is a directory!" >&2 284 exit 1 285 fi 286 rmf a.exe* a.out* conftest.c *core lft mksh* no *.bc *.ll *.o \ 287 Rebuild.sh signames.inc test.sh x vv.out 288 289 curdir=`pwd` srcdir=`dirname "$0"` check_categories= 290 test -n "$dirname" || dirname=. 291 dstversion=`sed -n '/define MKSH_VERSION/s/^.*"\(.*\)".*$/\1/p' $srcdir/sh.h` 292 293 e=echo 294 r=0 295 eq=0 296 pm=0 297 cm=normal 298 optflags=-std-compile-opts 299 last= 300 301 for i 302 do 303 case $last:$i in 304 c:combine|c:dragonegg|c:llvm) 305 cm=$i 306 last= 307 ;; 308 c:*) 309 echo "$me: Unknown option -c '$i'!" >&2 310 exit 1 311 ;; 312 o:*) 313 optflags=$i 314 last= 315 ;; 316 :-c) 317 last=c 318 ;; 319 :-combine) 320 cm=combine 321 echo "$me: Warning: '$i' is deprecated, use '-c combine' instead!" >&2 322 ;; 323 :-g) 324 # checker, debug, valgrind build 325 CPPFLAGS="$CPPFLAGS -DDEBUG" 326 CFLAGS="$CFLAGS -g3 -fno-builtin" 327 ;; 328 :-j) 329 pm=1 330 ;; 331 :-llvm) 332 cm=llvm 333 optflags=-std-compile-opts 334 echo "$me: Warning: '$i' is deprecated, use '-c llvm -O' instead!" >&2 335 ;; 336 :-llvm=*) 337 cm=llvm 338 optflags=`echo "x$i" | sed 's/^x-llvm=//'` 339 echo "$me: Warning: '$i' is deprecated, use '-c llvm -o $llvm' instead!" >&2 340 ;; 341 :-M) 342 cm=makefile 343 ;; 344 :-O) 345 optflags=-std-compile-opts 346 ;; 347 :-o) 348 last=o 349 ;; 350 :-Q) 351 eq=1 352 ;; 353 :-r) 354 r=1 355 ;; 356 :-v) 357 echo "Build.sh $srcversion" 358 echo "for mksh $dstversion" 359 exit 0 360 ;; 361 :*) 362 echo "$me: Unknown option '$i'!" >&2 363 exit 1 364 ;; 365 *) 366 echo "$me: Unknown option -'$last' '$i'!" >&2 367 exit 1 368 ;; 369 esac 370 done 371 if test -n "$last"; then 372 echo "$me: Option -'$last' not followed by argument!" >&2 373 exit 1 374 fi 375 376 SRCS="lalloc.c edit.c eval.c exec.c expr.c funcs.c histrap.c" 377 SRCS="$SRCS jobs.c lex.c main.c misc.c shf.c syn.c tree.c var.c" 378 379 if test x"$srcdir" = x"."; then 380 CPPFLAGS="-I. $CPPFLAGS" 381 else 382 CPPFLAGS="-I. -I'$srcdir' $CPPFLAGS" 383 fi 384 385 test x"$TARGET_OS" = x"" && TARGET_OS=`uname -s 2>/dev/null || uname` 386 oswarn= 387 ccpc=-Wc, 388 ccpl=-Wl, 389 tsts= 390 ccpr='|| for _f in ${tcfn}*; do test x"${_f}" = x"mksh.1" || rm -f "${_f}"; done' 391 392 # Configuration depending on OS revision, on OSes that need them 393 case $TARGET_OS in 394 QNX) 395 test x"$TARGET_OSREV" = x"" && TARGET_OSREV=`uname -r` 396 ;; 397 esac 398 399 # Configuration depending on OS name 400 case $TARGET_OS in 401 AIX) 402 CPPFLAGS="$CPPFLAGS -D_ALL_SOURCE" 403 : ${HAVE_SETLOCALE_CTYPE=0} 404 ;; 405 BeOS) 406 oswarn=' and will currently not work' 407 ;; 408 BSD/OS) 409 : ${HAVE_SETLOCALE_CTYPE=0} 410 ;; 411 CYGWIN*) 412 : ${HAVE_SETLOCALE_CTYPE=0} 413 ;; 414 Darwin) 415 ;; 416 DragonFly) 417 ;; 418 FreeBSD) 419 ;; 420 GNU) 421 # define NO_PATH_MAX to use Hurd-only functions 422 CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE -DNO_PATH_MAX" 423 ;; 424 GNU/kFreeBSD) 425 CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE" 426 ;; 427 Haiku) 428 CPPFLAGS="$CPPFLAGS -DMKSH_ASSUME_UTF8" 429 ;; 430 HP-UX) 431 ;; 432 Interix) 433 ccpc='-X ' 434 ccpl='-Y ' 435 CPPFLAGS="$CPPFLAGS -D_ALL_SOURCE" 436 : ${LIBS='-lcrypt'} 437 : ${HAVE_SETLOCALE_CTYPE=0} 438 ;; 439 IRIX*) 440 : ${HAVE_SETLOCALE_CTYPE=0} 441 ;; 442 Linux) 443 CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE" 444 : ${HAVE_REVOKE=0} 445 ;; 446 MidnightBSD) 447 ;; 448 Minix) 449 CPPFLAGS="$CPPFLAGS -DMKSH_UNEMPLOYED -DMKSH_CONSERVATIVE_FDS" 450 CPPFLAGS="$CPPFLAGS -D_POSIX_SOURCE -D_POSIX_1_SOURCE=2 -D_MINIX" 451 oldish_ed=no-stderr-ed # /usr/bin/ed(!) is broken 452 : ${HAVE_SETLOCALE_CTYPE=0} 453 ;; 454 MirBSD) 455 ;; 456 NetBSD) 457 ;; 458 OpenBSD) 459 : ${HAVE_SETLOCALE_CTYPE=0} 460 ;; 461 OSF1) 462 HAVE_SIG_T=0 # incompatible 463 CPPFLAGS="$CPPFLAGS -D_OSF_SOURCE -D_POSIX_C_SOURCE=200112L" 464 CPPFLAGS="$CPPFLAGS -D_XOPEN_SOURCE=600 -D_XOPEN_SOURCE_EXTENDED" 465 : ${HAVE_SETLOCALE_CTYPE=0} 466 ;; 467 Plan9) 468 CPPFLAGS="$CPPFLAGS -D_POSIX_SOURCE -D_LIMITS_EXTENSION" 469 CPPFLAGS="$CPPFLAGS -D_BSD_EXTENSION -D_SUSV2_SOURCE" 470 oswarn=' and will currently not work' 471 CPPFLAGS="$CPPFLAGS -DMKSH_ASSUME_UTF8 -DMKSH_UNEMPLOYED" 472 ;; 473 PW32*) 474 HAVE_SIG_T=0 # incompatible 475 oswarn=' and will currently not work' 476 : ${HAVE_SETLOCALE_CTYPE=0} 477 ;; 478 QNX) 479 CPPFLAGS="$CPPFLAGS -D__NO_EXT_QNX" 480 case $TARGET_OSREV in 481 [012345].*|6.[0123].*|6.4.[01]) 482 oldish_ed=no-stderr-ed # oldish /bin/ed is broken 483 ;; 484 esac 485 : ${HAVE_SETLOCALE_CTYPE=0} 486 ;; 487 SunOS) 488 CPPFLAGS="$CPPFLAGS -D_BSD_SOURCE -D__EXTENSIONS__" 489 ;; 490 syllable) 491 CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE" 492 oswarn=' and will currently not work' 493 ;; 494 ULTRIX) 495 : ${CC=cc -YPOSIX} 496 CPPFLAGS="$CPPFLAGS -Dssize_t=int" 497 : ${HAVE_SETLOCALE_CTYPE=0} 498 ;; 499 UWIN*) 500 ccpc='-Yc,' 501 ccpl='-Yl,' 502 tsts=" 3<>/dev/tty" 503 oswarn="; it will compile, but the target" 504 oswarn="$oswarn${nl}platform itself is very flakey/unreliable" 505 : ${HAVE_SETLOCALE_CTYPE=0} 506 ;; 507 *) 508 oswarn='; it may or may not work' 509 ;; 510 esac 511 512 : ${CC=cc} ${NROFF=nroff} 513 test 0 = $r && echo | $NROFF -v 2>&1 | grep GNU >/dev/null 2>&1 && \ 514 NROFF="$NROFF -c" 515 516 # this aids me in tracing FTBFSen without access to the buildd 517 $e "Hi from$ao $bi$srcversion$ao on:" 518 case $TARGET_OS in 519 Darwin) 520 vv '|' "hwprefs machine_type os_type os_class >&2" 521 vv '|' "uname -a >&2" 522 ;; 523 IRIX*) 524 vv '|' "uname -a >&2" 525 vv '|' "hinv -v >&2" 526 ;; 527 OSF1) 528 vv '|' "uname -a >&2" 529 vv '|' "/usr/sbin/sizer -v >&2" 530 ;; 531 *) 532 vv '|' "uname -a >&2" 533 ;; 534 esac 535 test -z "$oswarn" || echo >&2 " 536 Warning: mksh has not yet been ported to or tested on your 537 operating system '$TARGET_OS'$oswarn. If you can provide 538 a shell account to the developer, this may improve; please 539 drop us a success or failure notice or even send in diffs. 540 " 541 $e "$bi$me: Building the MirBSD Korn Shell$ao $ui$dstversion$ao" 542 543 # 544 # Begin of mirtoconf checks 545 # 546 $e $bi$me: Scanning for functions... please ignore any errors.$ao 547 548 # 549 # Compiler: which one? 550 # 551 # notes: 552 # - ICC defines __GNUC__ too 553 # - GCC defines __hpux too 554 # - LLVM+clang defines __GNUC__ too 555 # - nwcc defines __GNUC__ too 556 CPP="$CC -E" 557 $e ... which compiler seems to be used 558 cat >conftest.c <<'EOF' 559 #if defined(__ICC) || defined(__INTEL_COMPILER) 560 ct=icc 561 #elif defined(__xlC__) || defined(__IBMC__) 562 ct=xlc 563 #elif defined(__SUNPRO_C) 564 ct=sunpro 565 #elif defined(__ACK__) 566 ct=ack 567 #elif defined(__BORLANDC__) 568 ct=bcc 569 #elif defined(__WATCOMC__) 570 ct=watcom 571 #elif defined(__MWERKS__) 572 ct=metrowerks 573 #elif defined(__HP_cc) 574 ct=hpcc 575 #elif defined(__DECC) || (defined(__osf__) && !defined(__GNUC__)) 576 ct=dec 577 #elif defined(__PGI) 578 ct=pgi 579 #elif defined(__DMC__) 580 ct=dmc 581 #elif defined(_MSC_VER) 582 ct=msc 583 #elif defined(__ADSPBLACKFIN__) || defined(__ADSPTS__) || defined(__ADSP21000__) 584 ct=adsp 585 #elif defined(__IAR_SYSTEMS_ICC__) 586 ct=iar 587 #elif defined(SDCC) 588 ct=sdcc 589 #elif defined(__PCC__) 590 ct=pcc 591 #elif defined(__TenDRA__) 592 ct=tendra 593 #elif defined(__TINYC__) 594 ct=tcc 595 #elif defined(__llvm__) && defined(__clang__) 596 ct=clang 597 #elif defined(__NWCC__) 598 ct=nwcc 599 #elif defined(__GNUC__) 600 ct=gcc 601 #elif defined(_COMPILER_VERSION) 602 ct=mipspro 603 #elif defined(__sgi) 604 ct=mipspro 605 #elif defined(__hpux) || defined(__hpua) 606 ct=hpcc 607 #elif defined(__ultrix) 608 ct=ucode 609 #else 610 ct=unknown 611 #endif 612 EOF 613 ct=unknown 614 vv ']' "$CPP $CFLAGS $CPPFLAGS $NOWARN conftest.c | grep ct= | tr -d \\\\015 >x" 615 sed 's/^/[ /' x 616 eval `cat x` 617 rmf x vv.out 618 echo 'int main(void) { return (0); }' >conftest.c 619 case $ct in 620 ack) 621 # work around "the famous ACK const bug" 622 CPPFLAGS="-Dconst= $CPPFLAGS" 623 ;; 624 adsp) 625 echo >&2 'Warning: Analog Devices C++ compiler for Blackfin, TigerSHARC 626 and SHARC (21000) DSPs detected. This compiler has not yet 627 been tested for compatibility with mksh. Continue at your 628 own risk, please report success/failure to the developers.' 629 ;; 630 bcc) 631 echo >&2 "Warning: Borland C++ Builder detected. This compiler might 632 produce broken executables. Continue at your own risk, 633 please report success/failure to the developers." 634 ;; 635 clang) 636 # does not work with current "ccc" compiler driver 637 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -version" 638 # this works, for now 639 vv '|' "${CLANG-clang} -version" 640 # ensure compiler and linker are in sync unless overridden 641 case $CCC_CC:$CCC_LD in 642 :*) ;; 643 *:) CCC_LD=$CCC_CC; export CCC_LD ;; 644 esac 645 ;; 646 dec) 647 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -V" 648 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN -Wl,-V conftest.c $LIBS" 649 ;; 650 dmc) 651 echo >&2 "Warning: Digital Mars Compiler detected. When running under" 652 echo >&2 " UWIN, mksh tends to be unstable due to the limitations" 653 echo >&2 " of this platform. Continue at your own risk," 654 echo >&2 " please report success/failure to the developers." 655 ;; 656 gcc) 657 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN -v conftest.c $LIBS" 658 vv '|' 'echo `$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS \ 659 -dumpmachine` gcc`$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN \ 660 $LIBS -dumpversion`' 661 ;; 662 hpcc) 663 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN -V conftest.c $LIBS" 664 ;; 665 iar) 666 echo >&2 'Warning: IAR Systems (http://www.iar.com) compiler for embedded 667 systems detected. This unsupported compiler has not yet 668 been tested for compatibility with mksh. Continue at your 669 own risk, please report success/failure to the developers.' 670 ;; 671 icc) 672 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -V" 673 ;; 674 metrowerks) 675 echo >&2 'Warning: Metrowerks C compiler detected. This has not yet 676 been tested for compatibility with mksh. Continue at your 677 own risk, please report success/failure to the developers.' 678 ;; 679 mipspro) 680 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -version" 681 ;; 682 msc) 683 ccpr= # errorlevels are not reliable 684 case $TARGET_OS in 685 Interix) 686 if [[ -n $C89_COMPILER ]]; then 687 C89_COMPILER=`ntpath2posix -c "$C89_COMPILER"` 688 else 689 C89_COMPILER=CL.EXE 690 fi 691 if [[ -n $C89_LINKER ]]; then 692 C89_LINKER=`ntpath2posix -c "$C89_LINKER"` 693 else 694 C89_LINKER=LINK.EXE 695 fi 696 vv '|' "$C89_COMPILER /HELP >&2" 697 vv '|' "$C89_LINKER /LINK >&2" 698 ;; 699 esac 700 ;; 701 nwcc) 702 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -version" 703 ;; 704 pcc) 705 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -v" 706 ;; 707 pgi) 708 echo >&2 'Warning: PGI detected. This unknown compiler has not yet 709 been tested for compatibility with mksh. Continue at your 710 own risk, please report success/failure to the developers.' 711 ;; 712 sdcc) 713 echo >&2 'Warning: sdcc (http://sdcc.sourceforge.net), the small devices 714 C compiler for embedded systems detected. This has not yet 715 been tested for compatibility with mksh. Continue at your 716 own risk, please report success/failure to the developers.' 717 ;; 718 sunpro) 719 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN -V conftest.c $LIBS" 720 ;; 721 tcc) 722 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -v" 723 ;; 724 tendra) 725 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -V 2>&1 | \ 726 fgrep -i -e version -e release" 727 ;; 728 ucode) 729 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -V" 730 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN -Wl,-V conftest.c $LIBS" 731 ;; 732 watcom) 733 echo >&2 'Warning: Watcom C Compiler detected. This compiler has not yet 734 been tested for compatibility with mksh. Continue at your 735 own risk, please report success/failure to the developers.' 736 ;; 737 xlc) 738 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -qversion=verbose" 739 vv '|' "ld -V" 740 ;; 741 *) 742 ct=unknown 743 ;; 744 esac 745 case $cm in 746 dragonegg|llvm) 747 vv '|' "llc -version" 748 ;; 749 esac 750 $e "$bi==> which compiler seems to be used...$ao $ui$ct$ao" 751 rmf conftest.c conftest.o conftest a.out* a.exe* vv.out 752 753 # 754 # Compiler: works as-is, with -Wno-error and -Werror 755 # 756 save_NOWARN=$NOWARN 757 NOWARN= 758 DOWARN= 759 ac_flags 0 compiler_works '' 'if the compiler works' 760 test 1 = $HAVE_CAN_COMPILER_WORKS || exit 1 761 HAVE_COMPILER_KNOWN=0 762 test $ct = unknown || HAVE_COMPILER_KNOWN=1 763 if ac_ifcpp 'if 0' compiler_fails '' \ 764 'if the compiler does not fail correctly'; then 765 save_CFLAGS=$CFLAGS 766 : ${HAVE_CAN_DELEXE=x} 767 if test $ct = dmc; then 768 CFLAGS="$CFLAGS ${ccpl}/DELEXECUTABLE" 769 ac_testn can_delexe compiler_fails 0 'for the /DELEXECUTABLE linker option' <<-EOF 770 int main(void) { return (0); } 771 EOF 772 elif test $ct = dec; then 773 CFLAGS="$CFLAGS ${ccpl}-non_shared" 774 ac_testn can_delexe compiler_fails 0 'for the -non_shared linker option' <<-EOF 775 int main(void) { return (0); } 776 EOF 777 else 778 exit 1 779 fi 780 test 1 = $HAVE_CAN_DELEXE || CFLAGS=$save_CFLAGS 781 ac_testn compiler_still_fails '' 'if the compiler still does not fail correctly' <<-EOF 782 EOF 783 test 1 = $HAVE_COMPILER_STILL_FAILS && exit 1 784 fi 785 if ac_ifcpp 'ifdef __TINYC__' couldbe_tcc '!' compiler_known 0 \ 786 'if this could be tcc'; then 787 ct=tcc 788 CPP='cpp -D__TINYC__' 789 fi 790 791 if test $ct = sunpro; then 792 test x"$save_NOWARN" = x"" && save_NOWARN='-errwarn=%none' 793 ac_flags 0 errwarnnone "$save_NOWARN" 794 test 1 = $HAVE_CAN_ERRWARNNONE || save_NOWARN= 795 ac_flags 0 errwarnall "-errwarn=%all" 796 test 1 = $HAVE_CAN_ERRWARNALL && DOWARN="-errwarn=%all" 797 elif test $ct = hpcc; then 798 save_NOWARN= 799 DOWARN=+We 800 elif test $ct = mipspro; then 801 save_NOWARN= 802 DOWARN="-diag_error 1-10000" 803 elif test $ct = msc; then 804 save_NOWARN="${ccpc}/w" 805 DOWARN="${ccpc}/WX" 806 elif test $ct = dmc; then 807 save_NOWARN="${ccpc}-w" 808 DOWARN="${ccpc}-wx" 809 elif test $ct = bcc; then 810 save_NOWARN="${ccpc}-w" 811 DOWARN="${ccpc}-w!" 812 elif test $ct = dec; then 813 : -msg_* flags not used yet, or is -w2 correct? 814 elif test $ct = xlc; then 815 save_NOWARN=-qflag=i:e 816 DOWARN=-qflag=i:i 817 elif test $ct = tendra; then 818 save_NOWARN=-w 819 elif test $ct = ucode; then 820 save_NOWARN= 821 DOWARN=-w2 822 else 823 test x"$save_NOWARN" = x"" && save_NOWARN=-Wno-error 824 ac_flags 0 wnoerror "$save_NOWARN" 825 test 1 = $HAVE_CAN_WNOERROR || save_NOWARN= 826 ac_flags 0 werror -Werror 827 test 1 = $HAVE_CAN_WERROR && DOWARN=-Werror 828 fi 829 830 test $ct = icc && DOWARN="$DOWARN -wd1419" 831 NOWARN=$save_NOWARN 832 833 # 834 # Compiler: extra flags (-O2 -f* -W* etc.) 835 # 836 i=`echo :"$orig_CFLAGS" | sed 's/^://' | tr -c -d $alll$allu$alln` 837 # optimisation: only if orig_CFLAGS is empty 838 test x"$i" = x"" && if test $ct = sunpro; then 839 cat >x <<-'EOF' 840 int main(void) { return (0); } 841 #define __IDSTRING_CONCAT(l,p) __LINTED__ ## l ## _ ## p 842 #define __IDSTRING_EXPAND(l,p) __IDSTRING_CONCAT(l,p) 843 #define pad void __IDSTRING_EXPAND(__LINE__,x)(void) { } 844 EOF 845 yes pad | head -n 256 >>x 846 ac_flags - 1 otwo -xO2 <x 847 rmf x 848 elif test $ct = hpcc; then 849 phase=u 850 ac_flags 1 otwo +O2 851 phase=x 852 elif test $ct = xlc; then 853 ac_flags 1 othree "-O3 -qstrict" 854 test 1 = $HAVE_CAN_OTHREE || ac_flags 1 otwo -O2 855 elif test $ct = tcc || test $ct = tendra; then 856 : no special optimisation 857 else 858 ac_flags 1 otwo -O2 859 test 1 = $HAVE_CAN_OTWO || ac_flags 1 optimise -O 860 fi 861 # other flags: just add them if they are supported 862 i=0 863 if test $ct = gcc; then 864 # The following tests run with -Werror (gcc only) if possible 865 NOWARN=$DOWARN; phase=u 866 ac_flags 1 fnostrictaliasing -fno-strict-aliasing 867 ac_flags 1 fstackprotectorall -fstack-protector-all 868 ac_flags 1 fwrapv -fwrapv 869 test $cm = combine && ac_flags 0 combine \ 870 '-fwhole-program --combine' \ 871 'if gcc supports -fwhole-program --combine' 872 i=1 873 elif test $ct = icc; then 874 ac_flags 1 fnobuiltinsetmode -fno-builtin-setmode 875 ac_flags 1 fnostrictaliasing -fno-strict-aliasing 876 ac_flags 1 fstacksecuritycheck -fstack-security-check 877 i=1 878 elif test $ct = sunpro; then 879 phase=u 880 ac_flags 1 v -v 881 ac_flags 1 xc99 -xc99 'for support of ISO C99' 882 ac_flags 1 ipo -xipo 'for cross-module optimisation' 883 phase=x 884 elif test $ct = hpcc; then 885 phase=u 886 ac_flags 1 agcc -Agcc 'for support of GCC extensions' 887 ac_flags 1 ac99 -AC99 'for support of ISO C99' 888 phase=x 889 elif test $ct = dec; then 890 ac_flags 0 verb -verbose 891 ac_flags 1 rodata -readonly_strings 892 elif test $ct = dmc; then 893 ac_flags 1 decl "${ccpc}-r" 'for strict prototype checks' 894 ac_flags 1 schk "${ccpc}-s" 'for stack overflow checking' 895 elif test $ct = bcc; then 896 ac_flags 1 strpool "${ccpc}-d" 'if string pooling can be enabled' 897 elif test $ct = mipspro; then 898 ac_flags 1 xc99 -c99 'for support of ISO C99' 899 ac_flags 1 fullwarn -fullwarn 'for remark output support' 900 elif test $ct = msc; then 901 ac_flags 1 strpool "${ccpc}/GF" 'if string pooling can be enabled' 902 echo 'int main(void) { char test[64] = ""; return (*test); }' >x 903 ac_flags - 1 stackon "${ccpc}/GZ" 'if stack checks can be enabled' <x 904 ac_flags - 1 stckall "${ccpc}/Ge" 'stack checks for all functions' <x 905 ac_flags - 1 secuchk "${ccpc}/GS" 'for compiler security checks' <x 906 rmf x 907 ac_flags 1 wall "${ccpc}/Wall" 'to enable all warnings' 908 ac_flags 1 wp64 "${ccpc}/Wp64" 'to enable 64-bit warnings' 909 elif test $ct = xlc; then 910 ac_flags 1 x99 -qlanglvl=extc99 911 test 1 = $HAVE_CAN_X99 || ac_flags 1 c99 -qlanglvl=stdc99 912 ac_flags 1 rodata "-qro -qroconst -qroptr" 913 ac_flags 1 rtcheck -qcheck=all 914 ac_flags 1 rtchkc -qextchk 915 ac_flags 1 wformat "-qformat=all -qformat=nozln" 916 #ac_flags 1 wp64 -qwarn64 # too verbose for now 917 elif test $ct = tendra; then 918 ac_flags 0 ysystem -Ysystem 919 test 1 = $HAVE_CAN_YSYSTEM && CPPFLAGS="-Ysystem $CPPFLAGS" 920 ac_flags 1 extansi -Xa 921 elif test $ct = tcc; then 922 ac_flags 1 boundschk -b 923 elif test $ct = clang; then 924 i=1 925 elif test $ct = nwcc; then 926 i=1 927 #broken# ac_flags 1 ssp -stackprotect 928 fi 929 # flags common to a subset of compilers (run with -Werror on gcc) 930 if test 1 = $i; then 931 ac_flags 1 stdg99 -std=gnu99 'for support of ISO C99 + GCC extensions' 932 test 1 = $HAVE_CAN_STDG99 || \ 933 ac_flags 1 stdc99 -std=c99 'for support of ISO C99' 934 ac_flags 1 wall -Wall 935 fi 936 phase=x 937 938 # The following tests run with -Werror or similar (all compilers) if possible 939 NOWARN=$DOWARN 940 test $ct = pcc && phase=u 941 942 # 943 # Compiler: check for stuff that only generates warnings 944 # 945 ac_test attribute_bounded '' 'for __attribute__((bounded))' <<-'EOF' 946 #if defined(__GNUC__) && (__GNUC__ < 2) 947 /* force a failure: gcc 1.42 has a false positive here */ 948 int main(void) { return (thiswillneverbedefinedIhope()); } 949 #else 950 #include <string.h> 951 #undef __attribute__ 952 int xcopy(const void *, void *, size_t) 953 __attribute__((bounded (buffer, 1, 3))) 954 __attribute__((bounded (buffer, 2, 3))); 955 int main(int ac, char *av[]) { return (xcopy(av[0], av[--ac], 1)); } 956 int xcopy(const void *s, void *d, size_t n) { 957 memmove(d, s, n); return ((int)n); 958 } 959 #endif 960 EOF 961 ac_test attribute_format '' 'for __attribute__((format))' <<-'EOF' 962 #if defined(__GNUC__) && (__GNUC__ < 2) 963 /* force a failure: gcc 1.42 has a false positive here */ 964 int main(void) { return (thiswillneverbedefinedIhope()); } 965 #else 966 #include <stdio.h> 967 #undef __attribute__ 968 #undef printf 969 extern int printf(const char *format, ...) 970 __attribute__((format (printf, 1, 2))); 971 int main(int ac, char **av) { return (printf("%s%d", *av, ac)); } 972 #endif 973 EOF 974 ac_test attribute_nonnull '' 'for __attribute__((nonnull))' <<-'EOF' 975 #if defined(__GNUC__) && (__GNUC__ < 2) 976 /* force a failure: gcc 1.42 has a false positive here */ 977 int main(void) { return (thiswillneverbedefinedIhope()); } 978 #else 979 int foo(char *s1, char *s2) __attribute__((nonnull)); 980 int bar(char *s1, char *s2) __attribute__((nonnull (1, 2))); 981 int baz(char *s) __attribute__((nonnull (1))); 982 int foo(char *s1, char *s2) { return (bar(s2, s1)); } 983 int bar(char *s1, char *s2) { return (baz(s1) - baz(s2)); } 984 int baz(char *s) { return (*s); } 985 int main(int ac, char **av) { return (ac == foo(av[0], av[ac-1])); } 986 #endif 987 EOF 988 ac_test attribute_noreturn '' 'for __attribute__((noreturn))' <<-'EOF' 989 #if defined(__GNUC__) && (__GNUC__ < 2) 990 /* force a failure: gcc 1.42 has a false positive here */ 991 int main(void) { return (thiswillneverbedefinedIhope()); } 992 #else 993 #include <stdlib.h> 994 #undef __attribute__ 995 void fnord(void) __attribute__((noreturn)); 996 int main(void) { fnord(); } 997 void fnord(void) { exit(0); } 998 #endif 999 EOF 1000 ac_test attribute_unused '' 'for __attribute__((unused))' <<-'EOF' 1001 #if defined(__GNUC__) && (__GNUC__ < 2) 1002 /* force a failure: gcc 1.42 has a false positive here */ 1003 int main(void) { return (thiswillneverbedefinedIhope()); } 1004 #else 1005 int main(int ac __attribute__((unused)), char **av 1006 __attribute__((unused))) { return (0); } 1007 #endif 1008 EOF 1009 ac_test attribute_used '' 'for __attribute__((used))' <<-'EOF' 1010 #if defined(__GNUC__) && (__GNUC__ < 2) 1011 /* force a failure: gcc 1.42 has a false positive here */ 1012 int main(void) { return (thiswillneverbedefinedIhope()); } 1013 #else 1014 static const char fnord[] __attribute__((used)) = "42"; 1015 int main(void) { return (0); } 1016 #endif 1017 EOF 1018 1019 # End of tests run with -Werror 1020 NOWARN=$save_NOWARN 1021 phase=x 1022 1023 # 1024 # mksh: flavours (full/small mksh, omit certain stuff) 1025 # 1026 if ac_ifcpp 'ifdef MKSH_SMALL' isset_MKSH_SMALL '' \ 1027 "if a reduced-feature mksh is requested"; then 1028 #XXX this sucks; fix it for *all* compilers 1029 case $ct in 1030 clang|icc|nwcc) 1031 ac_flags 1 fnoinline -fno-inline 1032 ;; 1033 gcc) 1034 NOWARN=$DOWARN; phase=u 1035 ac_flags 1 fnoinline -fno-inline 1036 NOWARN=$save_NOWARN; phase=x 1037 ;; 1038 sunpro) 1039 ac_flags 1 fnoinline -xinline= 1040 ;; 1041 xlc) 1042 ac_flags 1 fnoinline -qnoinline 1043 ;; 1044 esac 1045 1046 : ${HAVE_MKNOD=0} 1047 : ${HAVE_NICE=0} 1048 : ${HAVE_REVOKE=0} 1049 : ${HAVE_PERSISTENT_HISTORY=0} 1050 check_categories=$check_categories,smksh 1051 HAVE_ISSET_MKSH_CONSERVATIVE_FDS=1 # from sh.h 1052 fi 1053 ac_ifcpp 'ifdef MKSH_BINSHREDUCED' isset_MKSH_BINSHREDUCED '' \ 1054 "if a reduced-feature sh is requested" && \ 1055 check_categories=$check_categories,binsh 1056 ac_ifcpp 'ifdef MKSH_UNEMPLOYED' isset_MKSH_UNEMPLOYED '' \ 1057 "if mksh will be built without job control" && \ 1058 check_categories=$check_categories,arge 1059 ac_ifcpp 'ifdef MKSH_ASSUME_UTF8' isset_MKSH_ASSUME_UTF8 '' \ 1060 'if the default UTF-8 mode is specified' && : ${HAVE_SETLOCALE_CTYPE=0} 1061 ac_ifcpp 'ifdef MKSH_CONSERVATIVE_FDS' isset_MKSH_CONSERVATIVE_FDS '' \ 1062 'if traditional/conservative fd use is requested' && \ 1063 check_categories=$check_categories,convfds 1064 1065 # 1066 # Environment: headers 1067 # 1068 ac_header sys/param.h 1069 ac_header sys/mkdev.h sys/types.h 1070 ac_header sys/mman.h sys/types.h 1071 ac_header sys/sysmacros.h 1072 ac_header grp.h sys/types.h 1073 ac_header libgen.h 1074 ac_header libutil.h sys/types.h 1075 ac_header paths.h 1076 ac_header stdbool.h 1077 ac_header stdint.h stdarg.h 1078 ac_header strings.h sys/types.h 1079 ac_header ulimit.h sys/types.h 1080 ac_header values.h 1081 1082 # 1083 # Environment: definitions 1084 # 1085 echo '#include <sys/types.h> 1086 /* check that off_t can represent 2^63-1 correctly, thx FSF */ 1087 #define LARGE_OFF_T (((off_t)1 << 62) - 1 + ((off_t)1 << 62)) 1088 int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721 && 1089 LARGE_OFF_T % 2147483647 == 1) ? 1 : -1]; 1090 int main(void) { return (0); }' >lft.c 1091 ac_testn can_lfs '' "for large file support" <lft.c 1092 save_CPPFLAGS=$CPPFLAGS 1093 CPPFLAGS="$CPPFLAGS -D_FILE_OFFSET_BITS=64" 1094 ac_testn can_lfs_sus '!' can_lfs 0 "... with -D_FILE_OFFSET_BITS=64" <lft.c 1095 if test 0 = $HAVE_CAN_LFS_SUS; then 1096 CPPFLAGS="$save_CPPFLAGS -D_LARGE_FILES=1" 1097 ac_testn can_lfs_aix '!' can_lfs 0 "... with -D_LARGE_FILES=1" <lft.c 1098 test 1 = $HAVE_CAN_LFS_AIX || CPPFLAGS=$save_CPPFLAGS 1099 fi 1100 rmf lft* # end of large file support test 1101 1102 # 1103 # Environment: types 1104 # 1105 ac_test can_inttypes '!' stdint_h 1 "for standard 32-bit integer types" <<-'EOF' 1106 #include <sys/types.h> 1107 #include <stddef.h> 1108 int main(int ac, char **av) { return ((uint32_t)(ptrdiff_t)*av + (int32_t)ac); } 1109 EOF 1110 ac_test can_ucbints '!' can_inttypes 1 "for UCB 32-bit integer types" <<-'EOF' 1111 #include <sys/types.h> 1112 #include <stddef.h> 1113 int main(int ac, char **av) { return ((u_int32_t)(ptrdiff_t)*av + (int32_t)ac); } 1114 EOF 1115 ac_test can_int8type '!' stdint_h 1 "for standard 8-bit integer type" <<-'EOF' 1116 #include <sys/types.h> 1117 #include <stddef.h> 1118 int main(int ac, char **av) { return ((uint8_t)(ptrdiff_t)av[ac]); } 1119 EOF 1120 ac_test can_ucbint8 '!' can_int8type 1 "for UCB 8-bit integer type" <<-'EOF' 1121 #include <sys/types.h> 1122 #include <stddef.h> 1123 int main(int ac, char **av) { return ((u_int8_t)(ptrdiff_t)av[ac]); } 1124 EOF 1125 1126 ac_test rlim_t <<-'EOF' 1127 #include <sys/types.h> 1128 #include <sys/time.h> 1129 #include <sys/resource.h> 1130 #include <unistd.h> 1131 int main(void) { return ((int)(rlim_t)0); } 1132 EOF 1133 1134 # only testn: added later below 1135 ac_testn sig_t <<-'EOF' 1136 #include <sys/types.h> 1137 #include <signal.h> 1138 #include <stddef.h> 1139 int main(void) { return ((int)(ptrdiff_t)(sig_t)kill(0,0)); } 1140 EOF 1141 1142 ac_testn sighandler_t '!' sig_t 0 <<-'EOF' 1143 #include <sys/types.h> 1144 #include <signal.h> 1145 #include <stddef.h> 1146 int main(void) { return ((int)(ptrdiff_t)(sighandler_t)kill(0,0)); } 1147 EOF 1148 if test 1 = $HAVE_SIGHANDLER_T; then 1149 CPPFLAGS="$CPPFLAGS -Dsig_t=sighandler_t" 1150 HAVE_SIG_T=1 1151 fi 1152 1153 ac_testn __sighandler_t '!' sig_t 0 <<-'EOF' 1154 #include <sys/types.h> 1155 #include <signal.h> 1156 #include <stddef.h> 1157 int main(void) { return ((int)(ptrdiff_t)(__sighandler_t)kill(0,0)); } 1158 EOF 1159 if test 1 = $HAVE___SIGHANDLER_T; then 1160 CPPFLAGS="$CPPFLAGS -Dsig_t=__sighandler_t" 1161 HAVE_SIG_T=1 1162 fi 1163 1164 test 1 = $HAVE_SIG_T || CPPFLAGS="$CPPFLAGS -Dsig_t=nosig_t" 1165 ac_cppflags SIG_T 1166 1167 # 1168 # Environment: signals 1169 # 1170 test x"NetBSD" = x"$TARGET_OS" && $e Ignore the compatibility warning. 1171 1172 for what in name list; do 1173 uwhat=`upper $what` 1174 ac_testn sys_sig$what '' "the sys_sig${what}[] array" <<-EOF 1175 extern const char *const sys_sig${what}[]; 1176 int main(void) { return (sys_sig${what}[0][0]); } 1177 EOF 1178 ac_testn _sys_sig$what '!' sys_sig$what 0 "the _sys_sig${what}[] array" <<-EOF 1179 extern const char *const _sys_sig${what}[]; 1180 int main(void) { return (_sys_sig${what}[0][0]); } 1181 EOF 1182 if eval "test 1 = \$HAVE__SYS_SIG$uwhat"; then 1183 CPPFLAGS="$CPPFLAGS -Dsys_sig$what=_sys_sig$what" 1184 eval "HAVE_SYS_SIG$uwhat=1" 1185 fi 1186 ac_cppflags SYS_SIG$uwhat 1187 done 1188 1189 ac_test strsignal '!' sys_siglist 0 <<-'EOF' 1190 #include <string.h> 1191 #include <signal.h> 1192 int main(void) { return (strsignal(1)[0]); } 1193 EOF 1194 1195 # 1196 # Environment: library functions 1197 # 1198 ac_testn flock_ex '' 'flock and mmap' <<-'EOF' 1199 #include <sys/types.h> 1200 #include <sys/file.h> 1201 #include <sys/mman.h> 1202 #include <fcntl.h> 1203 #include <stdlib.h> 1204 int main(void) { return ((void *)mmap(NULL, (size_t)flock(0, LOCK_EX), 1205 PROT_READ, MAP_PRIVATE, 0, (off_t)0) == (void *)NULL ? 1 : 1206 munmap(NULL, 0)); } 1207 EOF 1208 1209 ac_test getrusage <<-'EOF' 1210 #define MKSH_INCLUDES_ONLY 1211 #include "sh.h" 1212 int main(void) { 1213 struct rusage ru; 1214 return (getrusage(RUSAGE_SELF, &ru) + 1215 getrusage(RUSAGE_CHILDREN, &ru)); 1216 } 1217 EOF 1218 1219 ac_test killpg <<-'EOF' 1220 #include <signal.h> 1221 int main(int ac, char *av[]) { return (av[0][killpg(123, ac)]); } 1222 EOF 1223 1224 ac_test mknod '' 'if to use mknod(), makedev() and friends' <<-'EOF' 1225 #define MKSH_INCLUDES_ONLY 1226 #include "sh.h" 1227 int main(int ac, char *av[]) { 1228 dev_t dv; 1229 dv = makedev((unsigned int)ac, (unsigned int)av[0][0]); 1230 return (mknod(av[0], (mode_t)0, dv) ? (int)major(dv) : 1231 (int)minor(dv)); 1232 } 1233 EOF 1234 1235 ac_test mkstemp <<-'EOF' 1236 #include <stdlib.h> 1237 #include <unistd.h> 1238 int main(void) { char tmpl[] = "X"; return (mkstemp(tmpl)); } 1239 EOF 1240 1241 ac_test nice <<-'EOF' 1242 #include <unistd.h> 1243 int main(void) { return (nice(4)); } 1244 EOF 1245 1246 ac_test revoke <<-'EOF' 1247 #include <sys/types.h> 1248 #if HAVE_LIBUTIL_H 1249 #include <libutil.h> 1250 #endif 1251 #include <unistd.h> 1252 int main(int ac, char *av[]) { return (ac + revoke(av[0])); } 1253 EOF 1254 1255 ac_test setlocale_ctype '' 'setlocale(LC_CTYPE, "")' <<-'EOF' 1256 #include <locale.h> 1257 #include <stddef.h> 1258 int main(void) { return ((int)(ptrdiff_t)(void *)setlocale(LC_CTYPE, "")); } 1259 EOF 1260 1261 ac_test langinfo_codeset setlocale_ctype 0 'nl_langinfo(CODESET)' <<-'EOF' 1262 #include <langinfo.h> 1263 #include <stddef.h> 1264 int main(void) { return ((int)(ptrdiff_t)(void *)nl_langinfo(CODESET)); } 1265 EOF 1266 1267 ac_test setmode mknod 1 <<-'EOF' 1268 /* XXX imake style */ 1269 /* XXX conditions correct? */ 1270 #if defined(__MSVCRT__) || defined(__CYGWIN__) 1271 /* force a failure: Win32 setmode() is not what we want... */ 1272 int main(void) { return (thiswillneverbedefinedIhope()); } 1273 #else 1274 #include <sys/types.h> 1275 #include <unistd.h> 1276 int main(int ac, char *av[]) { return (getmode(setmode(av[0]), 1277 (mode_t)ac)); } 1278 #endif 1279 EOF 1280 1281 ac_test setresugid <<-'EOF' 1282 #include <sys/types.h> 1283 #include <unistd.h> 1284 int main(void) { setresuid(0,0,0); return (setresgid(0,0,0)); } 1285 EOF 1286 1287 ac_test setgroups setresugid 0 <<-'EOF' 1288 #include <sys/types.h> 1289 #if HAVE_GRP_H 1290 #include <grp.h> 1291 #endif 1292 #include <unistd.h> 1293 int main(void) { gid_t gid = 0; return (setgroups(0, &gid)); } 1294 EOF 1295 1296 ac_test strcasestr <<-'EOF' 1297 #include <sys/types.h> 1298 #include <stddef.h> 1299 #include <string.h> 1300 #if HAVE_STRINGS_H 1301 #include <strings.h> 1302 #endif 1303 int main(int ac, char *av[]) { 1304 return ((int)(ptrdiff_t)(void *)strcasestr(*av, av[ac])); 1305 } 1306 EOF 1307 1308 ac_test strlcpy <<-'EOF' 1309 #include <string.h> 1310 int main(int ac, char *av[]) { return (strlcpy(*av, av[1], 1311 (size_t)ac)); } 1312 EOF 1313 1314 # 1315 # check headers for declarations 1316 # 1317 save_CC=$CC; save_LDFLAGS=$LDFLAGS; save_LIBS=$LIBS 1318 CC="$CC -c -o $tcfn"; LDFLAGS=; LIBS= 1319 ac_test '!' flock_decl flock_ex 1 'if flock() does not need to be declared' <<-'EOF' 1320 #define MKSH_INCLUDES_ONLY 1321 #include "sh.h" 1322 long flock(void); /* this clashes if defined before */ 1323 int main(void) { return ((int)flock()); } 1324 EOF 1325 ac_test '!' revoke_decl revoke 1 'if revoke() does not need to be declared' <<-'EOF' 1326 #define MKSH_INCLUDES_ONLY 1327 #include "sh.h" 1328 long revoke(void); /* this clashes if defined before */ 1329 int main(void) { return ((int)revoke()); } 1330 EOF 1331 ac_test sys_siglist_decl sys_siglist 1 'if sys_siglist[] does not need to be declared' <<-'EOF' 1332 #define MKSH_INCLUDES_ONLY 1333 #include "sh.h" 1334 int main(void) { return (sys_siglist[0][0]); } 1335 EOF 1336 CC=$save_CC; LDFLAGS=$save_LDFLAGS; LIBS=$save_LIBS 1337 1338 # 1339 # other checks 1340 # 1341 fd='if to use persistent history' 1342 ac_cache PERSISTENT_HISTORY || test 0 = $HAVE_FLOCK_EX || fv=1 1343 test 1 = $fv || check_categories=$check_categories,no-histfile 1344 ac_testdone 1345 ac_cppflags 1346 1347 # 1348 # Compiler: Praeprocessor (only if needed) 1349 # 1350 test 0 = $HAVE_SYS_SIGNAME && if ac_testinit cpp_dd '' \ 1351 'checking if the C Preprocessor supports -dD'; then 1352 echo '#define foo bar' >conftest.c 1353 vv ']' "$CPP $CFLAGS $CPPFLAGS $NOWARN -dD conftest.c >x" 1354 grep '#define foo bar' x >/dev/null 2>&1 && fv=1 1355 rmf conftest.c x vv.out 1356 ac_testdone 1357 fi 1358 1359 # 1360 # End of mirtoconf checks 1361 # 1362 $e ... done. 1363 1364 # Some operating systems have ancient versions of ed(1) writing 1365 # the character count to standard output; cope for that 1366 echo wq >x 1367 ed x <x 2>/dev/null | grep 3 >/dev/null 2>&1 && \ 1368 check_categories=$check_categories,$oldish_ed 1369 rmf x vv.out 1370 1371 if test 0 = $HAVE_SYS_SIGNAME; then 1372 if test 1 = $HAVE_CPP_DD; then 1373 $e Generating list of signal names... 1374 else 1375 $e No list of signal names available via cpp. Falling back... 1376 fi 1377 sigseen=: 1378 echo '#include <signal.h> 1379 #ifndef NSIG 1380 #if defined(_NSIG) 1381 #define NSIG _NSIG 1382 #elif defined(SIGMAX) 1383 #define NSIG (SIGMAX+1) 1384 #endif 1385 #endif 1386 mksh_cfg: NSIG' >conftest.c 1387 NSIG=`vq "$CPP $CFLAGS $CPPFLAGS $NOWARN conftest.c" | \ 1388 grep mksh_cfg: | sed 's/^mksh_cfg:[ ]*\([0-9x ()+-]*\).*$/\1/'` 1389 case $NSIG in 1390 *[\ \(\)+-]*) NSIG=`awk "BEGIN { print $NSIG }"` ;; 1391 esac 1392 printf=printf 1393 (printf hallo) >/dev/null 2>&1 || printf=echo 1394 test $printf = echo || NSIG=`printf %d "$NSIG" 2>/dev/null` 1395 $printf "NSIG=$NSIG ... " 1396 sigs="ABRT ALRM BUS CHLD CLD CONT DIL EMT FPE HUP ILL INFO INT IO IOT" 1397 sigs="$sigs KILL LOST PIPE PROF PWR QUIT RESV SAK SEGV STOP SYS TERM" 1398 sigs="$sigs TRAP TSTP TTIN TTOU URG USR1 USR2 VTALRM WINCH XCPU XFSZ" 1399 test 1 = $HAVE_CPP_DD && test $NSIG -gt 1 && sigs="$sigs "`vq \ 1400 "$CPP $CFLAGS $CPPFLAGS $NOWARN -dD conftest.c" | \ 1401 grep '[ ]SIG[A-Z0-9]*[ ]' | \ 1402 sed 's/^\(.*[ ]SIG\)\([A-Z0-9]*\)\([ ].*\)$/\2/' | sort` 1403 test $NSIG -gt 1 || sigs= 1404 for name in $sigs; do 1405 echo '#include <signal.h>' >conftest.c 1406 echo mksh_cfg: SIG$name >>conftest.c 1407 vq "$CPP $CFLAGS $CPPFLAGS $NOWARN conftest.c" | \ 1408 grep mksh_cfg: | \ 1409 sed 's/^mksh_cfg:[ ]*\([0-9x]*\).*$/\1:'$name/ 1410 done | grep -v '^:' | while IFS=: read nr name; do 1411 test $printf = echo || nr=`printf %d "$nr" 2>/dev/null` 1412 test $nr -gt 0 && test $nr -le $NSIG || continue 1413 case $sigseen in 1414 *:$nr:*) ;; 1415 *) echo " { \"$name\", $nr }," 1416 sigseen=$sigseen$nr: 1417 $printf "$name=$nr " >&2 1418 ;; 1419 esac 1420 done 2>&1 >signames.inc 1421 rmf conftest.c 1422 $e done. 1423 fi 1424 1425 addsrcs '!' HAVE_SETMODE setmode.c 1426 addsrcs '!' HAVE_STRLCPY strlcpy.c 1427 addsrcs USE_PRINTF_BUILTIN printf.c 1428 test 1 = "$USE_PRINTF_BUILTIN" && CPPFLAGS="$CPPFLAGS -DMKSH_PRINTF_BUILTIN" 1429 test 0 = "$HAVE_SETMODE" && CPPFLAGS="$CPPFLAGS -DHAVE_CONFIG_H -DCONFIG_H_FILENAME=\\\"sh.h\\\"" 1430 test 1 = "$HAVE_CAN_VERB" && CFLAGS="$CFLAGS -verbose" 1431 1432 $e $bi$me: Finished configuration testing, now producing output.$ao 1433 1434 files= 1435 objs= 1436 sp= 1437 case $curdir in 1438 *\ *) echo "#!./mksh" >test.sh ;; 1439 *) echo "#!$curdir/mksh" >test.sh ;; 1440 esac 1441 cat >>test.sh <<-EOF 1442 LC_ALL=C PATH='$PATH'; export LC_ALL PATH 1443 test -n "\$KSH_VERSION" || exit 1 1444 check_categories=$check_categories 1445 print Testing mksh for conformance: 1446 fgrep MirOS: '$srcdir/check.t' 1447 fgrep MIRBSD '$srcdir/check.t' 1448 print "This shell is actually:\\n\\t\$KSH_VERSION" 1449 print 'test.sh built for mksh $dstversion' 1450 cstr='\$os = defined \$^O ? \$^O : "unknown";' 1451 cstr="\$cstr"'print \$os . ", Perl version " . \$];' 1452 for perli in \$PERL perl5 perl no; do 1453 [[ \$perli = no ]] && exit 1 1454 perlos=\$(\$perli -e "\$cstr") 2>&- || continue 1455 print "Perl interpreter '\$perli' running on '\$perlos'" 1456 [[ -n \$perlos ]] && break 1457 done 1458 exec \$perli '$srcdir/check.pl' -s '$srcdir/check.t' -p '$curdir/mksh' \${check_categories:+-C} \${check_categories#,} \$*$tsts 1459 EOF 1460 chmod 755 test.sh 1461 test $HAVE_CAN_COMBINE$cm = 0combine && cm=normal 1462 if test $cm = llvm; then 1463 emitbc="-emit-llvm -c" 1464 elif test $cm = dragonegg; then 1465 emitbc="-S -flto" 1466 else 1467 emitbc=-c 1468 fi 1469 echo set -x >Rebuild.sh 1470 for file in $SRCS; do 1471 op=`echo x"$file" | sed 's/^x\(.*\)\.c$/\1./'` 1472 test -f $file || file=$srcdir/$file 1473 files="$files$sp$file" 1474 sp=' ' 1475 echo "$CC $CFLAGS $CPPFLAGS $emitbc $file || exit 1" >>Rebuild.sh 1476 if test $cm = dragonegg; then 1477 echo "mv ${op}s ${op}ll" >>Rebuild.sh 1478 echo "llvm-as ${op}ll || exit 1" >>Rebuild.sh 1479 objs="$objs$sp${op}bc" 1480 else 1481 objs="$objs$sp${op}o" 1482 fi 1483 done 1484 case $cm in 1485 dragonegg|llvm) 1486 echo "rm -f mksh.s" >>Rebuild.sh 1487 echo "llvm-link -o - $objs | opt $optflags | llc -o mksh.s" >>Rebuild.sh 1488 lobjs=mksh.s 1489 ;; 1490 *) 1491 lobjs=$objs 1492 ;; 1493 esac 1494 case $tcfn in 1495 a.exe) mkshexe=mksh.exe ;; 1496 *) mkshexe=mksh ;; 1497 esac 1498 echo tcfn=$mkshexe >>Rebuild.sh 1499 echo "$CC $CFLAGS $LDFLAGS -o \$tcfn $lobjs $LIBS $ccpr" >>Rebuild.sh 1500 echo 'test -f $tcfn || exit 1; size $tcfn' >>Rebuild.sh 1501 if test $cm = makefile; then 1502 extras='emacsfn.h sh.h sh_flags.h var_spec.h' 1503 test 0 = $HAVE_SYS_SIGNAME && extras="$extras signames.inc" 1504 cat >Makefrag.inc <<EOF 1505 # Makefile fragment for building mksh $dstversion 1506 1507 PROG= $mkshexe 1508 MAN= mksh.1 1509 SRCS= $SRCS 1510 SRCS_FP= $files 1511 OBJS_BP= $objs 1512 INDSRCS= $extras 1513 NONSRCS_INST= dot.mkshrc \$(MAN) 1514 NONSRCS_NOINST= Build.sh Makefile Rebuild.sh check.pl check.t test.sh 1515 CC= $CC 1516 CFLAGS= $CFLAGS 1517 CPPFLAGS= $CPPFLAGS 1518 LDFLAGS= $LDFLAGS 1519 LIBS= $LIBS 1520 1521 # not BSD make only: 1522 #VPATH= $srcdir 1523 #all: \$(PROG) 1524 #\$(PROG): \$(OBJS_BP) 1525 # \$(CC) \$(CFLAGS) \$(LDFLAGS) -o \$@ \$(OBJS_BP) \$(LIBS) 1526 #\$(OBJS_BP): \$(SRCS_FP) \$(NONSRCS) 1527 #.c.o: 1528 # \$(CC) \$(CFLAGS) \$(CPPFLAGS) -c \$< 1529 1530 # for all make variants: 1531 #REGRESS_FLAGS= -v 1532 #regress: 1533 # ./test.sh \$(REGRESS_FLAGS) 1534 1535 # for BSD make only: 1536 #.PATH: $srcdir 1537 #.include <bsd.prog.mk> 1538 EOF 1539 $e 1540 $e Generated Makefrag.inc successfully. 1541 exit 0 1542 fi 1543 if test $cm = combine; then 1544 objs="-o $mkshexe" 1545 for file in $SRCS; do 1546 test -f $file || file=$srcdir/$file 1547 objs="$objs $file" 1548 done 1549 emitbc="-fwhole-program --combine" 1550 v "$CC $CFLAGS $CPPFLAGS $LDFLAGS $emitbc $objs $LIBS $ccpr" 1551 elif test 1 = $pm; then 1552 for file in $SRCS; do 1553 test -f $file || file=$srcdir/$file 1554 v "$CC $CFLAGS $CPPFLAGS $emitbc $file" & 1555 done 1556 wait 1557 else 1558 for file in $SRCS; do 1559 test $cm = dragonegg && \ 1560 op=`echo x"$file" | sed 's/^x\(.*\)\.c$/\1./'` 1561 test -f $file || file=$srcdir/$file 1562 v "$CC $CFLAGS $CPPFLAGS $emitbc $file" || exit 1 1563 if test $cm = dragonegg; then 1564 v "mv ${op}s ${op}ll" 1565 v "llvm-as ${op}ll" || exit 1 1566 fi 1567 done 1568 fi 1569 case $cm in 1570 dragonegg|llvm) 1571 rmf mksh.s 1572 v "llvm-link -o - $objs | opt $optflags | llc -o mksh.s" 1573 ;; 1574 esac 1575 tcfn=$mkshexe 1576 test $cm = combine || v "$CC $CFLAGS $LDFLAGS -o $tcfn $lobjs $LIBS $ccpr" 1577 test -f $tcfn || exit 1 1578 test 1 = $r || v "$NROFF -mdoc <'$srcdir/mksh.1' >mksh.cat1" || \ 1579 rmf mksh.cat1 1580 test 0 = $eq && v size $tcfn 1581 i=install 1582 test -f /usr/ucb/$i && i=/usr/ucb/$i 1583 test 1 = $eq && e=: 1584 $e 1585 $e Installing the shell: 1586 $e "# $i -c -s -o root -g bin -m 555 mksh /bin/mksh" 1587 $e "# grep -x /bin/mksh /etc/shells >/dev/null || echo /bin/mksh >>/etc/shells" 1588 $e "# $i -c -o root -g bin -m 444 dot.mkshrc /usr/share/doc/mksh/examples/" 1589 $e 1590 $e Installing the manual: 1591 if test -f mksh.cat1; then 1592 $e "# $i -c -o root -g bin -m 444 mksh.cat1" \ 1593 "/usr/share/man/cat1/mksh.0" 1594 $e or 1595 fi 1596 $e "# $i -c -o root -g bin -m 444 mksh.1 /usr/share/man/man1/mksh.1" 1597 $e 1598 $e Run the regression test suite: ./test.sh 1599 $e Please also read the sample file dot.mkshrc and the fine manual. 1600 exit 0 1601