home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 1 / crawlyvol1.bin / program / compiler / sozobon / scsrc20 / make / rules.c < prev    next >
C/C++ Source or Header  |  1988-10-13  |  5KB  |  190 lines

  1. /***************************************************************\
  2. *                                *
  3. *  PDMAKE, Atari ST version                    *
  4. *                                *
  5. *  Adapted from mod.sources Vol 7 Issue 71, 1986-12-03.        *
  6. *                                *
  7. *  This port makes extensive use of the original net.sources    *
  8. *  port by Jwahar Bammi.                    *
  9. *                                *
  10. *      Ton van Overbeek                        *
  11. *      Email: TPC862@ESTEC.BITNET                *
  12. *             TPC862%ESTEC.BITNET@WISCVM.WISC.EDU    (ARPA)    *
  13. *             ...!mcvax!tpc862%estec.bitnet   (UUCP Europe)    *
  14. *             ...!ucbvax!tpc862%estec.bitnet  (UUCP U.S.A.)    *
  15. *             71450,3537  (CompuServe)                *
  16. *                                *
  17. \***************************************************************/
  18.  
  19. /*
  20.  *    Control of the implicit suffix rules
  21.  */
  22.  
  23.  
  24. #include "h.h"
  25.  
  26.  
  27. /*
  28.  *    Return a pointer to the suffix of a name
  29.  */
  30. char    *
  31. suffix(name)
  32. char    *name;
  33. {
  34.     return strrchr(name, '.');
  35. }
  36.  
  37.  
  38. /*
  39.  *    Dynamic dependency.  This routine applies the suffix rules
  40.  *    to try and find a source and a set of rules for a missing
  41.  *    target.  If found, np is made into a target with the implicit
  42.  *    source name, and rules.  Returns TRUE if np was made into
  43.  *    a target.
  44.  */
  45. bool
  46. dyndep(np)
  47. struct name *    np;
  48. {
  49.     register char    *p;
  50.     register char    *q;
  51.     register char    *suff;        /*  Old suffix  */
  52.     register char    *basename;    /*  Name without suffix  */
  53.     struct name *op;        /*  New dependent  */
  54.     struct name *sp;        /*  Suffix  */
  55.     struct line *lp;
  56.     struct depend *dp;
  57.     char    *newsuff;
  58.  
  59.  
  60.     p = str1;
  61.     q = np->n_name;
  62.     if (!(suff = suffix(q)))
  63.         return FALSE;            /* No suffix */
  64.     while (q < suff)
  65.         *p++ = *q++;
  66.     *p = '\0';
  67.     basename = setmacro("*", str1)->m_val;
  68.  
  69.     if (!((sp = newname(".SUFFIXES"))->n_flag & N_TARG))
  70.         return FALSE;
  71.  
  72.     for (lp = sp->n_line; lp; lp = lp->l_next)
  73.         for (dp = lp->l_dep; dp; dp = dp->d_next) {
  74.             newsuff = dp->d_name->n_name;
  75.             if (strlen(suff) + strlen(newsuff) + 1 >= LZ)
  76.                 fatal("Suffix rule too long");
  77.             p = str1;
  78.             q = newsuff;
  79.             while (*p++ = *q++)
  80.                 ;
  81.             p--;
  82.             q = suff;
  83.             while (*p++ = *q++)
  84.                 ;
  85.             sp = newname(str1);
  86.             if (sp->n_flag & N_TARG) {
  87.                 p = str1;
  88.                 q = basename;
  89.                 if (strlen(basename)+strlen(newsuff) + 1 >= LZ)
  90.                     fatal("Implicit name too long");
  91.                 while (*p++ = *q++)
  92.                     ;
  93.                 p--;
  94.                 q = newsuff;
  95.                 while (*p++ = *q++)
  96.                     ;
  97.                 op = newname(str1);
  98.                 if (!op->n_time)
  99.                     modtime(op);
  100.                 if (op->n_time) {
  101.                     dp = newdep(op, (struct depend *) 0);
  102.                     newline(np, dp, sp->n_line->l_cmd, 0);
  103.                     setmacro("<", op->n_name);
  104.                     return TRUE;
  105.                 }
  106.             }
  107.         }
  108.     return FALSE;
  109. }
  110.  
  111.  
  112. /*
  113.  *    Make the default rules
  114.  */
  115. void
  116. makerules()
  117. {
  118.     struct cmd *    cp;
  119.     struct name *    np;
  120.     struct depend *    dp;
  121.  
  122.  
  123.     /* Atari special internal (to make) commands */
  124.     setmacro("RM", "%r");    /* Remove, any number of args, Wildcards OK */
  125.     setmacro("CP", "%c");    /* Copy file to file only     */
  126.     setmacro("ECHO", "%e");    /* Echo Argument          */
  127.  
  128.     /* Sozobon C Compiler rules */
  129.  
  130.     /*
  131.      * PATH is the path used by make if none is given in the
  132.      * environment or in the makefile. This macro is used to
  133.      * locate anything to be executed by make, so having a
  134.      * reasonable default allows make to be used directly
  135.      * from GEM much more easily.
  136.      */
  137.     setmacro("PATH", "\\bin,\\sozobon\\bin");
  138.  
  139.     /* Compiler driver program */
  140.     setmacro("CC", "cc");
  141.  
  142.     /* Compiler options */
  143.     setmacro("CFLAGS", "");
  144.  
  145.     /* Now make up the command lines */
  146.     cp = newcmd("$(CC) -c $(CFLAGS) $<", (struct cmd *) 0);
  147.     np = newname(".c.o");
  148.     newline(np, (struct depend *) 0, cp, 0);
  149.  
  150.     cp = newcmd("$(CC) -c $(CFLAGS) $<", (struct cmd *) 0);
  151.     np = newname(".s.o");
  152.     newline(np, (struct depend *) 0, cp, 0);
  153.  
  154.     cp = newcmd("$(CC) -S $(CFLAGS) $<", (struct cmd *) 0);
  155.     np = newname(".c.s");
  156.     newline(np, (struct depend *) 0, cp, 0);
  157.  
  158.     cp = newcmd("$(CC) $(CFLAGS) $< -o $*.prg", (struct cmd *) 0);
  159.     np = newname(".c.prg");
  160.     newline(np, (struct depend *) 0, cp, 0);
  161.  
  162.     cp = newcmd("$(CC) $(CFLAGS) $< -o $*.tos", (struct cmd *) 0);
  163.     np = newname(".c.tos");
  164.     newline(np, (struct depend *) 0, cp, 0);
  165.  
  166.     cp = newcmd("$(CC) $(CFLAGS) $< -o $*.ttp", (struct cmd *) 0);
  167.     np = newname(".c.ttp");
  168.     newline(np, (struct depend *) 0, cp, 0);
  169.  
  170.     /* Predefined suffixes */
  171.     np = newname(".prg");
  172.     dp = newdep(np, NULL);
  173.     np = newname(".tos");
  174.     dp = newdep(np, dp);
  175.     np = newname(".ttp");
  176.     dp = newdep(np, dp);
  177.     np = newname(".o");
  178.     dp = newdep(np, dp);
  179.     np = newname(".bin");
  180.     dp = newdep(np, dp);
  181.     np = newname(".s");
  182.     dp = newdep(np, dp);
  183.     np = newname(".c");
  184.     dp = newdep(np, dp);
  185.     np = newname(".pas");
  186.     dp = newdep(np, dp);
  187.     np = newname(".SUFFIXES");
  188.     newline(np, dp, (struct cmd *) 0, 0);
  189. }
  190.