Makefile revision 126266
1# $FreeBSD: head/gnu/usr.bin/cc/cc_tools/Makefile 126266 2004-02-26 07:08:33Z bde $
2
3#
4# This could probably be merged with ../cc_int/Makefile, but bsd.lib.mk
5# is such a !@#!*#% nightmare because of how it reprograms the dependencies,
6# suffix rules, SRCS, etc.  It's easiest to cheat by using bsd.prog.mk and
7# SRCS to get dependencies.
8#
9
10#
11# ../Makefile.inc will put an absolute path to our objdir in CFLAGS.
12# Prevent mkdep from using it, so that we don't have to give rules for
13# aliases of generated headers.
14#
15CFLAGS+=	-I.
16
17.include "../Makefile.inc"
18
19.PATH: ${GCCDIR}
20
21CFLAGS+=	-DGENERATOR_FILE
22
23#-----------------------------------------------------------------------
24# insn-* gunk
25
26.for F in attr codes config flags constants
27insn-$F.h: gen$F ${MD_FILE}
28	./gen$F ${MD_FILE} > insn-$F.h
29GENSRCS+=	insn-$F.h
30.endfor
31
32.for F in conditions
33insn-$F.c: gen$F ${MD_FILE}
34	./gen$F ${MD_FILE} > insn-$F.c
35GENSRCS+=	insn-$F.c
36.endfor
37
38GENSRCS+=	gen-time-stamp
39gen-time-stamp: genattr genattrtab genconditions genconstants genemit \
40		genextract gengtype genopinit genoutput genpeep genrecog
41	touch ${.TARGET}
42
43.for F in attr codes config emit extract flags opinit output peep recog
44build-tools: gen$F
45
46gen$F: gen$F.o rtl.o obstack.o print-rtl.o bitmap.o errors.o gensupport.o \
47	ggc-none.o hashtab.o read-rtl.o concat.o insn-conditions.o
48	${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${.ALLSRC}
49
50GENSRCS+=	gen$F.c
51CLEANFILES+=	gen$F
52.endfor
53
54#
55# genattrtab needs more complex build rule
56#
57build-tools: genattrtab
58
59genattrtab : genattrtab.o rtl.o obstack.o print-rtl.o bitmap.o errors.o \
60	gensupport.o ggc-none.o hashtab.o read-rtl.o concat.o \
61	insn-conditions.o genautomata.o varray.o getruntime.o
62	${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${.ALLSRC} -lm
63
64GENSRCS+=	genattrtab.c
65CLEANFILES+=	genattrtab
66
67#
68# genconstants and genconditions cannot depend on insn-conditions.o
69# they should be liked with dummy-conditions.o stubs instead
70#
71.for F in constants conditions
72build-tools: gen$F
73
74gen$F: gen$F.o rtl.o obstack.o bitmap.o errors.o gensupport.o \
75       ggc-none.o hashtab.o read-rtl.o concat.o dummy-conditions.o
76	${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${.ALLSRC}
77
78GENSRCS+=	gen$F.c
79CLEANFILES+=	gen$F
80.endfor
81
82.for F in check genrtl preds
83build-tools: gen$F
84
85gen$F: gen$F.o
86	${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${.ALLSRC}
87
88GENSRCS+=	gen$F.c
89CLEANFILES+=	gen$F
90.endfor
91
92.ORDER: genrtl.c genrtl.h
93genrtl.c genrtl.h: gengenrtl
94	./gengenrtl > genrtl.c
95	./gengenrtl -h > genrtl.h
96
97GENSRCS+=	genrtl.c genrtl.h
98
99SRCS+=	bitmap.c concat.c dummy-conditions.c errors.c genautomata.c \
100	gensupport.c getruntime.c ggc-none.c hashtab.c \
101	obstack.c physmem.c print-rtl.c read-rtl.c rtl.c varray.c xmemdup.c
102
103#-----------------------------------------------------------------------
104# Common parser stuff.
105
106tree-check.h: gencheck
107	./gencheck > ${.TARGET}
108GENSRCS+=	tree-check.h
109
110#-----------------------------------------------------------------------
111# Predicates stuff.
112
113tm-preds.h: genpreds
114	./genpreds > ${.TARGET}
115GENSRCS+=	tm-preds.h
116
117#-----------------------------------------------------------------------
118# Gengtype 
119
120gengtype-lex.c : gengtype-lex.l
121	${LEX} -t  ${.ALLSRC} | \
122	sed 's/^\(char msg\[\];\)/yyconst \1/' > ${.TARGET}
123
124.ORDER: gengtype-yacc.c gengtype-yacc.h
125gengtype-yacc.c gengtype-yacc.h: gengtype-yacc.y
126	${YACC} -d -o gengtype-yacc.c ${.ALLSRC}
127
128GENSRCS+=	gengtype-yacc+%DIKED.c gengtype-yacc.h gengtype-lex.c
129CLEANFILES+=	gengtype-yacc.c
130
131gengtype-yacc+%DIKED.c: gengtype-yacc.c
132	cat    ${.ALLSRC} > ${.TARGET}
133	sed -e "s/xmalloc/malloc/g" \
134	    -e "s/xrealloc/realloc/g" \
135	    -e "s/malloc/xmalloc/g" \
136	    -e "s/realloc/xrealloc/g" \
137	    ${.ALLSRC} > ${.TARGET}
138
139gengtype: gengtype.o gengtype-yacc+%DIKED.o gengtype-lex.o xmemdup.o
140	${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${.ALLSRC}
141
142GENSRCS+=	gengtype.c
143CLEANFILES+=	gengtype
144
145gengtype-lex.o: gengtype-yacc.h
146
147.ORDER: gtype-desc.c gtype-desc.h
148gtype-desc.c gtype-desc.h: gtype-time-stamp
149	@true
150
151GENSRCS+=	gtype-time-stamp
152gtype-time-stamp: gengtype ${GTFILES}
153	./gengtype
154	touch ${.TARGET}
155
156GENSRCS+=	gtype-desc.c gtype-desc.h
157CLEANFILES+=	gt-*.h gtype-*.h
158
159#-----------------------------------------------------------------------
160# Determine content of variables used by the target/host config files
161
162#
163# The list of headers to go into tconfig.h
164#
165TARGET_INC=	ansidecl.h
166TARGET_INC+=	${GCC_CPU}/${GCC_CPU}.h
167.if ${TARGET_ARCH} == "i386" || ${TARGET_ARCH} == "amd64"
168TARGET_INC+=	${GCC_CPU}/unix.h
169TARGET_INC+=	${GCC_CPU}/att.h
170.endif
171.if ${TARGET_ARCH} != "alpha"
172TARGET_INC+=	dbxelf.h
173TARGET_INC+=	elfos.h
174.endif
175TARGET_INC+=	freebsd-native.h
176TARGET_INC+=	freebsd-spec.h
177TARGET_INC+=	freebsd.h
178.if ${TARGET_ARCH} == "alpha"
179TARGET_INC+=	${GCC_CPU}/elf.h
180.endif
181.if ${TARGET_ARCH} != "i386" && ${TARGET_ARCH} != "amd64"
182.if exists(${GCCDIR}/config/${GCC_CPU}/sysv4.h)
183TARGET_INC+=	${GCC_CPU}/sysv4.h
184.endif
185.endif
186TARGET_INC+=	${GCC_CPU}/freebsd.h
187.if ${TARGET_ARCH} == "amd64"
188TARGET_INC+=	${GCC_CPU}/x86-64.h
189TARGET_INC+=	${GCC_CPU}/freebsd64.h
190.endif
191TARGET_INC+=	defaults.h
192
193#
194# Use TARGET_INC as a template and build a list of target specific
195# include files for gengtype to scan
196#
197GCONFIG_H=	${.OBJDIR}/tconfig.h ${.CURDIR}/auto-host.h
198
199.for H in ${TARGET_INC}
200.for D in ${GCCDIR}/config ${GCCDIR} ${.CURDIR}
201.if exists($D/$H)
202GCONFIG_H+=	$D/$H
203.endif
204.endfor
205.endfor
206
207#
208# Define some variables to make blocks copied from Makefile.in happy
209#
210srcdir=		${GCCDIR}
211HASHTAB_H=	${GCCDIR}/hashtab.h
212out_file=	${GCCDIR}/config/${GCC_CPU}/${GCC_CPU}.c
213GTFILES_SRCDIR=	${GCCDIR}
214
215#
216# Copied unchanged from gcc/Makefile.in
217#
218GTFILES = $(GCONFIG_H) $(srcdir)/location.h \
219  $(HASHTAB_H) \
220  $(srcdir)/bitmap.h $(srcdir)/function.h  $(srcdir)/rtl.h $(srcdir)/optabs.h \
221  $(srcdir)/tree.h $(srcdir)/libfuncs.h $(srcdir)/hashtable.h $(srcdir)/real.h \
222  $(srcdir)/varray.h $(srcdir)/ssa.h $(srcdir)/insn-addr.h $(srcdir)/cselib.h \
223  $(srcdir)/c-common.h $(srcdir)/c-tree.h \
224  $(srcdir)/basic-block.h \
225  $(srcdir)/alias.c $(srcdir)/bitmap.c $(srcdir)/cselib.c \
226  $(srcdir)/dwarf2out.c $(srcdir)/emit-rtl.c \
227  $(srcdir)/except.c $(srcdir)/explow.c $(srcdir)/expr.c \
228  $(srcdir)/fold-const.c $(srcdir)/function.c \
229  $(srcdir)/gcse.c $(srcdir)/integrate.c $(srcdir)/lists.c $(srcdir)/optabs.c \
230  $(srcdir)/profile.c $(srcdir)/ra-build.c $(srcdir)/regclass.c \
231  $(srcdir)/reg-stack.c \
232  $(srcdir)/sdbout.c $(srcdir)/stmt.c $(srcdir)/stor-layout.c \
233  $(srcdir)/tree.c $(srcdir)/varasm.c \
234  $(out_file)
235
236#
237# Build a list of frontend directories to look into
238#
239GTFILES_LANG_DIR_NAMES=
240
241.if !defined(NO_CXX)
242GTFILES_LANG_DIR_NAMES+=	cp
243.endif
244
245.if !defined(NO_OBJC)
246GTFILES_LANG_DIR_NAMES+=	objc
247.endif
248
249.if !defined(NO_FORTRAN)
250GTFILES_LANG_DIR_NAMES+=	f
251.endif
252
253#
254# Build a list of language specific files for gengtype
255#
256.for L in ${GTFILES_LANG_DIR_NAMES} c
257.if exists(${GCCDIR}/$L-config-lang.in)
258# Source the language config file
259L_GTFILES!=	sh -c '. ${GCCDIR}/$L-config-lang.in; echo $$gtfiles'
260.else
261L_GTFILES!=	sh -c '. ${GCCDIR}/$L/config-lang.in; echo $$gtfiles'
262.endif
263.for F in ${L_GTFILES}
264GTFILES_FILES+=	$F
265GTFILES_LANGS+= $L
266.endfor
267.endfor
268GTFILES+=	${GTFILES_FILES}
269
270#-----------------------------------------------------------------------
271# the host/target compiler config.
272
273COMMONHDRS=	config.h hconfig.h multilib.h options.h specs.h tconfig.h \
274		tm_p.h configargs.h safe-ctype.h
275GENSRCS+=	${COMMONHDRS} gencheck.h gtyp-gen.h
276
277MFILE?=	${.CURDIR}/Makefile
278${COMMONHDRS}: ${MFILE}
279
280configargs.h:
281	echo 'static const char configuration_arguments[] ='	> ${.TARGET}
282	echo '	"FreeBSD/${TARGET_ARCH} system compiler";'	>> ${.TARGET}
283	echo 'static const char thread_model[] = "posix";'	>> ${.TARGET}
284
285hconfig.h:
286	echo '#include "auto-host.h"'			> ${.TARGET}
287	echo '#include <tconfig.h>'			>> ${.TARGET}
288
289gencheck.h:
290	echo '#include "cp/cp-tree.def"'		> ${.TARGET}
291	echo '#include "objc/objc-tree.def"'		>> ${.TARGET}
292
293multilib.h:
294	echo 'static const char *const multilib_raw[] = { \
295	    "aout maout;", "elf !maout;", NULL };'	> ${.TARGET}
296	echo 'static const char *const multilib_matches_raw[] = { \
297	    "maout maout;", "melf melf;", NULL };'	>> ${.TARGET}
298	echo 'static const char *multilib_extra = "";'	>> ${.TARGET}
299	echo 'static const char *multilib_options = "";'>> ${.TARGET}
300	echo 'static const char *const multilib_exclusions_raw[] = { \
301	    NULL };'					>> ${.TARGET}
302
303options.h:
304	echo '#include "cp/lang-options.h"'		> ${.TARGET}
305	echo '#include "f/lang-options.h"'		>> ${.TARGET}
306	echo '#include "objc/lang-options.h"'		>> ${.TARGET}
307
308specs.h:
309	echo '#include "cp/lang-specs.h"'		> ${.TARGET}
310	echo '#include "f/lang-specs.h"'		>> ${.TARGET}
311	echo '#include "objc/lang-specs.h"'		>> ${.TARGET}
312
313config.h:
314	echo '#include <hconfig.h>'			> ${.TARGET}
315	echo '#ifndef GENERATOR_FILE'			>> ${.TARGET}
316	echo '#include "insn-constants.h"'		>> ${.TARGET}
317	echo '#include "insn-flags.h"'			>> ${.TARGET}
318	echo '#endif'					>> ${.TARGET}
319
320tconfig.h:
321	echo 'struct rtx_def;'				> ${.TARGET}
322	echo 'typedef struct rtx_def *rtx;'		>> ${.TARGET}
323	echo 'struct rtvec_def;'			>> ${.TARGET}
324	echo 'typedef struct rtvec_def *rtvec;'		>> ${.TARGET}
325	echo 'union tree_node;'				>> ${.TARGET}
326	echo 'typedef union tree_node *tree;'		>> ${.TARGET}
327	echo '#ifndef GTY'				>> ${.TARGET}
328	echo '# define GTY(x)'				>> ${.TARGET}
329	echo '#endif'					>> ${.TARGET}
330	echo ''						>> ${.TARGET}
331.if ${TARGET_ARCH} == "amd64"
332	echo '#include "i386/biarch64.h"'		>> ${.TARGET}
333.endif
334.if ${TARGET_ARCH} == "ia64"
335	echo '#define TARGET_CPU_DEFAULT (MASK_GNU_AS|MASK_GNU_LD)' >>${.TARGET}
336.endif
337.for H in ${TARGET_INC}
338	echo '#include "$H"'				>> ${.TARGET}
339.endfor
340	echo '#ifndef POSIX'				>> ${.TARGET}
341	echo '# define POSIX'				>> ${.TARGET}
342	echo '#endif'					>> ${.TARGET}
343.if exists(${GCCDIR}/config/${GCC_CPU}/${GCC_CPU}-modes.def)
344	echo '#define EXTRA_MODES_FILE "${GCC_CPU}/${GCC_CPU}-modes.def"' >> ${.TARGET}
345	echo '#define EXTRA_CC_MODES 1'			>> ${.TARGET}
346.endif
347
348tm_p.h:
349	echo '#include "${GCC_CPU}/${GCC_CPU}-protos.h"'	>> ${.TARGET}
350	echo '#include "tm-preds.h"'				>> ${.TARGET}
351
352safe-ctype.h: Makefile
353	echo '#include <ctype.h>'				> ${.TARGET}
354.for Z in TOUPPER TOLOWER ISDIGIT ISXDIGIT ISUPPER ISLOWER ISALPHA ISALNUM \
355    ISSPACE ISPUNCT ISGRAPH ISBLANK ISPRINT ISCNTRL
356	echo '#define ${Z}	${Z:L}'				>> ${.TARGET}
357.endfor
358	echo "#define ISIDST(x)		\
359		((x) == '_' || isalpha(x))"			>> ${.TARGET}
360	echo "#define ISIDNUM(x)	\
361		(isdigit(x) || ISIDST(x))"			>> ${.TARGET}
362	echo "#define IS_VSPACE(x)	\
363		((x) == '\n' || (x) == '\r')"			>> ${.TARGET}
364	echo "#define IS_NVSPACE(x)	\
365		(!IS_VSPACE(x) && (isspace(x) || (x) == '\0'))"	>> ${.TARGET}
366	echo "#define IS_SPACE_OR_NUL(x)	\
367		(isspace(x) || (x) == '\0')"			>> ${.TARGET}
368
369gtyp-gen.h:
370	echo "/* This file is machine generated.  Do not edit.  */" > ${.TARGET}
371	echo "static const char *srcdir = "			>> ${.TARGET}
372	echo "\"$(GTFILES_SRCDIR)\";"				>> ${.TARGET}
373	echo "static const char *lang_files[] = {"		>> ${.TARGET}
374.for F in ${GTFILES_FILES}
375	echo "\"$F\", "						>> ${.TARGET}
376.endfor
377	echo "NULL};"						>> ${.TARGET}
378	echo "static const char *langs_for_lang_files[] = {"	>> ${.TARGET}
379.for F in ${GTFILES_LANGS}
380	echo "\"$F\", "						>> ${.TARGET}
381.endfor
382	echo "NULL};"						>> ${.TARGET}
383	echo "static const char *all_files[] = {"		>> ${.TARGET}
384.for F in ${GTFILES}
385	echo "\"$F\", "						>> ${.TARGET}
386.endfor
387	echo "NULL};"						>> ${.TARGET}
388	echo "static const char *lang_dir_names[] = { \"c\", "	>> ${.TARGET}
389.for F in ${GTFILES_LANG_DIR_NAMES}
390	echo "\"$F\", "						>> ${.TARGET}
391.endfor
392	echo "NULL};"						>> ${.TARGET}
393	echo "#define	xexit exit"				>> ${.TARGET}
394
395
396#-----------------------------------------------------------------------
397# General things.
398
399SRCS+=		${GENSRCS}
400CLEANFILES+=	${GENSRCS}
401
402all: ${SRCS}
403
404.include <bsd.prog.mk>
405
406#-----------------------------------------------------------------------
407# Fixups.
408
409# Set OBJS the same as bsd.prog.mk would do if we defined PROG.  We can't
410# define PROG because we have multiple programs.
411#
412OBJS+=		${SRCS:N*.h:R:S/$/.o/g}
413CLEANFILES+=	${OBJS}
414
415.if !exists(${DEPENDFILE})
416# Fudge pre-dependfile dependencies of objects in much the same way as
417# bsd.prog.mk would do if we defined PROG.  There are complications to
418# avoid circular dependencies.  First, only make most objects depend on
419# all headers.  Filter out the objects that would cause problems (i.e.,
420# objects that will be used to create programs that will generate headers).
421#
422${OBJS}: ${SRCS:M*.h:Ngtype-desc.h:Ngenrtl.h:Ntree-check.h:Ntm-preds.h:Ninsn-*.h}
423
424${OBJS:Ngencheck.o:Ngengenrtl.o:Ngenpreds.o}: tree-check.h tm-preds.h genrtl.h
425
426${OBJS:Ngengtype*.o:Nxmemdup.o:Ngengenrtl.o:Ngencheck.o:Ngenpreds.o}: gtype-desc.h
427
428genextract.o: insn-config.h
429
430insn-conditions.o: insn-constants.h
431
432.endif
433