Makefile revision 124417
1189608Ssam# $FreeBSD: head/gnu/usr.bin/cc/cc_tools/Makefile 124417 2004-01-12 07:46:20Z ru $
2189608Ssam
3189608Ssam#
4189608Ssam# This could probably be merged with ../cc_int/Makefile, but bsd.lib.mk
5189608Ssam# is such a !@#!*#% nightmare because of how it reprograms the dependencies,
6189608Ssam# suffix rules, SRCS, etc.  It's easiest to cheat by using bsd.prog.mk and
7189608Ssam# SRCS to get dependencies.
8189608Ssam#
9189608Ssam
10189608Ssam# ../Makefile.inc will put an absolute path to our objdir in CFLAGS.
11189608Ssam# Prevent mkdep from using it, so that we don't have to give rules for
12189608Ssam# aliases of generated headers.
13189608Ssam
14189608SsamCFLAGS+=	-I. -static -DGENERATOR_FILE
15189608Ssam
16189608Ssam.include "../Makefile.inc"
17189608Ssam
18189608Ssam.PATH: ${GCCDIR}
19189608Ssam
20189608Ssam#-----------------------------------------------------------------------
21189608Ssam# insn-* gunk
22189608Ssam
23189608Ssam.for F in attr codes config flags constants
24189608Ssaminsn-$F.h: gen$F ${MD_FILE}
25189608Ssam	./gen$F ${MD_FILE} > insn-$F.h
26189608SsamGENSRCS+=	insn-$F.h
27189608Ssam.endfor
28189608Ssam
29189608Ssam.for F in conditions
30189608Ssaminsn-$F.c: gen$F ${MD_FILE}
31189608Ssam	./gen$F ${MD_FILE} > insn-$F.c
32189608SsamGENSRCS+=	insn-$F.c
33189608Ssam.endfor
34189608Ssam
35189608SsamGENSRCS+=	gen-time-stamp
36189608Ssamgen-time-stamp: genattr genattrtab genconditions genconstants genemit \
37189608Ssam		genextract gengtype genopinit genoutput genpeep genrecog
38189608Ssam	touch ${.TARGET}
39189608Ssam
40189608Ssam.for F in attr codes config emit extract flags opinit output peep recog
41189608Ssambuild-tools: gen$F
42189608Ssam
43189608Ssamgen$F: gen$F.o rtl.o obstack.o print-rtl.o bitmap.o errors.o gensupport.o \
44189608Ssam	ggc-none.o hashtab.o read-rtl.o concat.o insn-conditions.o
45189608Ssam	${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${.ALLSRC}
46189608Ssam
47189608SsamGENSRCS+=	gen$F.c
48189608SsamCLEANFILES+=	gen$F
49189608Ssam.endfor
50189608Ssam
51189608Ssam#
52189608Ssam# genattrtab needs more complex build rule
53189608Ssam#
54189608Ssambuild-tools: genattrtab
55189608Ssam
56189608Ssamgenattrtab : genattrtab.o rtl.o obstack.o print-rtl.o bitmap.o errors.o \
57189608Ssam	gensupport.o ggc-none.o hashtab.o read-rtl.o concat.o \
58189608Ssam	insn-conditions.o genautomata.o varray.o getruntime.o
59189608Ssam	${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${.ALLSRC} -lm
60189608Ssam
61189608SsamGENSRCS+=	genattrtab.c
62189608SsamCLEANFILES+=	genattrtab
63189608Ssam
64189608Ssam#
65189660Ssam# genconstants and genconditions cannot depend on insn-conditions.o
66189608Ssam# they should be liked with dummy-conditions.o stubs instead
67189608Ssam#
68189608Ssam.for F in constants conditions
69189608Ssambuild-tools: gen$F
70189608Ssam
71189608Ssamgen$F: gen$F.o rtl.o obstack.o bitmap.o errors.o gensupport.o \
72189608Ssam       ggc-none.o hashtab.o read-rtl.o concat.o dummy-conditions.o
73189608Ssam	${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${.ALLSRC}
74189660Ssam
75189660SsamGENSRCS+=	gen$F.c
76189608SsamCLEANFILES+=	gen$F
77189608Ssam.endfor
78189608Ssam
79189608Ssam.for F in check genrtl preds
80189608Ssambuild-tools: gen$F
81189608Ssam
82189608Ssamgen$F: gen$F.o
83189608Ssam	${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${.ALLSRC}
84189608Ssam
85189608SsamGENSRCS+=	gen$F.c
86189608SsamCLEANFILES+=	gen$F
87189608Ssam.endfor
88189608Ssam
89189608Ssam.ORDER: genrtl.c genrtl.h
90189608Ssamgenrtl.c genrtl.h: gengenrtl
91189608Ssam	./gengenrtl > genrtl.c
92189608Ssam	./gengenrtl -h > genrtl.h
93189608Ssam
94189608SsamGENSRCS+=	genrtl.c genrtl.h
95189608Ssam
96189660SsamSRCS+=	bitmap.c concat.c dummy-conditions.c errors.c genautomata.c \
97189660Ssam	gensupport.c getruntime.c ggc-none.c hashtab.c \
98189660Ssam	obstack.c physmem.c print-rtl.c read-rtl.c rtl.c varray.c xmemdup.c
99189660Ssam
100189660Ssam#-----------------------------------------------------------------------
101189660Ssam# Common parser stuff.
102189660Ssam
103189660Ssamtree-check.h: gencheck
104189660Ssam	./gencheck > ${.TARGET}
105189660SsamGENSRCS+=	tree-check.h
106189660Ssam
107189660Ssam#-----------------------------------------------------------------------
108189608Ssam# Predicates stuff.
109189608Ssam
110189608Ssamtm-preds.h: genpreds
111189608Ssam	./genpreds > ${.TARGET}
112189608SsamGENSRCS+=	tm-preds.h
113189608Ssam
114189608Ssam#-----------------------------------------------------------------------
115189608Ssam# Gengtype 
116189608Ssam
117189608Ssamgengtype-lex.c : gengtype-lex.l
118189608Ssam	${LEX} -t  ${.ALLSRC} | \
119189608Ssam	sed 's/^\(char msg\[\];\)/yyconst \1/' > ${.TARGET}
120189608Ssam
121189608Ssam.ORDER: gengtype-yacc.c gengtype-yacc.h
122189608Ssamgengtype-yacc.c gengtype-yacc.h: gengtype-yacc.y
123189608Ssam	${YACC} -d -o gengtype-yacc.c ${.ALLSRC}
124189608Ssam
125189608SsamGENSRCS+=	gengtype-yacc+%DIKED.c gengtype-yacc.h gengtype-lex.c
126189608SsamCLEANFILES+=	gengtype-yacc.c
127189608Ssam
128189608Ssamgengtype-yacc+%DIKED.c: gengtype-yacc.c
129189608Ssam	cat    ${.ALLSRC} > ${.TARGET}
130189608Ssam	sed -e "s/xmalloc/malloc/g" \
131189608Ssam	    -e "s/xrealloc/realloc/g" \
132189608Ssam	    -e "s/malloc/xmalloc/g" \
133189608Ssam	    -e "s/realloc/xrealloc/g" \
134189608Ssam	    ${.ALLSRC} > ${.TARGET}
135189608Ssam
136189608Ssamgengtype: gengtype.o gengtype-yacc+%DIKED.o gengtype-lex.o xmemdup.o
137189608Ssam	${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${.ALLSRC}
138189608Ssam
139189608SsamGENSRCS+=	gengtype.c
140189608SsamCLEANFILES+=	gengtype
141189608Ssam
142189608Ssamgengtype-lex.o: gengtype-yacc.h
143189608Ssam
144189608Ssam.ORDER: gtype-desc.c gtype-desc.h
145189608Ssamgtype-desc.c gtype-desc.h: gtype-time-stamp
146189608Ssam	@true
147189608Ssam
148189608SsamGENSRCS+=	gtype-time-stamp
149189608Ssamgtype-time-stamp: gengtype ${GTFILES}
150189608Ssam	./gengtype
151189608Ssam	touch ${.TARGET}
152189608Ssam
153189608SsamGENSRCS+=	gtype-desc.c gtype-desc.h
154189608SsamCLEANFILES+=	gt-*.h gtype-*.h
155189608Ssam
156189608Ssam#-----------------------------------------------------------------------
157189608Ssam# Determine content of variables used by the target/host config files
158189608Ssam
159189608Ssam#
160189608Ssam# The list of headers to go into tconfig.h
161189608Ssam#
162189608SsamTARGET_INC=	ansidecl.h
163189608SsamTARGET_INC+=	${GCC_CPU}/${GCC_CPU}.h
164189608Ssam.if ${TARGET_ARCH} == "i386" || ${TARGET_ARCH} == "amd64"
165189608SsamTARGET_INC+=	${GCC_CPU}/unix.h
166189608SsamTARGET_INC+=	${GCC_CPU}/att.h
167189608Ssam.endif
168189608Ssam.if ${TARGET_ARCH} != "alpha"
169189608SsamTARGET_INC+=	dbxelf.h
170189608SsamTARGET_INC+=	elfos.h
171189608Ssam.endif
172189608SsamTARGET_INC+=	freebsd-native.h
173189660SsamTARGET_INC+=	freebsd-spec.h
174189608SsamTARGET_INC+=	freebsd.h
175189608Ssam.if ${TARGET_ARCH} == "alpha"
176189608SsamTARGET_INC+=	${GCC_CPU}/elf.h
177189608Ssam.endif
178189608Ssam.if ${TARGET_ARCH} != "i386" && ${TARGET_ARCH} != "amd64"
179189608Ssam.if exists(${GCCDIR}/config/${GCC_CPU}/sysv4.h)
180189608SsamTARGET_INC+=	${GCC_CPU}/sysv4.h
181189608Ssam.endif
182189608Ssam.endif
183189608SsamTARGET_INC+=	${GCC_CPU}/freebsd.h
184189608Ssam.if ${TARGET_ARCH} == "amd64"
185189608SsamTARGET_INC+=	${GCC_CPU}/x86-64.h
186189608SsamTARGET_INC+=	${GCC_CPU}/freebsd64.h
187189608Ssam.endif
188189608SsamTARGET_INC+=	defaults.h
189189608Ssam
190189608Ssam#
191189608Ssam# Use TARGET_INC as a template and build a list of target specific
192189608Ssam# include files for gengtype to scan
193189608Ssam#
194189608SsamGCONFIG_H=	${.OBJDIR}/tconfig.h ${.CURDIR}/auto-host.h
195189608Ssam
196189608Ssam.for H in ${TARGET_INC}
197189608Ssam.for D in ${GCCDIR}/config ${GCCDIR} ${.CURDIR}
198189608Ssam.if exists($D/$H)
199189608SsamGCONFIG_H+=	$D/$H
200189608Ssam.endif
201189608Ssam.endfor
202189608Ssam.endfor
203189608Ssam
204189608Ssam#
205189608Ssam# Define some variables to make blocks copied from Makefile.in happy
206189608Ssam#
207189608Ssamsrcdir=		${GCCDIR}
208189608SsamHASHTAB_H=	${GCCDIR}/hashtab.h
209189608Ssamout_file=	${GCCDIR}/config/${GCC_CPU}/${GCC_CPU}.c
210189608SsamGTFILES_SRCDIR=	${GCCDIR}
211189608Ssam
212189608Ssam#
213189608Ssam# Copied unchanged from gcc/Makefile.in
214189608Ssam#
215189608SsamGTFILES = $(GCONFIG_H) $(srcdir)/location.h \
216189608Ssam  $(HASHTAB_H) \
217189608Ssam  $(srcdir)/bitmap.h $(srcdir)/function.h  $(srcdir)/rtl.h $(srcdir)/optabs.h \
218189608Ssam  $(srcdir)/tree.h $(srcdir)/libfuncs.h $(srcdir)/hashtable.h $(srcdir)/real.h \
219189608Ssam  $(srcdir)/varray.h $(srcdir)/ssa.h $(srcdir)/insn-addr.h $(srcdir)/cselib.h \
220189608Ssam  $(srcdir)/c-common.h $(srcdir)/c-tree.h \
221189608Ssam  $(srcdir)/basic-block.h \
222189608Ssam  $(srcdir)/alias.c $(srcdir)/bitmap.c $(srcdir)/cselib.c \
223189608Ssam  $(srcdir)/dwarf2out.c $(srcdir)/emit-rtl.c \
224189608Ssam  $(srcdir)/except.c $(srcdir)/explow.c $(srcdir)/expr.c \
225189608Ssam  $(srcdir)/fold-const.c $(srcdir)/function.c \
226189608Ssam  $(srcdir)/gcse.c $(srcdir)/integrate.c $(srcdir)/lists.c $(srcdir)/optabs.c \
227189608Ssam  $(srcdir)/profile.c $(srcdir)/ra-build.c $(srcdir)/regclass.c \
228189608Ssam  $(srcdir)/reg-stack.c \
229189608Ssam  $(srcdir)/sdbout.c $(srcdir)/stmt.c $(srcdir)/stor-layout.c \
230189608Ssam  $(srcdir)/tree.c $(srcdir)/varasm.c \
231189608Ssam  $(out_file)
232189608Ssam
233189608Ssam#
234189608Ssam# Build a list of frontend directories to look into
235189608Ssam#
236189608SsamGTFILES_LANG_DIR_NAMES=
237189608Ssam
238189608Ssam.if !defined(NO_CXX)
239189608SsamGTFILES_LANG_DIR_NAMES+=	cp
240189608Ssam.endif
241189608Ssam
242189608Ssam.if !defined(NO_OBJC)
243189608SsamGTFILES_LANG_DIR_NAMES+=	objc
244189608Ssam.endif
245189608Ssam
246189608Ssam.if !defined(NO_FORTRAN)
247189608SsamGTFILES_LANG_DIR_NAMES+=	f
248189608Ssam.endif
249189608Ssam
250189608Ssam#
251189608Ssam# Build a list of language specific files for gengtype
252189608Ssam#
253189608Ssam.for L in ${GTFILES_LANG_DIR_NAMES} c
254189608Ssam.if exists(${GCCDIR}/$L-config-lang.in)
255189608Ssam# Source the language config file
256189608Ssam$L_GTFILES!=	sh -c '. ${GCCDIR}/$L-config-lang.in; echo $$gtfiles'
257189608Ssam.else
258189608Ssam$L_GTFILES!=	sh -c '. ${GCCDIR}/$L/config-lang.in; echo $$gtfiles'
259189660Ssam.endif
260189660SsamGTFILES+=	${$L_GTFILES}
261189660Ssam.for F in ${$L_GTFILES}
262189660SsamGTFILES_FILES+=	$F
263189608SsamGTFILES_LANGS+= $L
264189608Ssam.endfor
265189608Ssam.endfor
266189608Ssam
267189608Ssam#-----------------------------------------------------------------------
268189608Ssam# the host/target compiler config.
269189608Ssam
270189608SsamCOMMONHDRS=	config.h hconfig.h multilib.h options.h specs.h tconfig.h \
271189608Ssam		tm_p.h configargs.h safe-ctype.h
272189608SsamGENSRCS+=	${COMMONHDRS} gencheck.h gtyp-gen.h
273189608Ssam
274189608SsamMFILE?=	${.CURDIR}/Makefile
275189608Ssam${COMMONHDRS}: ${MFILE}
276189608Ssam
277189608Ssamconfigargs.h:
278189608Ssam	echo 'static const char configuration_arguments[] ='	> ${.TARGET}
279189608Ssam	echo '	"FreeBSD/${TARGET_ARCH} system compiler";'	>> ${.TARGET}
280189608Ssam	echo 'static const char thread_model[] = "posix";'	>> ${.TARGET}
281189608Ssam
282189608Ssamhconfig.h:
283189608Ssam	echo '#include "auto-host.h"'			> ${.TARGET}
284189608Ssam	echo '#include <tconfig.h>'			>> ${.TARGET}
285189608Ssam
286189608Ssamgencheck.h:
287189608Ssam	echo '#include "cp/cp-tree.def"'		> ${.TARGET}
288189608Ssam	echo '#include "objc/objc-tree.def"'		>> ${.TARGET}
289189608Ssam
290189608Ssammultilib.h:
291189608Ssam	echo 'static const char *const multilib_raw[] = { \
292189608Ssam	    "aout maout;", "elf !maout;", NULL };'	> ${.TARGET}
293189608Ssam	echo 'static const char *const multilib_matches_raw[] = { \
294189608Ssam	    "maout maout;", "melf melf;", NULL };'	>> ${.TARGET}
295189608Ssam	echo 'static const char *multilib_extra = "";'	>> ${.TARGET}
296189608Ssam	echo 'static const char *multilib_options = "";'>> ${.TARGET}
297189608Ssam	echo 'static const char *const multilib_exclusions_raw[] = { \
298189608Ssam	    NULL };'					>> ${.TARGET}
299189608Ssam
300189608Ssamoptions.h:
301189608Ssam	echo '#include "cp/lang-options.h"'		> ${.TARGET}
302189608Ssam	echo '#include "f/lang-options.h"'		>> ${.TARGET}
303189608Ssam	echo '#include "objc/lang-options.h"'		>> ${.TARGET}
304189608Ssam
305189608Ssamspecs.h:
306189608Ssam	echo '#include "cp/lang-specs.h"'		> ${.TARGET}
307189608Ssam	echo '#include "f/lang-specs.h"'		>> ${.TARGET}
308189660Ssam	echo '#include "objc/lang-specs.h"'		>> ${.TARGET}
309189660Ssam
310189660Ssamconfig.h:
311189608Ssam	echo '#include <hconfig.h>'			> ${.TARGET}
312189608Ssam	echo '#ifndef GENERATOR_FILE'			>> ${.TARGET}
313189608Ssam	echo '#include "insn-constants.h"'		>> ${.TARGET}
314189608Ssam	echo '#include "insn-flags.h"'			>> ${.TARGET}
315189608Ssam	echo '#endif'					>> ${.TARGET}
316189608Ssam
317189608Ssamtconfig.h:
318189608Ssam	echo 'struct rtx_def;'				> ${.TARGET}
319189608Ssam	echo 'typedef struct rtx_def *rtx;'		>> ${.TARGET}
320189608Ssam	echo 'struct rtvec_def;'			>> ${.TARGET}
321189608Ssam	echo 'typedef struct rtvec_def *rtvec;'		>> ${.TARGET}
322189608Ssam	echo 'union tree_node;'				>> ${.TARGET}
323189608Ssam	echo 'typedef union tree_node *tree;'		>> ${.TARGET}
324189608Ssam	echo '#ifndef GTY'				>> ${.TARGET}
325189608Ssam	echo '# define GTY(x)'				>> ${.TARGET}
326189608Ssam	echo '#endif'					>> ${.TARGET}
327189608Ssam	echo ''						>> ${.TARGET}
328189608Ssam.if ${TARGET_ARCH} == "amd64"
329189608Ssam	echo '#include "i386/biarch64.h"'		>> ${.TARGET}
330189608Ssam.endif
331189608Ssam.if ${TARGET_ARCH} == "ia64"
332189608Ssam	echo '#define TARGET_CPU_DEFAULT (MASK_GNU_AS|MASK_GNU_LD)' >>${.TARGET}
333189608Ssam.endif
334189608Ssam.for H in ${TARGET_INC}
335189608Ssam	echo '#include "$H"'				>> ${.TARGET}
336189608Ssam.endfor
337189608Ssam	echo '#ifndef POSIX'				>> ${.TARGET}
338189608Ssam	echo '# define POSIX'				>> ${.TARGET}
339189608Ssam	echo '#endif'					>> ${.TARGET}
340189608Ssam.if exists(${GCCDIR}/config/${GCC_CPU}/${GCC_CPU}-modes.def)
341189608Ssam	echo '#define EXTRA_MODES_FILE "${GCC_CPU}/${GCC_CPU}-modes.def"' >> ${.TARGET}
342189608Ssam	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}
410
411.if !exists(${DEPENDFILE})
412# Fudge pre-dependfile dependencies of objects in much the same way as
413# bsd.prog.mk would do if we defined PROG.  There are complications to
414# avoid circular dependencies.  First, only make most objects depend on
415# all headers.  Filter out the objects that would cause problems (i.e.,
416# objects that will be used to create programs that will generate headers).
417#
418${OBJS}: ${SRCS:M*.h:Ngtype-desc.h:Ngenrtl.h:Ntree-check.h:Ntm-preds.h:Ninsn-*.h}
419
420${OBJS:Ngencheck.o:Ngengenrtl.o:Ngenpreds.o}: tree-check.h tm-preds.h genrtl.h
421
422${OBJS:Ngengtype*.o:Nxmemdup.o:Ngengenrtl.o:Ngencheck.o:Ngenpreds.o}: gtype-desc.h
423
424genextract.o: insn-config.h
425
426insn-conditions.o: insn-constants.h
427
428.endif
429