home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / fchk294s.zip / ftnchek-2.9.4 / configure_os2.cmd.distribution < prev    next >
Text File  |  1996-10-04  |  13KB  |  400 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. */
  17.  
  18. /* load library REXXUTIL */
  19.   call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  20.   call SysLoadFuncs
  21.  
  22.  
  23. /* get the command line arguments */
  24.   parse arg argv
  25.   argc = words(argv)
  26.  
  27. /* set some constants */
  28.   InputFile   = 'Makefile.in'
  29.   TmpFile     = SysTempFileName('Makefile.???')
  30.   OutputFile  = 'Makefile.os2'
  31.  
  32.   ObjectStyle = 'aout'
  33.   Linking     = 'dynamic'
  34.   PrefixDir   = 'c:\usr\local'
  35.  
  36.  
  37. /*******************************************/
  38. /*     parse command line arguments        */
  39. /*******************************************/
  40.  
  41.   i = 1
  42.   do while (i <= argc)
  43.      argum = word(argv,i)
  44.      i = i + 1
  45.  
  46. /*   check whether program options start correctly with '-'  */
  47.      c = substr(argum,1,1)
  48.      if (c \= '-') then
  49.         call Usage
  50.  
  51. /*   select the appropriate action for commandline options */
  52.      c = substr(argum,2,1)
  53.      select
  54.         when (c = 'f') then do
  55.            ObjectStyle = ToLower( word(argv,i) )
  56.            if (ObjectStyle \= 'omf') & (ObjectStyle \= 'aout') then do
  57.               say " Error: Only supported object formats are omf and aout."
  58.               say
  59.               exit 1
  60.            end
  61.            i = i + 1
  62.         end
  63.         when (c = 'h') then do
  64.            call Usage
  65.         end
  66.         when (c = 'l') then do
  67.            Linking = ToLower( word(argv,i) )
  68.            if (Linking \= 'static') & (Linking \= 'dynamic') then do
  69.               say " Error: Only static or dynamic linking is supported."
  70.               say
  71.               exit 1
  72.            end
  73.            i = i + 1
  74.         end
  75.         when (c = 'o') then do
  76.            OutputFile = word(argv,i)
  77.            i = i + 1
  78.         end
  79.         when (c = 'p') then do
  80.            PrefixDir = word(argv,i)
  81.            i = i + 1
  82.         end
  83.         otherwise do
  84.            say ' Error: Argument -'c' is unknown.'
  85.            say
  86.            call Usage
  87.         end
  88.      end
  89.   end
  90.  
  91.  
  92. /*******************************************/
  93. /*     check the system configuration      */
  94. /*******************************************/
  95.  
  96.   say ' Checking system configuration ....'
  97.  
  98. /* Check if sed is installed */
  99.   SedProg     = IsProgramInPath( 'sed.exe' )
  100.   if (SedProg = '') then do
  101.      say " Error: In order to run this procedure, 'sed.exe' has",
  102.          "to be installed."
  103.      say
  104.      exit 1
  105.   end
  106.  
  107. /* Check if emx+gcc is installed */
  108.   CCompiler   = IsProgramInPath( 'gcc.exe' )
  109.   if (CCompiler = '') then do
  110.      say ' Error: To build FTNCHEK you will have to install the',
  111.          'EMX program'
  112.      say '        development package including the GNU C compiler.'
  113.   end
  114.  
  115. /* Check which port of a new awk is installed */
  116.   AwkProg     = SearchProgramFromList( "gawk.exe mawk.exe" )
  117.  
  118. /* No port of strip to OS/2 allows stripping of debug information or
  119.    local symbols from an executable (neither EMX-bound nor LX). Therefore
  120.    under OS/2 the stripping is done while producing the object files and
  121.    during the link stage. Fill in a dummy for strip  */
  122.   StripProg   = 'echo Requested: strip'
  123.  
  124. /* Check which yacc is installed */
  125.   YaccProg    = SearchProgramFromList( "yacc.exe bison.exe")
  126.   if ( YaccProg = 'yacc.exe' ) then do
  127.      say ' Warning: If the installed yacc is a Berkeley YACC this',
  128.          'script will not work.'
  129.      end
  130.   else do
  131.      if ( YaccProg = 'bison.exe' ) then
  132.         YaccProg = YaccProg '-y'
  133.   end
  134.  
  135. /* Check if tar.exe is installed */
  136.   TarProg     = IsProgramInPath( 'tar.exe' )
  137.  
  138. /* To my knowledge no port of col to OS/2 exists, but check anyway */
  139.   ColProg     = IsProgramInPath( 'col.exe' )
  140.  
  141. /* Check if the groff port to OS/2 is fully installed */
  142.   NroffProg   = IsProgramInPath( 'groff.exe' )
  143.   SoelimProg  = IsProgramInPath( 'soelim.exe' )
  144.   EqnProg     = IsProgramInPath( 'eqn.exe' )
  145.   TblProg     = IsProgramInPath( 'tbl.exe' )
  146.  
  147. /* Check if a unix sh-like shell is installed */
  148. CmdShell    = SearchProgramFromList( "sh.exe ksh.exe bash.exe cmd.exe" )
  149.  
  150. /* Check which basic file utilities are installed */
  151. /*  --- chmod */
  152.   ChmodCmd    = IsProgramInPath( 'chmod.exe' )
  153.   if (ChmodCmd = '') then
  154.      ChmodCmd    = 'echo Requested: chmod'
  155. /*  --- cmp */
  156.   CmpCmd      = SearchProgramFromList( "diff.exe cmp.exe comp.com" )
  157.   if (CmpCmd \= 'diff.exe') then do
  158.      say ' Warning: 'CmpCmd' claims that files are different even if only'
  159.      say '          the OS/2 EOL sequence CRLF is used instead of LF.'
  160.   end
  161. /*  --- cp */
  162.   CpCmd       = IsProgramInPath( 'cp.exe' )
  163.   if (CpCmd = '') & (CmdShell = 'cmd.exe') then
  164.      CpCmd = 'copy'     /* use built-in command of cmd.exe */
  165. /*  --- mkdir */
  166.   MkdirCmd    = IsProgramInPath( 'mkdir.exe' )
  167.   if (MkdirCmd = '') & (CmdShell = 'cmd.exe') then
  168.      MkdirCmd = 'mkdir' /* use built-in command of cmd.exe */
  169. /*  --- mv */
  170.   MvCmd       = IsProgramInPath( 'mv.exe' )
  171.   if (MvCmd = '') & (CmdShell = 'cmd.exe') then do
  172.      MvCmd = 'move'     /* use built-in command of cmd.exe */
  173.      say ' Warning: The OS/2 command MOVE cannot move files across drives.'
  174.   end
  175. /*  --- rm */
  176.   RmCmd       = IsProgramInPath( 'rm.exe' )
  177.   if (RmCmd = '') & (CmdShell = 'cmd.exe') then do
  178.      RmCmd = 'del'      /* use built-in command of cmd.exe */
  179.      say ' Warning: The OS/2 command DEL cannot remove read-only files.'
  180.   end
  181.   if (RmCmd = 'rm.exe') then RmCmd = RmCmd '-f'
  182. /*  --- rmdir */
  183.   RmdirCmd    = IsProgramInPath( 'rmdir.exe' )
  184.   if (RmdirCmd = '') & (CmdShell = 'cmd.exe') then
  185.      RmdirCmd = 'rmdir' /* use built-in command of cmd.exe */
  186.  
  187.  
  188.  
  189. /* Check if omf type libraries are installed */
  190.   if ObjectStyle = 'omf' then do
  191.      CLibraryPath = value( 'library_path',, 'OS2ENVIRONMENT' )
  192.      CLibraryPath = translate( CLibraryPath, ' \', ';/' )
  193.      emx2lib = ''
  194.      gcclib  = ''
  195.      do i = 1 to words( CLibraryPath )
  196.         CurSearchDir = word( CLibraryPath, i )
  197.         if ( right( CurSearchDir, 1) \= '\' ) then
  198.            CurSearchDir = CurSearchDir'\'
  199.         test = stream( CurSearchDir'emx2.lib', 'C', 'QUERY EXIST' )
  200.         if ( test \= '' ) then
  201.            emx2lib = test
  202.         test = stream( CurSearchDir'gcc.lib', 'C', 'QUERY EXIST' )
  203.         if ( test \= '' ) then
  204.            gcclib = test
  205.      end
  206.      if (emx2lib = '') | (gcclib = '') then do
  207.         say ' Warning: The libraries necessary for linking with object',
  208.             'files in'
  209.         say '          OMF format do not exist. Object format reset to AOUT.'
  210.         ObjectStyle = 'aout'
  211.      end
  212.   end
  213.  
  214.  
  215. /****************************************************/
  216. /*     build the substitutes for some strings       */
  217. /****************************************************/
  218.  
  219. /* Cflags */
  220.   Cflags  = '-DUNIX -DLARGE_MACHINE -O2 -m486'
  221.  
  222. /* PrefixDir */
  223.   if CmdShell = 'cmd.exe' then do
  224.      PrefixDir = translate( PrefixDir, '\', '/')
  225.      if ( right( PrefixDir, 1 ) = '\' ) then
  226.         PrefixDir = left( PrefixDir, length(PrefixDir)-1 )
  227.      j = LastPos('\', PrefixDir)
  228.      do while (j \= 0)
  229.         j = j - 1
  230.         PrefixDir = insert('\\\', PrefixDir , j)
  231.         j = LastPos('\', SubStr( PrefixDir, 1, j ))
  232.      end
  233.      end
  234.   else do
  235.      PrefixDir = translate( PrefixDir, '/', '\')
  236.      if ( right( PrefixDir, 1 ) = '/' ) then
  237.         PrefixDir = left( PrefixDir, length(PrefixDir)- 1 )
  238.      j = LastPos('/', PrefixDir)
  239.      do while (j \= 0)
  240.         j = j - 1
  241.         PrefixDir = insert('\', PrefixDir , j)
  242.         j = LastPos('/', SubStr( PrefixDir, 1, j ))
  243.      end
  244.   end
  245.  
  246. /* Ldflags */
  247.   if ObjectStyle = 'omf' then do
  248.      if Linking = 'dynamic' then
  249.         Ldflags = '-s -Zomf -Zcrtdll -Zstack 8192 -Zlinker \/pm:vio'
  250.      else
  251.         Ldflags = '-s -Zomf -Zsys -Zstack 8192 -Zlinker \/pm:vio'
  252.      end
  253.   else do
  254.      if Linking = 'dynamic' then
  255.         Ldflags = '-s'
  256.      else
  257.         say ' Error: Static linking is not possible for ',
  258.             'aout object file format.'
  259.   end
  260.  
  261. /* ObjectsListName, ObjectsToDelete */
  262.   if ObjectStyle = 'omf' then do
  263.      ObjectsListName = '$(OBJS:.o=.obj)'
  264.      ObjectsToDelete = '*.o *.obj'
  265.      end
  266.   else do
  267.      ObjectsListName = '$(OBJS)'
  268.      ObjectsToDelete = '*.o'
  269.   end
  270.  
  271.  
  272. /****************************************/
  273. /*     process Makefile.in              */
  274. /****************************************/
  275.  
  276.   say ' Processing Makefile.in ...'
  277.  
  278.   '@echo off'
  279.   'sed -e "s/\/usr\/local/'PrefixDir'/" ',
  280.       '-e "s/@EXE@/.exe/" ',
  281.       '-e "s/@CMD@/.cmd/" ',
  282.       '-e "s/@CC@/'CCompiler'/" ',
  283.       '-e "s/@MANtoPS@//" ',
  284.       '-e "s/@AWK@/'AwkProg'/" ',
  285.       '-e "s/@NROFF@/'NroffProg'/" ',
  286.       '-e "s/@SED@/'SedProg'/" ',
  287.       '-e "s/@STRIP@/'StripProg'/" ',
  288.       '-e "s/@YACC@/'YaccProg'/" ',
  289.       '-e "s/@COL@/'ColProg'/" ',
  290.       '-e "s/@CHMOD@/'ChmodCmd'/" ',
  291.       '-e "s/@CMP@/'CmpCmd'/" ',
  292.       '-e "s/@CP@/'CpCmd'/" ',
  293.       '-e "s/@EQN@/'EqnProg'/" ',
  294.       '-e "s/@MKDIR@/'MkdirCmd'/" ',
  295.       '-e "s/@MV@/'MvCmd'/" ',
  296.       '-e "s/@RM@/'RmCmd'/" ',
  297.       '-e "s/@RMDIR@/'RmdirCmd'/" ',
  298.       '-e "s/@SH@/'CmdShell'/" ',
  299.       '-e "s/@SOELIM@/'SoelimProg'/" ',
  300.       '-e "s/@TBL@/'TblProg'/" ',
  301.       '-e "s/@TAR@/'TarProg'/" ',
  302.       '-e "s/@CFLAGS@/'Cflags'/" ',
  303.       '-e "s/@LDFLAGS@/'Ldflags'/" ',
  304.       '<'InputFile ' >'TmpFile
  305.  
  306.   'sed -e "s/$(OBJS)/'ObjectsListName'/" ',
  307.       '-e "s/(RM) \*\.o/(RM) 'ObjectsToDelete'/" ',
  308.       '<'TmpFile ' >'OutputFile
  309.  
  310.   if ObjectStyle = 'omf' then do
  311.      call lineout OutputFile, ""
  312.      call lineout OutputFile, "# Target to convert object files from",
  313.                               "a.out format to OMF format"
  314.      call lineout OutputFile, "%.obj: %.o"
  315.      call lineout OutputFile,"    emxomf -s $?"
  316.      call lineout OutputFile
  317.   end
  318.  
  319.   if CmdShell = 'cmd.exe' then do
  320.      'copy 'OutputFile TmpFile '>nul:'
  321.      'sed -e "s/X)\/bin/X)\\bin/" ',
  322.          '-e "s/X)\/man/X)\\man/" ',
  323.          '-e "s/X)\/lib\/ftnchek/X)\\\\lib\\\\ftnchek/" ',
  324.          '-e "s/DIR)\//DIR)\\/" ',
  325.          '-e "s/cat1\//cat1\\/" ',
  326.          '-e "s/man1\//man1\\/" ',
  327.          '-e "s/= \.\//= \.\\/" ',
  328.          '-e "s/^fortran.c:/fortran.c.unx:/" ',
  329.          ' <'TmpFile ' > ' OutputFile
  330.  
  331.      call lineout OutputFile, ''
  332.      call lineout OutputFile, '# Build dcl2inc.cmd using the local',
  333.                               'values for NAWK and LIBDIR.'
  334.      call lineout OutputFile, 'dcl2inc.cmd: dcl2inc.in' OutputFile
  335.      call lineout OutputFile, '    sed -e "s%#!/bin/sh%@echo off%"  \'
  336.      call lineout OutputFile, '        -e "s%#%rem %"               \'
  337.      call lineout OutputFile, '         dcl2inc.in > dcl2inc.cmd'
  338.      call lineout OutputFile, '    echo $(NAWK) -f $(LIBDIR)\\dcl2inc.awk',
  339.                               '%1 >> dcl2inc.cmd'
  340.      call lineout OutputFile, ''
  341.      call lineout OutputFile, '# N.B. tokdefs.h is copy of y.tab.h used',
  342.                               'to avoid remaking stuff when'
  343.      call lineout OutputFile, '# grammar changes but not tokens.'
  344.      call lineout OutputFile, '# The following copies y.tab.h to',
  345.                               'tokdefs.h if changed, then aborts make,'
  346.      call lineout OutputFile, '# since dependencies may have changed.'
  347.      call lineout OutputFile, 'fortran.c: fortran.y'
  348.      call lineout OutputFile, '    $(YACC) $(YFLAGS) fortran.y'
  349.      call lineout OutputFile, '    $(MV) y.tab.c fortran.c'
  350.      call lineout OutputFile, '    $(CMP) y.tab.h tokdefs.h ||  \'
  351.      call lineout OutputFile, '    (echo tokdefs.h changed -- repeat make  &  \'
  352.      call lineout OutputFile, '        $(CP) y.tab.h tokdefs.h)'
  353.      call lineout OutputFile
  354.   end
  355.   'del ' TmpFile
  356.  
  357.   exit 0
  358.  
  359. /* PROCEDURE Usage */
  360.   Usage: PROCEDURE
  361.      say ' Usage: configure_os2 [options]'
  362.      say
  363.      say '    Options:'
  364.      say '       -f <string>  format of object files: omf, aout'
  365.      say '       -l <string>  linking: static, dynamic'
  366.      say '       -o <string>  name of newly created Makefile'
  367.      say '       -p <string>  prefix directory'
  368.      say '       -h           show this help'
  369.      exit 1
  370.  
  371. /* PROCEDURE ToLower */
  372.   ToLower: PROCEDURE
  373.      parse arg OldString
  374.  
  375.      NewString = translate(OldString, xrange('a','z'), xrange('A','Z'))
  376.      return NewString
  377.  
  378. /* PROCEDURE IsProgramInPath */
  379.   IsProgramInPath: PROCEDURE
  380.      parse arg ProgramName
  381.  
  382.      Answer = FileSpec('name', SysSearchPath('PATH', ProgramName))
  383.      return Answer
  384.  
  385. /* PROCEDURE SearchProgramFromList */
  386.   SearchProgramFromList: PROCEDURE
  387.      parse arg ProgramList
  388.  
  389.      NumberInList = words( ProgramList )
  390.  
  391.      FirstFound = ''
  392.      i = 1
  393.      do while (i <= NumberInList) & (FirstFound = '')
  394.         Program = word( ProgramList, i )
  395.         i = i + 1
  396.  
  397.         FirstFound = IsProgramInPath( Program )
  398.      end
  399.      return FirstFound
  400.