1 #!/bin/sh 2 srcversion='$MirOS: src/bin/mksh/Build.sh,v 1.622 2013/02/19 18:45:15 tg Exp $' 3 #- 4 # Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 5 # 2011, 2012, 2013 6 # Thorsten Glaser <tg (at] mirbsd.org> 7 # 8 # Provided that these terms and disclaimer and all copyright notices 9 # are retained or reproduced in an accompanying document, permission 10 # is granted to deal in this work without restriction, including un- 11 # limited rights to use, publicly perform, distribute, sell, modify, 12 # merge, give away, or sublicence. 13 # 14 # This work is provided "AS IS" and WITHOUT WARRANTY of any kind, to 15 # the utmost extent permitted by applicable law, neither express nor 16 # implied; without malicious intent or gross negligence. In no event 17 # may a licensor, author or contributor be held liable for indirect, 18 # direct, other damage, loss, or other issues arising in any way out 19 # of dealing in the work, even if advised of the possibility of such 20 # damage or existence of a defect, except proven that it results out 21 # of said person's immediate fault when using the work as intended. 22 #- 23 # People analysing the output must whitelist conftest.c for any kind 24 # of compiler warning checks (mirtoconf is by design not quiet). 25 # 26 # Used environment documentation is at the end of this file. 27 28 LC_ALL=C 29 export LC_ALL 30 31 case $ZSH_VERSION:$VERSION in 32 :zsh*) ZSH_VERSION=2 ;; 33 esac 34 35 if test -n "${ZSH_VERSION+x}" && (emulate sh) >/dev/null 2>&1; then 36 emulate sh 37 NULLCMD=: 38 fi 39 40 if test -d /usr/xpg4/bin/. >/dev/null 2>&1; then 41 # Solaris: some of the tools have weird behaviour, use portable ones 42 PATH=/usr/xpg4/bin:$PATH 43 export PATH 44 fi 45 46 v() { 47 $e "$*" 48 eval "$@" 49 } 50 51 vv() { 52 _c=$1 53 shift 54 $e "\$ $*" 2>&1 55 eval "$@" >vv.out 2>&1 56 sed "s^${_c} " <vv.out 57 } 58 59 vq() { 60 eval "$@" 61 } 62 63 rmf() { 64 for _f in "$@"; do 65 case $_f in 66 Build.sh|check.pl|check.t|dot.mkshrc|*.c|*.h|mksh.1) ;; 67 *) rm -f "$_f" ;; 68 esac 69 done 70 } 71 72 allu=QWERTYUIOPASDFGHJKLZXCVBNM 73 alll=qwertyuiopasdfghjklzxcvbnm 74 alln=0123456789 75 alls=______________________________________________________________ 76 nl=' 77 ' 78 tcfn=no 79 bi= 80 ui= 81 ao= 82 fx= 83 me=`basename "$0"` 84 orig_CFLAGS=$CFLAGS 85 phase=x 86 oldish_ed=stdout-ed,no-stderr-ed 87 88 if test -t 1; then 89 bi='[1m' 90 ui='[4m' 91 ao='[0m' 92 fi 93 94 upper() { 95 echo :"$@" | sed 's/^://' | tr $alll $allu 96 } 97 98 # clean up after ac_testrun() 99 ac_testdone() { 100 eval HAVE_$fu=$fv 101 fr=no 102 test 0 = $fv || fr=yes 103 $e "$bi==> $fd...$ao $ui$fr$ao$fx" 104 fx= 105 } 106 107 # ac_cache label: sets f, fu, fv?=0 108 ac_cache() { 109 f=$1 110 fu=`upper $f` 111 eval fv=\$HAVE_$fu 112 case $fv in 113 0|1) 114 fx=' (cached)' 115 return 0 116 ;; 117 esac 118 fv=0 119 return 1 120 } 121 122 # ac_testinit label [!] checkif[!]0 [setlabelifcheckis[!]0] useroutput 123 # returns 1 if value was cached/implied, 0 otherwise: call ac_testdone 124 ac_testinit() { 125 if ac_cache $1; then 126 test x"$2" = x"!" && shift 127 test x"$2" = x"" || shift 128 fd=${3-$f} 129 ac_testdone 130 return 1 131 fi 132 fc=0 133 if test x"$2" = x""; then 134 ft=1 135 else 136 if test x"$2" = x"!"; then 137 fc=1 138 shift 139 fi 140 eval ft=\$HAVE_`upper $2` 141 shift 142 fi 143 fd=${3-$f} 144 if test $fc = "$ft"; then 145 fv=$2 146 fx=' (implied)' 147 ac_testdone 148 return 1 149 fi 150 $e ... $fd 151 return 0 152 } 153 154 # pipe .c | ac_test[n] [!] label [!] checkif[!]0 [setlabelifcheckis[!]0] useroutput 155 ac_testnnd() { 156 if test x"$1" = x"!"; then 157 fr=1 158 shift 159 else 160 fr=0 161 fi 162 ac_testinit "$@" || return 1 163 cat >conftest.c 164 vv ']' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN conftest.c $LIBS $ccpr" 165 test $tcfn = no && test -f a.out && tcfn=a.out 166 test $tcfn = no && test -f a.exe && tcfn=a.exe 167 test $tcfn = no && test -f conftest && tcfn=conftest 168 if test -f $tcfn; then 169 test 1 = $fr || fv=1 170 else 171 test 0 = $fr || fv=1 172 fi 173 vscan= 174 if test $phase = u; then 175 test $ct = gcc && vscan='unrecogni[sz]ed' 176 test $ct = hpcc && vscan='unsupported' 177 test $ct = pcc && vscan='unsupported' 178 test $ct = sunpro && vscan='-e ignored -e turned.off' 179 fi 180 test -n "$vscan" && grep $vscan vv.out >/dev/null 2>&1 && fv=$fr 181 return 0 182 } 183 ac_testn() { 184 ac_testnnd "$@" || return 185 rmf conftest.c conftest.o ${tcfn}* vv.out 186 ac_testdone 187 } 188 189 # ac_ifcpp cppexpr [!] label [!] checkif[!]0 [setlabelifcheckis[!]0] useroutput 190 ac_ifcpp() { 191 expr=$1; shift 192 ac_testn "$@" <<-EOF 193 int main(void) { return ( 194 #$expr 195 0 196 #else 197 /* force a failure: expr is false */ 198 thiswillneverbedefinedIhope() 199 #endif 200 ); } 201 EOF 202 test x"$1" = x"!" && shift 203 f=$1 204 fu=`upper $f` 205 eval fv=\$HAVE_$fu 206 test x"$fv" = x"1" 207 } 208 209 add_cppflags() { 210 CPPFLAGS="$CPPFLAGS $*" 211 } 212 213 ac_cppflags() { 214 test x"$1" = x"" || fu=$1 215 fv=$2 216 test x"$2" = x"" && eval fv=\$HAVE_$fu 217 add_cppflags -DHAVE_$fu=$fv 218 } 219 220 ac_test() { 221 ac_testn "$@" 222 ac_cppflags 223 } 224 225 # ac_flags [-] add varname cflags [text] [ldflags] 226 ac_flags() { 227 if test x"$1" = x"-"; then 228 shift 229 hf=1 230 else 231 hf=0 232 fi 233 fa=$1 234 vn=$2 235 f=$3 236 ft=$4 237 fl=$5 238 test x"$ft" = x"" && ft="if $f can be used" 239 save_CFLAGS=$CFLAGS 240 CFLAGS="$CFLAGS $f" 241 if test -n "$fl"; then 242 save_LDFLAGS=$LDFLAGS 243 LDFLAGS="$LDFLAGS $fl" 244 fi 245 if test 1 = $hf; then 246 ac_testn can_$vn '' "$ft" 247 else 248 ac_testn can_$vn '' "$ft" <<-'EOF' 249 /* evil apo'stroph in comment test */ 250 int main(void) { return (0); } 251 EOF 252 fi 253 eval fv=\$HAVE_CAN_`upper $vn` 254 if test -n "$fl"; then 255 test 11 = $fa$fv || LDFLAGS=$save_LDFLAGS 256 fi 257 test 11 = $fa$fv || CFLAGS=$save_CFLAGS 258 } 259 260 # ac_header [!] header [prereq ...] 261 ac_header() { 262 if test x"$1" = x"!"; then 263 na=1 264 shift 265 else 266 na=0 267 fi 268 hf=$1; shift 269 hv=`echo "$hf" | tr -d '\012\015' | tr -c $alll$allu$alln $alls` 270 echo "/* NeXTstep bug workaround */" >x 271 for i 272 do 273 case $i in 274 _time) 275 echo '#if HAVE_BOTH_TIME_H' >>x 276 echo '#include <sys/time.h>' >>x 277 echo '#include <time.h>' >>x 278 echo '#elif HAVE_SYS_TIME_H' >>x 279 echo '#include <sys/time.h>' >>x 280 echo '#elif HAVE_TIME_H' >>x 281 echo '#include <time.h>' >>x 282 echo '#endif' >>x 283 ;; 284 *) 285 echo "#include <$i>" >>x 286 ;; 287 esac 288 done 289 echo "#include <$hf>" >>x 290 echo 'int main(void) { return (0); }' >>x 291 ac_testn "$hv" "" "<$hf>" <x 292 rmf x 293 test 1 = $na || ac_cppflags 294 } 295 296 addsrcs() { 297 addsrcs_s=0 298 if test x"$1" = x"-s"; then 299 # optstatic 300 addsrcs_s=1 301 shift 302 fi 303 if test x"$1" = x"!"; then 304 fr=0 305 shift 306 else 307 fr=1 308 fi 309 eval i=\$$1 310 if test $addsrcs_s = 1; then 311 if test -f "$2" || test -f "$srcdir/$2"; then 312 # always add $2, since it exists 313 fr=1 314 i=1 315 fi 316 fi 317 test $fr = "$i" && case " $SRCS " in 318 *\ $2\ *) ;; 319 *) SRCS="$SRCS $2" ;; 320 esac 321 } 322 323 324 curdir=`pwd` srcdir=`dirname "$0" 2>/dev/null` check_categories= 325 test -n "$srcdir" || srcdir=. # in case dirname does not exist 326 dstversion=`sed -n '/define MKSH_VERSION/s/^.*"\([^"]*\)".*$/\1/p' $srcdir/sh.h` 327 add_cppflags -DMKSH_BUILDSH 328 329 e=echo 330 r=0 331 eq=0 332 pm=0 333 cm=normal 334 optflags=-std-compile-opts 335 last= 336 tfn= 337 legacy=0 338 339 for i 340 do 341 case $last:$i in 342 c:combine|c:dragonegg|c:llvm|c:lto) 343 cm=$i 344 last= 345 ;; 346 c:*) 347 echo "$me: Unknown option -c '$i'!" >&2 348 exit 1 349 ;; 350 o:*) 351 optflags=$i 352 last= 353 ;; 354 t:*) 355 tfn=$i 356 last= 357 ;; 358 :-c) 359 last=c 360 ;; 361 :-g) 362 # checker, debug, valgrind build 363 add_cppflags -DDEBUG 364 CFLAGS="$CFLAGS -g3 -fno-builtin" 365 ;; 366 :-j) 367 pm=1 368 ;; 369 :-L) 370 legacy=1 371 ;; 372 :+L) 373 legacy=0 374 ;; 375 :-M) 376 cm=makefile 377 ;; 378 :-O) 379 optflags=-std-compile-opts 380 ;; 381 :-o) 382 last=o 383 ;; 384 :-Q) 385 eq=1 386 ;; 387 :-r) 388 r=1 389 ;; 390 :-t) 391 last=t 392 ;; 393 :-v) 394 echo "Build.sh $srcversion" 395 echo "for mksh $dstversion" 396 exit 0 397 ;; 398 :*) 399 echo "$me: Unknown option '$i'!" >&2 400 exit 1 401 ;; 402 *) 403 echo "$me: Unknown option -'$last' '$i'!" >&2 404 exit 1 405 ;; 406 esac 407 done 408 if test -n "$last"; then 409 echo "$me: Option -'$last' not followed by argument!" >&2 410 exit 1 411 fi 412 413 test -z "$tfn" && if test $legacy = 0; then 414 tfn=mksh 415 else 416 tfn=lksh 417 fi 418 if test -d $tfn || test -d $tfn.exe; then 419 echo "$me: Error: ./$tfn is a directory!" >&2 420 exit 1 421 fi 422 rmf a.exe* a.out* conftest.c *core core.* lft ${tfn}* no *.bc *.ll *.o \ 423 Rebuild.sh signames.inc test.sh x vv.out 424 425 SRCS="lalloc.c eval.c exec.c expr.c funcs.c histrap.c jobs.c" 426 SRCS="$SRCS lex.c main.c misc.c shf.c syn.c tree.c var.c" 427 428 if test $legacy = 0; then 429 SRCS="$SRCS edit.c" 430 check_categories="$check_categories shell:legacy-no int:32" 431 else 432 check_categories="$check_categories shell:legacy-yes" 433 add_cppflags -DMKSH_LEGACY_MODE 434 HAVE_PERSISTENT_HISTORY=0 435 HAVE_ISSET_MKSH_CONSERVATIVE_FDS=1 # from sh.h 436 fi 437 438 if test x"$srcdir" = x"."; then 439 CPPFLAGS="-I. $CPPFLAGS" 440 else 441 CPPFLAGS="-I. -I'$srcdir' $CPPFLAGS" 442 fi 443 test -n "$LDSTATIC" && if test -n "$LDFLAGS"; then 444 LDFLAGS="$LDFLAGS $LDSTATIC" 445 else 446 LDFLAGS=$LDSTATIC 447 fi 448 449 if test -z "$TARGET_OS"; then 450 x=`uname -s 2>/dev/null || uname` 451 test x"$x" = x"`uname -n 2>/dev/null`" || TARGET_OS=$x 452 fi 453 if test -z "$TARGET_OS"; then 454 echo "$me: Set TARGET_OS, your uname is broken!" >&2 455 exit 1 456 fi 457 oswarn= 458 ccpc=-Wc, 459 ccpl=-Wl, 460 tsts= 461 ccpr='|| for _f in ${tcfn}*; do case $_f in Build.sh|check.pl|check.t|dot.mkshrc|*.c|*.h|mksh.1) ;; *) rm -f "$_f" ;; esac; done' 462 463 # Evil hack 464 if test x"$TARGET_OS" = x"Android"; then 465 check_categories="$check_categories android" 466 TARGET_OS=Linux 467 fi 468 469 # Evil OS 470 if test x"$TARGET_OS" = x"Minix"; then 471 echo >&2 " 472 WARNING: additional checks before running Build.sh required! 473 You can avoid these by calling Build.sh correctly, see below. 474 " 475 cat >conftest.c <<'EOF' 476 #include <sys/types.h> 477 const char * 478 #ifdef _NETBSD_SOURCE 479 ct="Ninix3" 480 #else 481 ct="Minix3" 482 #endif 483 ; 484 EOF 485 ct=unknown 486 vv ']' "${CC-cc} -E $CFLAGS $CPPFLAGS $NOWARN conftest.c | grep ct= | tr -d \\\\015 >x" 487 sed 's/^/[ /' x 488 eval `cat x` 489 rmf x vv.out 490 case $ct in 491 Minix3|Ninix3) 492 echo >&2 " 493 Warning: you set TARGET_OS to $TARGET_OS but that is ambiguous. 494 Please set it to either Minix3 or Ninix3, whereas the latter is 495 all versions of Minix with even partial NetBSD(R) userland. The 496 value determined from your compiler for the current compilation 497 (which may be wrong) is: $ct 498 " 499 TARGET_OS=$ct 500 ;; 501 *) 502 echo >&2 " 503 Warning: you set TARGET_OS to $TARGET_OS but that is ambiguous. 504 Please set it to either Minix3 or Ninix3, whereas the latter is 505 all versions of Minix with even partial NetBSD(R) userland. The 506 proper value couldn't be determined, continue at your own risk. 507 " 508 ;; 509 esac 510 fi 511 512 # Configuration depending on OS revision, on OSes that need them 513 case $TARGET_OS in 514 NEXTSTEP) 515 test x"$TARGET_OSREV" = x"" && TARGET_OSREV=`hostinfo 2>&1 | \ 516 grep 'NeXT Mach [0-9][0-9.]*:' | \ 517 sed 's/^.*NeXT Mach \([0-9][0-9.]*\):.*$/\1/'` 518 ;; 519 QNX|SCO_SV) 520 test x"$TARGET_OSREV" = x"" && TARGET_OSREV=`uname -r` 521 ;; 522 esac 523 524 # Configuration depending on OS name 525 case $TARGET_OS in 526 386BSD) 527 : ${HAVE_CAN_OTWO=0} 528 add_cppflags -DMKSH_NO_SIGSETJMP 529 add_cppflags -DMKSH_TYPEDEF_SIG_ATOMIC_T=int 530 add_cppflags -DMKSH_CONSERVATIVE_FDS 531 ;; 532 AIX) 533 add_cppflags -D_ALL_SOURCE 534 : ${HAVE_SETLOCALE_CTYPE=0} 535 ;; 536 BeOS) 537 case $KSH_VERSION in 538 *MIRBSD\ KSH*) 539 oswarn="; it has minor issues" 540 ;; 541 *) 542 oswarn="; you must recompile mksh with" 543 oswarn="$oswarn${nl}itself in a second stage" 544 ;; 545 esac 546 # BeOS has no real tty either 547 add_cppflags -DMKSH_UNEMPLOYED 548 add_cppflags -DMKSH_DISABLE_TTY_WARNING 549 # BeOS doesn't have different UIDs and GIDs 550 add_cppflags -DMKSH__NO_SETEUGID 551 ;; 552 BSD/OS) 553 : ${HAVE_SETLOCALE_CTYPE=0} 554 ;; 555 Coherent) 556 oswarn="; it has major issues" 557 add_cppflags -DMKSH__NO_SYMLINK 558 check_categories="$check_categories nosymlink" 559 add_cppflags -DMKSH__NO_SETEUGID 560 add_cppflags -DMKSH_CONSERVATIVE_FDS 561 add_cppflags -DMKSH_DISABLE_TTY_WARNING 562 ;; 563 CYGWIN*) 564 : ${HAVE_SETLOCALE_CTYPE=0} 565 ;; 566 Darwin) 567 add_cppflags -D_DARWIN_C_SOURCE 568 ;; 569 DragonFly) 570 ;; 571 FreeBSD) 572 ;; 573 FreeMiNT) 574 oswarn="; it has minor issues" 575 add_cppflags -D_GNU_SOURCE 576 add_cppflags -DMKSH_CONSERVATIVE_FDS 577 : ${HAVE_SETLOCALE_CTYPE=0} 578 ;; 579 GNU) 580 case $CC in 581 *tendracc*) ;; 582 *) add_cppflags -D_GNU_SOURCE ;; 583 esac 584 # define MKSH__NO_PATH_MAX to use Hurd-only functions 585 add_cppflags -DMKSH__NO_PATH_MAX 586 ;; 587 GNU/kFreeBSD) 588 case $CC in 589 *tendracc*) ;; 590 *) add_cppflags -D_GNU_SOURCE ;; 591 esac 592 ;; 593 Haiku) 594 add_cppflags -DMKSH_ASSUME_UTF8; HAVE_ISSET_MKSH_ASSUME_UTF8=1 595 ;; 596 HP-UX) 597 ;; 598 Interix) 599 ccpc='-X ' 600 ccpl='-Y ' 601 add_cppflags -D_ALL_SOURCE 602 : ${LIBS='-lcrypt'} 603 : ${HAVE_SETLOCALE_CTYPE=0} 604 ;; 605 IRIX*) 606 : ${HAVE_SETLOCALE_CTYPE=0} 607 ;; 608 Linux) 609 case $CC in 610 *tendracc*) ;; 611 *) add_cppflags -D_GNU_SOURCE ;; 612 esac 613 add_cppflags -DSETUID_CAN_FAIL_WITH_EAGAIN 614 : ${HAVE_REVOKE=0} 615 ;; 616 LynxOS) 617 oswarn="; it has minor issues" 618 ;; 619 MidnightBSD) 620 ;; 621 Minix-vmd) 622 add_cppflags -DMKSH__NO_SETEUGID 623 add_cppflags -DMKSH_UNEMPLOYED 624 add_cppflags -DMKSH_CONSERVATIVE_FDS 625 add_cppflags -D_MINIX_SOURCE 626 oldish_ed=no-stderr-ed # no /bin/ed, maybe see below 627 : ${HAVE_SETLOCALE_CTYPE=0} 628 ;; 629 Minix3) 630 add_cppflags -DMKSH_UNEMPLOYED 631 add_cppflags -DMKSH_CONSERVATIVE_FDS 632 add_cppflags -DMKSH_NO_LIMITS 633 add_cppflags -D_POSIX_SOURCE -D_POSIX_1_SOURCE=2 -D_MINIX 634 oldish_ed=no-stderr-ed # /usr/bin/ed(!) is broken 635 : ${HAVE_SETLOCALE_CTYPE=0} 636 ;; 637 MirBSD) 638 ;; 639 MSYS_*) 640 add_cppflags -DMKSH_ASSUME_UTF8=0; HAVE_ISSET_MKSH_ASSUME_UTF8=1 641 # almost same as CYGWIN* (from RT|Chatzilla) 642 : ${HAVE_SETLOCALE_CTYPE=0} 643 # broken on this OE (from ir0nh34d) 644 : ${HAVE_STDINT_H=0} 645 ;; 646 NetBSD) 647 ;; 648 NEXTSTEP) 649 add_cppflags -D_NEXT_SOURCE 650 add_cppflags -D_POSIX_SOURCE 651 : ${AWK=gawk} ${CC=cc -posix} 652 add_cppflags -DMKSH_NO_SIGSETJMP 653 # NeXTstep cannot get a controlling tty 654 add_cppflags -DMKSH_UNEMPLOYED 655 case $TARGET_OSREV in 656 4.2*) 657 # OpenStep 4.2 is broken by default 658 oswarn="; it needs libposix.a" 659 ;; 660 esac 661 add_cppflags -DMKSH_CONSERVATIVE_FDS 662 ;; 663 Ninix3) 664 # similar to Minix3 665 add_cppflags -DMKSH_UNEMPLOYED 666 add_cppflags -DMKSH_CONSERVATIVE_FDS 667 add_cppflags -DMKSH_NO_LIMITS 668 # but no idea what else could be needed 669 oswarn="; it has unknown issues" 670 ;; 671 OpenBSD) 672 : ${HAVE_SETLOCALE_CTYPE=0} 673 ;; 674 OSF1) 675 HAVE_SIG_T=0 # incompatible 676 add_cppflags -D_OSF_SOURCE 677 add_cppflags -D_POSIX_C_SOURCE=200112L 678 add_cppflags -D_XOPEN_SOURCE=600 679 add_cppflags -D_XOPEN_SOURCE_EXTENDED 680 : ${HAVE_SETLOCALE_CTYPE=0} 681 ;; 682 Plan9) 683 add_cppflags -D_POSIX_SOURCE 684 add_cppflags -D_LIMITS_EXTENSION 685 add_cppflags -D_BSD_EXTENSION 686 add_cppflags -D_SUSV2_SOURCE 687 add_cppflags -DMKSH_ASSUME_UTF8; HAVE_ISSET_MKSH_ASSUME_UTF8=1 688 add_cppflags -DMKSH_NO_CMDLINE_EDITING 689 oswarn=' and will currently not work' 690 add_cppflags -DMKSH_UNEMPLOYED 691 ;; 692 PW32*) 693 HAVE_SIG_T=0 # incompatible 694 oswarn=' and will currently not work' 695 : ${HAVE_SETLOCALE_CTYPE=0} 696 ;; 697 QNX) 698 add_cppflags -D__NO_EXT_QNX 699 add_cppflags -D__EXT_UNIX_MISC 700 case $TARGET_OSREV in 701 [012345].*|6.[0123].*|6.4.[01]) 702 oldish_ed=no-stderr-ed # oldish /bin/ed is broken 703 ;; 704 esac 705 : ${HAVE_SETLOCALE_CTYPE=0} 706 ;; 707 SCO_SV) 708 case $TARGET_OSREV in 709 3.2*) 710 # SCO OpenServer 5 711 add_cppflags -DMKSH_UNEMPLOYED 712 ;; 713 5*) 714 # SCO OpenServer 6 715 ;; 716 *) 717 oswarn='; this is an unknown version of' 718 oswarn="$oswarn$nl$TARGET_OS ${TARGET_OSREV}, please tell me what to do" 719 ;; 720 esac 721 add_cppflags -DMKSH_CONSERVATIVE_FDS 722 : ${HAVE_SYS_SIGLIST=0} ${HAVE__SYS_SIGLIST=0} 723 ;; 724 skyos) 725 oswarn="; it has minor issues" 726 ;; 727 SunOS) 728 add_cppflags -D_BSD_SOURCE 729 add_cppflags -D__EXTENSIONS__ 730 ;; 731 syllable) 732 add_cppflags -D_GNU_SOURCE 733 add_cppflags -DMKSH_NO_SIGSUSPEND 734 oswarn=' and will currently not work' 735 ;; 736 ULTRIX) 737 : ${CC=cc -YPOSIX} 738 add_cppflags -DMKSH_TYPEDEF_SSIZE_T=int 739 add_cppflags -DMKSH_CONSERVATIVE_FDS 740 : ${HAVE_SETLOCALE_CTYPE=0} 741 ;; 742 UnixWare|UNIX_SV) 743 # SCO UnixWare 744 add_cppflags -DMKSH_CONSERVATIVE_FDS 745 : ${HAVE_SYS_SIGLIST=0} ${HAVE__SYS_SIGLIST=0} 746 ;; 747 UWIN*) 748 ccpc='-Yc,' 749 ccpl='-Yl,' 750 tsts=" 3<>/dev/tty" 751 oswarn="; it will compile, but the target" 752 oswarn="$oswarn${nl}platform itself is very flakey/unreliable" 753 : ${HAVE_SETLOCALE_CTYPE=0} 754 ;; 755 _svr4) 756 # generic target for SVR4 Unix with uname -s = uname -n 757 # this duplicates the * target below 758 oswarn='; it may or may not work' 759 test x"$TARGET_OSREV" = x"" && TARGET_OSREV=`uname -r` 760 ;; 761 *) 762 oswarn='; it may or may not work' 763 test x"$TARGET_OSREV" = x"" && TARGET_OSREV=`uname -r` 764 ;; 765 esac 766 767 : ${HAVE_MKNOD=0} 768 769 : ${AWK=awk} ${CC=cc} ${NROFF=nroff} 770 test 0 = $r && echo | $NROFF -v 2>&1 | grep GNU >/dev/null 2>&1 && \ 771 NROFF="$NROFF -c" 772 773 # this aids me in tracing FTBFSen without access to the buildd 774 $e "Hi from$ao $bi$srcversion$ao on:" 775 case $TARGET_OS in 776 AIX) 777 vv '|' "oslevel >&2" 778 vv '|' "uname -a >&2" 779 ;; 780 Darwin) 781 vv '|' "hwprefs machine_type os_type os_class >&2" 782 vv '|' "uname -a >&2" 783 ;; 784 IRIX*) 785 vv '|' "uname -a >&2" 786 vv '|' "hinv -v >&2" 787 ;; 788 OSF1) 789 vv '|' "uname -a >&2" 790 vv '|' "/usr/sbin/sizer -v >&2" 791 ;; 792 SCO_SV|UnixWare|UNIX_SV) 793 vv '|' "uname -a >&2" 794 vv '|' "uname -X >&2" 795 ;; 796 *) 797 vv '|' "uname -a >&2" 798 ;; 799 esac 800 test -z "$oswarn" || echo >&2 " 801 Warning: mksh has not yet been ported to or tested on your 802 operating system '$TARGET_OS'$oswarn. If you can provide 803 a shell account to the developer, this may improve; please 804 drop us a success or failure notice or even send in diffs. 805 " 806 $e "$bi$me: Building the MirBSD Korn Shell$ao $ui$dstversion$ao on $TARGET_OS ${TARGET_OSREV}..." 807 808 # 809 # Begin of mirtoconf checks 810 # 811 $e $bi$me: Scanning for functions... please ignore any errors.$ao 812 813 # 814 # Compiler: which one? 815 # 816 # notes: 817 # - ICC defines __GNUC__ too 818 # - GCC defines __hpux too 819 # - LLVM+clang defines __GNUC__ too 820 # - nwcc defines __GNUC__ too 821 CPP="$CC -E" 822 $e ... which compiler seems to be used 823 cat >conftest.c <<'EOF' 824 const char * 825 #if defined(__ICC) || defined(__INTEL_COMPILER) 826 ct="icc" 827 #elif defined(__xlC__) || defined(__IBMC__) 828 ct="xlc" 829 #elif defined(__SUNPRO_C) 830 ct="sunpro" 831 #elif defined(__ACK__) 832 ct="ack" 833 #elif defined(__BORLANDC__) 834 ct="bcc" 835 #elif defined(__WATCOMC__) 836 ct="watcom" 837 #elif defined(__MWERKS__) 838 ct="metrowerks" 839 #elif defined(__HP_cc) 840 ct="hpcc" 841 #elif defined(__DECC) || (defined(__osf__) && !defined(__GNUC__)) 842 ct="dec" 843 #elif defined(__PGI) 844 ct="pgi" 845 #elif defined(__DMC__) 846 ct="dmc" 847 #elif defined(_MSC_VER) 848 ct="msc" 849 #elif defined(__ADSPBLACKFIN__) || defined(__ADSPTS__) || defined(__ADSP21000__) 850 ct="adsp" 851 #elif defined(__IAR_SYSTEMS_ICC__) 852 ct="iar" 853 #elif defined(SDCC) 854 ct="sdcc" 855 #elif defined(__PCC__) 856 ct="pcc" 857 #elif defined(__TenDRA__) 858 ct="tendra" 859 #elif defined(__TINYC__) 860 ct="tcc" 861 #elif defined(__llvm__) && defined(__clang__) 862 ct="clang" 863 #elif defined(__NWCC__) 864 ct="nwcc" 865 #elif defined(__GNUC__) 866 ct="gcc" 867 #elif defined(_COMPILER_VERSION) 868 ct="mipspro" 869 #elif defined(__sgi) 870 ct="mipspro" 871 #elif defined(__hpux) || defined(__hpua) 872 ct="hpcc" 873 #elif defined(__ultrix) 874 ct="ucode" 875 #elif defined(__USLC__) 876 ct="uslc" 877 #elif defined(__LCC__) 878 ct="lcc" 879 #else 880 ct="unknown" 881 #endif 882 ; 883 const char * 884 #if defined(__KLIBC__) 885 et="klibc" 886 #else 887 et="unknown" 888 #endif 889 ; 890 EOF 891 ct=untested 892 et=untested 893 vv ']' "$CPP $CFLAGS $CPPFLAGS $NOWARN conftest.c | \ 894 sed -n '/^ *[ce]t *= */s/^ *\([ce]t\) *= */\1=/p' | tr -d \\\\015 >x" 895 sed 's/^/[ /' x 896 eval `cat x` 897 rmf x vv.out 898 echo 'int main(void) { return (0); }' >conftest.c 899 case $ct in 900 ack) 901 # work around "the famous ACK const bug" 902 CPPFLAGS="-Dconst= $CPPFLAGS" 903 ;; 904 adsp) 905 echo >&2 'Warning: Analog Devices C++ compiler for Blackfin, TigerSHARC 906 and SHARC (21000) DSPs detected. This compiler has not yet 907 been tested for compatibility with mksh. Continue at your 908 own risk, please report success/failure to the developers.' 909 ;; 910 bcc) 911 echo >&2 "Warning: Borland C++ Builder detected. This compiler might 912 produce broken executables. Continue at your own risk, 913 please report success/failure to the developers." 914 ;; 915 clang) 916 # does not work with current "ccc" compiler driver 917 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -version" 918 # one of these two works, for now 919 vv '|' "${CLANG-clang} -version" 920 vv '|' "${CLANG-clang} --version" 921 # ensure compiler and linker are in sync unless overridden 922 case $CCC_CC:$CCC_LD in 923 :*) ;; 924 *:) CCC_LD=$CCC_CC; export CCC_LD ;; 925 esac 926 ;; 927 dec) 928 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -V" 929 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN -Wl,-V conftest.c $LIBS" 930 ;; 931 dmc) 932 echo >&2 "Warning: Digital Mars Compiler detected. When running under" 933 echo >&2 " UWIN, mksh tends to be unstable due to the limitations" 934 echo >&2 " of this platform. Continue at your own risk," 935 echo >&2 " please report success/failure to the developers." 936 ;; 937 gcc) 938 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN -v conftest.c $LIBS" 939 vv '|' 'echo `$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS \ 940 -dumpmachine` gcc`$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN \ 941 $LIBS -dumpversion`' 942 ;; 943 hpcc) 944 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN -V conftest.c $LIBS" 945 ;; 946 iar) 947 echo >&2 'Warning: IAR Systems (http://www.iar.com) compiler for embedded 948 systems detected. This unsupported compiler has not yet 949 been tested for compatibility with mksh. Continue at your 950 own risk, please report success/failure to the developers.' 951 ;; 952 icc) 953 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -V" 954 ;; 955 lcc) 956 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN -v conftest.c $LIBS" 957 add_cppflags -D__inline__=__inline 958 ;; 959 metrowerks) 960 echo >&2 'Warning: Metrowerks C compiler detected. This has not yet 961 been tested for compatibility with mksh. Continue at your 962 own risk, please report success/failure to the developers.' 963 ;; 964 mipspro) 965 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -version" 966 ;; 967 msc) 968 ccpr= # errorlevels are not reliable 969 case $TARGET_OS in 970 Interix) 971 if [[ -n $C89_COMPILER ]]; then 972 C89_COMPILER=`ntpath2posix -c "$C89_COMPILER"` 973 else 974 C89_COMPILER=CL.EXE 975 fi 976 if [[ -n $C89_LINKER ]]; then 977 C89_LINKER=`ntpath2posix -c "$C89_LINKER"` 978 else 979 C89_LINKER=LINK.EXE 980 fi 981 vv '|' "$C89_COMPILER /HELP >&2" 982 vv '|' "$C89_LINKER /LINK >&2" 983 ;; 984 esac 985 ;; 986 nwcc) 987 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -version" 988 ;; 989 pcc) 990 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -v" 991 ;; 992 pgi) 993 echo >&2 'Warning: PGI detected. This unknown compiler has not yet 994 been tested for compatibility with mksh. Continue at your 995 own risk, please report success/failure to the developers.' 996 ;; 997 sdcc) 998 echo >&2 'Warning: sdcc (http://sdcc.sourceforge.net), the small devices 999 C compiler for embedded systems detected. This has not yet 1000 been tested for compatibility with mksh. Continue at your 1001 own risk, please report success/failure to the developers.' 1002 ;; 1003 sunpro) 1004 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN -V conftest.c $LIBS" 1005 ;; 1006 tcc) 1007 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -v" 1008 ;; 1009 tendra) 1010 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -V 2>&1 | \ 1011 fgrep -i -e version -e release" 1012 ;; 1013 ucode) 1014 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -V" 1015 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN -Wl,-V conftest.c $LIBS" 1016 ;; 1017 uslc) 1018 case $TARGET_OS:$TARGET_OSREV in 1019 SCO_SV:3.2*) 1020 # SCO OpenServer 5 1021 CFLAGS="$CFLAGS -g" 1022 : ${HAVE_CAN_OTWO=0} ${HAVE_CAN_OPTIMISE=0} 1023 ;; 1024 esac 1025 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN -V conftest.c $LIBS" 1026 ;; 1027 watcom) 1028 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN -v conftest.c $LIBS" 1029 ;; 1030 xlc) 1031 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -qversion" 1032 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -qversion=verbose" 1033 vv '|' "ld -V" 1034 ;; 1035 *) 1036 test x"$ct" = x"untested" && $e "!!! detecting preprocessor failed" 1037 ct=unknown 1038 vv "$CC --version" 1039 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN -v conftest.c $LIBS" 1040 vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN -V conftest.c $LIBS" 1041 ;; 1042 esac 1043 case $cm in 1044 dragonegg|llvm) 1045 vv '|' "llc -version" 1046 ;; 1047 esac 1048 case $et in 1049 klibc) 1050 add_cppflags -DMKSH_NO_LIMITS 1051 ;; 1052 unknown) 1053 # nothing special detected, dont worry 1054 unset et 1055 ;; 1056 *) 1057 # huh? 1058 ;; 1059 esac 1060 $e "$bi==> which compiler seems to be used...$ao $ui$ct${et+ on $et}$ao" 1061 rmf conftest.c conftest.o conftest a.out* a.exe* vv.out 1062 1063 # 1064 # Compiler: works as-is, with -Wno-error and -Werror 1065 # 1066 save_NOWARN=$NOWARN 1067 NOWARN= 1068 DOWARN= 1069 ac_flags 0 compiler_works '' 'if the compiler works' 1070 test 1 = $HAVE_CAN_COMPILER_WORKS || exit 1 1071 HAVE_COMPILER_KNOWN=0 1072 test $ct = unknown || HAVE_COMPILER_KNOWN=1 1073 if ac_ifcpp 'if 0' compiler_fails '' \ 1074 'if the compiler does not fail correctly'; then 1075 save_CFLAGS=$CFLAGS 1076 : ${HAVE_CAN_DELEXE=x} 1077 if test $ct = dmc; then 1078 CFLAGS="$CFLAGS ${ccpl}/DELEXECUTABLE" 1079 ac_testn can_delexe compiler_fails 0 'for the /DELEXECUTABLE linker option' <<-EOF 1080 int main(void) { return (0); } 1081 EOF 1082 elif test $ct = dec; then 1083 CFLAGS="$CFLAGS ${ccpl}-non_shared" 1084 ac_testn can_delexe compiler_fails 0 'for the -non_shared linker option' <<-EOF 1085 int main(void) { return (0); } 1086 EOF 1087 else 1088 exit 1 1089 fi 1090 test 1 = $HAVE_CAN_DELEXE || CFLAGS=$save_CFLAGS 1091 ac_testn compiler_still_fails '' 'if the compiler still does not fail correctly' <<-EOF 1092 EOF 1093 test 1 = $HAVE_COMPILER_STILL_FAILS && exit 1 1094 fi 1095 if ac_ifcpp 'ifdef __TINYC__' couldbe_tcc '!' compiler_known 0 \ 1096 'if this could be tcc'; then 1097 ct=tcc 1098 CPP='cpp -D__TINYC__' 1099 HAVE_COMPILER_KNOWN=1 1100 fi 1101 1102 if test $ct = sunpro; then 1103 test x"$save_NOWARN" = x"" && save_NOWARN='-errwarn=%none' 1104 ac_flags 0 errwarnnone "$save_NOWARN" 1105 test 1 = $HAVE_CAN_ERRWARNNONE || save_NOWARN= 1106 ac_flags 0 errwarnall "-errwarn=%all" 1107 test 1 = $HAVE_CAN_ERRWARNALL && DOWARN="-errwarn=%all" 1108 elif test $ct = hpcc; then 1109 save_NOWARN= 1110 DOWARN=+We 1111 elif test $ct = mipspro; then 1112 save_NOWARN= 1113 DOWARN="-diag_error 1-10000" 1114 elif test $ct = msc; then 1115 save_NOWARN="${ccpc}/w" 1116 DOWARN="${ccpc}/WX" 1117 elif test $ct = dmc; then 1118 save_NOWARN="${ccpc}-w" 1119 DOWARN="${ccpc}-wx" 1120 elif test $ct = bcc; then 1121 save_NOWARN="${ccpc}-w" 1122 DOWARN="${ccpc}-w!" 1123 elif test $ct = dec; then 1124 : -msg_* flags not used yet, or is -w2 correct? 1125 elif test $ct = xlc; then 1126 save_NOWARN=-qflag=i:e 1127 DOWARN=-qflag=i:i 1128 elif test $ct = tendra; then 1129 save_NOWARN=-w 1130 elif test $ct = ucode; then 1131 save_NOWARN= 1132 DOWARN=-w2 1133 elif test $ct = watcom; then 1134 save_NOWARN= 1135 DOWARN=-Wc,-we 1136 else 1137 test x"$save_NOWARN" = x"" && save_NOWARN=-Wno-error 1138 ac_flags 0 wnoerror "$save_NOWARN" 1139 test 1 = $HAVE_CAN_WNOERROR || save_NOWARN= 1140 ac_flags 0 werror -Werror 1141 test 1 = $HAVE_CAN_WERROR && DOWARN=-Werror 1142 fi 1143 1144 test $ct = icc && DOWARN="$DOWARN -wd1419" 1145 NOWARN=$save_NOWARN 1146 1147 # 1148 # Compiler: extra flags (-O2 -f* -W* etc.) 1149 # 1150 i=`echo :"$orig_CFLAGS" | sed 's/^://' | tr -c -d $alll$allu$alln` 1151 # optimisation: only if orig_CFLAGS is empty 1152 test x"$i" = x"" && if test $ct = sunpro; then 1153 cat >x <<-'EOF' 1154 int main(void) { return (0); } 1155 #define __IDSTRING_CONCAT(l,p) __LINTED__ ## l ## _ ## p 1156 #define __IDSTRING_EXPAND(l,p) __IDSTRING_CONCAT(l,p) 1157 #define pad void __IDSTRING_EXPAND(__LINE__,x)(void) { } 1158 EOF 1159 yes pad | head -n 256 >>x 1160 ac_flags - 1 otwo -xO2 <x 1161 rmf x 1162 elif test $ct = hpcc; then 1163 phase=u 1164 ac_flags 1 otwo +O2 1165 phase=x 1166 elif test $ct = xlc; then 1167 ac_flags 1 othree "-O3 -qstrict" 1168 test 1 = $HAVE_CAN_OTHREE || ac_flags 1 otwo -O2 1169 elif test $ct = tcc || test $ct = tendra; then 1170 : no special optimisation 1171 else 1172 ac_flags 1 otwo -O2 1173 test 1 = $HAVE_CAN_OTWO || ac_flags 1 optimise -O 1174 fi 1175 # other flags: just add them if they are supported 1176 i=0 1177 if test $ct = gcc; then 1178 # The following tests run with -Werror (gcc only) if possible 1179 NOWARN=$DOWARN; phase=u 1180 ac_flags 0 wnooverflow -Wno-overflow 1181 # mksh is not written in CFrustFrust! 1182 ac_flags 1 no_eh_frame -fno-asynchronous-unwind-tables 1183 ac_flags 1 fnostrictaliasing -fno-strict-aliasing 1184 ac_flags 1 fstackprotectorall -fstack-protector-all 1185 test $cm = dragonegg && case " $CC $CFLAGS $LDFLAGS " in 1186 *\ -fplugin=*dragonegg*) ;; 1187 *) ac_flags 1 fplugin_dragonegg -fplugin=dragonegg ;; 1188 esac 1189 if test $cm = lto; then 1190 fv=0 1191 checks='1 2 3 4 5 6 7 8' 1192 elif test $cm = combine; then 1193 fv=0 1194 checks='7 8' 1195 else 1196 fv=1 1197 fi 1198 test $fv = 1 || for what in $checks; do 1199 test $fv = 1 && break 1200 case $what in 1201 1) t_cflags='-flto=jobserver' 1202 t_ldflags='-fuse-linker-plugin' 1203 t_use=1 t_name=fltojs_lp ;; 1204 2) t_cflags='-flto=jobserver' t_ldflags='' 1205 t_use=1 t_name=fltojs_nn ;; 1206 3) t_cflags='-flto=jobserver' 1207 t_ldflags='-fno-use-linker-plugin -fwhole-program' 1208 t_use=1 t_name=fltojs_np ;; 1209 4) t_cflags='-flto' 1210 t_ldflags='-fuse-linker-plugin' 1211 t_use=1 t_name=fltons_lp ;; 1212 5) t_cflags='-flto' t_ldflags='' 1213 t_use=1 t_name=fltons_nn ;; 1214 6) t_cflags='-flto' 1215 t_ldflags='-fno-use-linker-plugin -fwhole-program' 1216 t_use=1 t_name=fltons_np ;; 1217 7) t_cflags='-fwhole-program --combine' t_ldflags='' 1218 t_use=0 t_name=combine cm=combine ;; 1219 8) fv=1 cm=normal ;; 1220 esac 1221 test $fv = 1 && break 1222 ac_flags $t_use $t_name "$t_cflags" \ 1223 "if gcc supports $t_cflags $t_ldflags" "$t_ldflags" 1224 done 1225 i=1 1226 elif test $ct = icc; then 1227 ac_flags 1 fnobuiltinsetmode -fno-builtin-setmode 1228 ac_flags 1 fnostrictaliasing -fno-strict-aliasing 1229 ac_flags 1 fstacksecuritycheck -fstack-security-check 1230 i=1 1231 elif test $ct = sunpro; then 1232 phase=u 1233 ac_flags 1 v -v 1234 ac_flags 1 ipo -xipo 'for cross-module optimisation' 1235 phase=x 1236 elif test $ct = hpcc; then 1237 phase=u 1238 # probably not needed 1239 #ac_flags 1 agcc -Agcc 'for support of GCC extensions' 1240 phase=x 1241 elif test $ct = dec; then 1242 ac_flags 0 verb -verbose 1243 ac_flags 1 rodata -readonly_strings 1244 elif test $ct = dmc; then 1245 ac_flags 1 decl "${ccpc}-r" 'for strict prototype checks' 1246 ac_flags 1 schk "${ccpc}-s" 'for stack overflow checking' 1247 elif test $ct = bcc; then 1248 ac_flags 1 strpool "${ccpc}-d" 'if string pooling can be enabled' 1249 elif test $ct = mipspro; then 1250 ac_flags 1 fullwarn -fullwarn 'for remark output support' 1251 elif test $ct = msc; then 1252 ac_flags 1 strpool "${ccpc}/GF" 'if string pooling can be enabled' 1253 echo 'int main(void) { char test[64] = ""; return (*test); }' >x 1254 ac_flags - 1 stackon "${ccpc}/GZ" 'if stack checks can be enabled' <x 1255 ac_flags - 1 stckall "${ccpc}/Ge" 'stack checks for all functions' <x 1256 ac_flags - 1 secuchk "${ccpc}/GS" 'for compiler security checks' <x 1257 rmf x 1258 ac_flags 1 wall "${ccpc}/Wall" 'to enable all warnings' 1259 ac_flags 1 wp64 "${ccpc}/Wp64" 'to enable 64-bit warnings' 1260 elif test $ct = xlc; then 1261 ac_flags 1 rodata "-qro -qroconst -qroptr" 1262 ac_flags 1 rtcheck -qcheck=all 1263 #ac_flags 1 rtchkc -qextchk # reported broken 1264 ac_flags 1 wformat "-qformat=all -qformat=nozln" 1265 #ac_flags 1 wp64 -qwarn64 # too verbose for now 1266 elif test $ct = tendra; then 1267 ac_flags 0 ysystem -Ysystem 1268 test 1 = $HAVE_CAN_YSYSTEM && CPPFLAGS="-Ysystem $CPPFLAGS" 1269 ac_flags 1 extansi -Xa 1270 elif test $ct = tcc; then 1271 : #broken# ac_flags 1 boundschk -b 1272 elif test $ct = clang; then 1273 i=1 1274 elif test $ct = nwcc; then 1275 i=1 1276 : #broken# ac_flags 1 ssp -stackprotect 1277 fi 1278 # flags common to a subset of compilers (run with -Werror on gcc) 1279 if test 1 = $i; then 1280 ac_flags 1 wall -Wall 1281 ac_flags 1 fwrapv -fwrapv 1282 fi 1283 1284 phase=x 1285 # The following tests run with -Werror or similar (all compilers) if possible 1286 NOWARN=$DOWARN 1287 test $ct = pcc && phase=u 1288 1289 # 1290 # Compiler: check for stuff that only generates warnings 1291 # 1292 ac_test attribute_bounded '' 'for __attribute__((__bounded__))' <<-'EOF' 1293 #if defined(__TenDRA__) || (defined(__GNUC__) && (__GNUC__ < 2)) 1294 /* force a failure: TenDRA and gcc 1.42 have false positive here */ 1295 int main(void) { return (thiswillneverbedefinedIhope()); } 1296 #else 1297 #include <string.h> 1298 #undef __attribute__ 1299 int xcopy(const void *, void *, size_t) 1300 __attribute__((__bounded__ (__buffer__, 1, 3))) 1301 __attribute__((__bounded__ (__buffer__, 2, 3))); 1302 int main(int ac, char *av[]) { return (xcopy(av[0], av[--ac], 1)); } 1303 int xcopy(const void *s, void *d, size_t n) { 1304 /* 1305 * if memmove does not exist, we are not on a system 1306 * with GCC with __bounded__ attribute either so poo 1307 */ 1308 memmove(d, s, n); return ((int)n); 1309 } 1310 #endif 1311 EOF 1312 ac_test attribute_format '' 'for __attribute__((__format__))' <<-'EOF' 1313 #if defined(__TenDRA__) || (defined(__GNUC__) && (__GNUC__ < 2)) 1314 /* force a failure: TenDRA and gcc 1.42 have false positive here */ 1315 int main(void) { return (thiswillneverbedefinedIhope()); } 1316 #else 1317 #define fprintf printfoo 1318 #include <stdio.h> 1319 #undef __attribute__ 1320 #undef fprintf 1321 extern int fprintf(FILE *, const char *format, ...) 1322 __attribute__((__format__ (__printf__, 2, 3))); 1323 int main(int ac, char **av) { return (fprintf(stderr, "%s%d", *av, ac)); } 1324 #endif 1325 EOF 1326 ac_test attribute_noreturn '' 'for __attribute__((__noreturn__))' <<-'EOF' 1327 #if defined(__TenDRA__) || (defined(__GNUC__) && (__GNUC__ < 2)) 1328 /* force a failure: TenDRA and gcc 1.42 have false positive here */ 1329 int main(void) { return (thiswillneverbedefinedIhope()); } 1330 #else 1331 #include <stdlib.h> 1332 #undef __attribute__ 1333 void fnord(void) __attribute__((__noreturn__)); 1334 int main(void) { fnord(); } 1335 void fnord(void) { exit(0); } 1336 #endif 1337 EOF 1338 ac_test attribute_unused '' 'for __attribute__((__unused__))' <<-'EOF' 1339 #if defined(__TenDRA__) || (defined(__GNUC__) && (__GNUC__ < 2)) 1340 /* force a failure: TenDRA and gcc 1.42 have false positive here */ 1341 int main(void) { return (thiswillneverbedefinedIhope()); } 1342 #else 1343 int main(int ac __attribute__((__unused__)), char **av 1344 __attribute__((__unused__))) { return (0); } 1345 #endif 1346 EOF 1347 ac_test attribute_used '' 'for __attribute__((__used__))' <<-'EOF' 1348 #if defined(__TenDRA__) || (defined(__GNUC__) && (__GNUC__ < 2)) 1349 /* force a failure: TenDRA and gcc 1.42 have false positive here */ 1350 int main(void) { return (thiswillneverbedefinedIhope()); } 1351 #else 1352 static const char fnord[] __attribute__((__used__)) = "42"; 1353 int main(void) { return (0); } 1354 #endif 1355 EOF 1356 1357 # End of tests run with -Werror 1358 NOWARN=$save_NOWARN 1359 phase=x 1360 1361 # 1362 # mksh: flavours (full/small mksh, omit certain stuff) 1363 # 1364 if ac_ifcpp 'ifdef MKSH_SMALL' isset_MKSH_SMALL '' \ 1365 "if a reduced-feature mksh is requested"; then 1366 : ${HAVE_NICE=0} 1367 : ${HAVE_PERSISTENT_HISTORY=0} 1368 check_categories="$check_categories smksh" 1369 HAVE_ISSET_MKSH_CONSERVATIVE_FDS=1 # from sh.h 1370 fi 1371 ac_ifcpp 'ifdef MKSH_BINSHREDUCED' isset_MKSH_BINSHREDUCED '' \ 1372 "if a reduced-feature sh is requested" && \ 1373 check_categories="$check_categories binsh" 1374 ac_ifcpp 'ifdef MKSH_UNEMPLOYED' isset_MKSH_UNEMPLOYED '' \ 1375 "if mksh will be built without job control" && \ 1376 check_categories="$check_categories arge" 1377 ac_ifcpp 'ifdef MKSH_NOPROSPECTOFWORK' isset_MKSH_NOPROSPECTOFWORK '' \ 1378 "if mksh will be built without job signals" && \ 1379 check_categories="$check_categories arge nojsig" 1380 ac_ifcpp 'ifdef MKSH_ASSUME_UTF8' isset_MKSH_ASSUME_UTF8 '' \ 1381 'if the default UTF-8 mode is specified' && : ${HAVE_SETLOCALE_CTYPE=0} 1382 ac_ifcpp 'ifdef MKSH_CONSERVATIVE_FDS' isset_MKSH_CONSERVATIVE_FDS '' \ 1383 'if traditional/conservative fd use is requested' && \ 1384 check_categories="$check_categories convfds" 1385 #ac_ifcpp 'ifdef MKSH_DISABLE_DEPRECATED' isset_MKSH_DISABLE_DEPRECATED '' \ 1386 # "if deprecated features are to be omitted" && \ 1387 # check_categories="$check_categories nodeprecated" 1388 #ac_ifcpp 'ifdef MKSH_DISABLE_EXPERIMENTAL' isset_MKSH_DISABLE_EXPERIMENTAL '' \ 1389 # "if experimental features are to be omitted" && \ 1390 # check_categories="$check_categories noexperimental" 1391 ac_ifcpp 'ifdef MKSH_MIDNIGHTBSD01ASH_COMPAT' isset_MKSH_MIDNIGHTBSD01ASH_COMPAT '' \ 1392 'if the MidnightBSD 0.1 ash compatibility mode is requested' && \ 1393 check_categories="$check_categories mnbsdash" 1394 1395 # 1396 # Environment: headers 1397 # 1398 ac_header sys/time.h sys/types.h 1399 ac_header time.h sys/types.h 1400 test "11" = "$HAVE_SYS_TIME_H$HAVE_TIME_H" || HAVE_BOTH_TIME_H=0 1401 ac_test both_time_h '' 'whether <sys/time.h> and <time.h> can both be included' <<-'EOF' 1402 #include <sys/types.h> 1403 #include <sys/time.h> 1404 #include <time.h> 1405 int main(void) { struct tm tm; return ((int)sizeof(tm)); } 1406 EOF 1407 ac_header sys/bsdtypes.h 1408 ac_header sys/file.h sys/types.h 1409 ac_header sys/mkdev.h sys/types.h 1410 ac_header sys/mman.h sys/types.h 1411 ac_header sys/param.h 1412 ac_header sys/resource.h sys/types.h _time 1413 ac_header sys/select.h sys/types.h 1414 ac_header sys/sysmacros.h 1415 ac_header bstring.h 1416 ac_header grp.h sys/types.h 1417 ac_header libgen.h 1418 ac_header libutil.h sys/types.h 1419 ac_header paths.h 1420 ac_header stdint.h stdarg.h 1421 # include strings.h only if compatible with string.h 1422 ac_header strings.h sys/types.h string.h 1423 ac_header termios.h 1424 ac_header ulimit.h sys/types.h 1425 ac_header values.h 1426 1427 # 1428 # Environment: definitions 1429 # 1430 echo '#include <sys/types.h> 1431 /* check that off_t can represent 2^63-1 correctly, thx FSF */ 1432 #define LARGE_OFF_T (((off_t)1 << 62) - 1 + ((off_t)1 << 62)) 1433 int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721 && 1434 LARGE_OFF_T % 2147483647 == 1) ? 1 : -1]; 1435 int main(void) { return (0); }' >lft.c 1436 ac_testn can_lfs '' "for large file support" <lft.c 1437 save_CPPFLAGS=$CPPFLAGS 1438 add_cppflags -D_FILE_OFFSET_BITS=64 1439 ac_testn can_lfs_sus '!' can_lfs 0 "... with -D_FILE_OFFSET_BITS=64" <lft.c 1440 if test 0 = $HAVE_CAN_LFS_SUS; then 1441 CPPFLAGS=$save_CPPFLAGS 1442 add_cppflags -D_LARGE_FILES=1 1443 ac_testn can_lfs_aix '!' can_lfs 0 "... with -D_LARGE_FILES=1" <lft.c 1444 test 1 = $HAVE_CAN_LFS_AIX || CPPFLAGS=$save_CPPFLAGS 1445 fi 1446 rmf lft* # end of large file support test 1447 1448 # 1449 # Environment: types 1450 # 1451 ac_test can_inttypes '!' stdint_h 1 "for standard 32-bit integer types" <<-'EOF' 1452 #include <sys/types.h> 1453 #include <stddef.h> 1454 int main(int ac, char **av) { return ((uint32_t)(ptrdiff_t)*av + (int32_t)ac); } 1455 EOF 1456 ac_test can_ucbints '!' can_inttypes 1 "for UCB 32-bit integer types" <<-'EOF' 1457 #include <sys/types.h> 1458 #include <stddef.h> 1459 int main(int ac, char **av) { return ((u_int32_t)(ptrdiff_t)*av + (int32_t)ac); } 1460 EOF 1461 ac_test can_int8type '!' stdint_h 1 "for standard 8-bit integer type" <<-'EOF' 1462 #include <sys/types.h> 1463 #include <stddef.h> 1464 int main(int ac, char **av) { return ((uint8_t)(ptrdiff_t)av[ac]); } 1465 EOF 1466 ac_test can_ucbint8 '!' can_int8type 1 "for UCB 8-bit integer type" <<-'EOF' 1467 #include <sys/types.h> 1468 #include <stddef.h> 1469 int main(int ac, char **av) { return ((u_int8_t)(ptrdiff_t)av[ac]); } 1470 EOF 1471 1472 ac_test rlim_t <<-'EOF' 1473 #include <sys/types.h> 1474 #if HAVE_BOTH_TIME_H 1475 #include <sys/time.h> 1476 #include <time.h> 1477 #elif HAVE_SYS_TIME_H 1478 #include <sys/time.h> 1479 #elif HAVE_TIME_H 1480 #include <time.h> 1481 #endif 1482 #if HAVE_SYS_RESOURCE_H 1483 #include <sys/resource.h> 1484 #endif 1485 #include <unistd.h> 1486 int main(void) { return ((int)(rlim_t)0); } 1487 EOF 1488 1489 # only testn: added later below 1490 ac_testn sig_t <<-'EOF' 1491 #include <sys/types.h> 1492 #include <signal.h> 1493 #include <stddef.h> 1494 int main(void) { return ((int)(ptrdiff_t)(sig_t)(ptrdiff_t)kill(0,0)); } 1495 EOF 1496 1497 ac_testn sighandler_t '!' sig_t 0 <<-'EOF' 1498 #include <sys/types.h> 1499 #include <signal.h> 1500 #include <stddef.h> 1501 int main(void) { return ((int)(ptrdiff_t)(sighandler_t)(ptrdiff_t)kill(0,0)); } 1502 EOF 1503 if test 1 = $HAVE_SIGHANDLER_T; then 1504 add_cppflags -Dsig_t=sighandler_t 1505 HAVE_SIG_T=1 1506 fi 1507 1508 ac_testn __sighandler_t '!' sig_t 0 <<-'EOF' 1509 #include <sys/types.h> 1510 #include <signal.h> 1511 #include <stddef.h> 1512 int main(void) { return ((int)(ptrdiff_t)(__sighandler_t)(ptrdiff_t)kill(0,0)); } 1513 EOF 1514 if test 1 = $HAVE___SIGHANDLER_T; then 1515 add_cppflags -Dsig_t=__sighandler_t 1516 HAVE_SIG_T=1 1517 fi 1518 1519 test 1 = $HAVE_SIG_T || add_cppflags -Dsig_t=nosig_t 1520 ac_cppflags SIG_T 1521 1522 # 1523 # check whether whatever we use for the final link will succeed 1524 # 1525 if test $cm = makefile; then 1526 : nothing to check 1527 else 1528 HAVE_LINK_WORKS=x 1529 ac_testinit link_works '' 'checking if the final link command may succeed' 1530 fv=1 1531 cat >conftest.c <<-'EOF' 1532 #define EXTERN 1533 #define MKSH_INCLUDES_ONLY 1534 #include "sh.h" 1535 __RCSID("$MirOS: src/bin/mksh/Build.sh,v 1.622 2013/02/19 18:45:15 tg Exp $"); 1536 int main(void) { printf("Hello, World!\n"); return (0); } 1537 EOF 1538 case $cm in 1539 llvm) 1540 v "$CC $CFLAGS $CPPFLAGS $NOWARN -emit-llvm -c conftest.c" || fv=0 1541 rmf $tfn.s 1542 test $fv = 0 || v "llvm-link -o - conftest.o | opt $optflags | llc -o $tfn.s" || fv=0 1543 test $fv = 0 || v "$CC $CFLAGS $LDFLAGS -o $tcfn $tfn.s $LIBS $ccpr" 1544 ;; 1545 dragonegg) 1546 v "$CC $CFLAGS $CPPFLAGS $NOWARN -S -flto conftest.c" || fv=0 1547 test $fv = 0 || v "mv conftest.s conftest.ll" 1548 test $fv = 0 || v "llvm-as conftest.ll" || fv=0 1549 rmf $tfn.s 1550 test $fv = 0 || v "llvm-link -o - conftest.bc | opt $optflags | llc -o $tfn.s" || fv=0 1551 test $fv = 0 || v "$CC $CFLAGS $LDFLAGS -o $tcfn $tfn.s $LIBS $ccpr" 1552 ;; 1553 combine) 1554 v "$CC $CFLAGS $CPPFLAGS $LDFLAGS -fwhole-program --combine $NOWARN -o $tcfn conftest.c $LIBS $ccpr" 1555 ;; 1556 lto|normal) 1557 cm=normal 1558 v "$CC $CFLAGS $CPPFLAGS $NOWARN -c conftest.c" || fv=0 1559 test $fv = 0 || v "$CC $CFLAGS $LDFLAGS -o $tcfn conftest.o $LIBS $ccpr" 1560 ;; 1561 esac 1562 test -f $tcfn || fv=0 1563 ac_testdone 1564 test $fv = 1 || exit 1 1565 fi 1566 1567 # 1568 # Environment: errors and signals 1569 # 1570 test x"NetBSD" = x"$TARGET_OS" && $e Ignore the compatibility warning. 1571 1572 ac_testn sys_errlist '' "the sys_errlist[] array and sys_nerr" <<-'EOF' 1573 extern const int sys_nerr; 1574 extern const char * const sys_errlist[]; 1575 int main(void) { return (*sys_errlist[sys_nerr - 1]); } 1576 EOF 1577 ac_testn _sys_errlist '!' sys_errlist 0 "the _sys_errlist[] array and _sys_nerr" <<-'EOF' 1578 extern const int _sys_nerr; 1579 extern const char * const _sys_errlist[]; 1580 int main(void) { return (*_sys_errlist[_sys_nerr - 1]); } 1581 EOF 1582 if test 1 = "$HAVE__SYS_ERRLIST"; then 1583 add_cppflags -Dsys_nerr=_sys_nerr 1584 add_cppflags -Dsys_errlist=_sys_errlist 1585 HAVE_SYS_ERRLIST=1 1586 fi 1587 ac_cppflags SYS_ERRLIST 1588 1589 for what in name list; do 1590 uwhat=`upper $what` 1591 ac_testn sys_sig$what '' "the sys_sig${what}[] array" <<-EOF 1592 extern const char * const sys_sig${what}[]; 1593 int main(void) { return (sys_sig${what}[0][0]); } 1594 EOF 1595 ac_testn _sys_sig$what '!' sys_sig$what 0 "the _sys_sig${what}[] array" <<-EOF 1596 extern const char * const _sys_sig${what}[]; 1597 int main(void) { return (_sys_sig${what}[0][0]); } 1598 EOF 1599 eval uwhat_v=\$HAVE__SYS_SIG$uwhat 1600 if test 1 = "$uwhat_v"; then 1601 add_cppflags -Dsys_sig$what=_sys_sig$what 1602 eval HAVE_SYS_SIG$uwhat=1 1603 fi 1604 ac_cppflags SYS_SIG$uwhat 1605 done 1606 1607 # 1608 # Environment: library functions 1609 # 1610 ac_test flock <<-'EOF' 1611 #include <sys/types.h> 1612 #include <fcntl.h> 1613 #undef flock 1614 #if HAVE_SYS_FILE_H 1615 #include <sys/file.h> 1616 #endif 1617 int main(void) { return (flock(0, LOCK_EX | LOCK_UN)); } 1618 EOF 1619 1620 ac_test lock_fcntl '!' flock 1 'whether we can lock files with fcntl' <<-'EOF' 1621 #include <fcntl.h> 1622 #undef flock 1623 int main(void) { 1624 struct flock lks; 1625 lks.l_type = F_WRLCK | F_UNLCK; 1626 return (fcntl(0, F_SETLKW, &lks)); 1627 } 1628 EOF 1629 1630 ac_test getrusage <<-'EOF' 1631 #define MKSH_INCLUDES_ONLY 1632 #include "sh.h" 1633 int main(void) { 1634 struct rusage ru; 1635 return (getrusage(RUSAGE_SELF, &ru) + 1636 getrusage(RUSAGE_CHILDREN, &ru)); 1637 } 1638 EOF 1639 1640 ac_test gettimeofday <<-'EOF' 1641 #define MKSH_INCLUDES_ONLY 1642 #include "sh.h" 1643 int main(void) { struct timeval tv; return (gettimeofday(&tv, NULL)); } 1644 EOF 1645 1646 ac_test killpg <<-'EOF' 1647 #include <signal.h> 1648 int main(int ac, char *av[]) { return (av[0][killpg(123, ac)]); } 1649 EOF 1650 1651 ac_test memmove <<-'EOF' 1652 #include <sys/types.h> 1653 #include <stddef.h> 1654 #include <string.h> 1655 #if HAVE_STRINGS_H 1656 #include <strings.h> 1657 #endif 1658 int main(int ac, char *av[]) { 1659 return (*(int *)(void *)memmove(av[0], av[1], ac)); 1660 } 1661 EOF 1662 1663 ac_test mknod '' 'if to use mknod(), makedev() and friends' <<-'EOF' 1664 #define MKSH_INCLUDES_ONLY 1665 #include "sh.h" 1666 int main(int ac, char *av[]) { 1667 dev_t dv; 1668 dv = makedev((unsigned int)ac, (unsigned int)av[0][0]); 1669 return (mknod(av[0], (mode_t)0, dv) ? (int)major(dv) : 1670 (int)minor(dv)); 1671 } 1672 EOF 1673 1674 ac_test mmap lock_fcntl 0 'for mmap and munmap' <<-'EOF' 1675 #include <sys/types.h> 1676 #if HAVE_SYS_FILE_H 1677 #include <sys/file.h> 1678 #endif 1679 #if HAVE_SYS_MMAN_H 1680 #include <sys/mman.h> 1681 #endif 1682 #include <stddef.h> 1683 #include <stdlib.h> 1684 int main(void) { return ((void *)mmap(NULL, (size_t)0, 1685 PROT_READ, MAP_PRIVATE, 0, (off_t)0) == (void *)NULL ? 1 : 1686 munmap(NULL, 0)); } 1687 EOF 1688 1689 ac_test nice <<-'EOF' 1690 #include <unistd.h> 1691 int main(void) { return (nice(4)); } 1692 EOF 1693 1694 ac_test revoke <<-'EOF' 1695 #include <sys/types.h> 1696 #if HAVE_LIBUTIL_H 1697 #include <libutil.h> 1698 #endif 1699 #include <unistd.h> 1700 int main(int ac, char *av[]) { return (ac + revoke(av[0])); } 1701 EOF 1702 1703 ac_test setlocale_ctype '' 'setlocale(LC_CTYPE, "")' <<-'EOF' 1704 #include <locale.h> 1705 #include <stddef.h> 1706 int main(void) { return ((int)(ptrdiff_t)(void *)setlocale(LC_CTYPE, "")); } 1707 EOF 1708 1709 ac_test langinfo_codeset setlocale_ctype 0 'nl_langinfo(CODESET)' <<-'EOF' 1710 #include <langinfo.h> 1711 #include <stddef.h> 1712 int main(void) { return ((int)(ptrdiff_t)(void *)nl_langinfo(CODESET)); } 1713 EOF 1714 1715 ac_test select <<-'EOF' 1716 #include <sys/types.h> 1717 #if HAVE_BOTH_TIME_H 1718 #include <sys/time.h> 1719 #include <time.h> 1720 #elif HAVE_SYS_TIME_H 1721 #include <sys/time.h> 1722 #elif HAVE_TIME_H 1723 #include <time.h> 1724 #endif 1725 #if HAVE_SYS_BSDTYPES_H 1726 #include <sys/bsdtypes.h> 1727 #endif 1728 #if HAVE_SYS_SELECT_H 1729 #include <sys/select.h> 1730 #endif 1731 #if HAVE_BSTRING_H 1732 #include <bstring.h> 1733 #endif 1734 #include <stddef.h> 1735 #include <stdlib.h> 1736 #include <string.h> 1737 #if HAVE_STRINGS_H 1738 #include <strings.h> 1739 #endif 1740 #include <unistd.h> 1741 int main(void) { 1742 struct timeval tv = { 1, 200000 }; 1743 fd_set fds; FD_ZERO(&fds); FD_SET(0, &fds); 1744 return (select(FD_SETSIZE, &fds, NULL, NULL, &tv)); 1745 } 1746 EOF 1747 1748 ac_test setresugid <<-'EOF' 1749 #include <sys/types.h> 1750 #include <unistd.h> 1751 int main(void) { setresuid(0,0,0); return (setresgid(0,0,0)); } 1752 EOF 1753 1754 ac_test setgroups setresugid 0 <<-'EOF' 1755 #include <sys/types.h> 1756 #if HAVE_GRP_H 1757 #include <grp.h> 1758 #endif 1759 #include <unistd.h> 1760 int main(void) { gid_t gid = 0; return (setgroups(0, &gid)); } 1761 EOF 1762 1763 if test x"$et" = x"klibc"; then 1764 1765 ac_testn __rt_sigsuspend '' 'whether klibc uses RT signals' <<-'EOF' 1766 #define MKSH_INCLUDES_ONLY 1767 #include "sh.h" 1768 extern int __rt_sigsuspend(const sigset_t *, size_t); 1769 int main(void) { return (__rt_sigsuspend(NULL, 0)); } 1770 EOF 1771 1772 # no? damn! legacy crap ahead! 1773 1774 ac_testn __sigsuspend_s '!' __rt_sigsuspend 1 \ 1775 'whether sigsuspend is usable (1/2)' <<-'EOF' 1776 #define MKSH_INCLUDES_ONLY 1777 #include "sh.h" 1778 extern int __sigsuspend_s(sigset_t); 1779 int main(void) { return (__sigsuspend_s(0)); } 1780 EOF 1781 ac_testn __sigsuspend_xxs '!' __sigsuspend_s 1 \ 1782 'whether sigsuspend is usable (2/2)' <<-'EOF' 1783 #define MKSH_INCLUDES_ONLY 1784 #include "sh.h" 1785 extern int __sigsuspend_xxs(int, int, sigset_t); 1786 int main(void) { return (__sigsuspend_xxs(0, 0, 0)); } 1787 EOF 1788 1789 if test "000" = "$HAVE___RT_SIGSUSPEND$HAVE___SIGSUSPEND_S$HAVE___SIGSUSPEND_XXS"; then 1790 # no usable sigsuspend(), use pause() *ugh* 1791 add_cppflags -DMKSH_NO_SIGSUSPEND 1792 fi 1793 fi 1794 1795 ac_test strerror '!' sys_errlist 0 <<-'EOF' 1796 extern char *strerror(int); 1797 int main(int ac, char *av[]) { return (*strerror(*av[ac])); } 1798 EOF 1799 1800 ac_test strsignal '!' sys_siglist 0 <<-'EOF' 1801 #include <string.h> 1802 #include <signal.h> 1803 int main(void) { return (strsignal(1)[0]); } 1804 EOF 1805 1806 ac_test strlcpy <<-'EOF' 1807 #include <string.h> 1808 int main(int ac, char *av[]) { return (strlcpy(*av, av[1], 1809 (size_t)ac)); } 1810 EOF 1811 1812 # 1813 # check headers for declarations 1814 # 1815 ac_test flock_decl flock 1 'for declaration of flock()' <<-'EOF' 1816 #define MKSH_INCLUDES_ONLY 1817 #include "sh.h" 1818 #if HAVE_SYS_FILE_H 1819 #include <sys/file.h> 1820 #endif 1821 int main(void) { return ((flock)(0, 0)); } 1822 EOF 1823 ac_test revoke_decl revoke 1 'for declaration of revoke()' <<-'EOF' 1824 #define MKSH_INCLUDES_ONLY 1825 #include "sh.h" 1826 int main(void) { return ((revoke)("")); } 1827 EOF 1828 ac_test sys_errlist_decl sys_errlist 0 "for declaration of sys_errlist[] and sys_nerr" <<-'EOF' 1829 #define MKSH_INCLUDES_ONLY 1830 #include "sh.h" 1831 int main(void) { return (*sys_errlist[sys_nerr - 1]); } 1832 EOF 1833 ac_test sys_siglist_decl sys_siglist 0 'for declaration of sys_siglist[]' <<-'EOF' 1834 #define MKSH_INCLUDES_ONLY 1835 #include "sh.h" 1836 int main(void) { return (sys_siglist[0][0]); } 1837 EOF 1838 1839 # 1840 # other checks 1841 # 1842 fd='if to use persistent history' 1843 ac_cache PERSISTENT_HISTORY || case $HAVE_MMAP$HAVE_FLOCK$HAVE_LOCK_FCNTL in 1844 11*|101) fv=1 ;; 1845 esac 1846 test 1 = $fv || check_categories="$check_categories no-histfile" 1847 ac_testdone 1848 ac_cppflags 1849 1850 save_CFLAGS=$CFLAGS 1851 test x1 = x$HAVE_CAN_WNOOVERFLOW && CFLAGS="$CFLAGS -Wno-overflow" 1852 ac_testn compile_time_asserts_$$ '' 'whether compile-time assertions pass' <<-'EOF' 1853 #define MKSH_INCLUDES_ONLY 1854 #include "sh.h" 1855 #ifndef CHAR_BIT 1856 #define CHAR_BIT 8 /* defuse this test on really legacy systems */ 1857 #endif 1858 struct ctasserts { 1859 #define cta(name, assertion) char name[(assertion) ? 1 : -1] 1860 /* this one should be defined by the standard */ 1861 cta(char_is_1_char, (sizeof(char) == 1) && (sizeof(signed char) == 1) && 1862 (sizeof(unsigned char) == 1)); 1863 cta(char_is_8_bits, ((CHAR_BIT) == 8) && ((int)(unsigned char)0xFF == 0xFF) && 1864 ((int)(unsigned char)0x100 == 0) && ((int)(unsigned char)(int)-1 == 0xFF)); 1865 /* the next assertion is probably not really needed */ 1866 cta(short_is_2_char, sizeof(short) == 2); 1867 cta(short_size_no_matter_of_signedness, sizeof(short) == sizeof(unsigned short)); 1868 /* the next assertion is probably not really needed */ 1869 cta(int_is_4_char, sizeof(int) == 4); 1870 cta(int_size_no_matter_of_signedness, sizeof(int) == sizeof(unsigned int)); 1871 1872 cta(long_ge_int, sizeof(long) >= sizeof(int)); 1873 cta(long_size_no_matter_of_signedness, sizeof(long) == sizeof(unsigned long)); 1874 1875 #ifndef MKSH_LEGACY_MODE 1876 /* the next assertion is probably not really needed */ 1877 cta(ari_is_4_char, sizeof(mksh_ari_t) == 4); 1878 /* but the next two are; we REQUIRE signed integer wraparound */ 1879 cta(ari_has_31_bit, 0 < (mksh_ari_t)(((((mksh_ari_t)1 << 15) << 15) - 1) * 2 + 1)); 1880 #ifndef MKSH_GCC55009 1881 cta(ari_sign_32_bit_and_wrap, 1882 (mksh_ari_t)(((((mksh_ari_t)1 << 15) << 15) - 1) * 2 + 1) > 1883 (mksh_ari_t)(((((mksh_ari_t)1 << 15) << 15) - 1) * 2 + 2)); 1884 #endif 1885 /* the next assertion is probably not really needed */ 1886 cta(uari_is_4_char, sizeof(mksh_uari_t) == 4); 1887 /* but the next three are; we REQUIRE unsigned integer wraparound */ 1888 cta(uari_has_31_bit, 0 < (mksh_uari_t)(((((mksh_uari_t)1 << 15) << 15) - 1) * 2 + 1)); 1889 cta(uari_has_32_bit, 0 < (mksh_uari_t)(((((mksh_uari_t)1 << 15) << 15) - 1) * 4 + 3)); 1890 cta(uari_wrap_32_bit, 1891 (mksh_uari_t)(((((mksh_uari_t)1 << 15) << 15) - 1) * 4 + 3) > 1892 (mksh_uari_t)(((((mksh_uari_t)1 << 15) << 15) - 1) * 4 + 4)); 1893 #endif 1894 /* these are always required */ 1895 cta(ari_is_signed, (mksh_ari_t)-1 < (mksh_ari_t)0); 1896 cta(uari_is_unsigned, (mksh_uari_t)-1 > (mksh_uari_t)0); 1897 1898 cta(sizet_size_no_matter_of_signedness, sizeof(ssize_t) == sizeof(size_t)); 1899 cta(ptrdifft_sizet_same_size, sizeof(ptrdiff_t) == sizeof(size_t)); 1900 cta(ptrdifft_voidptr_same_size, sizeof(ptrdiff_t) == sizeof(void *)); 1901 cta(ptrdifft_funcptr_same_size, sizeof(ptrdiff_t) == sizeof(void (*)(void))); 1902 /* our formatting routines assume this */ 1903 cta(ptr_fits_in_long, sizeof(ptrdiff_t) <= sizeof(long)); 1904 }; 1905 #ifndef MKSH_LEGACY_MODE 1906 #ifndef MKSH_GCC55009 1907 #define NUM 22 1908 #else 1909 #define NUM 21 1910 #endif 1911 #else 1912 #define NUM 15 1913 #endif 1914 char ctasserts_dblcheck[sizeof(struct ctasserts) == NUM ? 1 : -1]; 1915 int main(void) { return (sizeof(ctasserts_dblcheck)); } 1916 EOF 1917 CFLAGS=$save_CFLAGS 1918 eval test 1 = \$HAVE_COMPILE_TIME_ASSERTS_$$ || exit 1 1919 1920 # 1921 # extra checks for legacy mksh 1922 # 1923 if test $legacy = 1; then 1924 ac_test long_32bit '' 'whether long is 32 bit wide' <<-'EOF' 1925 #define MKSH_INCLUDES_ONLY 1926 #include "sh.h" 1927 #ifndef CHAR_BIT 1928 #define CHAR_BIT 0 1929 #endif 1930 struct ctasserts { 1931 #define cta(name, assertion) char name[(assertion) ? 1 : -1] 1932 cta(char_is_8_bits, (CHAR_BIT) == 8); 1933 cta(long_is_32_bits, sizeof(long) == 4); 1934 }; 1935 int main(void) { return (sizeof(struct ctasserts)); } 1936 EOF 1937 1938 ac_test long_64bit '!' long_32bit 0 'whether long is 64 bit wide' <<-'EOF' 1939 #define MKSH_INCLUDES_ONLY 1940 #include "sh.h" 1941 #ifndef CHAR_BIT 1942 #define CHAR_BIT 0 1943 #endif 1944 struct ctasserts { 1945 #define cta(name, assertion) char name[(assertion) ? 1 : -1] 1946 cta(char_is_8_bits, (CHAR_BIT) == 8); 1947 cta(long_is_64_bits, sizeof(long) == 8); 1948 }; 1949 int main(void) { return (sizeof(struct ctasserts)); } 1950 EOF 1951 1952 case $HAVE_LONG_32BIT$HAVE_LONG_64BIT in 1953 10) check_categories="$check_categories int:32" ;; 1954 01) check_categories="$check_categories int:64" ;; 1955 *) check_categories="$check_categories int:u" ;; 1956 esac 1957 fi 1958 1959 # 1960 # runtime checks 1961 # once this is more than one, check if we can do runtime 1962 # checks (not cross-compiling) first to save on warnings 1963 # 1964 $e "${bi}run-time checks follow$ao, please ignore any weird errors" 1965 1966 if ac_testnnd silent_idivwrapv '' '(run-time) whether signed integer division overflows wrap silently' <<-'EOF' 1967 #define MKSH_INCLUDES_ONLY 1968 #include "sh.h" 1969 #if !defined(MKSH_LEGACY_MODE) || HAVE_LONG_32BIT 1970 #define IDIVWRAPV_VL (mksh_uari_t)0x80000000UL 1971 #elif HAVE_LONG_64BIT 1972 #define IDIVWRAPV_VL (mksh_uari_t)0x8000000000000000UL 1973 #else 1974 # error "cannot check this" 1975 #endif 1976 #ifdef SIGFPE 1977 static void fpe_catcher(int) MKSH_A_NORETURN; 1978 #endif 1979 int main(int ac, char **av) { 1980 mksh_ari_t o1, o2, r1, r2; 1981 1982 #ifdef SIGFPE 1983 signal(SIGFPE, fpe_catcher); 1984 #endif 1985 o1 = (mksh_ari_t)IDIVWRAPV_VL; 1986 o2 = -ac; 1987 r1 = o1 / o2; 1988 r2 = o1 % o2; 1989 if (r1 == o1 && r2 == 0) { 1990 printf("si"); 1991 return (0); 1992 } 1993 printf("no %d %d %d %d %s", (int)o1, (int)o2, (int)r1, 1994 (int)r2, av[0]); 1995 return (1); 1996 } 1997 #ifdef SIGFPE 1998 static const char fpe_msg[] = "no, got SIGFPE, what were they smoking?"; 1999 #define fpe_msglen (sizeof(fpe_msg) - 1) 2000 static void fpe_catcher(int sig MKSH_A_UNUSED) { 2001 _exit(write(1, fpe_msg, fpe_msglen) == fpe_msglen ? 2 : 3); 2002 } 2003 #endif 2004 EOF 2005 then 2006 if test $fv = 0; then 2007 echo "| hrm, compiling this failed, but we will just failback" 2008 else 2009 echo "| running test programme; this will fail if cross-compiling" 2010 echo "| in which case we will gracefully degrade to the default" 2011 ./$tcfn >vv.out 2>&1 2012 rv=$? 2013 echo "| result: `cat vv.out`" 2014 fv=0 2015 test $rv = 0 && test x"`cat vv.out`" = x"si" && fv=1 2016 fi 2017 rmf conftest.c conftest.o ${tcfn}* vv.out 2018 ac_testdone 2019 fi 2020 ac_cppflags 2021 2022 $e "${bi}end of run-time checks$ao" 2023 2024 # 2025 # Compiler: Praeprocessor (only if needed) 2026 # 2027 test 0 = $HAVE_SYS_SIGNAME && if ac_testinit cpp_dd '' \ 2028 'checking if the C Preprocessor supports -dD'; then 2029 echo '#define foo bar' >conftest.c 2030 vv ']' "$CPP $CFLAGS $CPPFLAGS $NOWARN -dD conftest.c >x" 2031 grep '#define foo bar' x >/dev/null 2>&1 && fv=1 2032 rmf conftest.c x vv.out 2033 ac_testdone 2034 fi 2035 2036 # 2037 # End of mirtoconf checks 2038 # 2039 $e ... done. 2040 2041 # Some operating systems have ancient versions of ed(1) writing 2042 # the character count to standard output; cope for that 2043 echo wq >x 2044 ed x <x 2>/dev/null | grep 3 >/dev/null 2>&1 && \ 2045 check_categories="$check_categories $oldish_ed" 2046 rmf x vv.out 2047 2048 if test 0 = $HAVE_SYS_SIGNAME; then 2049 if test 1 = $HAVE_CPP_DD; then 2050 $e Generating list of signal names... 2051 else 2052 $e No list of signal names available via cpp. Falling back... 2053 fi 2054 sigseenone=: 2055 sigseentwo=: 2056 echo '#include <signal.h> 2057 #ifndef NSIG 2058 #if defined(_NSIG) 2059 #define NSIG _NSIG 2060 #elif defined(SIGMAX) 2061 #define NSIG (SIGMAX+1) 2062 #elif defined(_SIGMAX) 2063 #define NSIG (_SIGMAX+1) 2064 #endif 2065 #endif 2066 int 2067 mksh_cfg= NSIG 2068 ;' >conftest.c 2069 # GNU sed 2.03 segfaults when optimising this to sed -n 2070 NSIG=`vq "$CPP $CFLAGS $CPPFLAGS $NOWARN conftest.c" | \ 2071 grep '^ *mksh_cfg *=' | \ 2072 sed 's/^ *mksh_cfg *=[ ]*\([()0-9x+-][()0-9x+ -]*\).*$/\1/'` 2073 case $NSIG in 2074 *mksh_cfg*) $e "Error: NSIG='$NSIG'"; NSIG=0 ;; 2075 *[\ \(\)+-]*) NSIG=`"$AWK" "BEGIN { print $NSIG }" </dev/null` ;; 2076 esac 2077 printf=printf 2078 (printf hallo) >/dev/null 2>&1 || printf=echo 2079 test $printf = echo || test "`printf %d 42`" = 42 || printf=echo 2080 test $printf = echo || NSIG=`printf %d "$NSIG" 2>/dev/null` 2081 $printf "NSIG=$NSIG ... " 2082 sigs="INT SEGV ABRT KILL ALRM BUS CHLD CLD CONT DIL EMT FPE HUP ILL" 2083 sigs="$sigs INFO IO IOT LOST PIPE PROF PWR QUIT RESV SAK STOP SYS TERM" 2084 sigs="$sigs TRAP TSTP TTIN TTOU URG USR1 USR2 VTALRM WINCH XCPU XFSZ" 2085 test 1 = $HAVE_CPP_DD && test $NSIG -gt 1 && sigs="$sigs "`vq \ 2086 "$CPP $CFLAGS $CPPFLAGS $NOWARN -dD conftest.c" | \ 2087 grep '[ ]SIG[A-Z0-9][A-Z0-9]*[ ]' | \ 2088 sed 's/^.*[ ]SIG\([A-Z0-9][A-Z0-9]*\)[ ].*$/\1/' | sort` 2089 test $NSIG -gt 1 || sigs= 2090 for name in $sigs; do 2091 case $sigseenone in 2092 *:$name:*) continue ;; 2093 esac 2094 sigseenone=$sigseenone$name: 2095 echo '#include <signal.h>' >conftest.c 2096 echo int >>conftest.c 2097 echo mksh_cfg= SIG$name >>conftest.c 2098 echo ';' >>conftest.c 2099 # GNU sed 2.03 croaks on optimising this, too 2100 vq "$CPP $CFLAGS $CPPFLAGS $NOWARN conftest.c" | \ 2101 grep '^ *mksh_cfg *=' | \ 2102 sed 's/^ *mksh_cfg *=[ ]*\([0-9][0-9x]*\).*$/:\1 '$name/ 2103 done | sed -n '/^:[^ ]/s/^://p' | while read nr name; do 2104 test $printf = echo || nr=`printf %d "$nr" 2>/dev/null` 2105 test $nr -gt 0 && test $nr -le $NSIG || continue 2106 case $sigseentwo in 2107 *:$nr:*) ;; 2108 *) echo " { \"$name\", $nr }," 2109 sigseentwo=$sigseentwo$nr: 2110 $printf "$name=$nr " >&2 2111 ;; 2112 esac 2113 done 2>&1 >signames.inc 2114 rmf conftest.c 2115 $e done. 2116 fi 2117 2118 addsrcs -s '!' HAVE_STRLCPY strlcpy.c 2119 addsrcs USE_PRINTF_BUILTIN printf.c 2120 test 1 = "$USE_PRINTF_BUILTIN" && add_cppflags -DMKSH_PRINTF_BUILTIN 2121 test 1 = "$HAVE_CAN_VERB" && CFLAGS="$CFLAGS -verbose" 2122 test -n "$LDSTATIC" && add_cppflags -DMKSH_OPTSTATIC 2123 add_cppflags -DMKSH_BUILD_R=431 2124 2125 $e $bi$me: Finished configuration testing, now producing output.$ao 2126 2127 files= 2128 objs= 2129 sp= 2130 case $tcfn in 2131 a.exe) mkshexe=$tfn.exe ;; 2132 *) mkshexe=$tfn ;; 2133 esac 2134 case $curdir in 2135 *\ *) mkshshebang="#!./$mkshexe" ;; 2136 *) mkshshebang="#!$curdir/$mkshexe" ;; 2137 esac 2138 cat >test.sh <<-EOF 2139 $mkshshebang 2140 LC_ALL=C PATH='$PATH'; export LC_ALL PATH 2141 test -n "\$KSH_VERSION" || exit 1 2142 set -A check_categories -- $check_categories 2143 pflag='$curdir/$mkshexe' 2144 sflag='$srcdir/check.t' 2145 usee=0 Pflag=0 Sflag=0 uset=0 vflag=1 xflag=0 2146 while getopts "C:e:fPp:QSs:t:v" ch; do case \$ch { 2147 (C) check_categories[\${#check_categories[*]}]=\$OPTARG ;; 2148 (e) usee=1; eflag=\$OPTARG ;; 2149 (f) check_categories[\${#check_categories[*]}]=fastbox ;; 2150 (P) Pflag=1 ;; 2151 (+P) Pflag=0 ;; 2152 (p) pflag=\$OPTARG ;; 2153 (Q) vflag=0 ;; 2154 (+Q) vflag=1 ;; 2155 (S) Sflag=1 ;; 2156 (+S) Sflag=0 ;; 2157 (s) sflag=\$OPTARG ;; 2158 (t) uset=1; tflag=\$OPTARG ;; 2159 (v) vflag=1 ;; 2160 (+v) vflag=0 ;; 2161 (*) xflag=1 ;; 2162 } 2163 done 2164 shift \$((OPTIND - 1)) 2165 set -A args -- '$srcdir/check.pl' -p "\$pflag" 2166 x= 2167 for y in "\${check_categories[@]}"; do 2168 x=\$x,\$y 2169 done 2170 if [[ -n \$x ]]; then 2171 args[\${#args[*]}]=-C 2172 args[\${#args[*]}]=\${x#,} 2173 fi 2174 if (( usee )); then 2175 args[\${#args[*]}]=-e 2176 args[\${#args[*]}]=\$eflag 2177 fi 2178 (( Pflag )) && args[\${#args[*]}]=-P 2179 if (( uset )); then 2180 args[\${#args[*]}]=-t 2181 args[\${#args[*]}]=\$tflag 2182 fi 2183 (( vflag )) && args[\${#args[*]}]=-v 2184 (( xflag )) && args[\${#args[*]}]=-x # force usage by synerr 2185 print Testing mksh for conformance: 2186 fgrep -e MirOS: -e MIRBSD "\$sflag" 2187 print "This shell is actually:\\n\\t\$KSH_VERSION" 2188 print 'test.sh built for mksh $dstversion' 2189 cstr='\$os = defined \$^O ? \$^O : "unknown";' 2190 cstr="\$cstr"'print \$os . ", Perl version " . \$];' 2191 for perli in \$PERL perl5 perl no; do 2192 if [[ \$perli = no ]]; then 2193 print Cannot find a working Perl interpreter, aborting. 2194 exit 1 2195 fi 2196 print "Trying Perl interpreter '\$perli'..." 2197 perlos=\$(\$perli -e "\$cstr") 2198 rv=\$? 2199 print "Errorlevel \$rv, running on '\$perlos'" 2200 if (( rv )); then 2201 print "=> not using" 2202 continue 2203 fi 2204 if [[ -n \$perlos ]]; then 2205 print "=> using it" 2206 break 2207 fi 2208 done 2209 (( Sflag )) || echo + \$perli "\${args[@]}" -s "\$sflag" "\$@" 2210 (( Sflag )) || exec \$perli "\${args[@]}" -s "\$sflag" "\$@"$tsts 2211 # use of the -S option for check.t split into multiple chunks 2212 rv=0 2213 for s in "\$sflag".*; do 2214 echo + \$perli "\${args[@]}" -s "\$s" "\$@" 2215 \$perli "\${args[@]}" -s "\$s" "\$@"$tsts 2216 rc=\$? 2217 (( rv = rv ? rv : rc )) 2218 done 2219 exit \$rv 2220 EOF 2221 chmod 755 test.sh 2222 if test $cm = llvm; then 2223 emitbc="-emit-llvm -c" 2224 elif test $cm = dragonegg; then 2225 emitbc="-S -flto" 2226 else 2227 emitbc=-c 2228 fi 2229 echo ": # work around NeXTstep bug" >Rebuild.sh 2230 echo set -x >>Rebuild.sh 2231 for file in $SRCS; do 2232 op=`echo x"$file" | sed 's/^x\(.*\)\.c$/\1./'` 2233 test -f $file || file=$srcdir/$file 2234 files="$files$sp$file" 2235 sp=' ' 2236 echo "$CC $CFLAGS $CPPFLAGS $emitbc $file || exit 1" >>Rebuild.sh 2237 if test $cm = dragonegg; then 2238 echo "mv ${op}s ${op}ll" >>Rebuild.sh 2239 echo "llvm-as ${op}ll || exit 1" >>Rebuild.sh 2240 objs="$objs$sp${op}bc" 2241 else 2242 objs="$objs$sp${op}o" 2243 fi 2244 done 2245 case $cm in 2246 dragonegg|llvm) 2247 echo "rm -f $tfn.s" >>Rebuild.sh 2248 echo "llvm-link -o - $objs | opt $optflags | llc -o $tfn.s" >>Rebuild.sh 2249 lobjs=$tfn.s 2250 ;; 2251 *) 2252 lobjs=$objs 2253 ;; 2254 esac 2255 echo tcfn=$mkshexe >>Rebuild.sh 2256 echo "$CC $CFLAGS $LDFLAGS -o \$tcfn $lobjs $LIBS $ccpr" >>Rebuild.sh 2257 echo 'test -f $tcfn || exit 1; size $tcfn' >>Rebuild.sh 2258 if test $cm = makefile; then 2259 extras='emacsfn.h sh.h sh_flags.h var_spec.h' 2260 test 0 = $HAVE_SYS_SIGNAME && extras="$extras signames.inc" 2261 cat >Makefrag.inc <<EOF 2262 # Makefile fragment for building mksh $dstversion 2263 2264 PROG= $mkshexe 2265 MAN= mksh.1 2266 SRCS= $SRCS 2267 SRCS_FP= $files 2268 OBJS_BP= $objs 2269 INDSRCS= $extras 2270 NONSRCS_INST= dot.mkshrc \$(MAN) 2271 NONSRCS_NOINST= Build.sh Makefile Rebuild.sh check.pl check.t test.sh 2272 CC= $CC 2273 CFLAGS= $CFLAGS 2274 CPPFLAGS= $CPPFLAGS 2275 LDFLAGS= $LDFLAGS 2276 LIBS= $LIBS 2277 2278 # not BSD make only: 2279 #VPATH= $srcdir 2280 #all: \$(PROG) 2281 #\$(PROG): \$(OBJS_BP) 2282 # \$(CC) \$(CFLAGS) \$(LDFLAGS) -o \$@ \$(OBJS_BP) \$(LIBS) 2283 #\$(OBJS_BP): \$(SRCS_FP) \$(NONSRCS) 2284 #.c.o: 2285 # \$(CC) \$(CFLAGS) \$(CPPFLAGS) -c \$< 2286 2287 # for all make variants: 2288 #REGRESS_FLAGS= -f 2289 #regress: 2290 # ./test.sh \$(REGRESS_FLAGS) 2291 check_categories=$check_categories 2292 2293 # for BSD make only: 2294 #.PATH: $srcdir 2295 #.include <bsd.prog.mk> 2296 EOF 2297 $e 2298 $e Generated Makefrag.inc successfully. 2299 exit 0 2300 fi 2301 if test $cm = combine; then 2302 objs="-o $mkshexe" 2303 for file in $SRCS; do 2304 test -f $file || file=$srcdir/$file 2305 objs="$objs $file" 2306 done 2307 emitbc="-fwhole-program --combine" 2308 v "$CC $CFLAGS $CPPFLAGS $LDFLAGS $emitbc $objs $LIBS $ccpr" 2309 elif test 1 = $pm; then 2310 for file in $SRCS; do 2311 test -f $file || file=$srcdir/$file 2312 v "$CC $CFLAGS $CPPFLAGS $emitbc $file" & 2313 done 2314 wait 2315 else 2316 for file in $SRCS; do 2317 test $cm = dragonegg && \ 2318 op=`echo x"$file" | sed 's/^x\(.*\)\.c$/\1./'` 2319 test -f $file || file=$srcdir/$file 2320 v "$CC $CFLAGS $CPPFLAGS $emitbc $file" || exit 1 2321 if test $cm = dragonegg; then 2322 v "mv ${op}s ${op}ll" 2323 v "llvm-as ${op}ll" || exit 1 2324 fi 2325 done 2326 fi 2327 case $cm in 2328 dragonegg|llvm) 2329 rmf $tfn.s 2330 v "llvm-link -o - $objs | opt $optflags | llc -o $tfn.s" 2331 ;; 2332 esac 2333 tcfn=$mkshexe 2334 test $cm = combine || v "$CC $CFLAGS $LDFLAGS -o $tcfn $lobjs $LIBS $ccpr" 2335 test -f $tcfn || exit 1 2336 test 1 = $r || v "$NROFF -mdoc <'$srcdir/mksh.1' >$tfn.cat1" || \ 2337 rmf $tfn.cat1 2338 test 0 = $eq && v size $tcfn 2339 i=install 2340 test -f /usr/ucb/$i && i=/usr/ucb/$i 2341 test 1 = $eq && e=: 2342 $e 2343 $e Installing the shell: 2344 $e "# $i -c -s -o root -g bin -m 555 $tfn /bin/$tfn" 2345 $e "# grep -x /bin/$tfn /etc/shells >/dev/null || echo /bin/$tfn >>/etc/shells" 2346 $e "# $i -c -o root -g bin -m 444 dot.mkshrc /usr/share/doc/mksh/examples/" 2347 $e 2348 $e Installing the manual: 2349 if test -f $tfn.cat1; then 2350 $e "# $i -c -o root -g bin -m 444 $tfn.cat1" \ 2351 "/usr/share/man/cat1/$tfn.0" 2352 $e or 2353 fi 2354 $e "# $i -c -o root -g bin -m 444 mksh.1 /usr/share/man/man1/$tfn.1" 2355 $e 2356 $e Run the regression test suite: ./test.sh 2357 $e Please also read the sample file dot.mkshrc and the fine manual. 2358 exit 0 2359 2360 : <<'EOD' 2361 2362 === Environment used === 2363 2364 ==== build environment ==== 2365 AWK default: awk 2366 CC default: cc 2367 CFLAGS if empty, defaults to -xO2 or +O2 2368 or -O3 -qstrict or -O2, per compiler 2369 CPPFLAGS default empty 2370 LDFLAGS default empty; added before sources 2371 LDSTATIC set this to '-static'; default unset 2372 LIBS default empty; added after sources 2373 [Interix] default: -lcrypt (XXX still needed?) 2374 NOWARN -Wno-error or similar 2375 NROFF default: nroff 2376 TARGET_OS default: $(uname -s || uname) 2377 TARGET_OSREV [QNX] default: $(uname -r) 2378 2379 ==== feature selectors ==== 2380 USE_PRINTF_BUILTIN 1 to include (unsupported) printf(1) as builtin 2381 ===== general format ===== 2382 HAVE_STRLEN ac_test 2383 HAVE_STRING_H ac_header 2384 HAVE_CAN_FSTACKPROTECTORALL ac_flags 2385 2386 ==== cpp definitions ==== 2387 DEBUG dont use in production, wants gcc, implies: 2388 DEBUG_LEAKS enable freeing resources before exiting 2389 MKSHRC_PATH "~/.mkshrc" (do not change) 2390 MKSH_A4PB force use of arc4random_pushb 2391 MKSH_ASSUME_UTF8 (0=disabled, 1=enabled; default: unset) 2392 MKSH_BINSHREDUCED if */sh or */-sh, enable set -o sh 2393 MKSH_CLRTOEOL_STRING "\033[K" 2394 MKSH_CLS_STRING "\033[;H\033[J" 2395 MKSH_CONSERVATIVE_FDS fd 0-9 for scripts, shell only up to 31 2396 MKSH_DEFAULT_EXECSHELL "/bin/sh" (do not change) 2397 MKSH_DEFAULT_PROFILEDIR "/etc" (do not change) 2398 MKSH_DEFAULT_TMPDIR "/tmp" (do not change) 2399 MKSH_DISABLE_DEPRECATED disable code paths scheduled for later removal 2400 MKSH_DISABLE_EXPERIMENTAL disable code not yet comfy for (LTS) snapshots 2401 MKSH_DISABLE_TTY_WARNING shut up warning about ctty if OS cant be fixed 2402 MKSH_DONT_EMIT_IDSTRING omit RCS IDs from binary 2403 MKSH_GCC55009 DANGER! see http://www.mirbsd.org/mksh.htm#p41 2404 MKSH_MIDNIGHTBSD01ASH_COMPAT set -o sh: additional compatibility quirk 2405 MKSH_NOPROSPECTOFWORK disable jobs, co-processes, etc. (do not use) 2406 MKSH_NOPWNAM skip PAM calls, for -static on eglibc, Solaris 2407 MKSH_NO_CMDLINE_EDITING disable command line editing code entirely 2408 MKSH_NO_DEPRECATED_WARNING omit warning when deprecated stuff is run 2409 MKSH_NO_EXTERNAL_CAT omit hack to skip cat builtin when flags passed 2410 MKSH_NO_LIMITS omit ulimit code 2411 MKSH_NO_SIGSETJMP define if sigsetjmp is broken or not available 2412 MKSH_NO_SIGSUSPEND use sigprocmask+pause instead of sigsuspend 2413 MKSH_SMALL omit some code, optimise hard for size (slower) 2414 MKSH_SMALL_BUT_FAST disable some hard-for-size optim. (modern sys.) 2415 MKSH_S_NOVI=1 disable Vi editing mode (default if MKSH_SMALL) 2416 MKSH_TYPEDEF_SIG_ATOMIC_T define to e.g. 'int' if sig_atomic_t is missing 2417 MKSH_TYPEDEF_SSIZE_T define to e.g. 'long' if your OS has no ssize_t 2418 MKSH_UNEMPLOYED disable job control (but not jobs/co-processes) 2419 2420 === generic installation instructions === 2421 2422 Set CC and possibly CFLAGS, CPPFLAGS, LDFLAGS, LIBS. If cross-compiling, 2423 also set TARGET_OS. To disable tests, set e.g. HAVE_STRLCPY=0; to enable 2424 them, set to a value other than 0 or 1. Ensure /bin/ed is installed. For 2425 MKSH_SMALL but with Vi mode, add -DMKSH_S_NOVI=0 to CPPFLAGS as well. 2426 2427 Normally, the following command is what you want to run, then: 2428 $ (sh Build.sh -r -c lto && ./test.sh -f) 2>&1 | tee log 2429 2430 Copy dot.mkshrc to /etc/skel/.mkshrc; install mksh into $prefix/bin; or 2431 /bin; install the manpage, if omitting the -r flag a catmanpage is made 2432 using $NROFF. Consider using a forward script as /etc/skel/.mkshrc like 2433 https://www.mirbsd.org/cvs.cgi/contrib/hosted/tg/deb/mksh/debian/.mkshrc?rev=HEAD 2434 and put dot.mkshrc as /etc/mkshrc so users need not keep up their HOME. 2435 2436 EOD 2437