home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume15 / hash8 / lcc.sh,v < prev    next >
Encoding:
Text File  |  1988-06-05  |  11.7 KB  |  613 lines

  1. head     1.5;
  2. access   ;
  3. symbols  ;
  4. locks    ; strict;
  5. comment  @# @;
  6.  
  7.  
  8. 1.5
  9. date     87.03.06.20.34.29;  author geoff;  state Exp;
  10. branches ;
  11. next     1.4;
  12.  
  13. 1.4
  14. date     87.02.28.00.56.50;  author geoff;  state Exp;
  15. branches ;
  16. next     1.3;
  17.  
  18. 1.3
  19. date     86.11.08.23.07.56;  author geoff;  state Exp;
  20. branches ;
  21. next     1.2;
  22.  
  23. 1.2
  24. date     86.11.08.22.15.24;  author geoff;  state Exp;
  25. branches ;
  26. next     1.1;
  27.  
  28. 1.1
  29. date     86.11.08.21.58.14;  author geoff;  state Exp;
  30. branches ;
  31. next     ;
  32.  
  33.  
  34. desc
  35. @Shell script to compile long-name C programs.
  36. @
  37.  
  38.  
  39. 1.5
  40. log
  41. @Make -p work correctly
  42. @
  43. text
  44. @: Use bin/sh
  45. #
  46. # $Header: lcc.sh,v 1.4 87/02/28 00:56:50 geoff Exp $
  47. #
  48. # $Log:    lcc.sh,v $
  49. # Revision 1.4  87/02/28  00:56:50  geoff
  50. # Major changes to handle things much better by running each compiler
  51. # pass separately.  Also add the -R switch, and support for -D and
  52. # library files.
  53. # Revision 1.3  86/11/08  23:07:56  geoff
  54. # Add error processing, not quite like cc's
  55. # Revision 1.2  86/11/08  22:15:24  geoff
  56. # Remove -HP, minor cleanup of output.  Working, except ignores errors
  57. # Revision 1.1  86/11/08  21:58:14  geoff
  58. # Works only if -HP specified
  59. #
  60. #    Replacement for the 'cc' command, with support for long
  61. #    identifiers.
  62. #
  63. #    Usage:
  64. #
  65. #    lcc [options] files
  66. #
  67. #    As with 'cc', the files mentioned can be .c, .s, or .o files.
  68. #
  69. #    All 'cc' options are support (or should be -- report bugs!).
  70. #
  71. #    There are some extra options.  All begin with H:
  72. #
  73. #    -HD    Don't preserve the encode/decode table.  (Normally, it is
  74. #        left in xxxx.t, where xxxx is the first file name encountered,
  75. #        or the -o file name if -o is specified.)
  76. #    -HA name The encode/decode table is put in <name>.  If it exists,
  77. #        the program will append to it.
  78. #    -HL    Only the C compiler itself is deficient;  the assembler
  79. #        and linker can handle long names.  Use this facility to
  80. #        generate long-name object files.  This is incompatible
  81. #        with -P and -S, but conflict is not checked.
  82. #    -R name    Add <name> to the reserved-word list.  Useful for
  83. #        library routines that have long names.
  84. #
  85. #    Options supported:
  86. #
  87. #    -I<dir>    Set include path for cpp
  88. #    -S    Generate .s files
  89. #    -c    Generate .o files;  don't load
  90. #    -n    Generate shared text (ld)
  91. #    -p    Generate profiled output
  92. #    -f*    Passed on to cc
  93. #
  94. TDIR=${TMPDIR:-/tmp}        # Where to put temp files
  95. TFILE=lcc$$            # Base name for encoded source files
  96. TMP=$TDIR/$TFILE        # Base name of cc's encoded input files
  97. TABLE=${TFILE}t            # Where the decode file goes
  98. c1sw=                # Switches for compiler pass 1
  99. ccsw=                # Switches for cc
  100. ldsw=                # Switches for ld
  101. suffix=o            # Suffix of output "object" files:  o, s, or i
  102. forceobj=-c            # How to force "objects":  -c, -P, or -S
  103. load=yes            # Yes to invoke loader
  104. numsrcfiles=            # If this is exactly one x, we kill objects
  105. ofiles=                # Files to be linked
  106. optimize=no            # -O switch specified
  107. optsw=                # Switches for optimizer
  108. preprocess=            # Preprocess option:  null, -P, or -E
  109. reserved=            # Reserved-word list
  110. rmfiles=            # List of object files to remove (only one)
  111. verbose=            # Verbose option:  -v or null
  112. killtable=no            # Yes if $TABLE is to be deleted
  113. tablename=            # Name of the output table
  114. madetable=no            # Yes if we added to the table
  115. dumbcc=no            # Yes if only cc is dumb about long names
  116.  
  117. if [ -x /lib/c ]
  118. then
  119.     COMPILER=/lib/c
  120. elif [ -x /usr/lib/c ]
  121. then
  122.     COMPILER=/usr/lib/c
  123. else
  124.     COMPILER=c
  125. fi
  126. if [ -x /lib/c2 ]
  127. then
  128.     OPTIMIZER=/lib/c2
  129. elif [ -x /usr/lib/c2 ]
  130. then
  131.     OPTIMIZER=/usr/lib/c2
  132. else
  133.     OPTIMIZER=c2
  134. fi
  135. trap '/bin/rm -f ${TFILE}.? ${TMP}* $TABLE; exit 1' 1 2 15
  136. # 7 is SIGEMT, a fairly obscure one
  137. failure=no
  138. trap "failure=yes" 7
  139. while [ $# -gt 0 ]
  140. do
  141.     case "$1" in
  142.     -HD)
  143.         TABLE=${TMP}t    # Put output table in $TMPDIR
  144.         killtable=yes
  145.         ;;
  146.     -HA)
  147.         tablename=$2
  148.         TABLE=$2
  149.         shift
  150.         ;;
  151.     -HL)
  152.         dumbcc=yes
  153.         ;;
  154.     -R)
  155.         reserved="$reserved -r $2"
  156.         shift
  157.         ;;
  158.     -n)
  159.         ldsw="$ldsw $1"
  160.         ;;
  161.     -v)
  162.         verbose=-v
  163.         ;;
  164.     -p)
  165.         ldsw="$ldsw $1"
  166.         c1sw="$c1sw -Xp"
  167.         ;;
  168.     -f*)
  169.         ldsw="$ldsw $1"
  170.         c1sw="$c1sw $1"
  171.         ;;
  172.     -o)
  173.         ldsw="$ldsw $1 $2"
  174.         tablename=$2.t
  175.         shift
  176.         ;;
  177.     -R)
  178.         ldsw="$ldsw $1 $2"
  179.         shift
  180.         ;;
  181.     -E|-P)
  182.         preprocess=$1
  183.         forceobj=$1
  184.         suffix=i
  185.         load=no
  186.         ;;
  187.     -O*)
  188.         optimize=yes
  189.         optsw=`echo $1 | tr -d O`
  190.         if [ "X$optsw" = "X-" ]
  191.         then
  192.         optsw=
  193.         fi
  194.         ;;
  195.     -C|-D*|-U*|-I*)
  196.         ccsw="$ccsw $1"
  197.         ;;
  198.     -S)
  199.         forceobj=-S
  200.         suffix=s
  201.         load=no
  202.         numsrcfiles=xx
  203.         ;;
  204.     -c)
  205.         load=no
  206.         numsrcfiles=xx
  207.         ;;
  208.     -l*)
  209.         ofiles="$ofiles $1"
  210.         ;;
  211.     *.o)
  212.         numsrcfiles=xx
  213.         ofiles="$ofiles $1"
  214.         if [ "$tablename" = "" ]
  215.         then
  216.         tablename=`basename $1 .o`.t
  217.         fi
  218.         ;;
  219.     *.s)
  220.         if  [ "$dumbcc" = "yes" -a "X$preprocess" = "X" ]
  221.         then
  222.         if cc $ccsw $verbose $forceobj $1
  223.         then
  224.             :
  225.         else
  226.             failure=yes
  227.             break
  228.         fi
  229.         elif [ "$suffix" != "s" -a "X$preprocess" = "X" ]
  230.         then
  231.         hash8 $reserved encode $TABLE < $1 > ${TMP}.s
  232.         madetable=yes
  233.         (cc $ccsw $forceobj $verbose ${TMP}.s 2> ${TMP}.e \
  234.             ||  kill -7 $$) \
  235.           | sed "s;${TMP}.s;$1;" | hash8 decode $TABLE
  236.         sed "s;${TMP}.s;$1;" ${TMP}.e | hash8 decode $TABLE 1>&2
  237.         if [ "$failure" = "yes" ]
  238.         then
  239.             break
  240.         fi
  241.         obj=`basename "$1" '.s'`.$suffix
  242.         ofiles="$ofiles $obj"
  243.         rmfiles="$rmfiles $obj"
  244.         mv ${TFILE}.$suffix $obj
  245.         numsrcfiles="x$numsrcfiles"
  246.         fi
  247.         if [ "$tablename" = "" ]
  248.         then
  249.         tablename=`basename $1 .s`.t
  250.         fi
  251.         ;;
  252.     *.c)
  253.         obj=`basename "$1" '.c'`.$suffix
  254.         ppfile=${TMP}.i
  255.         if [ "X$verbose" = "X-v" ]
  256.         then
  257.         echo "${1}:"
  258.         echo "  Preprocessing" 1>&2
  259.         fi
  260.         if [ "X$preprocess" = "X-E" ]
  261.         then
  262.         if cc $ccsw $preprocess $1
  263.         then
  264.             :
  265.         else
  266.             failure=yes
  267.         fi
  268.         elif [ "X$preprocess" = "X-P" ]
  269.         then
  270.         ppfile=$obj
  271.         fi
  272.         if cc $ccsw -E $1 > $ppfile
  273.         then
  274.         :
  275.         else
  276.         failure=yes
  277.         /bin/rm -f $ppfile
  278.         break
  279.         fi
  280.         if [ "X$preprocess" = "X-P" ]
  281.         then
  282.         break
  283.         fi
  284.         hash8 $reserved encode $TABLE < $ppfile > ${TMP}.c
  285.         madetable=yes
  286.         /bin/rm -f $ppfile
  287.         if [ "$optimize" = yes ]
  288.         then
  289.         unoptfile=${TMP}.s1
  290.         else
  291.         unoptfile=${TMP}.s
  292.         fi
  293.         if [ "X$verbose" = "X-v" ]
  294.         then
  295.         echo "  Compiling" 1>&2
  296.         fi
  297.         if $COMPILER $c1sw < ${TMP}.c > $unoptfile 2> ${TMP}.e
  298.         then
  299.         /bin/rm -f ${TMP}.c
  300.         else
  301.         hash8 decode $TABLE < ${TMP}.e 1>&2
  302.         /bin/rm $unoptfile ${TMP}.c ${TMP}.e
  303.         failure=yes
  304.         break
  305.         fi
  306.         if [ $optimize = yes ]
  307.         then
  308.         if [ "X$verbose" = "X-v" ]
  309.         then
  310.             echo "  Optimizing" 1>&2
  311.         fi
  312.         if $OPTIMIZER $optsw < $unoptfile > ${TMP}.s 2> ${TMP}.e
  313.         then
  314.             /bin/rm -f $unoptfile
  315.             unoptfile=${TMP}.s
  316.         else
  317.             hash8 decode $TABLE < ${TMP}.e 1>&2
  318.             /bin/rm -f $unoptfile ${TMP}.s ${TMP}.e
  319.             failure=yes
  320.             break
  321.         fi
  322.         fi
  323.         case "X$forceobj" in
  324.         X-S)
  325.             hash8 _decode $TABLE < $unoptfile > $obj
  326.             /bin/rm -f $unoptfile
  327.             ;;
  328.         *)
  329.             if [ "X$verbose" = "X-v" ]
  330.             then
  331.             echo "  Assembling" 1>&2
  332.             fi
  333.             if [ "$dumbcc" = "yes" ]
  334.             then
  335.             mv $unoptfile ${TMP}.s1
  336.             hash8 _decode $TABLE < ${TMP}.s1 > ${TMP}.s
  337.             /bin/rm -f ${TMP}.s1
  338.             if as -o $obj ${TMP}.s
  339.             then
  340.                 :
  341.             else
  342.                 /bin/rm -f ${TMP}.s $obj
  343.                 failure=yes
  344.                 break
  345.             fi
  346.             else
  347.             if as -o $obj $unoptfile 2> ${TMP}.e
  348.             then
  349.                 /bin/rm -f $unoptfile ${TMP}.e
  350.             else
  351.                 hash8 _decode $TABLE < ${TMP}.e 1>&2
  352.                 /bin/rm -f $unoptfile ${TMP}.e $obj
  353.                 failure=yes
  354.                 break
  355.             fi
  356.             fi
  357.             ofiles="$ofiles $obj"
  358.             rmfiles="$rmfiles $obj"
  359.             ;;
  360.         esac
  361.         numsrcfiles="x$numsrcfiles"
  362.         if [ "$tablename" = "" ]
  363.         then
  364.         tablename=`basename $1 .c`.t
  365.         fi
  366.         ;;
  367.     *)
  368.         echo "lcc:  unrecognized argument $1, passing to cc and ld" 1>&2
  369.         echo "type 'cat $0' to learn usage"
  370.         ccsw="$ccsw $1"
  371.         ldsw="$ldsw $1"
  372.         ;;
  373.     esac
  374.     shift
  375. done
  376. if [ "$load" = yes -a "$failure" = "no" ]
  377. then
  378.     if [ "X$verbose" = "X-v" ]
  379.     then
  380.     echo "  Loading" 1>&2
  381.     fi
  382.     (cc $ldsw $ofiles 2> ${TMP}.e  ||  kill -7 $$) \
  383.       | if [ "$madetable" = yes ]
  384.         then
  385.         hash8 _decode $TABLE
  386.         hash8 _decode $TABLE < ${TMP}.e 1>&2
  387.     elif [ -r "$tablename" ]
  388.     then
  389.         hash8 _decode $tablename
  390.         hash8 _decode $tablename < ${TMP}.e 1>&2
  391.     else
  392.         cat
  393.         cat ${TMP}.e 1>&2
  394.     fi
  395.     if [ "$numsrcfiles" = x ]
  396.     then
  397.     /bin/rm -f $rmfiles
  398.     fi
  399. fi
  400. /bin/rm -f ${TFILE}.? ${TMP}*
  401. if [ "$killtable" = "yes" -o "$tablename" = "" ]
  402. then
  403.     /bin/rm -f $TABLE
  404. elif [ "$madetable" = yes -a "$TABLE" != "$tablename" ]
  405. then
  406.     mv $TABLE $tablename
  407. fi
  408. if [ "$failure" = "yes" ]
  409. then
  410.     exit 1
  411. else
  412.     exit 0
  413. fi
  414. @
  415.  
  416.  
  417. 1.4
  418. log
  419. @Major changes to handle things much better by running each compiler
  420. pass separately.  Also add the -R switch, and support for -D and
  421. library files.
  422. @
  423. text
  424. @d3 1
  425. a3 1
  426. # $Header: lcc.sh,v 1.3 86/11/08 23:07:56 geoff Exp $
  427. d6 5
  428. d59 1
  429. d127 1
  430. a127 1
  431.         ccsw="$ccsw $1"
  432. d129 4
  433. d156 1
  434. a156 1
  435.     -f*|-C|-D*|-U*|-I*)
  436. d258 1
  437. a258 1
  438.         if $COMPILER < ${TMP}.c > $unoptfile 2> ${TMP}.e
  439. @
  440.  
  441.  
  442. 1.3
  443. log
  444. @Add error processing, not quite like cc's
  445. @
  446. text
  447. @d3 1
  448. a3 1
  449. # $Header: lcc.sh,v 1.2 86/11/08 22:15:24 geoff Exp $
  450. d6 3
  451. d37 3
  452. a39 1
  453. #        with -P and -S, but conflict is not cheked.
  454. d61 2
  455. d64 2
  456. d72 19
  457. a90 1
  458. trap "/bin/rm -f ${TFILE}.? ${TMP}* $TABLE; exit 1" 1 2 15
  459. a106 2
  460.         forceobj=-S
  461.         suffix=s
  462. d109 4
  463. d138 9
  464. a146 1
  465.     -f*|-O*|-C|-D*|-U*|-I*)
  466. d159 3
  467. d182 1
  468. a182 1
  469.         hash8 encode $TABLE < $1 > ${TMP}.s
  470. d194 1
  471. d204 32
  472. a235 1
  473.         hash8 encode $TABLE < $1 > ${TMP}.c
  474. d237 2
  475. a238 4
  476.         (cc $verbose $ccsw $forceobj ${TMP}.c 2> ${TMP}.e  ||  kill -7 $$) \
  477.           | sed "s;${TMP}.c;$1;" | hash8 decode $TABLE
  478.         sed "s;${TMP}.c;$1;" ${TMP}.e | hash8 decode $TABLE 1>&2
  479.         if [ "$failure" = "yes" ]
  480. d240 15
  481. d257 27
  482. a283 5
  483.         case "X${preprocess}Y$forceobj" in
  484.         X-P*|*Y-S)
  485.             obj=`basename "$1" '.c'`.$suffix
  486.             hash8 _decode $TABLE < ${TFILE}.$suffix > $obj
  487.             /bin/rm -f ${TFILE}.$suffix
  488. d286 4
  489. a289 1
  490.             if [ "X$verbose" = "X-v" ]
  491. d291 5
  492. a295 1
  493.                 echo "  Assembling" 1>&2
  494. d297 2
  495. a298 1
  496.             if cc $ccsw -c $obj
  497. d300 1
  498. a300 1
  499.                 :
  500. d302 2
  501. a306 2
  502.             /bin/rm -f $obj
  503.             obj=`basename "$1" '.c'`.o
  504. d309 1
  505. a310 7
  506.         X-E*)
  507.             ;;
  508.         *)
  509.             obj=`basename "$1" '.c'`.$suffix
  510.             ofiles="$ofiles $obj"
  511.             mv ${TFILE}.$suffix $obj
  512.             ;;
  513. d329 5
  514. a333 1
  515.     (cc $verbose $ldsw $ofiles 2> ${TMP}.e  ||  kill -7 $$) \
  516. d337 1
  517. d341 1
  518. d344 2
  519. a345 1
  520.     fi 1>&2
  521. d348 1
  522. a348 1
  523.     /bin/rm -f $ofiles
  524. @
  525.  
  526.  
  527. 1.2
  528. log
  529. @Remove -HP, minor cleanup of output.  Working, except ignores errors
  530. @
  531. text
  532. @d3 1
  533. a3 1
  534. # $Header: lcc.sh,v 1.1 86/11/08 21:58:14 geoff Exp $
  535. d6 3
  536. d64 3
  537. d133 7
  538. a139 1
  539.         cc $ccsw $verbose $forceobj $1
  540. d144 8
  541. a151 3
  542.         (cc $ccsw $forceobj $verbose ${TMP}.s 2>&1 ) \
  543.           | sed "s;${TMP}.s;$1;" \
  544.           | hash8 decode $TABLE 1>&2
  545. d165 1
  546. a165 1
  547.         (cc $verbose $ccsw $forceobj ${TMP}.c 2> ${TMP}.e ) \
  548. d168 4
  549. d183 7
  550. a189 1
  551.             cc $ccsw -c $obj
  552. d218 1
  553. a218 1
  554. if [ "$load" = yes ]
  555. d220 1
  556. a220 1
  557.     (cc $verbose $ldsw $ofiles 2>&1) \
  558. d243 6
  559. a248 1
  560. exit
  561. @
  562.  
  563.  
  564. 1.1
  565. log
  566. @Works only if -HP specified
  567. @
  568. text
  569. @d3 1
  570. a3 1
  571. # $Header$
  572. d5 4
  573. a8 1
  574. # $Log$
  575. a31 3
  576. #    -HP    Hash before passing information to the preprocessor, rather
  577. #        than after.  Useful if your preprocessor is dumb.  Conflicts
  578. #        with -E and -P.
  579. d53 1
  580. a53 1
  581. preprocess=            # Preprocess option:  null, -P, -E, or dumbpp
  582. a77 4
  583.     -HP)
  584.         preprocess=dumbpp
  585.         load=no
  586.         ;;
  587. d146 1
  588. a146 13
  589.         if [ "X$preprocess" = "X" ]
  590.         then
  591.         #
  592.         # We preprocess before hashing so that symbols in include
  593.         # files are picked up.  The disadvantage of this is that
  594.         # preprocessor names are not shortened, which gives trouble
  595.         # if your preprocessor is also dumb.  In this case,
  596.         # specify the -HP switch.
  597.         #
  598.         cc $ccsw -E $1 | hash8 encode $TABLE > ${TMP}.c
  599.         else
  600.         hash8 encode $TABLE < $1 > ${TMP}.c
  601.         fi
  602. d149 1
  603. a149 1
  604.           | hash8 decode $TABLE
  605. d193 1
  606. a193 1
  607.     (cc $ldsw $ofiles 2>&1) \
  608. @
  609.