home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / fchk294b.zip / ftnchek-2.9.4 / configure_os2.cmd < prev    next >
OS/2 REXX Batch file  |  1996-10-04  |  17KB  |  525 lines

  1. /* configure_os2.cmd -- Christian Bartels, 1996
  2.  
  3.    A REXX script to create an OS/2 specific makefile for FTNCHEK using
  4.    the file 'Makefile.in' as input.
  5.  
  6.    This script is based on ideas of:
  7.      Jan Ftacnik, 1993
  8.      Stefan A. Deutscher, 1996 (sad@utk.edu)
  9.  
  10.    The building of the makefile is a four phase process:
  11.    1) Parsing the command line arguments
  12.    2) Checking of the system configuration
  13.    3) Building of the actual substitutes for some variables
  14.    4) Processing of Makefile.in
  15.  
  16.    Extended by Stefan A. Deutscher to also generate stuff in test/
  17.    directory automagically.  10/96
  18.  
  19.    5) Processing of test/Makefile.in
  20.    6) Processing of test/Compare.in
  21.  
  22. */
  23.  
  24. /* load library REXXUTIL */
  25.   call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  26.   call SysLoadFuncs
  27.  
  28.  
  29. /* get the command line arguments */
  30.   parse arg argv
  31.   argc = words(argv)
  32.  
  33. /* set some constants */
  34.   InputFile   = 'Makefile.in'
  35.   TmpFile     = SysTempFileName('Makefile.???')
  36.   OutputFile  = 'Makefile'
  37.  
  38.   TestDir         = 'test'
  39.   TestInputFile   = 'Makefile.in'
  40.   TestOutputFile  = 'Makefile'
  41.  
  42.   CompInputFile   = 'Compare.in'
  43.   CompOutputFile  = 'Compare.sh'
  44.  
  45.   ObjectStyle = 'aout'
  46.   Linking     = 'dynamic'
  47.   PrefixDir   = 'c:\usr\local'
  48.  
  49.  
  50. /*******************************************/
  51. /*     parse command line arguments        */
  52. /*******************************************/
  53.  
  54.   i = 1
  55.   do while (i <= argc)
  56.      argum = word(argv,i)
  57.      i = i + 1
  58.  
  59. /*   check whether program options start correctly with '-'  */
  60.      c = substr(argum,1,1)
  61.      if (c \= '-') then
  62.         call Usage
  63.  
  64. /*   select the appropriate action for commandline options */
  65.      c = substr(argum,2,1)
  66.      select
  67.         when (c = 'f') then do
  68.            ObjectStyle = ToLower( word(argv,i) )
  69.            if (ObjectStyle \= 'omf') & (ObjectStyle \= 'aout') then do
  70.               say " Error: Only supported object formats are omf and aout."
  71.               say
  72.               exit 1
  73.            end
  74.            i = i + 1
  75.         end
  76.         when (c = 'h') then do
  77.            call Usage
  78.         end
  79.         when (c = 'l') then do
  80.            Linking = ToLower( word(argv,i) )
  81.            if (Linking \= 'static') & (Linking \= 'dynamic') then do
  82.               say " Error: Only static or dynamic linking is supported."
  83.               say
  84.               exit 1
  85.            end
  86.            i = i + 1
  87.         end
  88.         when (c = 'o') then do
  89.            OutputFile = word(argv,i)
  90.            i = i + 1
  91.         end
  92.         when (c = 'p') then do
  93.            PrefixDir = word(argv,i)
  94.            i = i + 1
  95.         end
  96.         otherwise do
  97.            say ' Error: Argument -'c' is unknown.'
  98.            say
  99.            call Usage
  100.         end
  101.      end
  102.   end
  103.  
  104.  
  105. /*******************************************/
  106. /*     check the system configuration      */
  107. /*******************************************/
  108.  
  109.   say ' Checking system configuration ....'
  110.  
  111. /* Check if sed is installed */
  112.   SedProg     = IsProgramInPath( 'sed.exe' )
  113.   if (SedProg = '') then do
  114.      say " Error: In order to run this procedure, 'sed.exe' has",
  115.          "to be installed."
  116.      say
  117.      exit 1
  118.   end
  119.  
  120. /* Check if emx+gcc is installed */
  121.   CCompiler   = IsProgramInPath( 'gcc.exe' )
  122.   if (CCompiler = '') then do
  123.      say ' Error: To build FTNCHEK you will have to install the',
  124.          'EMX program'
  125.      say '        development package including the GNU C compiler.'
  126.   end
  127.  
  128. /* Check which port of a new awk is installed */
  129.   AwkProg     = SearchProgramFromList( "gawk.exe mawk.exe" )
  130.  
  131. /* No port of strip to OS/2 allows stripping of debug information or
  132.    local symbols from an executable (neither EMX-bound nor LX). Therefore
  133.    under OS/2 the stripping is done while producing the object files and
  134.    during the link stage. Fill in a dummy for strip  */
  135.   StripProg   = 'echo Requested: strip'
  136.  
  137. /* Check which yacc is installed */
  138.   YaccProg    = SearchProgramFromList( "yacc.exe bison.exe")
  139.   if ( YaccProg = 'yacc.exe' ) then do
  140.      say ' Warning: If the installed yacc is a Berkeley YACC this',
  141.          'script will not work.'
  142.      end
  143.   else do
  144.      if ( YaccProg = 'bison.exe' ) then
  145.         YaccProg = YaccProg '-y'
  146.   end
  147.  
  148. /* Check if tar.exe is installed */
  149.   TarProg     = IsProgramInPath( 'tar.exe' )
  150.  
  151. /* To my knowledge no port of col to OS/2 exists, but check anyway */
  152.   ColProg     = IsProgramInPath( 'col.exe' )
  153.  
  154. /* Check if the groff port to OS/2 is fully installed */
  155.   NroffProg   = IsProgramInPath( 'groff.exe' )
  156.   SoelimProg  = IsProgramInPath( 'soelim.exe' )
  157.   EqnProg     = IsProgramInPath( 'eqn.exe' )
  158.   TblProg     = IsProgramInPath( 'tbl.exe' )
  159.  
  160. /* Check if a unix sh-like shell is installed */
  161. CmdShell    = SearchProgramFromList( "sh.exe ksh.exe bash.exe cmd.exe" )
  162.  
  163. /* Check which basic file utilities are installed */
  164. /*  --- chmod */
  165.   ChmodCmd    = IsProgramInPath( 'chmod.exe' )
  166.   if (ChmodCmd = '') then
  167.      ChmodCmd    = 'echo Requested: chmod'
  168. /*  --- cmp */
  169.   CmpCmd      = SearchProgramFromList( "diff.exe cmp.exe comp.com" )
  170.   if (CmpCmd \= 'diff.exe') then do
  171.      say ' Warning: 'CmpCmd' claims that files are different even if only'
  172.      say '          the OS/2 EOL sequence CRLF is used instead of LF.'
  173.   end
  174. /*  --- cp */
  175.   CpCmd       = IsProgramInPath( 'cp.exe' )
  176.   if (CpCmd = '') & (CmdShell = 'cmd.exe') then
  177.      CpCmd = 'copy'     /* use built-in command of cmd.exe */
  178. /*  --- diff */
  179.   DiffCmd     = SearchProgramFromList( "diff.exe cmp.exe comp.com" )
  180.   if (DiffCmd \= 'diff.exe') then do
  181.      say ' Warning: 'DiffCmd' claims that files are different even if only'
  182.      say '          the OS/2 EOL sequence CRLF is used instead of LF.'
  183.   end
  184. /*  --- mkdir */
  185.   MkdirCmd    = IsProgramInPath( 'mkdir.exe' )
  186.   if (MkdirCmd = '') & (CmdShell = 'cmd.exe') then
  187.      MkdirCmd = 'mkdir' /* use built-in command of cmd.exe */
  188. /*  --- mv */
  189.   MvCmd       = IsProgramInPath( 'mv.exe' )
  190.   if (MvCmd = '') & (CmdShell = 'cmd.exe') then do
  191.      MvCmd = 'move'     /* use built-in command of cmd.exe */
  192.      say ' Warning: The OS/2 command MOVE cannot move files across drives.'
  193.   end
  194. /*  --- rm */
  195.   RmCmd       = IsProgramInPath( 'rm.exe' )
  196.   if (RmCmd = '') & (CmdShell = 'cmd.exe') then do
  197.      RmCmd = 'del'      /* use built-in command of cmd.exe */
  198.      say ' Warning: The OS/2 command DEL cannot remove read-only files.'
  199.   end
  200.   if (RmCmd = 'rm.exe') then RmCmd = RmCmd '-f'
  201. /*  --- rmdir */
  202.   RmdirCmd    = IsProgramInPath( 'rmdir.exe' )
  203.   if (RmdirCmd = '') & (CmdShell = 'cmd.exe') then
  204.      RmdirCmd = 'rmdir' /* use built-in command of cmd.exe */
  205.  
  206.  
  207. /*  --- sh */
  208.   ShPath = Translate(SysSearchPath('PATH', 'sh.exe'), '/', '\')
  209.   if (ShPath = '') then do
  210.      say ' Warning: sh.exe was not found. make check will not work.'
  211.      say '          Setting path to UNIX default: /bin/sh'
  212.      ShPath = '/bin/sh'
  213.   end
  214.  
  215. /* Check if omf type libraries are installed */
  216.   if ObjectStyle = 'omf' then do
  217.      CLibraryPath = value( 'library_path',, 'OS2ENVIRONMENT' )
  218.      CLibraryPath = translate( CLibraryPath, ' \', ';/' )
  219.      emx2lib = ''
  220.      gcclib  = ''
  221.      do i = 1 to words( CLibraryPath )
  222.         CurSearchDir = word( CLibraryPath, i )
  223.         if ( right( CurSearchDir, 1) \= '\' ) then
  224.            CurSearchDir = CurSearchDir'\'
  225.         test = stream( CurSearchDir'emx2.lib', 'C', 'QUERY EXIST' )
  226.         if ( test \= '' ) then
  227.            emx2lib = test
  228.         test = stream( CurSearchDir'gcc.lib', 'C', 'QUERY EXIST' )
  229.         if ( test \= '' ) then
  230.            gcclib = test
  231.      end
  232.      if (emx2lib = '') | (gcclib = '') then do
  233.         say ' Warning: The libraries necessary for linking with object',
  234.             'files in'
  235.         say '          OMF format do not exist. Object format reset to AOUT.'
  236.         ObjectStyle = 'aout'
  237.      end
  238.   end
  239.  
  240.  
  241. /****************************************************/
  242. /*     build the substitutes for some strings       */
  243. /****************************************************/
  244.  
  245. /* Cflags */
  246.   Cflags  = '-DUNIX -DLARGE_MACHINE -O2 -m486'
  247.  
  248. /* PrefixDir */
  249.   if CmdShell = 'cmd.exe' then do
  250.      PrefixDir = translate( PrefixDir, '\', '/')
  251.      if ( right( PrefixDir, 1 ) = '\' ) then
  252.         PrefixDir = left( PrefixDir, length(PrefixDir)-1 )
  253.      j = LastPos('\', PrefixDir)
  254.      do while (j \= 0)
  255.         j = j - 1
  256.         PrefixDir = insert('\\\', PrefixDir , j)
  257.         j = LastPos('\', SubStr( PrefixDir, 1, j ))
  258.      end
  259.      end
  260.   else do
  261.      PrefixDir = translate( PrefixDir, '/', '\')
  262.      if ( right( PrefixDir, 1 ) = '/' ) then
  263.         PrefixDir = left( PrefixDir, length(PrefixDir)- 1 )
  264.      j = LastPos('/', PrefixDir)
  265.      do while (j \= 0)
  266.         j = j - 1
  267.         PrefixDir = insert('\', PrefixDir , j)
  268.         j = LastPos('/', SubStr( PrefixDir, 1, j ))
  269.      end
  270.   end
  271.  
  272. /* Ldflags */
  273.   if ObjectStyle = 'omf' then do
  274.      if Linking = 'dynamic' then
  275.         Ldflags = '-s -Zomf -Zcrtdll -Zstack 8192 -Zlinker \/pm:vio'
  276.      else
  277.         Ldflags = '-s -Zomf -Zsys -Zstack 8192 -Zlinker \/pm:vio'
  278.      end
  279.   else do
  280.      if Linking = 'dynamic' then
  281.         Ldflags = '-s'
  282.      else
  283.         say ' Error: Static linking is not possible for ',
  284.             'aout object file format.'
  285.   end
  286.  
  287. /* ObjectsListName, ObjectsToDelete */
  288.   if ObjectStyle = 'omf' then do
  289.      ObjectsListName = '$(OBJS:.o=.obj)'
  290.      ObjectsToDelete = '*.o *.obj'
  291.      end
  292.   else do
  293.      ObjectsListName = '$(OBJS)'
  294.      ObjectsToDelete = '*.o'
  295.   end
  296.  
  297.  
  298.   say ' Generating Makefiles : '
  299.  
  300. /****************************************/
  301. /*     process Makefile.in              */
  302. /****************************************/
  303.  
  304.   say '  Processing Makefile.in ...'
  305.  
  306.   '@echo off'
  307.   'sed -e "s/\/usr\/local/'PrefixDir'/" ',
  308.       '-e "s/@EXE@/.exe/" ',
  309.       '-e "s/@CMD@/.cmd/" ',
  310.       '-e "s/@CC@/'CCompiler'/" ',
  311.       '-e "s/@MANtoPS@//" ',
  312.       '-e "s/@AWK@/'AwkProg'/" ',
  313.       '-e "s/@NROFF@/'NroffProg'/" ',
  314.       '-e "s/@SED@/'SedProg'/" ',
  315.       '-e "s/@STRIP@/'StripProg'/" ',
  316.       '-e "s/@YACC@/'YaccProg'/" ',
  317.       '-e "s/@COL@/'ColProg'/" ',
  318.       '-e "s/@CHMOD@/'ChmodCmd'/" ',
  319.       '-e "s/@CMP@/'CmpCmd'/" ',
  320.       '-e "s/@CP@/'CpCmd'/" ',
  321.       '-e "s/@DIFF@/'DiffCmd'/" ',
  322.       '-e "s/@EQN@/'EqnProg'/" ',
  323.       '-e "s/@MKDIR@/'MkdirCmd'/" ',
  324.       '-e "s/@MV@/'MvCmd'/" ',
  325.       '-e "s/@RM@/'RmCmd'/" ',
  326.       '-e "s/@RMDIR@/'RmdirCmd'/" ',
  327.       '-e "s/@SH@/'CmdShell'/" ',
  328.       '-e "s/@SOELIM@/'SoelimProg'/" ',
  329.       '-e "s/@TBL@/'TblProg'/" ',
  330.       '-e "s/@TAR@/'TarProg'/" ',
  331.       '-e "s/@CFLAGS@/'Cflags'/" ',
  332.       '-e "s/@LDFLAGS@/'Ldflags'/" ',
  333.       '<'InputFile ' >'TmpFile
  334.  
  335.   'sed -e "s/$(OBJS)/'ObjectsListName'/" ',
  336.       '-e "s/(RM) \*\.o/(RM) 'ObjectsToDelete'/" ',
  337.       '<'TmpFile ' >'OutputFile
  338.  
  339.   if ObjectStyle = 'omf' then do
  340.      call lineout OutputFile, ""
  341.      call lineout OutputFile, "# Target to convert object files from",
  342.                               "a.out format to OMF format"
  343.      call lineout OutputFile, "%.obj: %.o"
  344.      call lineout OutputFile,"    emxomf -s $?"
  345.      call lineout OutputFile
  346.   end
  347.  
  348.   if CmdShell = 'cmd.exe' then do
  349.      'copy 'OutputFile TmpFile '>nul:'
  350.      'sed -e "s/X)\/bin/X)\\bin/" ',
  351.          '-e "s/X)\/man/X)\\man/" ',
  352.          '-e "s/X)\/lib\/ftnchek/X)\\\\lib\\\\ftnchek/" ',
  353.          '-e "s/DIR)\//DIR)\\/" ',
  354.          '-e "s/cat1\//cat1\\/" ',
  355.          '-e "s/man1\//man1\\/" ',
  356.          '-e "s/= \.\//= \.\\/" ',
  357.          '-e "s/^fortran.c:/fortran.c.unx:/" ',
  358.          ' <'TmpFile ' > ' OutputFile
  359.  
  360.      call lineout OutputFile, ''
  361.      call lineout OutputFile, '# Build dcl2inc.cmd using the local',
  362.                               'values for NAWK and LIBDIR.'
  363.      call lineout OutputFile, 'dcl2inc.cmd: dcl2inc.in' OutputFile
  364.      call lineout OutputFile, '    sed -e "s%#!/bin/sh%@echo off%"  \'
  365.      call lineout OutputFile, '        -e "s%#%rem %"               \'
  366.      call lineout OutputFile, '         dcl2inc.in > dcl2inc.cmd'
  367.      call lineout OutputFile, '    echo $(NAWK) -f $(LIBDIR)\\dcl2inc.awk',
  368.                               '%1 >> dcl2inc.cmd'
  369.      call lineout OutputFile, ''
  370.      call lineout OutputFile, '# N.B. tokdefs.h is copy of y.tab.h used',
  371.                               'to avoid remaking stuff when'
  372.      call lineout OutputFile, '# grammar changes but not tokens.'
  373.      call lineout OutputFile, '# The following copies y.tab.h to',
  374.                               'tokdefs.h if changed, then aborts make,'
  375.      call lineout OutputFile, '# since dependencies may have changed.'
  376.      call lineout OutputFile, 'fortran.c: fortran.y'
  377.      call lineout OutputFile, '    $(YACC) $(YFLAGS) fortran.y'
  378.      call lineout OutputFile, '    $(MV) y.tab.c fortran.c'
  379.      call lineout OutputFile, '    $(CMP) y.tab.h tokdefs.h ||  \'
  380.      call lineout OutputFile, '    (echo tokdefs.h changed -- repeat make  &  \'
  381.      call lineout OutputFile, '        $(CP) y.tab.h tokdefs.h)'
  382.      call lineout OutputFile
  383.   end
  384.   'del ' TmpFile
  385.   say '  Makefile written.'
  386.  
  387. /****************************************/
  388. /*     process files in test directory: */
  389. /****************************************/
  390.  
  391.   'cd 'TestDir
  392.  
  393. /****************************************/
  394. /*     process test/Makefile.in         */
  395. /****************************************/
  396.  
  397.   say '  Processing test/Makefile.in ...'
  398.  
  399.   '@echo off'
  400.   'sed -e "s/\/usr\/local/'PrefixDir'/" ',
  401.       '-e "s/@EXE@/.exe/" ',
  402.       '-e "s/@CMD@/.cmd/" ',
  403.       '-e "s/@CC@/'CCompiler'/" ',
  404.       '-e "s/@MANtoPS@//" ',
  405.       '-e "s/@AWK@/'AwkProg'/" ',
  406.       '-e "s/@NROFF@/'NroffProg'/" ',
  407.       '-e "s/@SED@/'SedProg'/" ',
  408.       '-e "s/@STRIP@/'StripProg'/" ',
  409.       '-e "s/@YACC@/'YaccProg'/" ',
  410.       '-e "s/@COL@/'ColProg'/" ',
  411.       '-e "s/@CHMOD@/'ChmodCmd'/" ',
  412.       '-e "s/@CMP@/'CmpCmd'/" ',
  413.       '-e "s/@CP@/'CpCmd'/" ',
  414.       '-e "s/@DIFF@/'DiffCmd'/" ',
  415.       '-e "s/@EQN@/'EqnProg'/" ',
  416.       '-e "s/@MKDIR@/'MkdirCmd'/" ',
  417.       '-e "s/@MV@/'MvCmd'/" ',
  418.       '-e "s/@RM@/'RmCmd'/" ',
  419.       '-e "s/@RMDIR@/'RmdirCmd'/" ',
  420.       '-e "s/@SH@/'CmdShell'/" ',
  421.       '-e "s/@SOELIM@/'SoelimProg'/" ',
  422.       '-e "s/@TBL@/'TblProg'/" ',
  423.       '-e "s/@TAR@/'TarProg'/" ',
  424.       '-e "s/@CFLAGS@/'Cflags'/" ',
  425.       '-e "s/@LDFLAGS@/'Ldflags'/" ',
  426.       '<'TestInputFile ' >'TestOutputFile
  427.  
  428.   say '  test/Makefile written.'
  429.  
  430. /****************************************/
  431. /*     process test/Compare.in          */
  432. /****************************************/
  433.  
  434.   say '  Processing test/Compare.in ...'
  435.  
  436.   '@echo off'
  437.   'sed -e "s/\/usr\/local/'PrefixDir'/" ',
  438.       '-e "s/@EXE@/.exe/" ',
  439.       '-e "s/@CMD@/.cmd/" ',
  440.       '-e "s/@CC@/'CCompiler'/" ',
  441.       '-e "s/@MANtoPS@//" ',
  442.       '-e "s/@AWK@/'AwkProg'/" ',
  443.       '-e "s/@NROFF@/'NroffProg'/" ',
  444.       '-e "s/@SED@/'SedProg'/" ',
  445.       '-e "s/@STRIP@/'StripProg'/" ',
  446.       '-e "s/@YACC@/'YaccProg'/" ',
  447.       '-e "s/@COL@/'ColProg'/" ',
  448.       '-e "s/@CHMOD@/'ChmodCmd'/" ',
  449.       '-e "s/@CMP@/'CmpCmd'/" ',
  450.       '-e "s/@CP@/'CpCmd'/" ',
  451.       '-e "s/@DIFF@/'DiffCmd'/" ',
  452.       '-e "s/@EQN@/'EqnProg'/" ',
  453.       '-e "s/@MKDIR@/'MkdirCmd'/" ',
  454.       '-e "s/@MV@/'MvCmd'/" ',
  455.       '-e "s/@RM@/'RmCmd'/" ',
  456.       '-e "s/@RMDIR@/'RmdirCmd'/" ',
  457.       '-e "s/@SH@/'CmdShell'/" ',
  458.       '-e "s/@SOELIM@/'SoelimProg'/" ',
  459.       '-e "s/@TBL@/'TblProg'/" ',
  460.       '-e "s/@TAR@/'TarProg'/" ',
  461.       '-e "s/@CFLAGS@/'Cflags'/" ',
  462.       '-e "s/@LDFLAGS@/'Ldflags'/" ',
  463.       '-e "s;/bin/sh;'ShPath';" ',
  464.       '<'CompInputFile ' >'CompOutputFile
  465.  
  466.  
  467. /* -------------------------------------------------------------- */
  468. /* Note: This can be done by REXX:                                */
  469. /* -------------------------------------------------------------- */
  470.  
  471.   say '  test/Compare.sh written. '
  472.   if (ShPath = '/bin/sh') then do
  473.     say '  Note: Edit first line by hand to point to sh.exe!'
  474.   end
  475.  
  476.   'cd ..'
  477.  
  478.   say ' Done. Now run'
  479.   say '               make          to make ftnchek.exe'
  480.   say '               make check    to run the tests (that takes time)'
  481.  
  482.   exit 0
  483.  
  484. /* PROCEDURE Usage */
  485.   Usage: PROCEDURE
  486.      say ' Usage: configure_os2 [options]'
  487.      say
  488.      say '    Options:'
  489.      say '       -f <string>  format of object files: omf, aout'
  490.      say '       -l <string>  linking: static, dynamic'
  491.      say '       -o <string>  name of newly created Makefile'
  492.      say '       -p <string>  prefix directory'
  493.      say '       -h           show this help'
  494.      exit 1
  495.  
  496. /* PROCEDURE ToLower */
  497.   ToLower: PROCEDURE
  498.      parse arg OldString
  499.  
  500.      NewString = translate(OldString, xrange('a','z'), xrange('A','Z'))
  501.      return NewString
  502.  
  503. /* PROCEDURE IsProgramInPath */
  504.   IsProgramInPath: PROCEDURE
  505.      parse arg ProgramName
  506.  
  507.      Answer = FileSpec('name', SysSearchPath('PATH', ProgramName))
  508.      return Answer
  509.  
  510. /* PROCEDURE SearchProgramFromList */
  511.   SearchProgramFromList: PROCEDURE
  512.      parse arg ProgramList
  513.  
  514.      NumberInList = words( ProgramList )
  515.  
  516.      FirstFound = ''
  517.      i = 1
  518.      do while (i <= NumberInList) & (FirstFound = '')
  519.         Program = word( ProgramList, i )
  520.         i = i + 1
  521.  
  522.         FirstFound = IsProgramInPath( Program )
  523.      end
  524.      return FirstFound
  525.