home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / PAMAKE18.ZIP / RULES.C < prev   
C/C++ Source or Header  |  1989-08-31  |  5KB  |  174 lines

  1. /*************************************************************************
  2. |                                                                        |
  3. |   RULES.C                                                     31.08.89 |
  4. |   PAMAKE Utility:  control of implicit suffix rules                    |
  5. |                                                                        |
  6. *************************************************************************/
  7.  
  8. #ifdef VMS
  9. #include stdio
  10. #include string
  11. #include "h.h"
  12. #else
  13. #include <stdio.h>
  14. #include <string.h>
  15. #include "h.h"
  16. #endif
  17.  
  18. /*****  return a pointer to the suffix of a name */
  19.  
  20. char *
  21. suffix(name)
  22. char *          name;
  23. {
  24.     register int i;
  25.     int l;
  26.     l = strlen(name);
  27.     for (i = l - 1; i >= 0; i--)
  28.     {
  29.         if (name[i] == '.') return name + i;
  30.     }
  31.     return name + l - 1;
  32.  }
  33.  
  34.  
  35. /*****  dynamic dependency */
  36.  
  37. /*************************************************************************
  38. |                                                                        |
  39. |   This routine applies the suffix rules to try and find a source and   |
  40. |   a set of rules for a missing target.  If found, np is made into a    |
  41. |   target with the implicit source name and rules.  Returns TRUE if np  |
  42. |   was made into a target.                                              |
  43. |                                                                        |
  44. *************************************************************************/
  45.  
  46. bool
  47. dyndep(np)
  48. struct name *   np;
  49. {
  50.     register char *         p;
  51.     register char *         q;
  52.     register char *         suff;           /*  Old suffix  */
  53.     register char *         basename;       /*  Name without suffix  */
  54.     struct name *           op;             /*  New dependent  */
  55.     struct name *           sp;             /*  Suffix  */
  56.     struct line *           lp;
  57.     struct depend *         dp;
  58.     char *                  newsuff;
  59.  
  60.     p = str1;
  61.     q = np->n_name;
  62.     suff = suffix(q);
  63.     while (q < suff)
  64.         *p++ = *q++;
  65.     *p = '\0';
  66.     basename = strcpy(str2,str1);
  67.  
  68.     if (!((sp = newname(".SUFFIXES"))->n_flag & N_TARG))
  69.         return FALSE;
  70.  
  71.     for (lp = sp->n_line; lp; lp = lp->l_next)
  72.         for (dp = lp->l_dep; dp; dp = dp->d_next)
  73.         {
  74.             newsuff = dp->d_name->n_name;
  75.             if (strlen(suff)+strlen(newsuff)+1 >= LZ)
  76.                 fatal("Inference rule too long");
  77.             p = str1;
  78.             q = newsuff;
  79.             while ((*p++ = *q++) != '\0') 
  80.                 ;
  81.             p--;
  82.             q = suff;
  83.             while ((*p++ = *q++) != '\0') 
  84.                 ;
  85.             sp = newname(str1);
  86.             if (sp->n_flag & N_TARG)
  87.             {
  88.                 p = str1;
  89.                 q = basename;
  90.                 if (strlen(basename) + strlen(newsuff)+1 >= LZ)
  91.                     fatal("Inferred name too long");
  92.                 while ((*p++ = *q++) != '\0') 
  93.                     ;
  94.                 p--;
  95.                 q = newsuff;
  96.                 while ((*p++ = *q++) != '\0') 
  97.                     ;
  98.                 if ((np->n_line) && 
  99.                     (pstrstr(q=np->n_line->l_dep->d_name->n_name,str1))) 
  100.                     op=newname(q);
  101.                 else
  102.                     op = newname(str1);
  103.                 if (!op->n_time) modtime(op);
  104.                 if ((op->n_time) || (op->n_flag & N_TARG) || dyndep(op))
  105.                 {
  106.                     dp = newdep(op, 0);
  107.                     newline(np, dp, sp->n_line->l_cmd,0);
  108.                     op->n_flag |= N_DYND;
  109.                     return TRUE;
  110.                 }
  111.             }
  112.         }
  113.     return FALSE;
  114. }
  115.  
  116.  
  117. /***** make the default rules */
  118.  
  119. void
  120. makerules()
  121. {
  122.     struct cmd *            cp;
  123.     struct name *           np;
  124.     struct depend *         dp;
  125.     struct cmd *            rcp;
  126.  
  127.     cp = newcmd("$(CC) $(CFLAGS) $(CFILES)", 0,&rcp);
  128.     np = newname(".c.obj");
  129.     newline(np, 0, cp, 0);
  130.     cp = newcmd("$(CC) $(CFLAGS) $(CFILES)", 0,&rcp);
  131.     np = newname(".c.o");
  132.     newline(np, 0, cp, 0);
  133.  
  134.     cp = newcmd("$(ASM) $(AFLAGS) $(AFILES)", 0,&rcp);
  135.     np = newname(".asm.obj");
  136.     newline(np, 0, cp, 0);
  137.     cp = newcmd("$(ASM) $(AFLAGS) $(AFILES)", 0,&rcp);
  138.     np = newname(".asm.o");
  139.     newline(np, 0, cp, 0);
  140.  
  141.     cp = newcmd("$(FOR) $(FFLAGS) $(FFILES)", 0,&rcp);
  142.     np = newname(".for.obj");
  143.     newline(np, 0, cp, 0);
  144.  
  145.     cp = newcmd("$(BAS) $(BFLAGS) $(BFILES)", 0,&rcp);
  146.     np = newname(".bas.obj");
  147.     newline(np, 0, cp, 0);
  148.  
  149.     cp = newcmd("$(PAS) $(PFLAGS) $(PFILES)", 0,&rcp);
  150.     np = newname(".pas.obj");
  151.     newline(np, 0, cp, 0);
  152.  
  153.     cp = newcmd("$(GEN) $(GFLAGS) $(GFILES)", 0,&rcp);
  154.     np = newname(".pnl.c");
  155.     newline(np, 0, cp, 0);
  156.  
  157.     cp = newcmd("$(GEN) $(GFLAGS) $(GFILES)", 0,&rcp);
  158.     np = newname(".pnl.for");
  159.     newline(np, 0, cp, 0); 
  160.  
  161.     cp = newcmd("$(GEN) $(GFLAGS) $(GFILES)", 0,&rcp);
  162.     np = newname(".pnl.pas");
  163.     newline(np, 0, cp, 0); 
  164.  
  165.     np = newname(".c");
  166.     dp = newdep(np, 0);
  167.     np = newname(".asm");
  168.     dp = newdep(np, dp);
  169.     np = newname(".pnl");
  170.     dp = newdep(np, dp);
  171.     np = newname(".SUFFIXES");
  172.     newline(np, dp, 0, 0);
  173. }
  174.