Makefile revision 96340
11573Srgrimes# $FreeBSD: head/gnu/usr.bin/cc/cc_tools/Makefile 96340 2002-05-10 08:54:50Z obrien $
2144545Sdas
3144545Sdas#
41573Srgrimes# This could probably be merged with ../cc_int/Makefile, but bsd.lib.mk
51573Srgrimes# is such a !@#!*#% nightmare because of how it reprograms the dependencies,
61573Srgrimes# suffix rules, SRCS, etc.  It's easiest to cheat by using bsd.prog.mk and
71573Srgrimes# SRCS to get dependencies.
81573Srgrimes#
91573Srgrimes
101573Srgrimes# ../Makefile.inc will put an absolute path to our objdir in CFLAGS.
111573Srgrimes# Prevent mkdep from using it, so that we don't have to give rules for
121573Srgrimes# aliases of generated headers.
131573Srgrimes
14144545SdasCFLAGS+=	-I.
151573Srgrimes
161573Srgrimes.include "../Makefile.inc"
17144545Sdas
181573Srgrimes.PATH: ${GCCDIR} ${GCCDIR}/cp		${GCCDIR}/../libiberty
191573Srgrimes
201573SrgrimesCFLAGS+=	-static -DGENERATOR_FILE
211573Srgrimes
221573Srgrimes#-----------------------------------------------------------------------
231573Srgrimes# insn-* gunk
241573Srgrimes
251573Srgrimes.for F in attr codes config flags
261573Srgrimesinsn-$F.h: gen$F ${MD_FILE}
2786170Sobrien	./gen$F ${MD_FILE} > insn-$F.h
2886170SobrienGENSRCS+=	insn-$F.h
291573Srgrimes.endfor
30144545Sdas
31144545SdasGENSRCS+=	gen-time-stamp
321573Srgrimesgen-time-stamp: genattrtab genemit genextract genopinit genoutput genpeep genrecog
331573Srgrimes	touch ${.TARGET}
34144545Sdas
35144545Sdas.for F in attr codes config emit extract flags opinit output peep recog
36144545Sdasbuild-tools: gen$F
371573Srgrimes
38144545Sdasgen$F: gen$F.o rtl.o obstack.o print-rtl.o bitmap.o errors.o gensupport.o        ggc-none.o hashtab.o read-rtl.o
391573Srgrimes	${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${.ALLSRC}
401573Srgrimes
41144545SdasGENSRCS+=	gen$F.c
42144545SdasCLEANFILES+=	gen$F
431573Srgrimes.endfor
44144545Sdas
45144545Sdas.for F in attrtab
46144545Sdasbuild-tools: gen$F
47144545Sdas
48144545Sdasgen$F: gen$F.o rtl.o print-rtl.o obstack.o bitmap.o errors.o gensupport.o        ggc-none.o hashtab.o read-rtl.o
49144545Sdas	${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${.ALLSRC}
50144545Sdas
51144545SdasGENSRCS+=	gen$F.c
52144545SdasCLEANFILES+=	gen$F
53144545Sdas.endfor
54144545Sdas
55144545SdasSRCS+=		bitmap.c errors.c gensupport.c        ggc-none.c hashtab.c obstack.c print-rtl.c regclass.c rtl.c rtlanal.c read-rtl.c
56144545Sdas
57144545Sdas.for F in check genrtl preds
58144545Sdasbuild-tools: gen$F
59144545Sdas
60144545Sdasgen$F: gen$F.o
61144545Sdas	${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${.ALLSRC}
62144545Sdas
631573SrgrimesGENSRCS+=	gen$F.c
64144545SdasCLEANFILES+=	gen$F
65144545Sdas.endfor
66144545Sdas
67144545Sdas.ORDER: genrtl.c genrtl.h
68144545Sdasgenrtl.c genrtl.h: gengenrtl
69144545Sdas	./gengenrtl > genrtl.c
70144545Sdas	./gengenrtl -h > genrtl.h
71144545Sdas
721573SrgrimesGENSRCS+=	genrtl.c genrtl.h
73
74#-----------------------------------------------------------------------
75# Common parser stuff.
76
77tree-check.h: gencheck
78	./gencheck > ${.TARGET}
79GENSRCS+=	tree-check.h
80
81#-----------------------------------------------------------------------
82# Predicates stuff.
83
84tm-preds.h: genpreds
85	./genpreds > ${.TARGET}
86GENSRCS+=	tm-preds.h
87
88#-----------------------------------------------------------------------
89# the host/target compiler config.
90
91COMMONHDRS=	config.h hconfig.h multilib.h options.h specs.h tconfig.h \
92		tm_p.h configargs.h safe-ctype.h
93GENSRCS+=	${COMMONHDRS} gencheck.h
94
95MFILE?=	${.CURDIR}/Makefile
96${COMMONHDRS}: ${MFILE}
97
98configargs.h:
99	echo 'static const char configuration_arguments[] ='	> ${.TARGET}
100	echo '	"FreeBSD/${TARGET_ARCH} system compiler";'		>> ${.TARGET}
101	echo 'static const char thread_model[] = "posix";'	>> ${.TARGET}
102
103hconfig.h:
104	echo '#include "auto-host.h"'			> ${.TARGET}
105	echo '#include <tconfig.h>'			>> ${.TARGET}
106
107gencheck.h:
108	echo '#include "cp/cp-tree.def"'		> ${.TARGET}
109	echo '#include "objc/objc-tree.def"'		>> ${.TARGET}
110
111multilib.h:
112	echo 'static const char *const multilib_raw[] = { \
113	    "aout maout;", "elf !maout;", NULL };'	> ${.TARGET}
114	echo 'static const char *const multilib_matches_raw[] = { \
115	    "maout maout;", "melf melf;", NULL };'	>> ${.TARGET}
116	echo 'static const char *multilib_extra = "";'	>> ${.TARGET}
117	echo 'static const char *const multilib_exclusions_raw[] = { \
118	    NULL };'					>> ${.TARGET}
119
120options.h:
121	echo '#include "cp/lang-options.h"'		> ${.TARGET}
122	echo '#include "f/lang-options.h"'		>> ${.TARGET}
123	echo '#include "objc/lang-options.h"'		>> ${.TARGET}
124
125specs.h:
126	echo '#include "cp/lang-specs.h"'		> ${.TARGET}
127	echo '#include "f/lang-specs.h"'		>> ${.TARGET}
128	echo '#include "objc/lang-specs.h"'		>> ${.TARGET}
129
130config.h:
131	echo '#include <hconfig.h>'			> ${.TARGET}
132	echo '#ifndef GENERATOR_FILE'			>> ${.TARGET}
133	echo '#include "insn-codes.h"'			>> ${.TARGET}
134	echo '#include "insn-flags.h"'			>> ${.TARGET}
135	echo '#endif'					>> ${.TARGET}
136
137tconfig.h:
138	echo 'struct rtx_def;'				> ${.TARGET}
139	echo 'typedef struct rtx_def *rtx;'		>> ${.TARGET}
140	echo 'struct rtvec_def;'			>> ${.TARGET}
141	echo 'typedef struct rtvec_def *rtvec;'		>> ${.TARGET}
142	echo 'union tree_node;'				>> ${.TARGET}
143	echo 'typedef union tree_node *tree;'		>> ${.TARGET}
144	echo ''						>> ${.TARGET}
145	echo '#include "ansidecl.h"'			>> ${.TARGET}
146	echo '#include "${GCC_CPU}/${GCC_CPU}.h"'	>> ${.TARGET}
147.if ${TARGET_ARCH} == "i386"
148	echo '#include "${GCC_CPU}/att.h"'		>> ${.TARGET}
149.endif
150.if ${TARGET_ARCH} != "alpha"
151	echo '#include "dbxelf.h"'			>> ${.TARGET}
152	echo '#include "elfos.h"'			>> ${.TARGET}
153.endif
154	echo '#include <freebsd-native.h>'		>> ${.TARGET}
155	echo '#include "freebsd-spec.h"'		>> ${.TARGET}
156	echo '#include "freebsd.h"'			>> ${.TARGET}
157.if ${TARGET_ARCH} == "alpha"
158	echo '#include "${GCC_CPU}/elf.h"'		>> ${.TARGET}
159.endif
160.if ${TARGET_ARCH} != "i386"
161.if exists(${GCCDIR}/config/${GCC_CPU}/sysv4.h)
162	echo '#include "${GCC_CPU}/sysv4.h"'		>> ${.TARGET}
163.endif
164.endif
165	echo '#include "${GCC_CPU}/freebsd.h"'		>> ${.TARGET}
166	echo '#include "defaults.h"'			>> ${.TARGET}
167	echo '#ifndef POSIX'				>> ${.TARGET}
168	echo '# define POSIX'				>> ${.TARGET}
169	echo '#endif'					>> ${.TARGET}
170	echo '#define CONFIG_SJLJ_EXCEPTIONS 0'		>> ${.TARGET}
171
172tm_p.h:
173	echo '#include "${GCC_CPU}/${GCC_CPU}-protos.h"'	>> ${.TARGET}
174	echo '#include "tm-preds.h"'				>> ${.TARGET}
175
176safe-ctype.h: Makefile
177	echo '#include <ctype.h>'				> ${.TARGET}
178.for Z in TOUPPER TOLOWER ISDIGIT ISXDIGIT ISUPPER ISLOWER ISALPHA ISALNUM \
179    ISSPACE ISPUNCT ISGRAPH ISBLANK ISPRINT ISCNTRL
180	echo '#define ${Z}	${Z:L}'				>> ${.TARGET}
181.endfor
182	echo "#define ISIDST(x)		\
183		((x) == '_' || isalpha(x))"			>> ${.TARGET}
184	echo "#define ISIDNUM(x)	\
185		(isdigit(x) || ISIDST(x))"			>> ${.TARGET}
186	echo "#define IS_VSPACE(x)	\
187		((x) == '\n' || (x) == '\r')"			>> ${.TARGET}
188	echo "#define IS_NVSPACE(x)	\
189		(!IS_VSPACE(x) && (isspace(x) || (x) == '\0'))"	>> ${.TARGET}
190	echo "#define IS_SPACE_OR_NUL(x)	\
191		(isspace(x) || (x) == '\0')"			>> ${.TARGET}
192
193#-----------------------------------------------------------------------
194# General things.
195
196SRCS+=		${GENSRCS}
197CLEANFILES+=	${GENSRCS}
198
199all: ${SRCS}
200
201.include <bsd.prog.mk>
202
203#-----------------------------------------------------------------------
204# Fixups.
205
206# Set OBJS the same as bsd.prog.mk would do if we defined PROG.  We can't
207# define PROG because we have multiple programs.
208#
209OBJS+=		${SRCS:N*.h:R:S/$/.o/g}
210
211.if !exists(${DEPENDFILE})
212# Fudge pre-dependfile dependencies of objects in much the same way as
213# bsd.prog.mk would do if we defined PROG.  There are complications to
214# avoid circular dependencies.  First, only make most objects depend on
215# all headers.  Filter out the objects that would cause problems (i.e.,
216# objects that will be used to create programs that will generate headers).
217#
218${OBJS:Nbitmap.o:Nerrors.o:Ngenattr.o:Ngencheck.o:Ngencodes.o:Ngenconfig.o:Ngenflags.o:Ngengenrtl.o:Ngenpreds.o:Ngensupport.o:Nggc-none.o:Nhashtab.o:Nobstack.o:Nprint-rtl.o:Nread-rtl.o:Nrtl.o}: ${SRCS:M*.h}
219
220# Next, make each of the problematic objects depend on only most headers.
221# Filter out the headers that would cause problems (and a few more when it
222# is inconvenient to filter precisely).
223#
224bitmap.o genattr.o gencodes.o genconfig.o genflags.o obstack.o print-rtl.o \
225    rtl.o: ${SRCS:M*.h:Ninsn-*.h}
226gencheck.o: gencheck.h ${SRCS:M*.h:Ngenrtl.h:Ntree-check.h:Ninsn-*.h}
227gengenrtl.o: ${SRCS:M*.h:Ngenrtl.h:Ninsn-*.h}
228genpreds.o: ${COMMONHDRS}
229.endif
230