Fixes for /usr/xbin binaries bootstrap dir.
[minix3.git] / commands / make / rules.c
bloba0335ba90b6966137512b8a2c5a3dbe0a5d85b99
1 /*************************************************************************
3 * m a k e : r u l e s . c
5 * Control of the implicit suffix rules
6 *========================================================================
7 * Edition history
9 * # Date Comments By
10 * --- -------- ---------------------------------------------------- ---
11 * 1 ?? ??
12 * 2 01.07.89 $<,$* bugs fixed, impl. r. ending in expl. r. added RAL
13 * 3 23.08.89 suffix as macro, testname intr., algorithem to find
14 * source dep. made more intelligent (see Readme3) RAL
15 * 4 30.08.89 indention changed PSH,RAL
16 * 5 03.09.89 fixed LZ eliminated RAL
17 * 6 07.09.89 rules of type '.c', .DEFAULT added, dep. search impr.RAL
18 * ------------ Version 2.0 released ------------------------------- RAL
20 *************************************************************************/
22 #include "h.h"
26 * Dynamic dependency. This routine applies the suffis rules
27 * to try and find a source and a set of rules for a missing
28 * target. If found, np is made into a target with the implicit
29 * source name, and rules. Returns TRUE if np was made into
30 * a target.
32 bool dyndep(np,pbasename,pinputname)
33 struct name *np;
34 char **pbasename; /* Name without suffix */
35 char **pinputname;
37 register char *p;
38 register char *q;
39 register char *suff; /* Old suffix */
40 struct name *op = (struct name *)0,*optmp; /* New dependent */
41 struct name *sp; /* Suffix */
42 struct line *lp,*nlp;
43 struct depend *dp,*ndp;
44 struct cmd *cmdp;
45 char *newsuff;
46 bool depexists = FALSE;
49 p = str1;
50 q = np->n_name;
51 suff = suffix(q);
52 while (*q && (q < suff || !suff)) *p++ = *q++;
53 *p = '\0';
54 if ((*pbasename = (char *) malloc(strlen(str1)+1)) == (char *)0 )
55 fatal("No memory for basename",(char *)0,0);
56 strcpy(*pbasename,str1);
57 if ( !suff) suff = p - str1 + *pbasename; /* set suffix to nullstring */
59 if (!((sp = newname(".SUFFIXES"))->n_flag & N_TARG)) return FALSE;
61 /* search all .SUFFIXES lines */
62 for (lp = sp->n_line; lp; lp = lp->l_next)
63 /* try all suffixes */
64 for (dp = lp->l_dep; dp; dp = dp->d_next) {
65 /* compose implicit rule name (.c.o)...*/
66 newsuff = dp->d_name->n_name;
67 while (strlen(suff)+strlen(newsuff)+1 >= str1s.len) strrealloc(&str1s);
68 p = str1;
69 q = newsuff;
70 while (*p++ = *q++) ;
71 p--;
72 q = suff;
73 while (*p++ = *q++) ;
74 /* look if the rule exists */
75 sp = newname(str1);
76 if (sp->n_flag & N_TARG) {
77 /* compose resulting dependency name */
78 while (strlen(*pbasename) + strlen(newsuff)+1 >= str1s.len)
79 strrealloc(&str1s);
80 q = *pbasename;
81 p = str1;
82 while (*p++ = *q++) ;
83 p--;
84 q = newsuff;
85 while (*p++ = *q++) ;
86 /* test if dependency file or an explicit rule exists */
87 if ((optmp= testname(str1)) != (struct name *)0) {
88 /* store first possible dependency as default */
89 if ( op == (struct name *)0) {
90 op = optmp;
91 cmdp = sp->n_line->l_cmd;
93 /* check if testname is an explicit dependency */
94 for ( nlp=np->n_line; nlp; nlp=nlp->l_next) {
95 for( ndp=nlp->l_dep; ndp; ndp=ndp->d_next) {
96 if ( strcmp( ndp->d_name->n_name, str1) == 0) {
97 op = optmp;
98 cmdp = sp->n_line->l_cmd;
99 ndp = (struct depend *) 0;
100 goto found2;
102 depexists = TRUE;
105 /* if no explicit dependencies : accept testname */
106 if (!depexists) goto found;
111 if ( op == (struct name *)0) {
112 if( np->n_flag & N_TARG) { /* DEFAULT handling */
113 if (!((sp = newname(".DEFAULT"))->n_flag & N_TARG)) return FALSE;
114 if (!(sp->n_line)) return FALSE;
115 cmdp = sp->n_line->l_cmd;
116 for ( nlp=np->n_line; nlp; nlp=nlp->l_next) {
117 if ( ndp=nlp->l_dep) {
118 op = ndp->d_name;
119 ndp = (struct depend *)0;
120 goto found2;
123 newline(np, (struct depend *)0, cmdp, 0);
124 *pinputname = (char *)0;
125 *pbasename = (char *)0;
126 return TRUE;
128 else return FALSE;
131 found:
132 ndp = newdep(op, (struct depend *)0);
133 found2:
134 newline(np, ndp, cmdp, 0);
135 *pinputname = op->n_name;
136 return TRUE;
141 * Make the default rules
143 void makerules()
145 struct cmd *cp;
146 struct name *np;
147 struct depend *dp;
150 #ifdef eon
151 setmacro("BDSCC", "asm");
152 /* setmacro("BDSCFLAGS", ""); */
153 cp = newcmd("$(BDSCC) $(BDSCFLAGS) -n $<", (struct cmd *)0);
154 np = newname(".c.o");
155 newline(np, (struct depend *)0, cp, 0);
157 setmacro("CC", "c");
158 setmacro("CFLAGS", "-O");
159 cp = newcmd("$(CC) $(CFLAGS) -c $<", (struct cmd *)0);
160 np = newname(".c.obj");
161 newline(np, (struct depend *)0, cp, 0);
163 setmacro("M80", "asm -n");
164 /* setmacro("M80FLAGS", ""); */
165 cp = newcmd("$(M80) $(M80FLAGS) $<", (struct cmd *)0);
166 np = newname(".mac.o");
167 newline(np, (struct depend *)0, cp, 0);
169 setmacro("AS", "zas");
170 /* setmacro("ASFLAGS", ""); */
171 cp = newcmd("$(ZAS) $(ASFLAGS) -o $@ $<", (struct cmd *)0);
172 np = newname(".as.obj");
173 newline(np, (struct depend *)0, cp, 0);
175 np = newname(".as");
176 dp = newdep(np, (struct depend *)0);
177 np = newname(".obj");
178 dp = newdep(np, dp);
179 np = newname(".c");
180 dp = newdep(np, dp);
181 np = newname(".o");
182 dp = newdep(np, dp);
183 np = newname(".mac");
184 dp = newdep(np, dp);
185 np = newname(".SUFFIXES");
186 newline(np, dp, (struct cmd *)0, 0);
187 #endif
189 #ifdef tos
190 #define unix
191 #endif
194 * Some of the UNIX implicit rules
197 #ifdef unix
199 setmacro("CC", "cc");
200 setmacro("CFLAGS", "");
202 cp = newcmd("$(CC) -S $(CFLAGS) $<", (struct cmd *)0);
203 np = newname(".c.s");
204 newline(np, (struct depend *)0, cp, 0);
206 cp = newcmd("$(CC) -c $(CFLAGS) $<", (struct cmd *)0);
207 np = newname(".c.o");
208 newline(np, (struct depend *)0, cp, 0);
210 #if this_rule_is_a_bit_too_much_of_a_good_thing
211 #ifdef MINIXPC
212 cp = newcmd("$(CC) $(CFLAGS) -i -o $@ $<", (struct cmd *)0);
213 #else
214 cp = newcmd("$(CC) $(CFLAGS) -o $@ $<", (struct cmd *)0);
215 #endif /* MINIXPC */
216 np = newname(".c");
217 newline(np, (struct depend *)0, cp, 0);
218 #endif
220 cp = newcmd("$(CC) -c $(CFLAGS) $<", (struct cmd *)0);
221 np = newname(".s.o");
222 newline(np, (struct depend *)0, cp, 0);
224 setmacro("YACC", "yacc");
225 /*setmacro("YFLAGS", ""); */
226 cp = newcmd("$(YACC) $(YFLAGS) $<", (struct cmd *)0);
227 cp = newcmd("mv y.tab.c $@", cp);
228 np = newname(".y.c");
229 newline(np, (struct depend *)0, cp, 0);
231 cp = newcmd("$(YACC) $(YFLAGS) $<", (struct cmd *)0);
232 cp = newcmd("$(CC) $(CFLAGS) -c y.tab.c", cp);
233 cp = newcmd("mv y.tab.o $@", cp);
234 np = newname(".y.o");
235 cp = newcmd("rm y.tab.c", cp);
236 newline(np, (struct depend *)0, cp, 0);
238 setmacro("FLEX", "flex");
239 cp = newcmd("$(FLEX) $(FLEX_FLAGS) $<", (struct cmd *)0);
240 cp = newcmd("mv lex.yy.c $@", cp);
241 np = newname(".l.c");
242 newline(np, (struct depend *)0, cp, 0);
244 cp = newcmd("$(FLEX) $(FLEX_FLAGS) $<", (struct cmd *)0);
245 cp = newcmd("$(CC) $(CFLAGS) -c lex.yy.c", cp);
246 cp = newcmd("mv lex.yy.o $@", cp);
247 np = newname(".l.o");
248 cp = newcmd("rm lex.yy.c", cp);
249 newline(np, (struct depend *)0, cp, 0);
251 np = newname(".o");
252 dp = newdep(np, (struct depend *)0);
253 np = newname(".s");
254 dp = newdep(np, dp);
255 np = newname(".c");
256 dp = newdep(np, dp);
257 np = newname(".y");
258 dp = newdep(np, dp);
259 np = newname(".l");
260 dp = newdep(np, dp);
261 np = newname(".SUFFIXES");
262 newline(np, dp, (struct cmd *)0, 0);
264 #endif /* unix */
267 #ifdef os9
269 * Fairlight use an enhanced version of the C sub-system.
270 * They have a specialised macro pre-processor.
272 setmacro("CC", "cc");
273 setmacro("CFLAGS", "-z");
274 cp = newcmd("$(CC) $(CFLAGS) -r $<", (struct cmd *)0);
276 np = newname(".c.r");
277 newline(np, (struct depend *)0, cp, 0);
278 np = newname(".ca.r");
279 newline(np, (struct depend *)0, cp, 0);
280 np = newname(".a.r");
281 newline(np, (struct depend *)0, cp, 0);
282 np = newname(".o.r");
283 newline(np, (struct depend *)0, cp, 0);
284 np = newname(".mc.r");
285 newline(np, (struct depend *)0, cp, 0);
286 np = newname(".mca.r");
287 newline(np, (struct depend *)0, cp, 0);
288 np = newname(".ma.r");
289 newline(np, (struct depend *)0, cp, 0);
290 np = newname(".mo.r");
291 newline(np, (struct depend *)0, cp, 0);
293 np = newname(".r");
294 dp = newdep(np, (struct depend *)0);
295 np = newname(".mc");
296 dp = newdep(np, dp);
297 np = newname(".mca");
298 dp = newdep(np, dp);
299 np = newname(".c");
300 dp = newdep(np, dp);
301 np = newname(".ca");
302 dp = newdep(np, dp);
303 np = newname(".ma");
304 dp = newdep(np, dp);
305 np = newname(".mo");
306 dp = newdep(np, dp);
307 np = newname(".o");
308 dp = newdep(np, dp);
309 np = newname(".a");
310 dp = newdep(np, dp);
311 np = newname(".SUFFIXES");
312 newline(np, dp, (struct cmd *)0, 0);
313 #endif