* Added the test suite to the main distribution.
[make.git] / default.c
blob79f313ea80f5e6423a151893d6f7d1ecbdda814f
1 /* Data base of default implicit rules for GNU Make.
2 Copyright (C) 1988,89,90,91,92,93,94,95,96 Free Software Foundation, Inc.
3 This file is part of GNU Make.
5 GNU Make is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
8 any later version.
10 GNU Make is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNU Make; see the file COPYING. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
20 #include "make.h"
21 #include "rule.h"
22 #include "dep.h"
23 #include "filedef.h"
24 #include "job.h"
25 #include "commands.h"
26 #include "variable.h"
28 /* Define GCC_IS_NATIVE if gcc is the native development environment on
29 your system (gcc/bison/flex vs cc/yacc/lex). */
30 #ifdef __MSDOS__
31 #define GCC_IS_NATIVE
32 #endif
35 /* This is the default list of suffixes for suffix rules.
36 `.s' must come last, so that a `.o' file will be made from
37 a `.c' or `.p' or ... file rather than from a .s file. */
39 static char default_suffixes[]
40 #ifdef VMS
41 = ".exe .olb .ln .obj .c .cc .pas .p .for .f .r .y .l .mar \
42 .mod .sym .def .h .info .dvi .tex .texinfo .texi .txinfo \
43 .w .ch .cweb .web .com .sh .elc .el";
44 #else
45 = ".out .a .ln .o .c .cc .C .cpp .p .f .F .r .y .l .s .S \
46 .mod .sym .def .h .info .dvi .tex .texinfo .texi .txinfo \
47 .w .ch .web .sh .elc .el";
48 #endif
50 static struct pspec default_pattern_rules[] =
52 { "(%)", "%",
53 "$(AR) $(ARFLAGS) $@ $<" },
55 /* The X.out rules are only in BSD's default set because
56 BSD Make has no null-suffix rules, so `foo.out' and
57 `foo' are the same thing. */
58 #ifdef VMS
59 { "%.exe", "%",
60 "copy $< $@" },
61 #else
62 { "%.out", "%",
63 "@rm -f $@ \n cp $< $@" },
64 #endif
65 /* Syntax is "ctangle foo.w foo.ch foo.c". */
66 { "%.c", "%.w %.ch",
67 "$(CTANGLE) $^ $@" },
68 { "%.tex", "%.w %.ch",
69 "$(CWEAVE) $^ $@" },
71 { 0, 0, 0 }
74 static struct pspec default_terminal_rules[] =
76 #ifdef VMS
77 /* RCS. */
78 { "%", "%$$5lv", /* Multinet style */
79 "if f$$search($@) .nes. \"\" then +$(CHECKOUT,v)" },
80 { "%", "[.$$rcs]%$$5lv", /* Multinet style */
81 "if f$$search($@) .nes. \"\" then +$(CHECKOUT,v)" },
82 { "%", "%_v", /* Normal style */
83 "if f$$search($@) .nes. \"\" then +$(CHECKOUT,v)" },
84 { "%", "[.rcs]%_v", /* Normal style */
85 "if f$$search($@) .nes. \"\" then +$(CHECKOUT,v)" },
87 /* SCCS. */
88 /* ain't no SCCS on vms */
89 #else
90 /* RCS. */
91 { "%", "%,v",
92 "$(CHECKOUT,v)" },
93 { "%", "RCS/%,v",
94 "$(CHECKOUT,v)" },
95 { "%", "RCS/%",
96 "$(CHECKOUT,v)" },
98 /* SCCS. */
99 { "%", "s.%",
100 "$(GET) $(GFLAGS) $(SCCS_OUTPUT_OPTION) $<" },
101 { "%", "SCCS/s.%",
102 "$(GET) $(GFLAGS) $(SCCS_OUTPUT_OPTION) $<" },
103 #endif /* !VMS */
104 { 0, 0, 0 }
107 static char *default_suffix_rules[] =
109 #ifdef VMS
110 ".obj.exe",
111 "$(LINK.obj) $^ $(LOADLIBES) $(LDLIBS) /exe=$@",
112 ".mar.exe",
113 "$(LINK.mar) $^ $(LOADLIBES) $(LDLIBS) /exe=$@",
114 ".c.exe",
115 "$(COMPILE.c) $^ \n $(LINK.obj) $(subst .c,.obj,$^) $(LOADLIBES) $(LDLIBS) /exe=$@",
116 ".cc.exe",
117 "$(COMPILE.cc) $^ \n $(LINK.obj) $(subst .cc,.obj,$^) $(LOADLIBES) $(LDLIBS) /exe=$@",
118 ".for.exe",
119 "$(COMPILE.for) $^ \n $(LINK.obj) $(subst .for,.obj,$^) $(LOADLIBES) $(LDLIBS) /exe=$@",
120 ".pas.exe",
121 "$(COMPILE.pas) $^ \n $(LINK.obj) $(subst .pas,.obj,$^) $(LOADLIBES) $(LDLIBS) /exe=$@",
123 ".com",
124 "copy $< >$@",
126 ".mar.obj",
127 "$(COMPILE.mar) /obj=$@ $<",
128 ".c.obj",
129 "$(COMPILE.c) /obj=$@ $<",
130 ".cc.obj",
131 "$(COMPILE.cc) /obj=$@ $<",
132 ".for.obj",
133 "$(COMPILE.for) /obj=$@ $<",
134 ".pas.obj",
135 "$(COMPILE.pas) /obj=$@ $<",
137 ".y.c",
138 "$(YACC.y) $< \n rename y_tab.c $@",
139 ".l.c",
140 "$(LEX.l) $< \n rename lexyy.c $@",
142 ".texinfo.info",
143 "$(MAKEINFO) $<",
145 ".tex.dvi",
146 "$(TEX) $<",
148 #else /* ! VMS */
150 ".o",
151 "$(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -o $@",
152 ".s",
153 "$(LINK.s) $^ $(LOADLIBES) $(LDLIBS) -o $@",
154 ".S",
155 "$(LINK.S) $^ $(LOADLIBES) $(LDLIBS) -o $@",
156 ".c",
157 "$(LINK.c) $^ $(LOADLIBES) $(LDLIBS) -o $@",
158 ".cc",
159 "$(LINK.cc) $^ $(LOADLIBES) $(LDLIBS) -o $@",
160 ".C",
161 "$(LINK.C) $^ $(LOADLIBES) $(LDLIBS) -o $@",
162 ".cpp",
163 "$(LINK.cpp) $^ $(LOADLIBES) $(LDLIBS) -o $@",
164 ".f",
165 "$(LINK.f) $^ $(LOADLIBES) $(LDLIBS) -o $@",
166 ".p",
167 "$(LINK.p) $^ $(LOADLIBES) $(LDLIBS) -o $@",
168 ".F",
169 "$(LINK.F) $^ $(LOADLIBES) $(LDLIBS) -o $@",
170 ".r",
171 "$(LINK.r) $^ $(LOADLIBES) $(LDLIBS) -o $@",
172 ".mod",
173 "$(COMPILE.mod) -o $@ -e $@ $^",
175 ".def.sym",
176 "$(COMPILE.def) -o $@ $<",
178 ".sh",
179 "cat $< >$@ \n chmod a+x $@",
181 ".s.o",
182 "$(COMPILE.s) -o $@ $<",
183 ".S.o",
184 "$(COMPILE.S) -o $@ $<",
185 ".c.o",
186 "$(COMPILE.c) $(OUTPUT_OPTION) $<",
187 ".cc.o",
188 "$(COMPILE.cc) $(OUTPUT_OPTION) $<",
189 ".C.o",
190 "$(COMPILE.C) $(OUTPUT_OPTION) $<",
191 ".cpp.o",
192 "$(COMPILE.cpp) $(OUTPUT_OPTION) $<",
193 ".f.o",
194 "$(COMPILE.f) $(OUTPUT_OPTION) $<",
195 ".p.o",
196 "$(COMPILE.p) $(OUTPUT_OPTION) $<",
197 ".F.o",
198 "$(COMPILE.F) $(OUTPUT_OPTION) $<",
199 ".r.o",
200 "$(COMPILE.r) $(OUTPUT_OPTION) $<",
201 ".mod.o",
202 "$(COMPILE.mod) -o $@ $<",
204 ".c.ln",
205 "$(LINT.c) -C$* $<",
206 ".y.ln",
207 #ifndef __MSDOS__
208 "$(YACC.y) $< \n $(LINT.c) -C$* y.tab.c \n $(RM) y.tab.c",
209 #else
210 "$(YACC.y) $< \n $(LINT.c) -C$* y_tab.c \n $(RM) y_tab.c",
211 #endif
212 ".l.ln",
213 "@$(RM) $*.c\n $(LEX.l) $< > $*.c\n$(LINT.c) -i $*.c -o $@\n $(RM) $*.c",
215 ".y.c",
216 #ifndef __MSDOS__
217 "$(YACC.y) $< \n mv -f y.tab.c $@",
218 #else
219 "$(YACC.y) $< \n mv -f y_tab.c $@",
220 #endif
221 ".l.c",
222 "@$(RM) $@ \n $(LEX.l) $< > $@",
224 ".F.f",
225 "$(PREPROCESS.F) $(OUTPUT_OPTION) $<",
226 ".r.f",
227 "$(PREPROCESS.r) $(OUTPUT_OPTION) $<",
229 /* This might actually make lex.yy.c if there's no %R%
230 directive in $*.l, but in that case why were you
231 trying to make $*.r anyway? */
232 ".l.r",
233 "$(LEX.l) $< > $@ \n mv -f lex.yy.r $@",
235 ".S.s",
236 "$(PREPROCESS.S) $< > $@",
238 ".texinfo.info",
239 "$(MAKEINFO) $(MAKEINFO_FLAGS) $< -o $@",
241 ".texi.info",
242 "$(MAKEINFO) $(MAKEINFO_FLAGS) $< -o $@",
244 ".txinfo.info",
245 "$(MAKEINFO) $(MAKEINFO_FLAGS) $< -o $@",
247 ".tex.dvi",
248 "$(TEX) $<",
250 ".texinfo.dvi",
251 "$(TEXI2DVI) $(TEXI2DVI_FLAGS) $<",
253 ".texi.dvi",
254 "$(TEXI2DVI) $(TEXI2DVI_FLAGS) $<",
256 ".txinfo.dvi",
257 "$(TEXI2DVI) $(TEXI2DVI_FLAGS) $<",
259 ".w.c",
260 "$(CTANGLE) $< - $@", /* The `-' says there is no `.ch' file. */
262 ".web.p",
263 "$(TANGLE) $<",
265 ".w.tex",
266 "$(CWEAVE) $< - $@", /* The `-' says there is no `.ch' file. */
268 ".web.tex",
269 "$(WEAVE) $<",
271 #endif /* !VMS */
273 0, 0,
276 static char *default_variables[] =
278 #ifdef VMS
279 "AR", "library/obj",
280 "ARFLAGS", "/replace",
281 "AS", "macro",
282 "CC", "cc",
283 "C++", "gcc/plus",
284 "CXX", "gcc/plus",
285 "CO", "co",
286 "CPP", "$(CC) /preprocess_only",
287 "FC", "fortran",
288 /* System V uses these, so explicit rules using them should work.
289 However, there is no way to make implicit rules use them and FC. */
290 "F77", "$(FC)",
291 "F77FLAGS", "$(FFLAGS)",
292 "LD", "link",
293 "LEX", "lex",
294 "PC", "pascal",
295 "YACC", "yacc", /* Or "bison -y" */
296 "MAKEINFO", "makeinfo",
297 "TEX", "tex",
298 "TEXINDEX", "texindex",
300 "RM", "delete/nolog",
302 "LINK.obj", "$(LD) $(LDFLAGS)",
303 "COMPILE.c", "$(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH)",
304 "COMPILE.cc", "$(C++) $(C++FLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c",
305 "YACC.y", "$(YACC) $(YFLAGS)",
306 "LEX.l", "$(LEX) $(LFLAGS)",
307 "COMPILE.for", "$(FC) $(FFLAGS) $(TARGET_ARCH)",
308 "COMPILE.pas", "$(PC) $(PFLAGS) $(CPPFLAGS) $(TARGET_ARCH)",
309 "COMPILE.mar", "$(AS) $(ASFLAGS) $(TARGET_MACH)",
310 "LINT.c", "$(LINT) $(LINTFLAGS) $(CPPFLAGS) $(TARGET_ARCH)",
312 "MV", "rename/new_version",
313 "CP", "copy",
315 #else /* !VMS */
317 "AR", "ar",
318 "ARFLAGS", "rv",
319 "AS", "as",
320 #ifdef GCC_IS_NATIVE
321 "CC", "gcc",
322 "CXX", "gcc",
323 #else
324 "CC", "cc",
325 "CXX", "g++",
326 #endif
328 /* This expands to $(CO) $(COFLAGS) $< $@ if $@ does not exist,
329 and to the empty string if $@ does exist. */
330 "CHECKOUT,v",
331 "+$(patsubst $@-noexist,$(CO) $(COFLAGS) $< $@,\
332 $(filter-out $@,$(firstword $(wildcard $@) $@-noexist)))",
334 "CO", "co",
335 "CPP", "$(CC) -E",
336 #ifdef CRAY
337 "CF77PPFLAGS", "-P",
338 "CF77PP", "/lib/cpp",
339 "CFT", "cft77",
340 "CF", "cf77",
341 "FC", "$(CF)",
342 #else /* Not CRAY. */
343 #ifdef _IBMR2
344 "FC", "xlf",
345 #else
346 #ifdef __convex__
347 "FC", "fc",
348 #else
349 "FC", "f77",
350 #endif /* __convex__ */
351 #endif /* _IBMR2 */
352 /* System V uses these, so explicit rules using them should work.
353 However, there is no way to make implicit rules use them and FC. */
354 "F77", "$(FC)",
355 "F77FLAGS", "$(FFLAGS)",
356 #endif /* Cray. */
357 "GET", SCCS_GET,
358 "LD", "ld",
359 #ifdef GCC_IS_NATIVE
360 "LEX", "flex",
361 #else
362 "LEX", "lex",
363 #endif
364 "LINT", "lint",
365 "M2C", "m2c",
366 #ifdef pyr
367 "PC", "pascal",
368 #else
369 #ifdef CRAY
370 "PC", "PASCAL",
371 "SEGLDR", "segldr",
372 #else
373 "PC", "pc",
374 #endif /* CRAY. */
375 #endif /* pyr. */
376 #ifdef GCC_IS_NATIVE
377 "YACC", "bison -y",
378 #else
379 "YACC", "yacc", /* Or "bison -y" */
380 #endif
381 "MAKEINFO", "makeinfo",
382 "TEX", "tex",
383 "TEXI2DVI", "texi2dvi",
384 "WEAVE", "weave",
385 "CWEAVE", "cweave",
386 "TANGLE", "tangle",
387 "CTANGLE", "ctangle",
389 "RM", "rm -f",
391 "LINK.o", "$(CC) $(LDFLAGS) $(TARGET_ARCH)",
392 "COMPILE.c", "$(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c",
393 "LINK.c", "$(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)",
394 "COMPILE.cc", "$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c",
395 "COMPILE.C", "$(COMPILE.cc)",
396 "COMPILE.cpp", "$(COMPILE.cc)",
397 "LINK.cc", "$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)",
398 "LINK.C", "$(LINK.cc)",
399 "LINK.cpp", "$(LINK.cc)",
400 "YACC.y", "$(YACC) $(YFLAGS)",
401 "LEX.l", "$(LEX) $(LFLAGS) -t",
402 "COMPILE.f", "$(FC) $(FFLAGS) $(TARGET_ARCH) -c",
403 "LINK.f", "$(FC) $(FFLAGS) $(LDFLAGS) $(TARGET_ARCH)",
404 "COMPILE.F", "$(FC) $(FFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c",
405 "LINK.F", "$(FC) $(FFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)",
406 "COMPILE.r", "$(FC) $(FFLAGS) $(RFLAGS) $(TARGET_ARCH) -c",
407 "LINK.r", "$(FC) $(FFLAGS) $(RFLAGS) $(LDFLAGS) $(TARGET_ARCH)",
408 "COMPILE.def", "$(M2C) $(M2FLAGS) $(DEFFLAGS) $(TARGET_ARCH)",
409 "COMPILE.mod", "$(M2C) $(M2FLAGS) $(MODFLAGS) $(TARGET_ARCH)",
410 "COMPILE.p", "$(PC) $(PFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c",
411 "LINK.p", "$(PC) $(PFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)",
412 "LINK.s", "$(CC) $(ASFLAGS) $(LDFLAGS) $(TARGET_MACH)",
413 "COMPILE.s", "$(AS) $(ASFLAGS) $(TARGET_MACH)",
414 "LINK.S", "$(CC) $(ASFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_MACH)",
415 "COMPILE.S", "$(CC) $(ASFLAGS) $(CPPFLAGS) $(TARGET_MACH) -c",
416 "PREPROCESS.S", "$(CC) -E $(CPPFLAGS)",
417 "PREPROCESS.F", "$(FC) $(FFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -F",
418 "PREPROCESS.r", "$(FC) $(FFLAGS) $(RFLAGS) $(TARGET_ARCH) -F",
419 "LINT.c", "$(LINT) $(LINTFLAGS) $(CPPFLAGS) $(TARGET_ARCH)",
421 #ifndef NO_MINUS_C_MINUS_O
422 "OUTPUT_OPTION", "-o $@",
423 #endif
425 #ifdef SCCS_GET_MINUS_G
426 "SCCS_OUTPUT_OPTION", "-G$@",
427 #endif
429 #ifdef _AMIGA
430 ".LIBPATTERNS", "%.lib",
431 #else
432 #ifdef __MSDOS__
433 ".LIBPATTERNS", "lib%.a $(DJDIR)/lib/lib%.a",
434 #else
435 ".LIBPATTERNS", "lib%.so lib%.a",
436 #endif
437 #endif
439 #endif /* !VMS */
440 0, 0
443 /* Set up the default .SUFFIXES list. */
445 void
446 set_default_suffixes ()
448 suffix_file = enter_file (".SUFFIXES");
450 if (no_builtin_rules_flag)
451 (void) define_variable ("SUFFIXES", 8, "", o_default, 0);
452 else
454 char *p = default_suffixes;
455 suffix_file->deps = (struct dep *)
456 multi_glob (parse_file_seq (&p, '\0', sizeof (struct dep), 1),
457 sizeof (struct dep));
458 (void) define_variable ("SUFFIXES", 8, default_suffixes, o_default, 0);
462 /* Enter the default suffix rules as file rules. This used to be done in
463 install_default_implicit_rules, but that loses because we want the
464 suffix rules installed before reading makefiles, and thee pattern rules
465 installed after. */
467 void
468 install_default_suffix_rules ()
470 register char **s;
472 if (no_builtin_rules_flag)
473 return;
475 for (s = default_suffix_rules; *s != 0; s += 2)
477 register struct file *f = enter_file (s[0]);
478 /* Don't clobber cmds given in a makefile if there were any. */
479 if (f->cmds == 0)
481 f->cmds = (struct commands *) xmalloc (sizeof (struct commands));
482 f->cmds->fileinfo.filenm = 0;
483 f->cmds->commands = s[1];
484 f->cmds->command_lines = 0;
490 /* Install the default pattern rules. */
492 void
493 install_default_implicit_rules ()
495 register struct pspec *p;
497 if (no_builtin_rules_flag)
498 return;
500 for (p = default_pattern_rules; p->target != 0; ++p)
501 install_pattern_rule (p, 0);
503 for (p = default_terminal_rules; p->target != 0; ++p)
504 install_pattern_rule (p, 1);
507 void
508 define_default_variables ()
510 register char **s;
512 if (no_builtin_variables_flag)
513 return;
515 for (s = default_variables; *s != 0; s += 2)
516 (void) define_variable (s[0], strlen (s[0]), s[1], o_default, 1);