home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 22 gnu / 22-gnu.zip / f77cmd.zip / f77 / f77.cmd < prev    next >
OS/2 REXX Batch file  |  1994-09-10  |  9KB  |  494 lines

  1. extproc ksh d:/os2/bin/f77.cmd
  2. #           ^- LOCAL CONFIG -^
  3. # NOTE: full path for f77.cmd is required! (CMD.EXE brain damage)
  4. #
  5. # $Id: f77.cmd,v 1.1 1994/09/11 05:47:18 jcp Exp jcp $
  6. #
  7. # f77 "look & feel" script to compile & link Fortran 77 and C code
  8. #
  9. # usage: f77 [options] source_files [-l library]
  10. #
  11. # f77 recognizes the following options;
  12. #
  13. #    -a        enable dynamic allocation of memory for local variables
  14. #
  15. #    -C        compile code to check for legal array subscripts values
  16. #
  17. #    -c        compile only, disable linking by the loader
  18. #
  19. #    -Dmacro[=def]    define a C preprocessor macro name
  20. #
  21. #    -f        allow statements longer than 72 characters
  22. #
  23. #    -g        generate symbol table information for debugging
  24. #
  25. #    -Idir        insert dir at start of search path for include files
  26. #
  27. #    -k        keep .c output from f2c (and .f when compiling .F files)
  28. #
  29. #    -Ldir        insert dir at start of search path for library files
  30. #
  31. #    -Ntnnn        allow nnn entries in table t (passed to f2c)
  32. #
  33. #    -ooutput    name the linker output file "output" instead of a.exe
  34. #
  35. #    -O        compiler tries to reduce code size and execution time
  36. #
  37. #    -P prog:opt    pass "opt" to "prog" compilation phase(cpp,f2c,cc,ld)
  38. #
  39. #       -r8             promote REAL to DOUBLE, COMPLEX to DOUBLE COMPLEX
  40. #
  41. #    -S        generate assembly code only, output goes to .s file
  42. #
  43. #    -Tdir        create temporary files in directory dir
  44. #
  45. #    -u        make the default type of all f77 variables undefined
  46. #
  47. #    -v        print the command line for each subprocess executed
  48. #
  49. #    -w        suppress the printing of all warning messages
  50. #
  51. #    -w66        suppress Fortran 66 compatibility warning messages
  52. #
  53. #    -Zopt        pass EMX -Zopt to compiler and linker (see EMX docs)
  54. #
  55. #    -1        Fortran DO loops are always executed at least once
  56. #
  57. #    input_files    input file(s) with .F, .f, .c, or .o suffix
  58. #
  59. #    -lx        link with object library libx.a (passed to ld).
  60. #
  61. ################################################################################
  62. # beg configuration section
  63.  
  64. # configure the search path for executables
  65. # If for some reason your default executable search path (from your
  66. # config.sys) is incorrect, you can uncomment the two lines below and
  67. # set it here. The '' quotes are needed to keep the shell from
  68. # parsing the ";" as a command seperator. DON'T use "\" in paths!
  69. #
  70. # PATH='d:/os2/bin;d:/os2/usr/emx/bin;c:/os2'
  71. # export PATH;
  72.  
  73. # configure f2c
  74. F2C=f2c
  75. F2CFLAGS='-Nn1024 -Nx512 -R'
  76.  
  77. # configure which cpp to use
  78. CPP=gcc
  79. CPPFLAGS='-E -x c'
  80.  
  81. # configure which C compiler to use
  82. CC=gcc
  83. CCFLAGS=
  84. # C compiler flags for compiling f2c generated .c files
  85. CFLAGS_F2C='-traditional -I/os2/include'
  86. #                        ^LOCAL CONFIG^
  87.  
  88. # configure which linker to use
  89. LD=gcc
  90. LDFLAGS=
  91. # default libraries when linking using EMX Method 1
  92. METHOD1DEFLIBS='-L/os2/lib -lf2c -lm'
  93. #               ^ LOCAL CONFIG ^
  94. # default libraries when linking using EMX Method 2
  95. # if you use my dynamic support libs, use -lf2clib -lf2cdll
  96. METHOD2DEFLIBS='-L/os2/lib -lf2c -lm'
  97. #               ^ LOCAL CONFIG ^
  98.  
  99. # configure support executables
  100. # see the README if you don't have these, you'll need them.
  101. BASENAME=basename
  102. ECHO=echo
  103. GETOPT=getopt
  104. RM='rm -f'
  105. SED=sed
  106.  
  107. # configure suffix to use for .F and .f files
  108. # If you cut your teeth on VAXen, you may prefer FOR=FOR and for=for
  109. FPP=FPP
  110. fpp=fpp
  111. FOR=F
  112. for=f
  113.  
  114. # configure basename of temporary files
  115. # Should work for those poor souls using the ghastly FAT file system.
  116. tempbase=f77_$$
  117.  
  118. # end configuration section
  119. ################################################################################
  120.  
  121. # initialize
  122.  
  123. # (these are automagically reset when the -Zomf option is encountered)
  124. OBJ=O
  125. obj=o
  126. OBJFILES=
  127. DEFLIBS=$METHOD1DEFLIBS
  128. # default executable name
  129. OUTFILE=a.exe
  130.  
  131. t=$tempbase
  132. cOPT=1
  133. kOPT=1
  134. oOPT=1
  135. sOPT=1
  136. vOPT=1
  137. rc=0
  138.  
  139. check_directory()
  140. {
  141.     test -d "$1"
  142.     case $? in
  143.         0) ;;
  144.         *)    $ECHO "directory: $1 does not exist, or is not a directory" 1>&2
  145.             exit $? ;;
  146.     esac
  147. }
  148.  
  149. check_file()
  150. {
  151.     test -f "$1"
  152.     case $? in
  153.         0) ;;
  154.         *)    $ECHO "file: $1 does not exist, or is not a regular file" 1>&2
  155.             exit $? ;;
  156.     esac
  157. }
  158.  
  159. execute_process()
  160. {
  161.     case $vOPT in
  162.         0) $ECHO "$1" 1>&2 ;;
  163.     esac
  164.     eval "$1"
  165.     rc=$?
  166.     case $rc in
  167.         0) ;;
  168.         *) exit $rc ;;
  169.     esac
  170. }
  171.  
  172. # define trap handler
  173.  
  174. clean_up()
  175. {
  176.     execute_process "$RM $t.$FOR $t.c"
  177. }
  178.  
  179. # install trap handler
  180.  
  181. trap "clean_up; exit \$rc" 0
  182.  
  183. # shift off the /path/f77.cmd (the one *we* provide on the extproc line)
  184. #  *and* the really useful "f77.cmd" compliments of OS/2 CMD.EXE
  185.  
  186. shift 2
  187.  
  188. # parse command line options
  189.  
  190. set -- `$GETOPT "acCD:fgI:kL:N:Oo:P:r:ST:uvwZ:16" $*`
  191.  
  192. case $? in
  193.     0) ;;
  194.     *) exit 1 ;;
  195. esac
  196.  
  197. while
  198.     test X$1 != X--
  199. do
  200.  
  201.     case "$1" in
  202.  
  203.     -a)
  204.         F2CFLAGS="$F2CFLAGS -a"
  205.         shift
  206.         ;;
  207.  
  208.     -C)
  209.         F2CFLAGS="$F2CFLAGS -C"
  210.         shift
  211.         ;;
  212.  
  213.     -c)
  214.         cOPT=0
  215.         shift
  216.         ;;
  217.  
  218.     -D)
  219.         CCFLAGS="$CCFLAGS -D$2"
  220.         CPPFLAGS="$CPPFLAGS -D$2"
  221.         shift 2
  222.         ;;
  223.  
  224.     -f)
  225.         F2CFLAGS="$F2CFLAGS -f"
  226.         shift
  227.         ;;
  228.  
  229.     -g)
  230.         CCFLAGS="$CCFLAGS -g"
  231.         LDFLAGS="$LDFLAGS -g"
  232.         shift
  233.         ;;
  234.  
  235.     -I)
  236.         check_directory "$2"
  237.         CCFLAGS="$CCFLAGS -I$2"
  238.         CPPFLAGS="$CPPFLAGS -I$2"
  239.         shift 2
  240.         ;;
  241.  
  242.     -k)
  243.         kOPT=0
  244.         shift
  245.         ;;
  246.  
  247.     -L)
  248.         check_directory "$2"
  249.         OBJFILES="$OBJFILES -L$2"
  250.         shift 2
  251.         ;;
  252.  
  253.     -N)
  254.         F2CFLAGS="$F2CFLAGS -N$2"
  255.         shift 2
  256.         ;;
  257.  
  258.     -O)
  259.         CCFLAGS="$CCFLAGS -O"
  260.         shift
  261.         ;;
  262.  
  263.     -o)
  264.         OUTFILE=$2
  265.         oOPT=0
  266.         shift 2
  267.         ;;
  268.  
  269.     -P)
  270.         case $2 in
  271.             cpp:*)    CPPFLAGS="$CPPFLAGS `$ECHO $2 |$SED 's/^cpp://'`"
  272.                 ;;
  273.             f2c:*)    F2CFLAGS="$F2CFLAGS `$ECHO $2 |$SED 's/^f2c://'`"
  274.                 ;;
  275.             cc:*)    CCFLAGS="$CCFLAGS `$ECHO $2 | $SED 's/^cc://'`"
  276.                 ;;
  277.             ld:*)    LDFLAGS="$LDFLAGS `$ECHO $2 | $SED 's/^ld://'`"
  278.                 ;;
  279.             *)    $ECHO "warning: option -P $2 was ignored" 1>&2
  280.                 ;;
  281.         esac
  282.         shift 2
  283.         ;;
  284.  
  285.     -r)
  286.         case $2 in
  287.             8)    F2CFLAGS="$F2CFLAGS -r8"
  288.                 ;;
  289.             *)    $ECHO "warning: -r$2 option was ignored" 1>&2
  290.                 ;;
  291.         esac
  292.         shift 2
  293.         ;;
  294.  
  295.     -S)
  296.         CCFLAGS="$CCFLAGS -S"
  297.         sOPT=0
  298.         cOPT=0
  299.         shift
  300.         ;;
  301.  
  302.     -T)
  303.         check_directory "$2"
  304.         F2CFLAGS="$F2CFLAGS -T$2"
  305.         t=$2/$tempbase
  306.         shift 2
  307.         ;;
  308.  
  309.     -u)
  310.         F2CFLAGS="$F2CFLAGS -u"
  311.         shift
  312.         ;;
  313.  
  314.     -v)
  315.         CCFLAGS="$CCFLAGS -v"
  316.         LDFLAGS="$LDFLAGS -v"
  317.         vOPT=0
  318.         shift
  319.         ;;
  320.  
  321.     -w)
  322.         F2CFLAGS="$F2CFLAGS -w"
  323.         case $2 in
  324.             -6)    shift
  325.                 case $2 in
  326.                     -6)    F2CFLAGS="$F2CFLAGS"66
  327.                         shift ;;
  328.                 esac ;;
  329.         esac
  330.         shift
  331.         ;;
  332.  
  333.     -Z)
  334.         case $2 in
  335.             omf)    OBJ=OBJ
  336.                 obj=obj
  337.                 DEFLIBS=$METHOD2DEFLIBS
  338.                 ;;
  339.         esac
  340.         CCFLAGS="$CCFLAGS -Z$2"
  341.         LDFLAGS="$LDFLAGS -Z$2"
  342.         shift 2
  343.         ;;
  344.  
  345.     -1)
  346.         F2CFLAGS="$F2CFLAGS -onetrip"
  347.         shift
  348.         ;;
  349.  
  350.     *)
  351.         $ECHO "warning: option $1 was ignored" 1>&2
  352.         shift
  353.         ;;
  354.  
  355.     esac
  356.  
  357. done
  358.  
  359. # parse source file arguments
  360.  
  361. shift
  362.  
  363. while
  364.     test -n "$1"
  365. do
  366.  
  367.     case "$1" in
  368.  
  369.     *.c)
  370.         check_file "$1"
  371.         $ECHO $1: 1>&2
  372.         b=`$BASENAME $1 .c`
  373.         case $cOPT in
  374.             0)    case $oOPT in
  375.                     0)    o=$OUTFILE ;;
  376.                     *)    case $sOPT in
  377.                             0) o=$b.s ;;
  378.                             *) o=$b.$obj ;;
  379.                         esac ;;
  380.                 esac ;;
  381.             *)    o=$b.$obj ;;
  382.         esac
  383.         CMD="$CC -c -o $o $CCFLAGS $1"
  384.         execute_process "$CMD"
  385.         OBJFILES="$OBJFILES $o"
  386.         case $cOPT in 1) cOPT=2 ;; esac
  387.         shift
  388.         ;;
  389.  
  390.     *.DEF|*.def)
  391.         check_file "$1"
  392.         OBJFILES="$OBJFILES $1"
  393.         case $cOPT in 1) cOPT=2 ;; esac
  394.         shift
  395.         ;;
  396.  
  397.     *.$FPP|*.$fpp|*.$FOR|*.$for)
  398.         check_file "$1"
  399.         case "$1" in
  400.             *.$FPP)    b=`$BASENAME $1 .$FPP`
  401.                 case $kOPT in
  402.                     0) f=$b.$FOR ;;
  403.                     *) f=$t.$FOR ;;
  404.                 esac
  405.                 CMD="$CPP $CPPFLAGS $1 | $SED '/^#/d' > $f"
  406.                 execute_process "$CMD"
  407.                 O=$OBJ
  408.                 ;;
  409.             *.$fpp)    b=`$BASENAME $1 .$fpp`
  410.                 case $kOPT in
  411.                     0) f=$b.$for ;;
  412.                     *) f=$t.$for ;;
  413.                 esac
  414.                 CMD="$CPP $CPPFLAGS $1 | $SED '/^#/d' > $f"
  415.                 execute_process "$CMD"
  416.                 O=$obj
  417.                 ;;
  418.             *.$FOR)    b=`$BASENAME $1 .$FOR`
  419.                 f=$1
  420.                 O=$OBJ
  421.                 ;;
  422.             *.$for)    b=`$BASENAME $1 .$for`
  423.                 f=$1
  424.                 O=$obj
  425.                 ;;
  426.         esac
  427.         case $kOPT in
  428.             0) c=$b.c ;;
  429.             *) c=$t.c ;;
  430.         esac
  431.         CMD="$F2C $F2CFLAGS < $f > $c"
  432.         execute_process "$CMD"
  433.         case $cOPT in
  434.             0)    case $oOPT in
  435.                     0)    o=$OUTFILE ;;
  436.                     *)    case $sOPT in
  437.                             0) o=$b.s ;;
  438.                             *) o=$b.$O ;;
  439.                         esac ;;
  440.                 esac ;;
  441.             *)    o=$b.$O ;;
  442.         esac
  443.         CMD="$CC -c -o $o $CFLAGS_F2C $CCFLAGS $c"
  444.         execute_process "$CMD"
  445.         OBJFILES="$OBJFILES $o"
  446.         case $cOPT in 1) cOPT=2 ;; esac
  447.         shift
  448.         ;;
  449.  
  450.     *.$OBJ|*.$obj)
  451.         check_file "$1"
  452.         OBJFILES="$OBJFILES $1"
  453.         case $cOPT in 1) cOPT=2 ;; esac
  454.         shift
  455.         ;;
  456.  
  457.     -L)
  458.         check_directory "$2"
  459.         OBJFILES="$OBJFILES -L$2"
  460.         case $cOPT in 1) cOPT=2 ;; esac
  461.         shift 2
  462.         ;;
  463.  
  464.     -l)
  465.         OBJFILES="$OBJFILES -l$2"
  466.         case $cOPT in 1) cOPT=2 ;; esac
  467.         shift 2
  468.         ;;
  469.  
  470.     -o)
  471.         OUTFILE=$2
  472.         shift 2
  473.         ;;
  474.  
  475.     *)
  476.         OBJFILES="$OBJFILES $1"
  477.         case $cOPT in 1) cOPT=2 ;; esac
  478.         shift
  479.         ;;
  480.  
  481.     esac
  482.  
  483. done
  484.  
  485. # final link phase
  486.  
  487. case $cOPT in
  488.     2)    CMD="$LD -o $OUTFILE $LDFLAGS $OBJFILES $DEFLIBS"
  489.         execute_process "$CMD"
  490.         ;;
  491. esac
  492.  
  493. exit $rc
  494.