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