(define_automatic_variables): Define +D and +F.
[make.git] / default.c
blob154cb82547e629852dc0c7182beaa1ed459fdfe0
1 /* Data base of default implicit rules for GNU Make.
2 Copyright (C) 1988, 89, 90, 91, 92, 93, 94 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 #if !defined(M_XENIX) || defined(__GNUC__)
112 "$(COMPILE.s) -o $@ $<",
113 #else /* Xenix. */
114 "$(COMPILE.s) -o$@ $<",
115 #endif /* Not Xenix. */
116 ".S.o",
117 #if !defined(M_XENIX) || defined(__GNUC__)
118 "$(COMPILE.S) -o $@ $<",
119 #else /* Xenix. */
120 "$(COMPILE.S) -o$@ $<",
121 #endif /* Not Xenix. */
122 ".c.o",
123 "$(COMPILE.c) $< $(OUTPUT_OPTION)",
124 ".cc.o",
125 "$(COMPILE.cc) $< $(OUTPUT_OPTION)",
126 ".C.o",
127 "$(COMPILE.C) $< $(OUTPUT_OPTION)",
128 ".f.o",
129 "$(COMPILE.f) $< $(OUTPUT_OPTION)",
130 ".p.o",
131 "$(COMPILE.p) $< $(OUTPUT_OPTION)",
132 ".F.o",
133 "$(COMPILE.F) $< $(OUTPUT_OPTION)",
134 ".r.o",
135 "$(COMPILE.r) $< $(OUTPUT_OPTION)",
136 ".mod.o",
137 "$(COMPILE.mod) -o $@ $<",
139 ".c.ln",
140 "$(LINT.c) -C$* $<",
141 ".y.ln",
142 #ifndef __MSDOS__
143 "$(YACC.y) $< \n $(LINT.c) -C$* y.tab.c \n $(RM) y.tab.c",
144 #else
145 "$(YACC.y) $< \n $(LINT.c) -C$* y_tab.c \n $(RM) y_tab.c",
146 #endif
147 ".l.ln",
148 "@$(RM) $*.c\n $(LEX.l) $< > $*.c\n$(LINT.c) -i $*.c -o $@\n $(RM) $*.c",
150 ".y.c",
151 #ifndef __MSDOS__
152 "$(YACC.y) $< \n mv -f y.tab.c $@",
153 #else
154 "$(YACC.y) $< \n mv -f y_tab.c $@",
155 #endif
156 ".l.c",
157 "@$(RM) $@ \n $(LEX.l) $< > $@",
159 ".F.f",
160 "$(PREPROCESS.F) $< $(OUTPUT_OPTION)",
161 ".r.f",
162 "$(PREPROCESS.r) $< $(OUTPUT_OPTION)",
164 /* This might actually make lex.yy.c if there's no %R%
165 directive in $*.l, but in that case why were you
166 trying to make $*.r anyway? */
167 ".l.r",
168 "$(LEX.l) $< > $@ \n mv -f lex.yy.r $@",
170 ".S.s",
171 "$(PREPROCESS.S) $< > $@",
173 ".texinfo.info",
174 "$(MAKEINFO) $(MAKEINFO_FLAGS) $< -o $@",
176 ".texi.info",
177 "$(MAKEINFO) $(MAKEINFO_FLAGS) $< -o $@",
179 ".txinfo.info",
180 "$(MAKEINFO) $(MAKEINFO_FLAGS) $< -o $@",
182 ".tex.dvi",
183 "$(TEX) $<",
185 ".texinfo.dvi",
186 "$(TEXI2DVI) $(TEXI2DVI_FLAGS) $<",
188 ".texi.dvi",
189 "$(TEXI2DVI) $(TEXI2DVI_FLAGS) $<",
191 ".txinfo.dvi",
192 "$(TEXI2DVI) $(TEXI2DVI_FLAGS) $<",
194 ".w.c",
195 "$(CTANGLE) $< - $@", /* The `-' says there is no `.ch' file. */
197 ".web.p",
198 "$(TANGLE) $<",
200 ".w.tex",
201 "$(CWEAVE) $< - $@", /* The `-' says there is no `.ch' file. */
203 ".web.tex",
204 "$(WEAVE) $<",
206 0, 0,
209 static char *default_variables[] =
211 "AR", "ar",
212 #ifndef __hpux
213 "ARFLAGS", "rv",
214 #else
215 /* HPUX ar's f flag says to truncate the file names to archive member
216 name length in comparisons, so replacement notices the equality. */
217 "ARFLAGS", "rfv",
218 #endif
219 "AS", "as",
220 #ifdef GCC_IS_NATIVE
221 "CC", "gcc",
222 "CXX", "gcc",
223 #else
224 "CC", "cc",
225 "CXX", "g++",
226 #endif
228 /* This expands to $(CO) $(COFLAGS) $< $@ if $@ does not exist,
229 and to the empty string if $@ does exist. */
230 "CHECKOUT,v",
231 "$(patsubst $@-noexist,$(CO) $(COFLAGS) $< $@,\
232 $(filter-out $@,$(firstword $(wildcard $@) $@-noexist)))",
234 "CO", "co",
235 "CPP", "$(CC) -E",
236 #ifdef CRAY
237 "CF77PPFLAGS", "-P",
238 "CF77PP", "/lib/cpp",
239 "CFT", "cft77",
240 "CF", "cf77",
241 "FC", "$(CF)",
242 #else /* Not CRAY. */
243 #ifdef _IBMR2
244 "FC", "xlf",
245 #else
246 #ifdef __convex__
247 "FC", "fc",
248 #else
249 "FC", "f77",
250 #endif /* __convex__ */
251 #endif /* _IBMR2 */
252 /* System V uses these, so explicit rules using them should work.
253 However, there is no way to make implicit rules use them and FC. */
254 "F77", "$(FC)",
255 "F77FLAGS", "$(FFLAGS)",
256 #endif /* Cray. */
257 "GET", SCCS_GET,
258 "LD", "ld",
259 #ifdef GCC_IS_NATIVE
260 "LEX", "flex",
261 #else
262 "LEX", "lex",
263 #endif
264 "LINT", "lint",
265 "M2C", "m2c",
266 #ifdef pyr
267 "PC", "pascal",
268 #else
269 #ifdef CRAY
270 "PC", "PASCAL",
271 "SEGLDR", "segldr",
272 #else
273 "PC", "pc",
274 #endif /* CRAY. */
275 #endif /* pyr. */
276 #ifdef GCC_IS_NATIVE
277 "YACC", "bison -y",
278 #else
279 "YACC", "yacc", /* Or "bison -y" */
280 #endif
281 "MAKEINFO", "makeinfo",
282 "TEX", "tex",
283 "TEXI2DVI", "texi2dvi",
284 "WEAVE", "weave",
285 "CWEAVE", "cweave",
286 "TANGLE", "tangle",
287 "CTANGLE", "ctangle",
289 "RM", "rm -f",
291 "LINK.o", "$(CC) $(LDFLAGS) $(TARGET_ARCH)",
292 "COMPILE.c", "$(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c",
293 "LINK.c", "$(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)",
294 "COMPILE.cc", "$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c",
295 "COMPILE.C", "$(COMPILE.cc)",
296 "LINK.cc", "$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)",
297 "LINK.C", "$(LINK.cc)",
298 "YACC.y", "$(YACC) $(YFLAGS)",
299 "LEX.l", "$(LEX) $(LFLAGS) -t",
300 "COMPILE.f", "$(FC) $(FFLAGS) $(TARGET_ARCH) -c",
301 "LINK.f", "$(FC) $(FFLAGS) $(LDFLAGS) $(TARGET_ARCH)",
302 "COMPILE.F", "$(FC) $(FFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c",
303 "LINK.F", "$(FC) $(FFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)",
304 "COMPILE.r", "$(FC) $(FFLAGS) $(RFLAGS) $(TARGET_ARCH) -c",
305 "LINK.r", "$(FC) $(FFLAGS) $(RFLAGS) $(LDFLAGS) $(TARGET_ARCH)",
306 "COMPILE.def", "$(M2C) $(M2FLAGS) $(DEFFLAGS) $(TARGET_ARCH)",
307 "COMPILE.mod", "$(M2C) $(M2FLAGS) $(MODFLAGS) $(TARGET_ARCH)",
308 "COMPILE.p", "$(PC) $(PFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c",
309 "LINK.p", "$(PC) $(PFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)",
310 "LINK.s", "$(CC) $(ASFLAGS) $(LDFLAGS) $(TARGET_MACH)",
311 "COMPILE.s", "$(AS) $(ASFLAGS) $(TARGET_MACH)",
312 "LINK.S", "$(CC) $(ASFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_MACH)",
313 "COMPILE.S", "$(CC) $(ASFLAGS) $(CPPFLAGS) $(TARGET_MACH) -c",
314 #if !defined(M_XENIX) || defined(__GNUC__)
315 "PREPROCESS.S", "$(CC) -E $(CPPFLAGS)",
316 #else /* Xenix. */
317 "PREPROCESS.S", "$(CC) -EP $(CPPFLAGS)",
318 #endif /* Not Xenix. */
319 "PREPROCESS.F", "$(FC) $(FFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -F",
320 "PREPROCESS.r", "$(FC) $(FFLAGS) $(RFLAGS) $(TARGET_ARCH) -F",
321 "LINT.c", "$(LINT) $(LINTFLAGS) $(CPPFLAGS) $(TARGET_ARCH)",
323 #ifndef NO_MINUS_C_MINUS_O
324 #if !defined(M_XENIX) || defined(__GNUC__)
325 "OUTPUT_OPTION", "-o $@",
326 #else /* Xenix. */
327 "OUTPUT_OPTION", "-Fo$@",
328 #endif /* Not Xenix. */
329 #endif
331 #ifdef SCCS_GET_MINUS_G
332 "SCCS_OUTPUT_OPTION", "-G$@",
333 #endif
335 0, 0
338 /* Set up the default .SUFFIXES list. */
340 void
341 set_default_suffixes ()
343 suffix_file = enter_file (".SUFFIXES");
345 if (no_builtin_rules_flag)
346 (void) define_variable ("SUFFIXES", 8, "", o_default, 0);
347 else
349 char *p = default_suffixes;
350 suffix_file->deps = (struct dep *)
351 multi_glob (parse_file_seq (&p, '\0', sizeof (struct dep), 1),
352 sizeof (struct dep));
353 (void) define_variable ("SUFFIXES", 8, default_suffixes, o_default, 0);
357 /* Enter the default suffix rules as file rules. This used to be done in
358 install_default_implicit_rules, but that loses because we want the
359 suffix rules installed before reading makefiles, and thee pattern rules
360 installed after. */
362 void
363 install_default_suffix_rules ()
365 register char **s;
367 if (no_builtin_rules_flag)
368 return;
370 for (s = default_suffix_rules; *s != 0; s += 2)
372 register struct file *f = enter_file (s[0]);
373 /* Don't clobber cmds given in a makefile if there were any. */
374 if (f->cmds == 0)
376 f->cmds = (struct commands *) xmalloc (sizeof (struct commands));
377 f->cmds->filename = 0;
378 f->cmds->commands = s[1];
379 f->cmds->command_lines = 0;
385 /* Install the default pattern rules. */
387 void
388 install_default_implicit_rules ()
390 register struct pspec *p;
392 if (no_builtin_rules_flag)
393 return;
395 for (p = default_pattern_rules; p->target != 0; ++p)
396 install_pattern_rule (p, 0);
398 for (p = default_terminal_rules; p->target != 0; ++p)
399 install_pattern_rule (p, 1);
402 void
403 define_default_variables ()
405 register char **s;
407 for (s = default_variables; *s != 0; s += 2)
408 (void) define_variable (s[0], strlen (s[0]), s[1], o_default, 1);