Sun Jul 30 00:49:53 1995 Richard Stallman <rms@mole.gnu.ai.mit.edu>
[make.git] / default.c
blob7c487d14e1f0258b7f6fc013138543a64b8dc084
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, 675 Mass Ave, Cambridge, MA 02139, USA. */
19 #include "make.h"
20 #include "rule.h"
21 #include "dep.h"
22 #include "file.h"
23 #include "commands.h"
24 #include "variable.h"
26 /* Define GCC_IS_NATIVE if gcc is the native development environment on
27 your system (gcc/bison/flex vs cc/yacc/lex). */
28 #ifdef __MSDOS__
29 #define GCC_IS_NATIVE
30 #endif
33 /* This is the default list of suffixes for suffix rules.
34 `.s' must come last, so that a `.o' file will be made from
35 a `.c' or `.p' or ... file rather than from a .s file. */
37 static char default_suffixes[]
38 = ".out .a .ln .o .c .cc .C .p .f .F .r .y .l .s .S \
39 .mod .sym .def .h .info .dvi .tex .texinfo .texi .txinfo \
40 .w .ch .web .sh .elc .el";
42 static struct pspec default_pattern_rules[] =
44 { "(%)", "%",
45 "$(AR) $(ARFLAGS) $@ $<" },
47 /* The X.out rules are only in BSD's default set because
48 BSD Make has no null-suffix rules, so `foo.out' and
49 `foo' are the same thing. */
50 { "%.out", "%",
51 "@rm -f $@ \n cp $< $@" },
53 /* Syntax is "ctangle foo.w foo.ch foo.c". */
54 { "%.c", "%.w %.ch",
55 "$(CTANGLE) $^ $@" },
56 { "%.tex", "%.w %.ch",
57 "$(CWEAVE) $^ $@" },
59 { 0, 0, 0 }
62 static struct pspec default_terminal_rules[] =
64 /* RCS. */
65 { "%", "%,v",
66 "$(CHECKOUT,v)" },
67 { "%", "RCS/%,v",
68 "$(CHECKOUT,v)" },
70 /* SCCS. */
71 { "%", "s.%",
72 "$(GET) $(GFLAGS) $(SCCS_OUTPUT_OPTION) $<" },
73 { "%", "SCCS/s.%",
74 "$(GET) $(GFLAGS) $(SCCS_OUTPUT_OPTION) $<" },
76 { 0, 0, 0 }
79 static char *default_suffix_rules[] =
81 ".o",
82 "$(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -o $@",
83 ".s",
84 "$(LINK.s) $^ $(LOADLIBES) $(LDLIBS) -o $@",
85 ".S",
86 "$(LINK.S) $^ $(LOADLIBES) $(LDLIBS) -o $@",
87 ".c",
88 "$(LINK.c) $^ $(LOADLIBES) $(LDLIBS) -o $@",
89 ".cc",
90 "$(LINK.cc) $^ $(LOADLIBES) $(LDLIBS) -o $@",
91 ".C",
92 "$(LINK.C) $^ $(LOADLIBES) $(LDLIBS) -o $@",
93 ".f",
94 "$(LINK.f) $^ $(LOADLIBES) $(LDLIBS) -o $@",
95 ".p",
96 "$(LINK.p) $^ $(LOADLIBES) $(LDLIBS) -o $@",
97 ".F",
98 "$(LINK.F) $^ $(LOADLIBES) $(LDLIBS) -o $@",
99 ".r",
100 "$(LINK.r) $^ $(LOADLIBES) $(LDLIBS) -o $@",
101 ".mod",
102 "$(COMPILE.mod) -o $@ -e $@ $^",
104 ".def.sym",
105 "$(COMPILE.def) -o $@ $<",
107 ".sh",
108 "cat $< >$@ \n chmod a+x $@",
110 ".s.o",
111 "$(COMPILE.s) -o $@ $<",
112 ".S.o",
113 "$(COMPILE.S) -o $@ $<",
114 ".c.o",
115 "$(COMPILE.c) $< $(OUTPUT_OPTION)",
116 ".cc.o",
117 "$(COMPILE.cc) $< $(OUTPUT_OPTION)",
118 ".C.o",
119 "$(COMPILE.C) $< $(OUTPUT_OPTION)",
120 ".f.o",
121 "$(COMPILE.f) $< $(OUTPUT_OPTION)",
122 ".p.o",
123 "$(COMPILE.p) $< $(OUTPUT_OPTION)",
124 ".F.o",
125 "$(COMPILE.F) $< $(OUTPUT_OPTION)",
126 ".r.o",
127 "$(COMPILE.r) $< $(OUTPUT_OPTION)",
128 ".mod.o",
129 "$(COMPILE.mod) -o $@ $<",
131 ".c.ln",
132 "$(LINT.c) -C$* $<",
133 ".y.ln",
134 #ifndef __MSDOS__
135 "$(YACC.y) $< \n $(LINT.c) -C$* y.tab.c \n $(RM) y.tab.c",
136 #else
137 "$(YACC.y) $< \n $(LINT.c) -C$* y_tab.c \n $(RM) y_tab.c",
138 #endif
139 ".l.ln",
140 "@$(RM) $*.c\n $(LEX.l) $< > $*.c\n$(LINT.c) -i $*.c -o $@\n $(RM) $*.c",
142 ".y.c",
143 #ifndef __MSDOS__
144 "$(YACC.y) $< \n mv -f y.tab.c $@",
145 #else
146 "$(YACC.y) $< \n mv -f y_tab.c $@",
147 #endif
148 ".l.c",
149 "@$(RM) $@ \n $(LEX.l) $< > $@",
151 ".F.f",
152 "$(PREPROCESS.F) $< $(OUTPUT_OPTION)",
153 ".r.f",
154 "$(PREPROCESS.r) $< $(OUTPUT_OPTION)",
156 /* This might actually make lex.yy.c if there's no %R%
157 directive in $*.l, but in that case why were you
158 trying to make $*.r anyway? */
159 ".l.r",
160 "$(LEX.l) $< > $@ \n mv -f lex.yy.r $@",
162 ".S.s",
163 "$(PREPROCESS.S) $< > $@",
165 ".texinfo.info",
166 "$(MAKEINFO) $(MAKEINFO_FLAGS) $< -o $@",
168 ".texi.info",
169 "$(MAKEINFO) $(MAKEINFO_FLAGS) $< -o $@",
171 ".txinfo.info",
172 "$(MAKEINFO) $(MAKEINFO_FLAGS) $< -o $@",
174 ".tex.dvi",
175 "$(TEX) $<",
177 ".texinfo.dvi",
178 "$(TEXI2DVI) $(TEXI2DVI_FLAGS) $<",
180 ".texi.dvi",
181 "$(TEXI2DVI) $(TEXI2DVI_FLAGS) $<",
183 ".txinfo.dvi",
184 "$(TEXI2DVI) $(TEXI2DVI_FLAGS) $<",
186 ".w.c",
187 "$(CTANGLE) $< - $@", /* The `-' says there is no `.ch' file. */
189 ".web.p",
190 "$(TANGLE) $<",
192 ".w.tex",
193 "$(CWEAVE) $< - $@", /* The `-' says there is no `.ch' file. */
195 ".web.tex",
196 "$(WEAVE) $<",
198 0, 0,
201 static char *default_variables[] =
203 "AR", "ar",
204 "ARFLAGS", "rv",
205 "AS", "as",
206 #ifdef GCC_IS_NATIVE
207 "CC", "gcc",
208 "CXX", "gcc",
209 #else
210 "CC", "cc",
211 "CXX", "g++",
212 #endif
214 /* This expands to $(CO) $(COFLAGS) $< $@ if $@ does not exist,
215 and to the empty string if $@ does exist. */
216 "CHECKOUT,v",
217 "+$(patsubst $@-noexist,$(CO) $(COFLAGS) $< $@,\
218 $(filter-out $@,$(firstword $(wildcard $@) $@-noexist)))",
220 "CO", "co",
221 "CPP", "$(CC) -E",
222 #ifdef CRAY
223 "CF77PPFLAGS", "-P",
224 "CF77PP", "/lib/cpp",
225 "CFT", "cft77",
226 "CF", "cf77",
227 "FC", "$(CF)",
228 #else /* Not CRAY. */
229 #ifdef _IBMR2
230 "FC", "xlf",
231 #else
232 #ifdef __convex__
233 "FC", "fc",
234 #else
235 "FC", "f77",
236 #endif /* __convex__ */
237 #endif /* _IBMR2 */
238 /* System V uses these, so explicit rules using them should work.
239 However, there is no way to make implicit rules use them and FC. */
240 "F77", "$(FC)",
241 "F77FLAGS", "$(FFLAGS)",
242 #endif /* Cray. */
243 "GET", SCCS_GET,
244 "LD", "ld",
245 #ifdef GCC_IS_NATIVE
246 "LEX", "flex",
247 #else
248 "LEX", "lex",
249 #endif
250 "LINT", "lint",
251 "M2C", "m2c",
252 #ifdef pyr
253 "PC", "pascal",
254 #else
255 #ifdef CRAY
256 "PC", "PASCAL",
257 "SEGLDR", "segldr",
258 #else
259 "PC", "pc",
260 #endif /* CRAY. */
261 #endif /* pyr. */
262 #ifdef GCC_IS_NATIVE
263 "YACC", "bison -y",
264 #else
265 "YACC", "yacc", /* Or "bison -y" */
266 #endif
267 "MAKEINFO", "makeinfo",
268 "TEX", "tex",
269 "TEXI2DVI", "texi2dvi",
270 "WEAVE", "weave",
271 "CWEAVE", "cweave",
272 "TANGLE", "tangle",
273 "CTANGLE", "ctangle",
275 "RM", "rm -f",
277 "LINK.o", "$(CC) $(LDFLAGS) $(TARGET_ARCH)",
278 "COMPILE.c", "$(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c",
279 "LINK.c", "$(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)",
280 "COMPILE.cc", "$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c",
281 "COMPILE.C", "$(COMPILE.cc)",
282 "LINK.cc", "$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)",
283 "LINK.C", "$(LINK.cc)",
284 "YACC.y", "$(YACC) $(YFLAGS)",
285 "LEX.l", "$(LEX) $(LFLAGS) -t",
286 "COMPILE.f", "$(FC) $(FFLAGS) $(TARGET_ARCH) -c",
287 "LINK.f", "$(FC) $(FFLAGS) $(LDFLAGS) $(TARGET_ARCH)",
288 "COMPILE.F", "$(FC) $(FFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c",
289 "LINK.F", "$(FC) $(FFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)",
290 "COMPILE.r", "$(FC) $(FFLAGS) $(RFLAGS) $(TARGET_ARCH) -c",
291 "LINK.r", "$(FC) $(FFLAGS) $(RFLAGS) $(LDFLAGS) $(TARGET_ARCH)",
292 "COMPILE.def", "$(M2C) $(M2FLAGS) $(DEFFLAGS) $(TARGET_ARCH)",
293 "COMPILE.mod", "$(M2C) $(M2FLAGS) $(MODFLAGS) $(TARGET_ARCH)",
294 "COMPILE.p", "$(PC) $(PFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c",
295 "LINK.p", "$(PC) $(PFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)",
296 "LINK.s", "$(CC) $(ASFLAGS) $(LDFLAGS) $(TARGET_MACH)",
297 "COMPILE.s", "$(AS) $(ASFLAGS) $(TARGET_MACH)",
298 "LINK.S", "$(CC) $(ASFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_MACH)",
299 "COMPILE.S", "$(CC) $(ASFLAGS) $(CPPFLAGS) $(TARGET_MACH) -c",
300 "PREPROCESS.S", "$(CC) -E $(CPPFLAGS)",
301 "PREPROCESS.F", "$(FC) $(FFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -F",
302 "PREPROCESS.r", "$(FC) $(FFLAGS) $(RFLAGS) $(TARGET_ARCH) -F",
303 "LINT.c", "$(LINT) $(LINTFLAGS) $(CPPFLAGS) $(TARGET_ARCH)",
305 #ifndef NO_MINUS_C_MINUS_O
306 "OUTPUT_OPTION", "-o $@",
307 #endif
309 #ifdef SCCS_GET_MINUS_G
310 "SCCS_OUTPUT_OPTION", "-G$@",
311 #endif
313 0, 0
316 /* Set up the default .SUFFIXES list. */
318 void
319 set_default_suffixes ()
321 suffix_file = enter_file (".SUFFIXES");
323 if (no_builtin_rules_flag)
324 (void) define_variable ("SUFFIXES", 8, "", o_default, 0);
325 else
327 char *p = default_suffixes;
328 suffix_file->deps = (struct dep *)
329 multi_glob (parse_file_seq (&p, '\0', sizeof (struct dep), 1),
330 sizeof (struct dep));
331 (void) define_variable ("SUFFIXES", 8, default_suffixes, o_default, 0);
335 /* Enter the default suffix rules as file rules. This used to be done in
336 install_default_implicit_rules, but that loses because we want the
337 suffix rules installed before reading makefiles, and thee pattern rules
338 installed after. */
340 void
341 install_default_suffix_rules ()
343 register char **s;
345 if (no_builtin_rules_flag)
346 return;
348 for (s = default_suffix_rules; *s != 0; s += 2)
350 register struct file *f = enter_file (s[0]);
351 /* Don't clobber cmds given in a makefile if there were any. */
352 if (f->cmds == 0)
354 f->cmds = (struct commands *) xmalloc (sizeof (struct commands));
355 f->cmds->filename = 0;
356 f->cmds->commands = s[1];
357 f->cmds->command_lines = 0;
363 /* Install the default pattern rules. */
365 void
366 install_default_implicit_rules ()
368 register struct pspec *p;
370 if (no_builtin_rules_flag)
371 return;
373 for (p = default_pattern_rules; p->target != 0; ++p)
374 install_pattern_rule (p, 0);
376 for (p = default_terminal_rules; p->target != 0; ++p)
377 install_pattern_rule (p, 1);
380 void
381 define_default_variables ()
383 register char **s;
385 for (s = default_variables; *s != 0; s += 2)
386 (void) define_variable (s[0], strlen (s[0]), s[1], o_default, 1);