|
|
1.1 ! root 1: #!/bin/sh ! 2: ############################################################ ! 3: ## ! 4: ## implementation of the "build" target of cc makefile ! 5: ## ! 6: ############################################################ ! 7: ! 8: PATH=/bin:/usr/bin ! 9: export PATH ! 10: ! 11: # what targets to produce compilers to ! 12: TARGETS=`arch` ! 13: ! 14: # what host we should produce executables for ! 15: HOSTS=`arch` ! 16: ! 17: # the host on which we are running at now ! 18: BUILD=`arch` ! 19: ! 20: # where to do the build .. better have lots of space there! ! 21: SRCROOT=~comp/cc_proj/cc ! 22: ! 23: # where to do the build .. better have lots of space there! ! 24: OBJROOT= ! 25: ! 26: # where to do the build .. better have lots of space there! ! 27: SYMROOT= ! 28: ! 29: # where to do the build .. better have lots of space there! ! 30: DSTROOT= ! 31: ! 32: # where to do the build .. better have lots of space there! ! 33: BUILDROOT=/private/tmp ! 34: ! 35: # what compilers to build. On NeXT, we only use those two. ! 36: LANGUAGES="objc objc++" ! 37: ! 38: # Optimize flags when compiling the compiler ! 39: CFLAGS=-g ! 40: OPTIMIZE=-O ! 41: ! 42: result=fats ! 43: ! 44: for arg ! 45: do ! 46: case $next_arg in ! 47: --srcroot) ! 48: SRCROOT=$arg ! 49: next_arg= ! 50: ;; ! 51: --objroot) ! 52: OBJROOT=$arg ! 53: next_arg= ! 54: ;; ! 55: --dstroot) ! 56: DSTROOT=$arg ! 57: next_arg= ! 58: ;; ! 59: --symroot) ! 60: SYMROOT=$arg ! 61: next_arg= ! 62: ;; ! 63: --buildroot) ! 64: BUILDROOT=$arg ! 65: next_arg= ! 66: ;; ! 67: --host*) ! 68: HOSTS=$arg ! 69: next_arg= ! 70: ;; ! 71: --target*) ! 72: TARGETS=$arg ! 73: next_arg= ! 74: ;; ! 75: --cflags) ! 76: CFLAGS=$arg ! 77: next_arg= ! 78: ;; ! 79: *) ! 80: case $arg in ! 81: --srcroot=*) ! 82: SRCROOT=`echo $arg | sed 's/-*s[a-z]*=//'` ! 83: ;; ! 84: ! 85: --objroot=*) ! 86: OBJROOT=`echo $arg | sed 's/-*o[a-z]*=//'` ! 87: ;; ! 88: ! 89: --dstroot=*) ! 90: DSTROOT=`echo $arg | sed 's/-*d[a-z]*=//'` ! 91: ;; ! 92: ! 93: --symroot=*) ! 94: SYMROOT=`echo $arg | sed 's/-*s[a-z]*=//'` ! 95: ;; ! 96: ! 97: --buildroot=*) ! 98: BUILDROOT=`echo $arg | sed 's/-*b[a-z]*=//'` ! 99: ;; ! 100: ! 101: --hosts=*|--host=*) ! 102: HOSTS=`echo $arg | sed 's/-*h[a-z]*=//'` ! 103: ;; ! 104: ! 105: --targets=*|--target=*) ! 106: TARGETS=`echo $arg | sed 's/-*t[a-z]*=//'` ! 107: ;; ! 108: ! 109: --cflags=*) ! 110: CFLAGS=`echo $arg | sed 's/-*c[a-z]*=//'` ! 111: ;; ! 112: ! 113: --optimize=*) ! 114: if [ `echo $arg | sed 's/-*o[a-z]*=//'` = yes ]; then ! 115: OPTIMIZE=-O ! 116: else ! 117: OPTIMIZE= ! 118: fi ! 119: ;; ! 120: ! 121: --fat|--fats) ! 122: result=fats ! 123: ;; ! 124: ! 125: --thin|--thins) ! 126: result=thins ! 127: ;; ! 128: ! 129: --clean) ! 130: result=clean ! 131: ;; ! 132: ! 133: --configure) ! 134: result=configure ! 135: ;; ! 136: ! 137: --optimize) ! 138: OPTIMIZE=-O ! 139: ;; ! 140: ! 141: --no-optimize) ! 142: OPTIMIZE= ! 143: ;; ! 144: ! 145: --*) ! 146: next_arg=$arg ! 147: ;; ! 148: *) ! 149: echo unknown option $arg ! 150: exit 1 ! 151: ;; ! 152: esac ! 153: esac ! 154: done ! 155: ! 156: # get the version ! 157: CCVERS=`cd $SRCROOT; vers_string -f cc` ! 158: ! 159: # remove any -arch flags from CFLAGS ! 160: CFLAGS=`echo $CFLAGS|sed 's/-arch [a-z0-9]*//g'` ! 161: ! 162: # add target arch... ! 163: if [ x$RC_RELEASE != x ]; then ! 164: CFLAGS="$CFLAGS -DRC_RELEASE_"`echo $RC_RELEASE|tr '.' '_'` ! 165: fi ! 166: ! 167: if [ x$SYMROOT = x ]; then ! 168: SYMROOT=$BUILDROOT/$CCVERS.sym ! 169: fi ! 170: ! 171: if [ x$OBJROOT = x ]; then ! 172: OBJROOT=$BUILDROOT/$CCVERS.obj ! 173: fi ! 174: ! 175: if [ x$DSTROOT = x ]; then ! 176: DSTROOT=$BUILDROOT/$CCVERS.dst ! 177: fi ! 178: ! 179: # set up bison environment ! 180: BISON=$OBJROOT/bison_`arch`_obj/bison ! 181: BISON_SIMPLE=$BISON.s1 ! 182: export BISON_SIMPLE ! 183: ! 184: echo =========================================================== ! 185: echo == 'Building NeXT C compiler(s) **' $result '**' ! 186: echo =========================================================== ! 187: echo == 'HOSTS :' ${HOSTS} ! 188: echo == 'TARGETS :' ${TARGETS} ! 189: echo == 'BUILDHOST :' `hostname` -- a `arch` ! 190: echo == 'OBJROOT :' ${OBJROOT} ! 191: echo == 'SYMROOT :' ${SYMROOT} ! 192: echo == 'SRCROOT :' ${SRCROOT} ! 193: echo == 'DSTROOT :' ${DSTROOT} ! 194: echo == 'VERSION :' ${CCVERS} ! 195: echo == 'CFLAGS :' ${OPTIMIZE} ${CFLAGS} ! 196: echo =========================================================== ! 197: ! 198: ! 199: # ! 200: # Check that cross compilers are available ! 201: # ! 202: ! 203: missing_cross=no ! 204: ! 205: for host in ${HOSTS}; do ! 206: if [ -d /lib/$host ]; then true; else ! 207: echo "************************************************************" ! 208: echo "** You must have a cross compiler for $host installed" ! 209: missing_cross=yes ! 210: fi; ! 211: done ! 212: ! 213: for host in $HOSTS; do ! 214: if echo $TARGETS | grep $host > /dev/null 2>&1; then true; else ! 215: echo '************************************************************' ! 216: echo '**' "hosttype $host must also be a target" ! 217: missing_cross=yes ! 218: fi ! 219: done ! 220: ! 221: if [ $missing_cross = yes ]; then ! 222: echo "************************************************************" ! 223: exit 1; ! 224: fi ! 225: ! 226: ! 227: safe_exec () { ! 228: if ($*); then true; else exit 1; fi ! 229: } ! 230: ! 231: clean_gcc () { ! 232: echo =========================================================== ! 233: echo == 'Cleaning NeXT C compiler(s)' ! 234: echo =========================================================== ! 235: ! 236: for target in ${TARGETS}; do ! 237: for host in ${HOSTS}; do ! 238: echo '==' ${OBJROOT}/cc-$target-on-$host; ! 239: if [ -d ${OBJROOT}/cc-$target-on-$host ]; then ! 240: /bin/rm -Rf ${OBJROOT}/cc-$target-on-$host; ! 241: fi ! 242: done ! 243: done ! 244: for host in ${HOSTS}; do ! 245: if [ -d ${SYMROOT}/$host ]; then ! 246: echo '==' ${SYMROOT}/$host; ! 247: /bin/rm -Rf ${SYMROOT}/$host; ! 248: fi ! 249: done ! 250: if [ X${DSTROOT} != X${SRCROOT} ]; then ! 251: if [ -d ${DSTROOT} ]; then ! 252: echo '==' ${DSTROOT}; ! 253: /bin/rm -Rf ${DSTROOT}; ! 254: fi ! 255: fi ! 256: echo =========================================================== ! 257: } ! 258: ! 259: configure_gcc () { ! 260: for target in ${TARGETS}; do ! 261: for host in ${HOSTS}; do ! 262: mkdirs ${OBJROOT}/cc-$target-on-$host; ! 263: cd ${OBJROOT}/cc-$target-on-$host; ! 264: ! 265: source=bad ! 266: if [ -f make.id ]; then ! 267: if [ X`cat make.id` = X${SRCROOT}/cc:`arch` ]; then ! 268: source=ok ! 269: fi ! 270: fi ! 271: ! 272: if [ X$source = Xok -a -f Makefile ]; then ! 273: echo ===========================================================; ! 274: echo == updating Makefile for cc-$target-on-$host\; buildhost=`arch` ! 275: echo ===========================================================; ! 276: safe_exec make Makefile ! 277: else ! 278: echo ===========================================================; ! 279: echo == configuring cc-$target-on-$host\; buildhost=`arch` ! 280: echo ===========================================================; ! 281: /bin/rm -f make.id ! 282: echo ${SRCROOT}/cc:`arch` > make.id ! 283: /bin/rm -f rtl.o bc-*.o ! 284: ${SRCROOT}/cc/configure \ ! 285: --host=$host-next-mach \ ! 286: --target=$target-next-mach \ ! 287: --build=`arch`-next-mach \ ! 288: --srcdir=${SRCROOT}/cc \ ! 289: --force-build; ! 290: fi; ! 291: done; ! 292: done ! 293: } ! 294: ! 295: install_newer () { ! 296: if [ -f "$1" ]; then ! 297: rm -f /tmp/make.$$ ! 298: touch -f /tmp/make.$$ ! 299: echo "$2: $1" >> /tmp/make.$$ ! 300: echo " /bin/rm -f $2" >> /tmp/make.$$ ! 301: echo " install -c $3 $1 $2" >> /tmp/make.$$ ! 302: safe_exec make -f /tmp/make.$$ ! 303: rm -f /tmp/make.$$ ! 304: else ! 305: echo "build_gcc: $1: no such file" ! 306: fi ! 307: } ! 308: ! 309: ! 310: build_compiler () { ! 311: for host in ${HOSTS}; do ! 312: for target in ${TARGETS}; do ! 313: cd ${OBJROOT}/cc-$target-on-$host; ! 314: echo ===========================================================; ! 315: echo == building cc-$target-on-$host\; buildhost:`arch`; ! 316: echo ===========================================================; ! 317: ! 318: ############################################################# ! 319: # this will build the core compilers ! 320: ############################################################# ! 321: ! 322: if [ -d `arch` ]; then true; else mkdir `arch`; fi ! 323: if make all.build \ ! 324: srcdir=${SRCROOT}/cc \ ! 325: LANGUAGES="${LANGUAGES}" \ ! 326: HOST_PREFIX="`arch`-" HOST_PREFIX_1="`arch`-" \ ! 327: HOST_CC="cc -arch `arch` -traditional-cpp" \ ! 328: BISON=${BISON} \ ! 329: CFLAGS="${OPTIMIZE} ${CFLAGS}" \ ! 330: CC="cc -arch $host -traditional-cpp"; \ ! 331: then echo '== ok' ; else exit 1; fi ! 332: ! 333: sym=$SYMROOT/$host ! 334: ! 335: mkdirs $sym/lib/$target ! 336: mkdirs $sym/bin ! 337: ! 338: install_newer cpp $sym/lib/$target/cpp "-m 555" ! 339: install_newer cc1obj $sym/lib/$target/cc1obj "-m 555" ! 340: install_newer cc1objplus $sym/lib/$target/cc1objplus "-m 555" ! 341: ! 342: done ! 343: ! 344: if echo $TARGETS | grep $host; then ! 345: install_newer ${OBJROOT}/cc-$host-on-$host/xgcc $sym/bin/cc "-m 555" ! 346: else ! 347: echo '************************************************************' ! 348: echo '**' "hosttype $host must also be a target" ! 349: echo '************************************************************' ! 350: exit 1; ! 351: fi ! 352: ! 353: done ! 354: } ! 355: ! 356: ! 357: build_libgcc () { ! 358: for target in ${TARGETS}; do ! 359: ! 360: host=`arch` ! 361: mkdirs ${OBJROOT}/cc-$target-on-$host; ! 362: cd ${OBJROOT}/cc-$target-on-$host; ! 363: ! 364: # the buildhost is in hosts.. ! 365: if echo $HOSTS | grep $host; then ! 366: ! 367: ############################################################# ! 368: # now, build the gcc specs and runtime libraries ! 369: ############################################################# ! 370: ! 371: echo "============================================================" ! 372: echo "== Building runtime libraries, using new compiler:" ! 373: ./xgcc -B./ -v ! 374: echo "============================================================" ! 375: ! 376: echo '== building static version' ! 377: if [ -f libgcc_static.a ]; then mv -f libgcc_static.a libgcc.a; fi ! 378: if [ -f libgcc1_static.a ]; then mv -f libgcc1_static.a libgcc1.a; fi ! 379: if [ -f libgcc2_static.a ]; then mv -f libgcc2_static.a libgcc2.a; fi ! 380: ! 381: if make specs libgcc1.a libgcc.a \ ! 382: srcdir=${SRCROOT}/cc \ ! 383: LANGUAGES="${LANGUAGES}" \ ! 384: HOST_PREFIX="`arch`-" HOST_PREFIX_1="`arch`-" \ ! 385: HOST_CC="cc -arch `arch` -traditional-cpp" \ ! 386: OLDCC="./xgcc -B./" \ ! 387: CCLIBFLAGS="${OPTIMIZE} ${CFLAGS}" \ ! 388: GCC_FOR_TARGET="./xgcc -B./" \ ! 389: CFLAGS="${OPTIMIZE} ${CFLAGS}" \ ! 390: BISON=${BISON} \ ! 391: GCC_CFLAGS="-traditional-cpp ${CFLAGS}" \ ! 392: AR_FOR_TARGET=ar LIBGCC1=libgcc1.a \ ! 393: CC="cc -arch $host -traditional-cpp"; \ ! 394: then echo '== ok'; else exit 1; fi ! 395: ! 396: mv -f libgcc.a libgcc_static.a ! 397: mv -f libgcc1.a libgcc1_static.a ! 398: mv -f libgcc2.a libgcc2_static.a ! 399: echo '== building shlib version' ! 400: if [ -f libgcc_shlib.a ]; then mv -f libgcc_shlib.a libgcc.a; fi ! 401: if [ -f libgcc1_shlib.a ]; then mv -f libgcc1_shlib.a libgcc1.a; fi ! 402: if [ -f libgcc2_shlib.a ]; then mv -f libgcc2_shlib.a libgcc2.a; fi ! 403: ! 404: if make specs libgcc1.a libgcc.a \ ! 405: srcdir=${SRCROOT}/cc \ ! 406: LANGUAGES="${LANGUAGES}" \ ! 407: HOST_PREFIX="`arch`-" HOST_PREFIX_1="`arch`-" \ ! 408: HOST_CC="cc -arch `arch` -traditional-cpp -DSHLIB" \ ! 409: OLDCC="./xgcc -B./ -DSHLIB" \ ! 410: CCLIBFLAGS="${OPTIMIZE} ${CFLAGS} -DSHLIB" \ ! 411: GCC_FOR_TARGET="./xgcc -B./ -DSHLIB" \ ! 412: CFLAGS="${OPTIMIZE} ${CFLAGS} -DSHLIB" \ ! 413: BISON=${BISON} \ ! 414: GCC_CFLAGS="-traditional-cpp ${CFLAGS} -DSHLIB" \ ! 415: AR_FOR_TARGET=ar LIBGCC1=libgcc1.a \ ! 416: CC="cc -arch $host -traditional-cpp -DSHLIB"; \ ! 417: then echo '== ok'; else exit 1; fi ! 418: ! 419: mv -f libgcc.a libgcc_shlib.a ! 420: mv -f libgcc1.a libgcc1_shlib.a ! 421: mv -f libgcc2.a libgcc2_shlib.a ! 422: ! 423: for host in ${HOSTS}; do ! 424: sym=$SYMROOT/$host ! 425: ! 426: mkdirs $sym/lib/$target ! 427: install_newer specs $sym/lib/$target/specs "-m 444" ! 428: install_newer libgcc_static.a $sym/lib/$target/libcc.a "-r -m 444" ! 429: ! 430: done ! 431: ! 432: libgcc=`pwd`/libgcc_shlib.a ! 433: shlib=${OBJROOT}/shlib_${target}_obj ! 434: (mkdirs $shlib; cd $shlib; ar x $libgcc) ! 435: ! 436: else ! 437: ! 438: ############################################################ ! 439: # copy specs /lib/$target... ! 440: ############################################################ ! 441: ! 442: if [ -d /lib/$target ]; then ! 443: ! 444: # get version of installed $target compiler ! 445: ! 446: cc -arch $target -v 2> /tmp/tmp.$$ ! 447: target_vers=`cat /tmp/tmp.$$ \ ! 448: | grep 'version' \ ! 449: | sed 's/, gcc.*$//' \ ! 450: | sed 's/^.*version //'` ! 451: rm /tmp/tmp.$$ ! 452: ! 453: if [ X$target_vers != X$CCVERS ]; then ! 454: echo "************************************************************"; ! 455: echo "** You must have the most resent version of the compiler " ! 456: echo "** (host=" `arch` " target=$target version=$CCVERS) installed" ! 457: echo "** on the build host to finish this build... " ! 458: echo "** Currently, version $target_vers is installed " ! 459: echo "************************************************************"; ! 460: exit 1; ! 461: fi ! 462: ! 463: echo "============================================================" ! 464: echo "== Building runtime libraries, using installed compiler:" ! 465: cc -arch $target -v ! 466: echo "============================================================" ! 467: ! 468: rm -f specs ! 469: cp /lib/$target/specs specs ! 470: ! 471: echo '== building static version' ! 472: if [ -f libgcc_static.a ]; then mv -f libgcc_static.a libgcc.a; fi ! 473: if [ -f libgcc1_static.a ]; then mv -f libgcc1_static.a libgcc1.a; fi ! 474: if [ -f libgcc2_static.a ]; then mv -f libgcc2_static.a libgcc2.a; fi ! 475: ! 476: if make libgcc1.a libgcc.a \ ! 477: srcdir=${SRCROOT}/cc \ ! 478: LANGUAGES="${LANGUAGES}" \ ! 479: HOST_PREFIX="`arch`-" HOST_PREFIX_1="`arch`-" \ ! 480: HOST_CC="cc -arch `arch` -traditional-cpp" \ ! 481: OLDCC="cc -arch $target" \ ! 482: BISON=${BISON} \ ! 483: GCC_FOR_TARGET="cc -arch $target" \ ! 484: CFLAGS="${OPTIMIZE} ${CFLAGS}" \ ! 485: GCC_CFLAGS="-traditional-cpp" \ ! 486: AR_FOR_TARGET=ar LIBGCC1=libgcc1.a \ ! 487: CC="cc -arch $host -traditional-cpp"; \ ! 488: then echo '== ok'; else exit 1; fi ! 489: ! 490: mv -f libgcc.a libgcc_static.a ! 491: mv -f libgcc1.a libgcc1_static.a ! 492: mv -f libgcc2.a libgcc2_static.a ! 493: echo '== building shlib version' ! 494: if [ -f libgcc_shlib.a ]; then mv -f libgcc_shlib.a libgcc.a; fi ! 495: if [ -f libgcc1_shlib.a ]; then mv -f libgcc1_shlib.a libgcc1.a; fi ! 496: if [ -f libgcc2_shlib.a ]; then mv -f libgcc2_shlib.a libgcc2.a; fi ! 497: ! 498: if make libgcc1.a libgcc.a \ ! 499: srcdir=${SRCROOT}/cc \ ! 500: LANGUAGES="${LANGUAGES}" \ ! 501: HOST_PREFIX="`arch`-" HOST_PREFIX_1="`arch`-" \ ! 502: HOST_CC="cc -arch `arch` -traditional-cpp -DSHLIB" \ ! 503: OLDCC="cc -arch $target -DSHLIB" \ ! 504: BISON=${BISON} \ ! 505: GCC_FOR_TARGET="cc -arch $target -DSHLIB" \ ! 506: CFLAGS="${OPTIMIZE} ${CFLAGS} -DSHLIB" \ ! 507: GCC_CFLAGS="-traditional-cpp -DSHLIB" \ ! 508: AR_FOR_TARGET=ar LIBGCC1=libgcc1.a \ ! 509: CC="cc -arch $host -traditional-cpp -DSHLIB"; \ ! 510: then echo '== ok'; else exit 1; fi ! 511: ! 512: mv -f libgcc.a libgcc_shlib.a ! 513: mv -f libgcc1.a libgcc1_shlib.a ! 514: mv -f libgcc2.a libgcc2_shlib.a ! 515: ! 516: for host in ${HOSTS}; do ! 517: sym=$SYMROOT/$host ! 518: mkdirs $sym/lib/$target ! 519: install_newer /lib/$target/specs $sym/lib/$target/specs "-m 444" ! 520: install_newer /lib/$target/libgcc_static.a $sym/lib/$target/libcc.a "-r -m 444" ! 521: done ! 522: ! 523: libgcc=`pwd`/libgcc_shlib.a ! 524: shlib=${OBJROOT}/shlib_${target}_obj ! 525: (mkdirs $shlib; cd $shlib; ar x $libgcc) ! 526: ! 527: ! 528: else ! 529: echo "************************************************************"; ! 530: echo "** You must have the most resent version of the compiler " ! 531: echo "** (host=" `arch` "; target=$target; version=$CCVERS) installed" ! 532: echo "** on the build host to finish this build... " ! 533: echo "** Currently, no such compiler is installed " ! 534: echo "************************************************************"; ! 535: exit 1; ! 536: fi; ! 537: fi ! 538: done ! 539: } ! 540: ! 541: install_fat () { ! 542: ! 543: echo "============================================================" ! 544: echo "== Building fat binaries [$HOSTS] fat for targets: $TARGETS" ! 545: echo "============================================================" ! 546: ! 547: fat=$DSTROOT ! 548: sym=$SYMROOT ! 549: mkdirs $fat ! 550: mkdirs $fat/bin ! 551: mkdirs $fat/lib ! 552: ! 553: for target in ${TARGETS}; do ! 554: mkdirs $fat/lib/$target; ! 555: for file in bin/cc \ ! 556: lib/$target/cpp \ ! 557: lib/$target/cc1obj \ ! 558: lib/$target/cc1objplus; do ! 559: thin_files="" ! 560: for host in ${HOSTS}; do ! 561: thin_files="$thin_files $sym/$host/$file" ! 562: done ! 563: rm -f $fat/$file ! 564: ! 565: rm -f /tmp/make.$$ ! 566: touch -f /tmp/make.$$ ! 567: echo "$fat/$file: $thin_files" >> /tmp/make.$$ ! 568: echo " /bin/rm -f $fat/$file" >> /tmp/make.$$ ! 569: echo " lipo -create -output $fat/$file $thin_files" >> /tmp/make.$$ ! 570: echo " strip $fat/$file" >> /tmp/make.$$ ! 571: echo " chmod 555 $fat/$file" >> /tmp/make.$$ ! 572: safe_exec make -f /tmp/make.$$ ! 573: rm -f /tmp/make.$$ ! 574: done ! 575: ! 576: install_newer $sym/$host/lib/$target/specs $fat/lib/$target/specs "-m 444" ! 577: install_newer $sym/$host/lib/$target/libcc.a $fat/lib/$target/libcc.a "-r -m 444" ! 578: done; ! 579: ! 580: } ! 581: ! 582: if [ X$result = Xclean ]; then ! 583: clean_gcc ! 584: exit 0 ! 585: fi ! 586: ! 587: configure_gcc ! 588: ! 589: if [ X$result = Xconfigure ]; then ! 590: exit 0 ! 591: fi ! 592: ! 593: build_compiler ! 594: build_libgcc ! 595: ! 596: if [ $result = thins ]; then ! 597: exit 0; ! 598: fi ! 599: ! 600: install_fat ! 601: ! 602: ! 603: ! 604: ! 605: ! 606:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.