rules.c

Go to the documentation of this file.
00001 /*************************************************************************
00002  *
00003  *  m a k e :   r u l e s . c
00004  *
00005  *  Control of the implicit suffix rules
00006  *========================================================================
00007  * Edition history
00008  *
00009  *  #    Date                         Comments                       By
00010  * --- -------- ---------------------------------------------------- ---
00011  *   1    ??                                                         ??
00012  *   2 01.07.89 $<,$* bugs fixed, impl. r. ending in expl. r. added  RAL
00013  *   3 23.08.89 suffix as macro, testname intr., algorithem to find
00014  *              source dep. made more intelligent (see Readme3)      RAL
00015  *   4 30.08.89 indention changed                                    PSH,RAL
00016  *   5 03.09.89 fixed LZ eliminated                                  RAL
00017  *   6 07.09.89 rules of type '.c', .DEFAULT added, dep. search impr.RAL
00018  * ------------ Version 2.0 released ------------------------------- RAL
00019  *
00020  *************************************************************************/
00021 
00022 #include "h.h"
00023 
00024 
00025 /*
00026  *      Dynamic dependency.  This routine applies the suffis rules
00027  *      to try and find a source and a set of rules for a missing
00028  *      target.  If found, np is made into a target with the implicit
00029  *      source name, and rules.  Returns TRUE if np was made into
00030  *      a target.
00031  */
00032 bool dyndep(np,pbasename,pinputname)
00033 struct name  *np;
00034 char        **pbasename;                /*  Name without suffix  */
00035 char        **pinputname;
00036 {
00037   register char *p;
00038   register char *q;
00039   register char *suff;                          /*  Old suffix  */
00040   struct name   *op = (struct name *)0,*optmp;  /*  New dependent  */
00041   struct name   *sp;                            /*  Suffix  */
00042   struct line   *lp,*nlp;
00043   struct depend *dp,*ndp;
00044   struct cmd    *cmdp;
00045   char          *newsuff;
00046   bool           depexists = FALSE;
00047 
00048 
00049   p = str1;
00050   q = np->n_name;
00051   suff = suffix(q);
00052   while (*q && (q < suff || !suff)) *p++ = *q++;
00053   *p = '\0';
00054   if ((*pbasename = (char *) malloc(strlen(str1)+1)) == (char *)0 )
00055      fatal("No memory for basename",(char *)0,0);
00056   strcpy(*pbasename,str1);
00057   if ( !suff) suff = p - str1 + *pbasename;  /* set suffix to nullstring */
00058 
00059   if (!((sp = newname(".SUFFIXES"))->n_flag & N_TARG))  return FALSE;
00060 
00061   /* search all .SUFFIXES lines */
00062   for (lp = sp->n_line; lp; lp = lp->l_next)
00063      /* try all suffixes */
00064      for (dp = lp->l_dep; dp; dp = dp->d_next) {
00065         /* compose implicit rule name (.c.o)...*/
00066         newsuff = dp->d_name->n_name;
00067         while (strlen(suff)+strlen(newsuff)+1 >= str1s.len) strrealloc(&str1s);
00068         p = str1;
00069         q = newsuff;
00070         while (*p++ = *q++) ;
00071         p--;
00072         q = suff;
00073         while (*p++ = *q++) ;
00074         /* look if the rule exists */
00075         sp = newname(str1);
00076         if (sp->n_flag & N_TARG) {
00077            /* compose resulting dependency name */
00078            while (strlen(*pbasename) + strlen(newsuff)+1 >= str1s.len)
00079               strrealloc(&str1s);
00080            q = *pbasename;
00081            p = str1;
00082            while (*p++ = *q++) ;
00083            p--;
00084            q = newsuff;
00085            while (*p++ = *q++) ;
00086            /* test if dependency file or an explicit rule exists */
00087            if ((optmp= testname(str1)) != (struct name *)0) {
00088               /* store first possible dependency as default */
00089               if ( op == (struct name *)0) {
00090                  op = optmp;
00091                  cmdp = sp->n_line->l_cmd;
00092               }
00093               /* check if testname is an explicit dependency */
00094               for ( nlp=np->n_line; nlp; nlp=nlp->l_next) {
00095                  for( ndp=nlp->l_dep; ndp; ndp=ndp->d_next) {
00096                     if ( strcmp( ndp->d_name->n_name, str1) == 0) {
00097                        op = optmp;
00098                        cmdp = sp->n_line->l_cmd;
00099                        ndp = (struct depend *) 0;
00100                        goto found2;
00101                     }
00102                     depexists = TRUE;
00103                  }
00104               }
00105               /* if no explicit dependencies : accept testname */
00106               if (!depexists)  goto found;
00107            }
00108         }
00109      }
00110 
00111   if ( op == (struct name *)0) {
00112      if( np->n_flag & N_TARG) {     /* DEFAULT handling */
00113         if (!((sp = newname(".DEFAULT"))->n_flag & N_TARG))  return FALSE;
00114         if (!(sp->n_line)) return FALSE;
00115         cmdp = sp->n_line->l_cmd;
00116         for ( nlp=np->n_line; nlp; nlp=nlp->l_next) {
00117            if ( ndp=nlp->l_dep) {
00118               op = ndp->d_name;
00119               ndp = (struct depend *)0;
00120               goto found2;
00121            }
00122         }
00123         newline(np, (struct depend *)0, cmdp, 0);
00124         *pinputname = (char *)0;
00125         *pbasename  = (char *)0;
00126         return TRUE;
00127      }
00128   else return FALSE;
00129   }
00130 
00131 found:
00132   ndp = newdep(op, (struct depend *)0);
00133 found2:
00134   newline(np, ndp, cmdp, 0);
00135   *pinputname = op->n_name;
00136   return TRUE;
00137 }
00138 
00139 
00140 /*
00141  *      Make the default rules
00142  */
00143 void makerules()
00144 {
00145   struct cmd    *cp;
00146   struct name   *np;
00147   struct depend *dp;
00148 
00149 
00150 #ifdef eon
00151   setmacro("BDSCC", "asm");
00152   /*    setmacro("BDSCFLAGS", "");      */
00153   cp = newcmd("$(BDSCC) $(BDSCFLAGS) -n $<", (struct cmd *)0);
00154   np = newname(".c.o");
00155   newline(np, (struct depend *)0, cp, 0);
00156 
00157   setmacro("CC", "c");
00158   setmacro("CFLAGS", "-O");
00159   cp = newcmd("$(CC) $(CFLAGS) -c $<", (struct cmd *)0);
00160   np = newname(".c.obj");
00161   newline(np, (struct depend *)0, cp, 0);
00162 
00163   setmacro("M80", "asm -n");
00164   /*    setmacro("M80FLAGS", "");       */
00165   cp = newcmd("$(M80) $(M80FLAGS) $<", (struct cmd *)0);
00166   np = newname(".mac.o");
00167   newline(np, (struct depend *)0, cp, 0);
00168 
00169   setmacro("AS", "zas");
00170   /*    setmacro("ASFLAGS", "");        */
00171   cp = newcmd("$(ZAS) $(ASFLAGS) -o $@ $<", (struct cmd *)0);
00172   np = newname(".as.obj");
00173   newline(np, (struct depend *)0, cp, 0);
00174 
00175   np = newname(".as");
00176   dp = newdep(np, (struct depend *)0);
00177   np = newname(".obj");
00178   dp = newdep(np, dp);
00179   np = newname(".c");
00180   dp = newdep(np, dp);
00181   np = newname(".o");
00182   dp = newdep(np, dp);
00183   np = newname(".mac");
00184   dp = newdep(np, dp);
00185   np = newname(".SUFFIXES");
00186   newline(np, dp, (struct cmd *)0, 0);
00187 #endif
00188 
00189 #ifdef tos
00190 #define unix
00191 #endif
00192 
00193 /*
00194  *      Some of the UNIX implicit rules
00195  */
00196 
00197 #ifdef unix
00198 
00199   setmacro("CC", "cc");
00200   setmacro("CFLAGS", "");
00201 
00202   cp = newcmd("$(CC) -S $(CFLAGS) $<", (struct cmd *)0);
00203   np = newname(".c.s");
00204   newline(np, (struct depend *)0, cp, 0);
00205 
00206   cp = newcmd("$(CC) -c $(CFLAGS) $<", (struct cmd *)0);
00207   np = newname(".c.o");
00208   newline(np, (struct depend *)0, cp, 0);
00209 
00210 #if this_rule_is_a_bit_too_much_of_a_good_thing
00211 #ifdef MINIXPC
00212   cp = newcmd("$(CC) $(CFLAGS) -i -o $@ $<", (struct cmd *)0);
00213 #else
00214   cp = newcmd("$(CC) $(CFLAGS) -o $@ $<", (struct cmd *)0);
00215 #endif /* MINIXPC */
00216   np = newname(".c");
00217   newline(np, (struct depend *)0, cp, 0);
00218 #endif
00219 
00220   cp = newcmd("$(CC) -c $(CFLAGS) $<", (struct cmd *)0);
00221   np = newname(".s.o");
00222   newline(np, (struct depend *)0, cp, 0);
00223 
00224   setmacro("YACC", "yacc");
00225   /*setmacro("YFLAGS", "");     */
00226   cp = newcmd("$(YACC) $(YFLAGS) $<", (struct cmd *)0);
00227   cp = newcmd("mv y.tab.c $@", cp);
00228   np = newname(".y.c");
00229   newline(np, (struct depend *)0, cp, 0);
00230 
00231   cp = newcmd("$(YACC) $(YFLAGS) $<", (struct cmd *)0);
00232   cp = newcmd("$(CC) $(CFLAGS) -c y.tab.c", cp);
00233   cp = newcmd("mv y.tab.o $@", cp);
00234   np = newname(".y.o");
00235   cp = newcmd("rm y.tab.c", cp);
00236   newline(np, (struct depend *)0, cp, 0);
00237 
00238   setmacro("FLEX", "flex");
00239   cp = newcmd("$(FLEX) $(FLEX_FLAGS) $<", (struct cmd *)0);
00240   cp = newcmd("mv lex.yy.c $@", cp);
00241   np = newname(".l.c");
00242   newline(np, (struct depend *)0, cp, 0);
00243 
00244   cp = newcmd("$(FLEX) $(FLEX_FLAGS) $<", (struct cmd *)0);
00245   cp = newcmd("$(CC) $(CFLAGS) -c lex.yy.c", cp);
00246   cp = newcmd("mv lex.yy.o $@", cp);
00247   np = newname(".l.o");
00248   cp = newcmd("rm lex.yy.c", cp);
00249   newline(np, (struct depend *)0, cp, 0);
00250 
00251   np = newname(".o");
00252   dp = newdep(np, (struct depend *)0);
00253   np = newname(".s");
00254   dp = newdep(np, dp);
00255   np = newname(".c");
00256   dp = newdep(np, dp);
00257   np = newname(".y");
00258   dp = newdep(np, dp);
00259   np = newname(".l");
00260   dp = newdep(np, dp);
00261   np = newname(".SUFFIXES");
00262   newline(np, dp, (struct cmd *)0, 0);
00263 
00264 #endif /* unix */
00265 
00266 
00267 #ifdef os9
00268 /*
00269  *      Fairlight use an enhanced version of the C sub-system.
00270  *      They have a specialised macro pre-processor.
00271  */
00272   setmacro("CC", "cc");
00273   setmacro("CFLAGS", "-z");
00274   cp = newcmd("$(CC) $(CFLAGS) -r $<", (struct cmd *)0);
00275 
00276   np = newname(".c.r");
00277   newline(np, (struct depend *)0, cp, 0);
00278   np = newname(".ca.r");
00279   newline(np, (struct depend *)0, cp, 0);
00280   np = newname(".a.r");
00281   newline(np, (struct depend *)0, cp, 0);
00282   np = newname(".o.r");
00283   newline(np, (struct depend *)0, cp, 0);
00284   np = newname(".mc.r");
00285   newline(np, (struct depend *)0, cp, 0);
00286   np = newname(".mca.r");
00287   newline(np, (struct depend *)0, cp, 0);
00288   np = newname(".ma.r");
00289   newline(np, (struct depend *)0, cp, 0);
00290   np = newname(".mo.r");
00291   newline(np, (struct depend *)0, cp, 0);
00292 
00293   np = newname(".r");
00294   dp = newdep(np, (struct depend *)0);
00295   np = newname(".mc");
00296   dp = newdep(np, dp);
00297   np = newname(".mca");
00298   dp = newdep(np, dp);
00299   np = newname(".c");
00300   dp = newdep(np, dp);
00301   np = newname(".ca");
00302   dp = newdep(np, dp);
00303   np = newname(".ma");
00304   dp = newdep(np, dp);
00305   np = newname(".mo");
00306   dp = newdep(np, dp);
00307   np = newname(".o");
00308   dp = newdep(np, dp);
00309   np = newname(".a");
00310   dp = newdep(np, dp);
00311   np = newname(".SUFFIXES");
00312   newline(np, dp, (struct cmd *)0, 0);
00313 #endif
00314 }

Generated on Fri Apr 14 22:56:59 2006 for minix by  doxygen 1.4.6