home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / VSCPPv2.zip / VACPP / IBMCPP / BIN / IWFMMGEN.CMD < prev    next >
OS/2 REXX Batch file  |  1995-06-02  |  9KB  |  233 lines

  1. /*---------------------------------------------------------------------------*/
  2. /*      Licensed Materials - Property of IBM                                 */
  3. /*                                                                           */
  4. /*      "Restricted Materials of IBM"                                        */
  5. /*                                                                           */
  6. /*      IBM WorkFrame                                                        */
  7. /*                                                                           */
  8. /*      (C) Copyright IBM Corp. 1991, 1995. All Rights Reserved.             */
  9. /*                                                                           */
  10. /*      US Government Users Restricted Rights - Use, duplication or          */
  11. /*      disclosure restricted by GSA ADP Schedule Contract with IBM Corp.    */
  12. /*---------------------------------------------------------------------------*/
  13. /*REXX*/
  14.  
  15. /**************************************************************************
  16. *  iwfmmgen.cmd  WorkFrame sample MAKEMAKE makefile generation script.    *
  17. *                                                                         *
  18. *  (c) Copyright International Business Machines Corporation 1994.        *
  19. *  All rights reserved.                                                   *
  20. *                                                                         *
  21. **************************************************************************/
  22.  
  23. /* Initialize. */
  24. RC.OK     = 0;
  25. RC.CANCEL = 8;
  26. RC.ERROR  = 8;
  27. RC.FATAL  = 16;
  28. NEWLINE   = '0d'x;
  29.  
  30. Trace 'A'
  31.  
  32. /* Load the REXX utility functions. */
  33. rc = RxFuncAdd('RxMessageBox', 'RexxUtil', 'RxMessageBox');
  34.  
  35. /* Extract the passed parameters. */
  36. /*if (Arg() <> 1) then*/
  37. /*   call Abort("Usage is: IWFMake IntermediateFile MakeFile DependencyFile");*/
  38. parse arg IntermediateFile,MakeFile,DependencyFile;
  39.  
  40. /* Parse the intermediate file to generate the make and dependency files. */
  41. rc = Parse(IntermediateFile);
  42. rc = Generate(Makefile, DependencyFile);
  43.  
  44. /* We are done. */
  45. call Done(RC_OK);
  46.  
  47. /**************************************************************************
  48. *  Parse(Stem, IntermediateFile);                                         *
  49. *  Parse the passed intermediate file into a REXX stem variable.          *
  50. *                                                                         *
  51. *  The intermediate file contains entries of the form:                    *
  52. *      :TAG.<VALUE1>...<VALUEn>                                           *
  53. *                                                                         *
  54. *  The stem variable represents the intermediate file as follows:         *
  55. *      STEM.TAG.0                                                         *
  56. *      STEM.TAG.NAME                                                      *
  57. ***************************************************************************/
  58.  
  59. Parse: procedure expose RC. NEWLINE  Stem.
  60. arg IntermediateFile;
  61. say "Parsing intermediate file.";
  62. Stem. = 0;
  63. LastTag = "";
  64. LastTarget = "";
  65. rc = RC_OK;
  66.  
  67. /* Process while not end of file. */
  68. do while (lines(IntermediateFile) > 0)
  69.    /* Get the current line. */
  70.    Line = linein(IntermediateFile);
  71.    
  72.    /* Parse the line into a (TAG,VALUE) pair. */
  73.    if (substr(Line,1,1) = ":") then do;
  74.       parse var Line ":" Tag "." Value
  75.    end;
  76.    else do;
  77.       Tag   = LastTag;
  78.       Value = Line;
  79.    end;
  80.    if (Tag = "") then call Abort("Error parsing intermediate file.");
  81.    LastTag = Tag;
  82.    if (Value = "") then iterate;
  83.  
  84.    /* Add the (TAG,VALUE) pair to the stem variable. */
  85.    /* All values are kept subordinate to the current RULE/TARGET tag. */
  86.    if ((Tag = "TARGET") | (Tag = "RULE")) then do;
  87.       Count = Stem.Tag.0;               /* Get the number of values for the tag. */
  88.       Count = Count + 1;                /* We now have one more value. */
  89.       Stem.Tag.0     = Count;           /* Set the new count. */
  90.       Stem.Tag.Count = Value;           /* Set the new value. */
  91.       LastTarget     = Tag"."Count;     /* Set the tag for the last target. */
  92.    end;
  93.    else do;
  94.       Count = Stem.LastTarget.Tag.0;    /* Get the number of values for the tag. */
  95.       Count = Count + 1;                /* We now have one more value. */
  96.       Stem.LastTarget.Tag.0     = Count;/* Set the new count. */
  97.       Stem.LastTarget.Tag.Count = Value;/* Set the new value. */
  98.    end;
  99. end 
  100. return(rc);
  101.  
  102. /**************************************************************************
  103. *  Generate(Stem, MakeFile, DependencyFile).                              *
  104. *  Generate a makefile and a separate dependency file (if requested)      *
  105. *  from the specified stem variable.                                      *
  106. ***************************************************************************/
  107.  
  108. Generate: procedure expose RC. NEWLINE  Stem.
  109. arg MakeFile, DependencyFile;
  110. say "Generating make file.";
  111. rc = RC_OK;
  112.  
  113. /* Determine if the make and dependency files are one and the same. */
  114. if (DependencyFile = "") then
  115.    DependencyFile = MakeFile;
  116.  
  117. /* Generate the make file. */
  118. call GenerateTargets;
  119. return(rc);
  120.  
  121. /**************************************************************************
  122. *  Generation utilities:                                                  *
  123. *  (a) GenerateTargets.                                                    *
  124. *  (a) GenerateTarget.                                                     *
  125. *  (a) GenerateTrailer.                                                   *
  126. **************************************************************************/
  127.  
  128. GenerateTargets: 
  129. /*if (Stem.TARGET.0 < 2) then
  130. return(RC.ERROR);*/
  131.  
  132. rc = GeneratePreTargets("TARGET."1, "TARGET."2);
  133.  
  134. do ix=1 to Stem.RULE.0;
  135.    rc = GenerateTarget("RULE."ix);
  136. end 
  137. if (Stem.TARGET.0 > 2) then
  138. do ix=3 to Stem.TARGET.0;
  139.    rc = GenerateTarget("TARGET."ix);
  140. end 
  141. else
  142. return(RC.OK);
  143. return(RC.OK);
  144.  
  145. GenerateTarget:
  146. arg ThisTarget;
  147. if (Stem.ThisTarget.COMMAND.0 <> 0) then
  148.    File = MakeFile;
  149. else
  150.    File = DependencyFile;
  151. rc = lineout(File, NEWLINE);
  152. if Stem.ThisTarget.DEPENDENCY.0 > 0 then
  153.    rc = lineout(File, Stem.ThisTarget": \");
  154.    else
  155.    rc = lineout(File, Stem.ThisTarget":");
  156. do xix=1 to Stem.ThisTarget.DEPENDENCY.0;
  157.    if xix < Stem.ThisTarget.DEPENDENCY.0 then
  158.    rc = lineout(File, "    "Stem.ThisTarget.DEPENDENCY.xix" \");
  159.    else
  160.    rc = lineout(File, "    "Stem.ThisTarget.DEPENDENCY.xix);
  161. end 
  162. do xix=1 to Stem.ThisTarget.ACTION.0;
  163.    rc = lineout(File, "    @echo """ Stem.ThisTarget.ACTION.xix """");
  164. end 
  165. do xix=1 to Stem.ThisTarget.COMMAND.0;
  166.    if Stem.ThisTarget.COMMAND.xix = "<<" then
  167.    rc = lineout(File, Stem.ThisTarget.COMMAND.xix);
  168.    else
  169.    rc = lineout(File, "    "Stem.ThisTarget.COMMAND.xix);
  170. end 
  171. return(RC.OK);
  172.  
  173. GeneratePreTargets:
  174. arg SuffixTarget, AllTarget
  175. File = MakeFile;
  176. rc = lineout(File, NEWLINE);
  177. rc = charout(File, "."Stem.SuffixTarget":");
  178.  
  179. do xix=1 to Stem.SuffixTarget.DEPENDENCY.0;
  180.    rc = charout(File, " "Stem.SuffixTarget.DEPENDENCY.xix);
  181. end 
  182. rc = lineout(File, NEWLINE);
  183. rc = lineout(File, NEWLINE);
  184.  
  185. File = MakeFile;
  186.  
  187. if Stem.AllTarget.DEPENDENCY.0 > 0 then
  188.    rc = lineout(File, "."Stem.AllTarget": \");
  189.    else
  190.    rc = lineout(File, "."Stem.AllTarget":");
  191. do xix=1 to Stem.AllTarget.DEPENDENCY.0;
  192.    if xix < Stem.AllTarget.DEPENDENCY.0 then
  193.    rc = lineout(File, "    "Stem.AllTarget.DEPENDENCY.xix" \");
  194.    else
  195.    rc = lineout(File, "    "Stem.AllTarget.DEPENDENCY.xix);
  196. end 
  197. do xix=1 to Stem.AllTarget.ACTION.0;
  198.    rc = lineout(File, "    @echo """ Stem.AllTarget.ACTION.xix """");
  199. end 
  200. do xix=1 to Stem.AllTarget.COMMAND.0;
  201.    if Stem.AllTarget.COMMAND.xix = "<<" then
  202.    rc = lineout(File, Stem.AllTarget.COMMAND.xix);
  203.    else
  204.    rc = lineout(File, "    "Stem.AllTarget.COMMAND.xix);
  205. end 
  206. return(RC.OK);
  207.  
  208. /**************************************************************************
  209. *  General purpose utilities:                                             *
  210. *  (a) cancel():        ask the user if processing should be cancelled.   *
  211. *  (b) abort(message):  abort processing (with the given message).        *
  212. *  (c) done(rc):        terminate processing (with the given return code).*
  213. ***************************************************************************/
  214.  
  215. Cancel: procedure expose RC. NEWLINE 
  216. rc = RxMessageBox("Do you really want to cancel?", , "YesNo", "Query");
  217. if (rc = 6) then
  218.    call Done(RC_CANCEL);
  219. return(RC_OK);
  220.  
  221. Abort: procedure expose RC. NEWLINE 
  222. arg abortMessage;
  223. rc =  RxMessageBox(abortMessage, , "Ok", "Error");
  224. call Done(RC_FATAL);
  225.  
  226. Done: procedure expose RC. NEWLINE 
  227. arg exitRc;
  228. if (exitRc = RC_OK) then 
  229.    say "The make file was generated successfully.";
  230. else                     
  231.    say "The make file was not generated due to errors.";
  232. exit(exitRc);
  233.