home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / NMAKER.ZIP / NMAKER.CMD
OS/2 REXX Batch file  |  1991-07-09  |  7KB  |  176 lines

  1. /* Rexx to read in all you .mak files in the directory and builds new files*/
  2. /* in reverse format used by NMAKE.  Read for program comments for more */
  3. /* information.                             */
  4. /* Copyright 1991  Joe McVerry     Raleigh NC  USA    All rights reserved */
  5. /* This program assumes there is one .LRF file for each .EXE file it finds */
  6. /* in the mak files.   The program will create one MAKEFILE for all exe's. */
  7. /* And the program will create one .NMK file for each exe.  You should */
  8. /* rename these .nmk's to .mak's if you're going to use them.  The program */
  9. /* does not edit the original make commands except for the new dependencies*/
  10. /* I do not guantee valid results due to dependencies of your original make */
  11. /* files.   Use this program and its resulting output at your own risk */
  12. /* If you have any questions please feel free to call me at 919-846-2014 or*/
  13. /* write me:  Joe McVerry at 8004 Selfridge Ct.    Raleigh NC 27615 */
  14.  
  15. "copy *.mak mak.all"        /* copy all .mak files to a working file */
  16. make_line_found = 0        /* set up line counter */
  17. alls = ""            /* executable file name string */
  18. make_line_pos = 1        /* current position on line */
  19. do while(lines(mak.all))    /* do until end of working file    */
  20. parse value linein("mak.all") with first_word ":" second_word
  21.                 /* get first dependency */
  22.   if substr(second_word,1,1) = "\" & length(first_word) > 12 then do
  23.                         /* found one with disk id in it */
  24.      first_word = first_word || ":" || second_word /* replace disk id */
  25.      second_word = ""
  26.    end
  27.   if first_word = ""  then do        /* ignore blank line */
  28.   end
  29.   else
  30.   if second_word = "" then do        /* looks like a make command line */
  31.      if skip = 0 then do
  32.        make_line_pos = make_line_pos + 1
  33.        make_line.make_line_found.make_line_pos = first_word
  34.        end
  35.     end
  36.   else do             /* must be a make target-dependent line */
  37.      skip = 0
  38.      do key_cnt1 = 1 to make_line_found   /* one one target description per file */
  39.        if first_word = key.key_cnt1 then do /* so find out if we have done already */
  40.      skip = 1                /* exit boolean */
  41.      say first_word "is already processed, we won't process again."
  42.        end
  43.      end
  44.      name = ""
  45.      extension    = ""
  46.      parse upper value first_word with name "." extension
  47.      if name = "ALL" then do         /* doing a nmake file skip ALL target */
  48.        skip = 1                      /* exit boolean */
  49.      end
  50.      if skip = 0 then do                 /* let's do this line */
  51.     make_lines.make_line_found = make_line_pos
  52.     make_line_pos = 0
  53.     make_line_found = make_line_found + 1
  54.     if extension = "EXE" then do    /* is the target an executable */
  55.       alls = alls||name||".EXE "    /* yes, get its LRF file for its true*/
  56.       namelrf = name||".lrf"    /* dependencies */
  57.       done = 0
  58.       objstr = ""
  59.       do while lines(namelrf) > 0 & done = 0
  60.          lrfin = linein(namelrf)
  61.          lrflen = length(lrfin)
  62.          if substr(lrfin,lrflen,1) \= "+" then done = 1  /* continues ? */
  63.          do while length(lrfin) > 0
  64.         parse upper value lrfin with objname "+" lrfin
  65.         objstr = objstr||objname||".OBJ "
  66.          end
  67.        end
  68.       say stream(namelrf,c,"close")
  69.       if objstr = "" then skip = 1
  70.       else     make_line.make_line_found.make_line_pos = first_word":" objstr
  71.     end
  72.     else           /* not an executable so use the depencies specified */
  73.       make_line.make_line_found.make_line_pos = first_word":" second_word
  74.     say first_word                   /* send it to the screen */
  75.     key.make_line_found = first_word
  76.      end
  77.   end
  78. end
  79. make_lines.make_line_found = make_line_pos
  80.  
  81. /* program priority by extention */
  82. extension.1 = "EXE"
  83. extension.2 = "DLL"
  84. extension.3 = "LIB"
  85. extension.4 = "OBJ"
  86. extension.5 = "C"
  87. extension.6 = "PAS"
  88. extension.7 = "ASM"
  89. extension.8 = "CBL"
  90. extension.9 = "SQC"
  91. extension.10 = "H"
  92. extension.11 = "INC"
  93. extension.cnt = 10
  94.  
  95. /* create a MAKEFILE */
  96. "del MAKEFILE"
  97. ALLS = "ALL: "||ALLS
  98. mfile = "makefile"
  99. call lineout  mfile, ALLS
  100. do extcnt = 1 to extension.cnt          /* do it by extension priority order */
  101.  do line_pos = 1 to make_line_found
  102.     parse upper value key.line_pos with name "." extype
  103.     if extype = extension.extcnt then do
  104.       say key.line_pos                /* send it to the screen */
  105.       call lineout mfile, " "
  106.       if make_lines.line_pos > 0 then
  107.       do line_cnt = 0 to make_lines.line_pos   /* write out all dependences */
  108.     call lineout mfile, make_line.line_pos.line_cnt
  109.     end
  110.    end
  111.  end
  112. end
  113. say stream(mfile,c,"close")
  114.  
  115. /* make individual make files for EXE files*/
  116. do make_pos = 1 to make_line_found     /* all exe's are in first extenstion */
  117.   parse upper value key.make_pos with name "." extension
  118.   if extension \= "EXE" then iterate            /* skip over non exe's */
  119.   mfile = name".nmk"
  120.   "del " mfile
  121.   do line_cnt = 0 to make_lines.make_pos
  122.    call lineout mfile, make_line.make_pos.line_cnt
  123.   end
  124.   call lineout mfile, " "
  125.   parse upper value make_line.make_pos.0 with name ":" dependencies
  126.   do quecnt = 1 to extension.cnt
  127.     depend_line.quecnt.cnt = 0
  128.   end
  129.   quecnt = 0
  130.   call find_dependencies make_pos dependencies
  131.   say name  upper_loop              /* display to screen current target */
  132.   do quecnt = 1 to extension.cnt
  133.     do extcnt = 1 to depend_line.quecnt.cnt
  134.       say key.extcnt
  135.       line_pos = depend_line.quecnt.extcnt
  136.       do line_cnt = 0 to make_lines.line_pos
  137.     say make_line.line_pos.line_cnt
  138.     call lineout mfile, make_line.line_pos.line_cnt
  139.     end
  140.       call lineout mfile, " "
  141.     end
  142.    end
  143.   say stream(mfile,c,"close")
  144. end
  145. exit
  146.  
  147. find_dependencies: procedure expose mfile make_line_found make_line. quecnt depend_line. extension.
  148. parse arg make_line_foundpos dependents
  149. parse value dependents with name dependents
  150. foundit = 0                           /* find counter */
  151. do while name \= " "
  152.  do line_pos = 1 to make_line_found
  153.   parse upper value make_line.line_pos.0 with name2 ":" depends_on
  154.   if name = name2 then do
  155.      parse value name2 with name3 "." extension
  156.      do extype = 1 to extension.cnt until extension = extension.extype
  157.      end
  158.      if extype <= extension.cnt then do
  159.        foundit = foundit + 1
  160.        lookhere.foundit = line_pos
  161.        newpos =    depend_line.extype.cnt + 1
  162.        depend_line.extype.newpos = line_pos
  163.        depend_line.extype.cnt = newpos
  164.      end
  165.      leave        /* get out of do line_pos loop    because we found it */
  166.    end
  167.  end
  168.  parse value dependents with name dependents
  169. end
  170. do findline = 1 to foundit
  171.   lookatline = lookhere.findline
  172.   parse upper value make_line.lookatline.0 with name ":" dependencies
  173.   call find_dependencies line_pos dependencies
  174. end
  175. return
  176.