Makefile revision 162209
1# $FreeBSD: head/gnu/usr.bin/cc/cc_tools/Makefile 162209 2006-09-11 05:12:12Z imp $
2
3.include <bsd.own.mk>
4
5#
6# This could probably be merged with ../cc_int/Makefile, but bsd.lib.mk
7# is such a !@#!*#% nightmare because of how it reprograms the dependencies,
8# suffix rules, SRCS, etc.  It's easiest to cheat by using bsd.prog.mk and
9# SRCS to get dependencies.
10#
11
12#
13# ../Makefile.inc will put an absolute path to our objdir in CFLAGS.
14# Prevent mkdep from using it, so that we don't have to give rules for
15# aliases of generated headers.
16#
17CFLAGS+=	-I.
18
19.include "../Makefile.inc"
20
21.PATH: ${GCCDIR} ${GCCDIR}/f
22
23CFLAGS+=	-DGENERATOR_FILE
24
25#
26#-----------------------------------------------------------------------
27# Build 'pocket' libiberty exclusively for build tools use.
28
29LIBIBERTY_SRCS=	choose-temp.c concat.c cp-demangle.c cp-demint.c cplus-dem.c \
30	dyn-string.c fibheap.c getpwd.c getruntime.c hashtab.c hex.c \
31	lbasename.c make-temp-file.c md5.c obstack.c partition.c pex-unix.c \
32	physmem.c splay-tree.c xexit.c xmalloc.c xmemdup.c xstrdup.c xstrerror.c
33LIBIBERTY_OBJS=	${LIBIBERTY_SRCS:R:S/$/.o/g}
34
35SRCS+=	${LIBIBERTY_SRCS}
36
37LIBIBERTY=libiberty.a
38${LIBIBERTY}: ${LIBIBERTY_OBJS}
39	@rm -f ${.TARGET}
40	@${AR} cq ${.TARGET} `lorder ${LIBIBERTY_OBJS} | tsort -q`
41	${RANLIB} ${.TARGET}
42CLEANFILES+=	${LIBIBERTY}
43
44#
45#-----------------------------------------------------------------------
46# options
47OPTION_FILES=${GCCDIR}/f/lang.opt ${GCCDIR}/c.opt ${GCCDIR}/common.opt
48
49.ORDER: options.h options.c
50options.h options.c: opts.sh ${OPTION_FILES}
51	/bin/sh ${GCCDIR}/opts.sh mv options.c options.h ${OPTION_FILES}
52
53GENSRCS+=	options.c options.h
54CLEANFILES+=	options.c options.h
55
56#-----------------------------------------------------------------------
57# insn-* gunk
58
59.for F in attr codes config flags constants
60insn-$F.h: gen$F ${MD_FILE}
61	./gen$F ${MD_FILE} > insn-$F.h
62GENSRCS+=	insn-$F.h
63.endfor
64
65.for F in conditions
66insn-$F.c: gen$F ${MD_FILE}
67	./gen$F ${MD_FILE} > insn-$F.c
68GENSRCS+=	insn-$F.c
69.endfor
70
71GENSRCS+=	gen-time-stamp
72gen-time-stamp: genattr genattrtab genconditions genconstants genemit \
73		genextract gengtype genopinit genoutput genpeep genrecog
74	touch ${.TARGET}
75
76.for F in attr codes config emit extract flags opinit output peep recog
77gen$F: gen$F.o rtl.o print-rtl.o bitmap.o gensupport.o  ggc-none.o \
78	read-rtl.o insn-conditions.o min-insn-modes.o errors.o ${LIBIBERTY}
79	${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${.ALLSRC}
80
81GENSRCS+=	gen$F.c
82CLEANFILES+=	gen$F
83.endfor
84
85#
86# genattrtab needs more complex build rule
87#
88genattrtab : genattrtab.o rtl.o print-rtl.o bitmap.o gensupport.o ggc-none.o \
89	read-rtl.o insn-conditions.o genautomata.o varray.o min-insn-modes.o \
90	errors.o ${LIBIBERTY}
91	${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${.ALLSRC} -lm
92
93GENSRCS+=	genattrtab.c
94CLEANFILES+=	genattrtab
95
96#
97# genconstants and genconditions cannot depend on insn-conditions.o
98# they should be liked with dummy-conditions.o stubs instead
99#
100.for F in constants conditions
101gen$F: gen$F.o rtl.o bitmap.o gensupport.o ggc-none.o read-rtl.o dummy-conditions.o min-insn-modes.o errors.o ${LIBIBERTY}
102	${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${.ALLSRC}
103
104GENSRCS+=	gen$F.c
105CLEANFILES+=	gen$F
106.endfor
107
108.for F in modes check genrtl preds
109gen$F: gen$F.o errors.o ${LIBIBERTY}
110	${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${.ALLSRC}
111
112GENSRCS+=	gen$F.c
113CLEANFILES+=	gen$F
114.endfor
115
116.ORDER: genrtl.c genrtl.h
117genrtl.c genrtl.h: gengenrtl
118	./gengenrtl > genrtl.c
119	./gengenrtl -h > genrtl.h
120
121GENSRCS+=	genrtl.c genrtl.h
122
123SRCS+=	bitmap.c dummy-conditions.c errors.c genautomata.c gensupport.c \
124	ggc-none.c print-rtl.c read-rtl.c rtl.c varray.c
125
126#-----------------------------------------------------------------------
127# insn modes stuff.
128
129.ORDER: insn-modes.c insn-modes.h
130insn-modes.h: genmodes
131	./genmodes -h > insn-modes.h
132
133insn-modes.c: genmodes
134	./genmodes > insn-modes.c
135
136min-insn-modes.c: genmodes
137	./genmodes -m > min-insn-modes.c
138
139GENSRCS+= insn-modes.c min-insn-modes.c insn-modes.h
140
141#-----------------------------------------------------------------------
142# Common parser stuff.
143
144tree-check.h: gencheck
145	./gencheck > ${.TARGET}
146GENSRCS+=	tree-check.h
147
148#-----------------------------------------------------------------------
149# Predicates stuff.
150
151tm-preds.h: genpreds
152	./genpreds > ${.TARGET}
153GENSRCS+=	tm-preds.h
154
155#-----------------------------------------------------------------------
156# Gengtype
157
158gengtype-lex.c : gengtype-lex.l
159	${LEX} -t  ${.ALLSRC} | \
160	sed 's/^\(char msg\[\];\)/yyconst \1/' > ${.TARGET}
161
162.ORDER: gengtype-yacc.c gengtype-yacc.h
163gengtype-yacc.c gengtype-yacc.h: gengtype-yacc.y
164	${YACC} -d -o gengtype-yacc.c ${.ALLSRC}
165
166GENSRCS+=	gengtype-yacc+%DIKED.c gengtype-yacc.h gengtype-lex.c
167CLEANFILES+=	gengtype-yacc.c
168
169gengtype-yacc+%DIKED.c: gengtype-yacc.c
170	cat    ${.ALLSRC} > ${.TARGET}
171	sed -e "s/xmalloc/malloc/g" \
172	    -e "s/xrealloc/realloc/g" \
173	    -e "s/malloc/xmalloc/g" \
174	    -e "s/realloc/xrealloc/g" \
175	    ${.ALLSRC} > ${.TARGET}
176
177gengtype: gengtype.o gengtype-yacc+%DIKED.o gengtype-lex.o ${LIBIBERTY}
178	${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${.ALLSRC}
179
180GENSRCS+=	gengtype.c
181CLEANFILES+=	gengtype
182
183gengtype-lex.o: gengtype-yacc.h
184
185.ORDER: gtype-desc.c gtype-desc.h
186gtype-desc.c gtype-desc.h: gtype-time-stamp
187	@true
188
189GENSRCS+=	gtype-time-stamp
190gtype-time-stamp: gengtype ${GTFILES}
191	./gengtype
192	touch ${.TARGET}
193
194GENSRCS+=	gtype-desc.c gtype-desc.h
195CLEANFILES+=	gt-*.h gtype-*.h
196
197#
198#-----------------------------------------------------------------------
199# Fortran build tools
200
201.if ${MK_FORTRAN} != "no"
202gen-time-stamp: fini
203fini: fini.o ${LIBIBERTY}
204	${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${.ALLSRC}
205SRCS+=		fini.c
206CLEANFILES+=	fini
207.endif
208
209#-----------------------------------------------------------------------
210# Determine content of variables used by the target/host config files
211
212#
213# The list of headers to go into tm.h
214#
215.if ${TARGET_ARCH} == "amd64"
216TARGET_INC=	i386/biarch64.h
217.endif
218TARGET_INC+=	${GCC_CPU}/${GCC_CPU}.h
219.if ${TARGET_ARCH} == "i386" || ${TARGET_ARCH} == "amd64"
220TARGET_INC+=	${GCC_CPU}/unix.h
221TARGET_INC+=	${GCC_CPU}/att.h
222.endif
223.if ${TARGET_ARCH} != "alpha"
224TARGET_INC+=	dbxelf.h
225TARGET_INC+=	elfos.h
226.endif
227TARGET_INC+=	freebsd-native.h
228TARGET_INC+=	freebsd-spec.h
229TARGET_INC+=	freebsd.h
230.if ${TARGET_ARCH} == "alpha"
231TARGET_INC+=	${GCC_CPU}/elf.h
232.endif
233.if ${TARGET_ARCH} != "i386" && ${TARGET_ARCH} != "amd64"
234.if exists(${GCCDIR}/config/${GCC_CPU}/sysv4.h)
235TARGET_INC+=	${GCC_CPU}/sysv4.h
236.endif
237.endif
238TARGET_INC+=	${GCC_CPU}/freebsd.h
239.if ${TARGET_ARCH} == "amd64"
240TARGET_INC+=	${GCC_CPU}/x86-64.h
241TARGET_INC+=	${GCC_CPU}/freebsd64.h
242TARGET_INC+=	freebsd64-fix.h
243.endif
244.if ${TARGET_ARCH} == "powepc"
245TARGET_INC+=	altivec-defs.h
246.endif
247TARGET_INC+=	defaults.h
248
249#
250# Use TARGET_INC as a template and build a list of target specific
251# include files for gengtype to scan
252#
253GCONFIG_H=	${.CURDIR}/auto-host.h
254
255.for H in ${TARGET_INC}
256.for D in ${GCCDIR}/config ${GCCDIR} ${.CURDIR}
257.if exists($D/$H)
258GCONFIG_H+=	$D/$H
259.endif
260.endfor
261.endfor
262
263#
264# Define some variables to make blocks copied from Makefile.in happy
265#
266srcdir=		${GCCDIR}
267HASHTAB_H=	${GCCDIR}/hashtab.h
268SPLAY_TREE_H=	${GCCDIR}/splay-tree.h
269out_file=	${GCCDIR}/config/${GCC_CPU}/${GCC_CPU}.c
270GTFILES_SRCDIR=	${GCCDIR}
271
272#
273# Copied unchanged from gcc/Makefile.in
274#
275GTFILES = $(srcdir)/input.h $(srcdir)/coretypes.h $(srcdir)/cpplib.h \
276  $(GCONFIG_H) $(HASHTAB_H) $(SPLAY_TREE_H) \
277  $(srcdir)/bitmap.h $(srcdir)/coverage.c $(srcdir)/function.h  $(srcdir)/rtl.h \
278  $(srcdir)/optabs.h $(srcdir)/tree.h $(srcdir)/libfuncs.h $(srcdir)/hashtable.h \
279  $(srcdir)/real.h $(srcdir)/varray.h $(srcdir)/insn-addr.h \
280  $(srcdir)/cselib.h $(srcdir)/basic-block.h  $(srcdir)/cgraph.h \
281  $(srcdir)/c-common.h $(srcdir)/c-tree.h \
282  $(srcdir)/alias.c $(srcdir)/bitmap.c $(srcdir)/cselib.c $(srcdir)/cgraph.c \
283  $(srcdir)/dbxout.c $(srcdir)/dwarf2out.c $(srcdir)/dwarf2asm.c \
284  $(srcdir)/dojump.c \
285  $(srcdir)/emit-rtl.c $(srcdir)/except.c $(srcdir)/explow.c $(srcdir)/expr.c \
286  $(srcdir)/fold-const.c $(srcdir)/function.c \
287  $(srcdir)/gcse.c $(srcdir)/integrate.c $(srcdir)/lists.c $(srcdir)/optabs.c \
288  $(srcdir)/profile.c $(srcdir)/ra-build.c $(srcdir)/regclass.c \
289  $(srcdir)/reg-stack.c $(srcdir)/cfglayout.c $(srcdir)/langhooks.c \
290  $(srcdir)/sdbout.c $(srcdir)/stmt.c $(srcdir)/stor-layout.c \
291  $(srcdir)/stringpool.c $(srcdir)/tree.c $(srcdir)/varasm.c \
292  $(out_file)
293
294#
295# Build a list of frontend directories to look into
296#
297GTFILES_LANG_DIR_NAMES=
298
299.if ${MK_CXX} != "no"
300GTFILES_LANG_DIR_NAMES+=	cp
301.endif
302
303.if ${MK_OBJC} != "no"
304GTFILES_LANG_DIR_NAMES+=	objc
305.endif
306
307.if ${MK_FORTRAN} != "no"
308GTFILES_LANG_DIR_NAMES+=	f
309.endif
310
311#
312# Build a list of language specific files for gengtype
313#
314.for L in ${GTFILES_LANG_DIR_NAMES} c
315.if exists(${GCCDIR}/$L-config-lang.in)
316# Source the language config file
317L_GTFILES!=	sh -c '. ${GCCDIR}/$L-config-lang.in; echo $$gtfiles'
318.else
319L_GTFILES!=	sh -c '. ${GCCDIR}/$L/config-lang.in; echo $$gtfiles'
320.endif
321.for F in ${L_GTFILES}
322GTFILES_FILES+=	$F
323GTFILES_LANGS+= $L
324.endfor
325.endfor
326GTFILES+=	${GTFILES_FILES}
327
328#-----------------------------------------------------------------------
329# the host/target compiler config.
330
331COMMONHDRS=	bconfig.h config.h configargs.h gencheck.h multilib.h \
332		specs.h safe-ctype.h tconfig.h tm.h tm_p.h gcov-iov.h \
333		gtyp-gen.h
334GENSRCS+=	${COMMONHDRS}
335
336MFILE?=	${.CURDIR}/Makefile
337${COMMONHDRS}: ${MFILE}
338
339configargs.h:
340	echo 'static const char configuration_arguments[] ='	> ${.TARGET}
341	echo '	"FreeBSD/${TARGET_ARCH} system compiler";'	>> ${.TARGET}
342	echo 'static const char thread_model[] = "posix";'	>> ${.TARGET}
343	echo 'static const struct {'				>> ${.TARGET}
344	echo '	const char *name, *value;'			>> ${.TARGET}
345	echo '} configure_default_options[] = {'		>> ${.TARGET}
346	echo '	{ "NULL", "NULL" } };'				>> ${.TARGET}
347
348tconfig.h:
349	echo '#ifndef GCC_TCONFIG_H'			> ${.TARGET}
350	echo '#define GCC_TCONFIG_H'			>> ${.TARGET}
351	echo '#ifdef IN_GCC'				>> ${.TARGET}
352	echo '# include "ansidecl.h"'			>> ${.TARGET}
353	echo '#endif'					>> ${.TARGET}
354	echo '#define USED_FOR_TARGET'			>> ${.TARGET}
355	echo '#endif /* GCC_TCONFIG_H */'		>> ${.TARGET}
356
357bconfig.h:
358	echo '#ifndef GCC_BCONFIG_H'			> ${.TARGET}
359	echo '#define GCC_BCONFIG_H'			>> ${.TARGET}
360	echo '#include "auto-host.h"'			>> ${.TARGET}
361.if exists(${GCCDIR}/config/${GCC_CPU}/${GCC_CPU}-modes.def)
362	echo '#define EXTRA_MODES_FILE "${GCC_CPU}/${GCC_CPU}-modes.def"' >> ${.TARGET}
363.endif
364	echo '#ifdef IN_GCC'				>> ${.TARGET}
365	echo '# include "ansidecl.h"'			>> ${.TARGET}
366	echo '#endif'					>> ${.TARGET}
367	echo '#endif /* GCC_BCONFIG_H */'		>> ${.TARGET}
368
369gencheck.h:
370	echo '#include "cp/cp-tree.def"'		> ${.TARGET}
371	echo '#include "objc/objc-tree.def"'		>> ${.TARGET}
372
373multilib.h:
374	echo 'static const char *const multilib_raw[] = { \
375	    "aout maout;", "elf !maout;", NULL };'	> ${.TARGET}
376	echo 'static const char *const multilib_matches_raw[] = { \
377	    "maout maout;", "melf melf;", NULL };'	>> ${.TARGET}
378	echo 'static const char *multilib_extra = "";'	>> ${.TARGET}
379	echo 'static const char *multilib_options = "";'>> ${.TARGET}
380	echo 'static const char *const multilib_exclusions_raw[] = { \
381	    NULL };'					>> ${.TARGET}
382
383specs.h:
384	echo '#include "cp/lang-specs.h"'		> ${.TARGET}
385	echo '#include "f/lang-specs.h"'		>> ${.TARGET}
386	echo '#include "objc/lang-specs.h"'		>> ${.TARGET}
387
388config.h: bconfig.h
389	echo '#include <bconfig.h>'			> ${.TARGET}
390
391tm.h:
392	echo '#ifndef GCC_TM_H'				> ${.TARGET}
393	echo '#define GCC_TM_H'				>> ${.TARGET}
394.if defined(TARGET_CPU_DEFAULT)
395	echo "#define TARGET_CPU_DEFAULT (${TARGET_CPU_DEFAULT})" >> ${.TARGET}
396.endif
397	echo '#ifdef IN_GCC'				>> ${.TARGET}
398.for H in ${TARGET_INC}
399	echo '#include "$H"'				>> ${.TARGET}
400.endfor
401	echo '#if !defined GENERATOR_FILE && !defined USED_FOR_TARGET' >> ${.TARGET}
402	echo '# include "insn-constants.h"'		>> ${.TARGET}
403	echo '# include "insn-flags.h"'			>> ${.TARGET}
404	echo '#endif'					>> ${.TARGET}
405	echo '#endif'					>> ${.TARGET}
406.if exists(${GCCDIR}/config/${GCC_CPU}/${GCC_CPU}-modes.def)
407	echo '#define EXTRA_MODES_FILE "${GCC_CPU}/${GCC_CPU}-modes.def"' >> ${.TARGET}
408.endif
409	echo '#endif /* GCC_TM_H */'			>> ${.TARGET}
410
411tm_p.h:
412	echo '#include "${GCC_CPU}/${GCC_CPU}-protos.h"'	>> ${.TARGET}
413	echo '#include "tm-preds.h"'				>> ${.TARGET}
414
415safe-ctype.h:
416	echo '#include <ctype.h>'				> ${.TARGET}
417.for Z in TOUPPER TOLOWER ISDIGIT ISXDIGIT ISUPPER ISLOWER ISALPHA ISALNUM \
418    ISSPACE ISPUNCT ISGRAPH ISBLANK ISPRINT ISCNTRL
419	echo '#define ${Z}	${Z:L}'				>> ${.TARGET}
420.endfor
421	echo "#define ISIDST(x)		\
422		((x) == '_' || isalpha(x))"			>> ${.TARGET}
423	echo "#define ISIDNUM(x)	\
424		(isdigit(x) || ISIDST(x))"			>> ${.TARGET}
425	echo "#define IS_VSPACE(x)	\
426		((x) == '\n' || (x) == '\r')"			>> ${.TARGET}
427	echo "#define IS_NVSPACE(x)	\
428		(!IS_VSPACE(x) && (isspace(x) || (x) == '\0'))"	>> ${.TARGET}
429	echo "#define IS_SPACE_OR_NUL(x)	\
430		(isspace(x) || (x) == '\0')"			>> ${.TARGET}
431
432gtyp-gen.h:
433	echo "/* This file is machine generated.  Do not edit.  */" > ${.TARGET}
434	echo "static const char *srcdir = "			>> ${.TARGET}
435	echo "\"$(GTFILES_SRCDIR)\";"				>> ${.TARGET}
436	echo "static const char *lang_files[] = {"		>> ${.TARGET}
437.for F in ${GTFILES_FILES}
438	echo "\"$F\", "						>> ${.TARGET}
439.endfor
440	echo "NULL};"						>> ${.TARGET}
441	echo "static const char *langs_for_lang_files[] = {"	>> ${.TARGET}
442.for F in ${GTFILES_LANGS}
443	echo "\"$F\", "						>> ${.TARGET}
444.endfor
445	echo "NULL};"						>> ${.TARGET}
446	echo "static const char *all_files[] = {"		>> ${.TARGET}
447.for F in ${GTFILES}
448	echo "\"$F\", "						>> ${.TARGET}
449.endfor
450	echo "NULL};"						>> ${.TARGET}
451	echo "static const char *lang_dir_names[] = { \"c\", "	>> ${.TARGET}
452.for F in ${GTFILES_LANG_DIR_NAMES}
453	echo "\"$F\", "						>> ${.TARGET}
454.endfor
455	echo "NULL};"						>> ${.TARGET}
456
457gcov-iov.h:
458	echo "#define GCOV_VERSION ((gcov_unsigned_t)0x33303470)" >> ${.TARGET}
459
460#-----------------------------------------------------------------------
461# General things.
462
463SRCS+=		${GENSRCS}
464CLEANFILES+=	${GENSRCS}
465
466all:		${SRCS}
467
468.include <bsd.prog.mk>
469
470#-----------------------------------------------------------------------
471# Fixups.
472
473# Set OBJS the same as bsd.prog.mk would do if we defined PROG.  We can't
474# define PROG because we have multiple programs.
475#
476OBJS+=		${SRCS:N*.h:R:S/$/.o/g}
477CLEANFILES+=	${OBJS}
478
479.if !exists(${DEPENDFILE})
480# Fudge pre-dependfile dependencies of objects in much the same way as
481# bsd.prog.mk would do if we defined PROG.
482
483${OBJS}: ${COMMONHDRS}
484
485dummy-conditions.o:
486gencheck.o:
487genmodes.o:
488
489genpreds.o: insn-modes.h
490genconstants.o: insn-modes.h genrtl.h
491gengtype.o: insn-modes.h genrtl.h gtyp-gen.h
492rtl.o: insn-modes.h gtype-desc.h genrtl.h
493bitmap.o: insn-modes.h gtype-desc.h genrtl.h
494ggc-none.o: gtype-desc.h
495gensupport.o: insn-modes.h genrtl.h
496varray.o: gtype-desc.h
497genautomata.o: insn-modes.h genrtl.h
498genconditions.o: insn-modes.h genrtl.h
499gencodes.o: insn-modes.h genrtl.h
500genconfig.o: insn-modes.h genrtl.h
501print-rtl.o: insn-modes.h genrtl.h tm-preds.h tree-check.h
502read-rtl.o: insn-modes.h genrtl.h
503genattr.o: insn-modes.h genrtl.h
504genemit.o: insn-modes.h genrtl.h
505genflags.o: insn-modes.h genrtl.h
506genopinit.o: insn-modes.h genrtl.h
507genoutput.o: insn-modes.h genrtl.h
508genpeep.o: insn-modes.h genrtl.h
509genrecog.o: insn-modes.h genrtl.h
510genextract.o: genrtl.h insn-config.h
511genattrtab.o: insn-modes.h gtype-desc.h genrtl.h
512genrtl.o: insn-modes.h genrtl.h gtype-desc.h
513
514insn-conditions.o: insn-constants.h tm-preds.h
515insn-modes.o: insn-modes.h
516min-insn-modes.o: insn-modes.h
517gtype-desc.o: insn-modes.h insn-config.h insn-codes.h tree-check.h
518
519.endif
520