rules.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. /*
  2. * Control of the implicit suffix rules
  3. *
  4. * $Header$
  5. */
  6. #include "h.h"
  7. /*
  8. * Return a pointer to the suffix of a name
  9. */
  10. char *
  11. suffix(name)
  12. char * name;
  13. {
  14. return rindex(name, '.');
  15. }
  16. /*
  17. * Dynamic dependency. This routine applies the suffis rules
  18. * to try and find a source and a set of rules for a missing
  19. * target. If found, np is made into a target with the implicit
  20. * source name, and rules. Returns TRUE if np was made into
  21. * a target.
  22. */
  23. bool
  24. dyndep(np)
  25. struct name * np;
  26. {
  27. register char * p;
  28. register char * q;
  29. register char * suff; /* Old suffix */
  30. register char * basename; /* Name without suffix */
  31. struct name * op; /* New dependent */
  32. struct name * sp; /* Suffix */
  33. struct line * lp;
  34. struct depend * dp;
  35. char * newsuff;
  36. p = str1;
  37. q = np->n_name;
  38. if (!(suff = suffix(q)))
  39. return FALSE; /* No suffix */
  40. while (q < suff)
  41. *p++ = *q++;
  42. *p = '\0';
  43. basename = setmacro("*", str1, 4)->m_val;
  44. if (!((sp = newname(".SUFFIXES"))->n_flag & N_TARG))
  45. return FALSE;
  46. for (lp = sp->n_line; lp; lp = lp->l_next)
  47. for (dp = lp->l_dep; dp; dp = dp->d_next)
  48. {
  49. newsuff = dp->d_name->n_name;
  50. if (strlen(suff)+strlen(newsuff)+1 >= LZ)
  51. fatal("Suffix rule too long");
  52. p = str1;
  53. q = newsuff;
  54. while (*p++ = *q++)
  55. ;
  56. p--;
  57. q = suff;
  58. while (*p++ = *q++)
  59. ;
  60. sp = newname(str1);
  61. if (sp->n_flag & N_TARG)
  62. {
  63. p = str1;
  64. q = basename;
  65. if (strlen(basename) + strlen(newsuff)+1 >= LZ)
  66. fatal("Implicit name too long");
  67. while (*p++ = *q++)
  68. ;
  69. p--;
  70. q = newsuff;
  71. while (*p++ = *q++)
  72. ;
  73. op = newname(str1);
  74. if (!op->n_time)
  75. modtime(op);
  76. if (op->n_time || (op->n_flag & N_TARG))
  77. {
  78. dp = newdep(op, (struct depend *)0);
  79. newline(np, dp, sp->n_line->l_cmd, 0);
  80. setmacro("<", op->n_name, 4);
  81. return TRUE;
  82. }
  83. }
  84. }
  85. return FALSE;
  86. }
  87. /*
  88. * Make the default rules
  89. */
  90. void
  91. makerules()
  92. {
  93. struct cmd * cp;
  94. struct name * np;
  95. struct depend * dp;
  96. #ifdef eon
  97. setmacro("BDSCC", "asm", 0);
  98. /* setmacro("BDSCFLAGS", "", 0); */
  99. cp = newcmd("$(BDSCC) $(BDSCFLAGS) -n $<", (struct cmd *)0);
  100. np = newname(".c.o");
  101. newline(np, (struct depend *)0, cp, 0);
  102. setmacro("CC", "c", 0);
  103. setmacro("CFLAGS", "-O", 0);
  104. cp = newcmd("$(CC) $(CFLAGS) -c $<", (struct cmd *)0);
  105. np = newname(".c.obj");
  106. newline(np, (struct depend *)0, cp, 0);
  107. setmacro("M80", "asm -n", 0);
  108. /* setmacro("M80FLAGS", "", 0); */
  109. cp = newcmd("$(M80) $(M80FLAGS) $<", (struct cmd *)0);
  110. np = newname(".mac.o");
  111. newline(np, (struct depend *)0, cp, 0);
  112. setmacro("AS", "zas", 0);
  113. /* setmacro("ASFLAGS", "", 0); */
  114. cp = newcmd("$(ZAS) $(ASFLAGS) -o $@ $<", (struct cmd *)0);
  115. np = newname(".as.obj");
  116. newline(np, (struct depend *)0, cp, 0);
  117. np = newname(".as");
  118. dp = newdep(np, (struct depend *)0);
  119. np = newname(".obj");
  120. dp = newdep(np, dp);
  121. np = newname(".c");
  122. dp = newdep(np, dp);
  123. np = newname(".o");
  124. dp = newdep(np, dp);
  125. np = newname(".mac");
  126. dp = newdep(np, dp);
  127. np = newname(".SUFFIXES");
  128. newline(np, dp, (struct cmd *)0, 0);
  129. #endif
  130. /*
  131. * Some of the UNIX implicit rules
  132. */
  133. #ifdef unix
  134. setmacro("CC", "cc", 0);
  135. setmacro("CFLAGS", "-O", 0);
  136. #ifdef MINIX
  137. cp = newcmd("$(CC) $(CFLAGS) -S $<", (struct cmd *)0);
  138. np = newname(".c.s");
  139. #else
  140. cp = newcmd("$(CC) $(CFLAGS) -c $<", (struct cmd *)0);
  141. np = newname(".c.o");
  142. #endif MINIX
  143. newline(np, (struct depend *)0, cp, 0);
  144. setmacro("AS", "as", 0);
  145. cp = newcmd("$(AS) -o $@ $<", (struct cmd *)0);
  146. np = newname(".s.o");
  147. newline(np, (struct depend *)0, cp, 0);
  148. setmacro("YACC", "yacc", 0);
  149. /* setmacro("YFLAGS", "", 0); */
  150. cp = newcmd("$(YACC) $(YFLAGS) $<", (struct cmd *)0);
  151. cp = newcmd("mv y.tab.c $@", cp);
  152. np = newname(".y.c");
  153. newline(np, (struct depend *)0, cp, 0);
  154. cp = newcmd("$(YACC) $(YFLAGS) $<", (struct cmd *)0);
  155. cp = newcmd("$(CC) $(CFLAGS) -c y.tab.c", cp);
  156. cp = newcmd("rm y.tab.c", cp);
  157. cp = newcmd("mv y.tab.o $@", cp);
  158. np = newname(".y.o");
  159. newline(np, (struct depend *)0, cp, 0);
  160. setmacro("LEX", "lex", 0);
  161. /* setmacro("LFLAGS", "", 0); */
  162. cp = newcmd("$(LEX) $(LFLAGS) $<", (struct cmd *)0);
  163. cp = newcmd("mv lex.yy.c $@", cp);
  164. np = newname(".l.c");
  165. newline(np, (struct depend *)0, cp, 0);
  166. cp = newcmd("$(LEX) $(LFLAGS) $<", (struct cmd *)0);
  167. cp = newcmd("$(CC) $(CFLAGS) -c lex.yy.c", cp);
  168. cp = newcmd("rm lex.yy.c", cp);
  169. cp = newcmd("mv lex.yy.o $@", cp);
  170. np = newname(".l.o");
  171. newline(np, (struct depend *)0, cp, 0);
  172. np = newname(".s");
  173. dp = newdep(np, (struct depend *)0);
  174. np = newname(".o");
  175. dp = newdep(np, dp);
  176. np = newname(".c");
  177. dp = newdep(np, dp);
  178. np = newname(".y");
  179. dp = newdep(np, dp);
  180. np = newname(".l");
  181. dp = newdep(np, dp);
  182. np = newname(".SUFFIXES");
  183. newline(np, dp, (struct cmd *)0, 0);
  184. #endif
  185. #ifdef os9
  186. /*
  187. * Fairlight use an enhanced version of the C sub-system.
  188. * They have a specialised macro pre-processor.
  189. */
  190. setmacro("CC", "cc", 0);
  191. setmacro("CFLAGS", "-z", 0);
  192. cp = newcmd("$(CC) $(CFLAGS) -r $<", (struct cmd *)0);
  193. np = newname(".c.r");
  194. newline(np, (struct depend *)0, cp, 0);
  195. np = newname(".ca.r");
  196. newline(np, (struct depend *)0, cp, 0);
  197. np = newname(".a.r");
  198. newline(np, (struct depend *)0, cp, 0);
  199. np = newname(".o.r");
  200. newline(np, (struct depend *)0, cp, 0);
  201. np = newname(".mc.r");
  202. newline(np, (struct depend *)0, cp, 0);
  203. np = newname(".mca.r");
  204. newline(np, (struct depend *)0, cp, 0);
  205. np = newname(".ma.r");
  206. newline(np, (struct depend *)0, cp, 0);
  207. np = newname(".mo.r");
  208. newline(np, (struct depend *)0, cp, 0);
  209. np = newname(".r");
  210. dp = newdep(np, (struct depend *)0);
  211. np = newname(".mc");
  212. dp = newdep(np, dp);
  213. np = newname(".mca");
  214. dp = newdep(np, dp);
  215. np = newname(".c");
  216. dp = newdep(np, dp);
  217. np = newname(".ca");
  218. dp = newdep(np, dp);
  219. np = newname(".ma");
  220. dp = newdep(np, dp);
  221. np = newname(".mo");
  222. dp = newdep(np, dp);
  223. np = newname(".o");
  224. dp = newdep(np, dp);
  225. np = newname(".a");
  226. dp = newdep(np, dp);
  227. np = newname(".SUFFIXES");
  228. newline(np, dp, (struct cmd *)0, 0);
  229. #endif
  230. }