1 /*************************************************************************
3 * m a k e : r u l e s . c
5 * Control of the implicit suffix rules
6 *========================================================================
10 * --- -------- ---------------------------------------------------- ---
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 *************************************************************************/
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
32 bool dyndep(np
,pbasename
,pinputname
)
34 char **pbasename
; /* Name without suffix */
39 register char *suff
; /* Old suffix */
40 struct name
*op
= (struct name
*)0,*optmp
; /* New dependent */
41 struct name
*sp
; /* Suffix */
43 struct depend
*dp
,*ndp
;
46 bool depexists
= FALSE
;
52 while (*q
&& (q
< suff
|| !suff
)) *p
++ = *q
++;
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
);
74 /* look if the rule exists */
76 if (sp
->n_flag
& N_TARG
) {
77 /* compose resulting dependency name */
78 while (strlen(*pbasename
) + strlen(newsuff
)+1 >= str1s
.len
)
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) {
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) {
98 cmdp
= sp
->n_line
->l_cmd
;
99 ndp
= (struct depend
*) 0;
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
) {
119 ndp
= (struct depend
*)0;
123 newline(np
, (struct depend
*)0, cmdp
, 0);
124 *pinputname
= (char *)0;
125 *pbasename
= (char *)0;
132 ndp
= newdep(op
, (struct depend
*)0);
134 newline(np
, ndp
, cmdp
, 0);
135 *pinputname
= op
->n_name
;
141 * Make the default rules
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);
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);
176 dp
= newdep(np
, (struct depend
*)0);
177 np
= newname(".obj");
183 np
= newname(".mac");
185 np
= newname(".SUFFIXES");
186 newline(np
, dp
, (struct cmd
*)0, 0);
194 * Some of the UNIX implicit rules
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
212 cp
= newcmd("$(CC) $(CFLAGS) -i -o $@ $<", (struct cmd
*)0);
214 cp
= newcmd("$(CC) $(CFLAGS) -o $@ $<", (struct cmd
*)0);
217 newline(np
, (struct depend
*)0, cp
, 0);
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);
252 dp
= newdep(np
, (struct depend
*)0);
261 np
= newname(".SUFFIXES");
262 newline(np
, dp
, (struct cmd
*)0, 0);
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);
294 dp
= newdep(np
, (struct depend
*)0);
297 np
= newname(".mca");
311 np
= newname(".SUFFIXES");
312 newline(np
, dp
, (struct cmd
*)0, 0);