1#	$NetBSD: Makefile,v 1.13 2008/10/25 22:27:35 apb Exp $
2
3LIBISPRIVATE=	yes
4
5LIB=		backend
6
7SRCS=		${G_OBJS:.o=.c} ${G_out_file:T}
8
9CPPFLAGS+=	-I. -I${GCCARCH} ${G_ALL_CFLAGS:M-D*} ${G_INCLUDES:M-I*:N-I.*} \
10		-DTARGET_NAME=\"${MACHINE_GNU_PLATFORM}\"
11HOST_CPPFLAGS+=	-I. -I${GCCARCH} ${G_ALL_CFLAGS:M-D*} ${G_INCLUDES:M-I*:N-I.*}
12DPSRCS+=	insn-attr.h insn-codes.h insn-config.h insn-flags.h tree-check.h
13CPPFLAGS.prefix.c+=     -DPREFIX=\"/usr\"
14
15.include <bsd.lib.mk>
16
17# For early builders.
18EXTRADEPENDSEARLY=	${G_BUILD_EARLY_SUPPORT:.o=.lo} ${G_BUILD_RTL:.o=.lo} \
19			${G_BUILD_ERRORS:.o=.lo}
20
21# Don't auto-frob .y or .l files.
22.l.c .y.c .y.h:
23	@true
24
25#
26# Independent generation programs.
27#
28CLEANFILES+=	gengenrtl genrtl.c genrtl.h \
29		gengtype gtyp-gen.h gtype-desc.c gtype-desc.h \
30		gtype-c.h gtype-cp.h gtype-f.h gtype-objc.h \
31		genflags genflags.h \
32		gencheck tree-check.h \
33		insn-preds.c genpreds tm-preds.h tm_p.h cs-tm_p.h \
34		genmodes insn-modes.c insn-modes.h min-insn-modes.c \
35		auto-host.h build-print-rtl.c \
36		build-rtl.c build-errors.c build-varray.c \
37		build-bitmap.c build-ggc-none.c \
38		gt-*.h *.o *.lo \
39		cs-config.h \
40		gcov-iov gcov-iov.h \
41
42#
43# These files have special needs
44#
45.for f in \
46	build-errors build-ggc-none build-print-rtl build-rtl build-varray dummy-conditions gcov-iov genattr genattrtab genautomata gencheck genchecksum gencodes genconditions genconfig genconstants genemit genextract genflags gengenrtl gengtype gengtype-lex gengtype-yacc genmddeps genmodes genopinit genoutput genpeep genpreds genrecog gensupport insn-conditions min-insn-modes read-rtl
47CPPFLAGS.${f}.c=		-DGENERATOR_FILE
48.endfor
49
50# XXX
51COPTS.varasm.c=			-Wno-error
52
53
54# Headers that host objects depend on (except gen*rtl*)
55HH_NORTL=	${G_tm_file_list} ${G_build_xm_include_list}
56HH=		${HH_NORTL} genrtl.h insn-modes.h
57
58#
59# Generate the various header files we need.
60#
61genrtl.c: gengenrtl
62	${_MKTARGET_CREATE}
63	./gengenrtl >${.TARGET}
64genrtl.h: gengenrtl
65	${_MKTARGET_CREATE}
66	./gengenrtl -h >${.TARGET}
67gengenrtl.lo: ${HH_NORTL}
68gengenrtl: gengenrtl.lo build-errors.lo
69	${_MKTARGET_LINK}
70	${HOST_LINK.c} -o ${.TARGET} ${.ALLSRC} ${NBCOMPATLIB} ${HOSTLIBIBERTY}
71
72tm-preds.h: genpreds ${G_md_file}
73	${_MKTARGET_CREATE}
74	./genpreds -h ${G_md_file} >${.TARGET}
75insn-preds.c: genpreds ${G_md_file}
76	${_MKTARGET_CREATE}
77	./genpreds ${G_md_file} >${.TARGET}
78genpreds.lo: ${HH}
79genpreds: genpreds.lo ${EXTRADEPENDSEARLY}
80	${_MKTARGET_LINK}
81	${HOST_LINK.c} -o ${.TARGET} ${.ALLSRC} ${NBCOMPATLIB} ${HOSTLIBIBERTY}
82
83tree-check.h: gencheck
84	${_MKTARGET_CREATE}
85	./gencheck >${.TARGET}
86gencheck.lo: ${HH}
87gencheck: gencheck.lo
88	${_MKTARGET_LINK}
89	${HOST_LINK.c} -o ${.TARGET} ${.ALLSRC} ${NBCOMPATLIB} ${HOSTLIBIBERTY}
90
91gtype-desc.c: gtype-desc.h
92gtype-desc.h: gengtype
93	${_MKTARGET_CREATE}
94	rm -f auto-host.h
95	ln -s ${.CURDIR}/../arch/${MACHINE_ARCH}/auto-host.h .
96	./gengtype
97# gengtype is the real need for options.h
98gengtype.lo gengtype-lex.lo gengtype-yacc.lo: ${HH} gtyp-gen.h config.h options.h
99gengtype: gengtype.lo gengtype-lex.lo gengtype-yacc.lo build-errors.lo
100	${_MKTARGET_LINK}
101	${HOST_LINK.c} -o ${.TARGET} ${.ALLSRC} ${NBCOMPATLIB} ${HOSTLIBIBERTY}
102
103gtyp-gen.h: Makefile
104	${_MKTARGET_CREATE}
105	(\
106	echo "static const char *srcdir = \"$(G_GTFILES_SRCDIR)\";"	; \
107	echo "static const char *lang_files[] = {"			; \
108	for f in $(G_GTFILES_FILES_FILES); do echo "\"$$f\", "; done	; \
109	echo "NULL };"							; \
110	echo "static const char *langs_for_lang_files[] = {"		; \
111	for f in $(G_GTFILES_FILES_LANGS); do echo "\"$$f\", "; done 	; \
112	echo "NULL };"							; \
113	echo "static const char *all_files[] = {"			; \
114	for f in $(G_GTFILES); do echo "\"$$f\", "; done		; \
115	echo " NULL };"							; \
116	echo "static const char *lang_dir_names[] = {"			; \
117	echo "\"c\", "							; \
118	for f in $(G_GTFILES_LANG_DIR_NAMES); do echo "\"$$f\", "; done	; \
119	echo "NULL };"							; \
120	) >${.TARGET}
121
122insn-modes.c: genmodes
123	${_MKTARGET_CREATE}
124	./genmodes >${.TARGET}
125insn-modes.h: genmodes
126	${_MKTARGET_CREATE}
127	./genmodes -h >${.TARGET}
128min-insn-modes.c: genmodes
129	${_MKTARGET_CREATE}
130	./genmodes -m >${.TARGET}
131genmodes.lo: ${HH_NORTL}
132genmodes: genmodes.lo build-errors.lo
133	${_MKTARGET_LINK}
134	${HOST_LINK.c} -o ${.TARGET} ${.ALLSRC} ${NBCOMPATLIB} ${HOSTLIBIBERTY}
135
136gcov-iov.h: gcov-iov
137	${_MKTARGET_CREATE}
138	./gcov-iov "${BASEVER}" "${DEVPHASE}" >${.TARGET}
139gcov-iov.lo: ${HH_NORTL}
140gcov-iov: gcov-iov.lo
141	${_MKTARGET_CREATE}
142	${HOST_LINK.c} -o ${.TARGET} ${.ALLSRC} ${NBCOMPATLIB} ${HOSTLIBIBERTY}
143
144#config.h: Makefile
145#	${_MKTARGET_CREATE}
146#	TM_DEFINES="$(G_tm_defines)" \
147#	HEADERS="$(G_host_xm_file)" XM_DEFINES="$(G_host_xm_defines)" \
148#	TARGET_CPU_DEFAULT="$(G_target_cpu_default)" \
149#	${HOST_SH} ${GNUHOSTDIST}/gcc/mkconfig.sh ${.TARGET}
150
151tm_p.h: Makefile
152	${_MKTARGET_CREATE}
153	TARGET_CPU_DEFAULT="" \
154	HEADERS="$(G_tm_p_include_list)" DEFINES="" \
155	${HOST_SH} ${GNUHOSTDIST}/gcc/mkconfig.sh ${.TARGET}
156
157CLEANFILES+=	options.h options.c optionlist
158optionlist: ${G_ALL_OPT_FILES} ${GCCARCH}/defs.mk Makefile ${DIST}/gcc/opt-gather.awk
159	${TOOL_AWK} -f ${DIST}/gcc/opt-gather.awk ${G_ALL_OPT_FILES} > ${.TARGET}
160
161options.c: optionlist ${DIST}/gcc/opt-functions.awk ${DIST}/gcc/optc-gen.awk
162	${TOOL_AWK} -f ${DIST}/gcc/opt-functions.awk -f ${DIST}/gcc/optc-gen.awk \
163		-v header_name="config.h system.h coretypes.h tm.h" < optionlist > ${.TARGET}
164
165options.h: optionlist ${DIST}/gcc/opt-functions.awk ${DIST}/gcc/opth-gen.awk
166	${TOOL_AWK} -f ${DIST}/gcc/opt-functions.awk -f ${DIST}/gcc/opth-gen.awk \
167		< optionlist > ${.TARGET}
168
169options.o: options.c coretypes.h opts.h intl.h
170#options.o: options.c ${G_CONFIG_H} ${G_SYSTEM_H} coretypes.h ${G_TM_H} opts.h intl.h
171
172# Yuck, we have to run configure to generate this one...
173CLEANFILES+=	auto-build.h
174auto-build.h: Makefile
175	${_MKTARGET_CREATE}
176	rm -rf .ab && \
177	mkdir .ab && \
178	(cd .ab && \
179		AWK=${TOOL_AWK:Q} \
180		CC=${HOST_CC:Q} CFLAGS=${HOST_CFLAGS:Q} \
181		MAKE=${MAKE:Q} \
182		CONFIG_SHELL=${HOST_SH:Q} \
183		${HOST_SH} ${GNUHOSTDIST}/gcc/configure \
184			--build=`${HOST_SH} ${GNUHOSTDIST}/config.guess` \
185			--host=`${HOST_SH} ${GNUHOSTDIST}/config.guess` \
186			--target=${MACHINE_GNU_PLATFORM} && \
187		mv auto-host.h ../auto-build.h) && \
188	rm -rf .ab
189
190#
191# These are copies of files we build for the build host that are used
192# by the genfoo programs.
193#
194
195build-rtl.c: rtl.c \
196  ${G_RTL_H} real.h ${G_GCC_H} errors.h gtype-desc.h
197	${_MKTARGET_CREATE}
198	rm -f build-rtl.c
199	${TOOL_SED} -e 's/<config[.]h/hconfig.h/' \
200		${GNUHOSTDIST}/gcc/rtl.c >${.TARGET}
201build-rtl.lo: ${HH}
202
203build-print-rtl.c: print-rtl.c \
204  ${G_RTL_H} ${G_TREE_H} hard-reg-set.h ${G_BASIC_BLOCK_H}
205	${_MKTARGET_CREATE}
206	rm -f buid-print-rtl.c
207	${TOOL_SED} -e 's/<config[.]h/hconfig.h/' \
208		${GNUHOSTDIST}/gcc/print-rtl.c >${.TARGET}
209build-print-rtl.lo: ${HH}
210
211build-bitmap.c: bitmap.c \
212  ${G_RTL_H} flags.h ${G_BASIC_BLOCK_H} ${REGS_H} ${G_GCC_H} gtype-desc.h
213	${_MKTARGET_CREATE}
214	rm -f build-bitmap.c
215	${TOOL_SED} -e 's/<config[.]h/hconfig.h/' \
216		${GNUHOSTDIST}/gcc/bitmap.c >${.TARGET}
217build-bitmap.lo: ${HH}
218
219build-errors.c: errors.c errors.h
220	${_MKTARGET_CREATE}
221	rm -f build-errors.c
222	cat ${GNUHOSTDIST}/gcc/errors.c >${.TARGET}
223build-errors.lo: ${HH_NORTL}
224
225build-varray.c: varray.c \
226  ${G_RTL_H} ${G_GCC_H} ${TREE_H} bitmap.h errors.h
227	${_MKTARGET_CREATE}
228	rm -f build-varray.c
229	${TOOL_SED} -e 's/<config[.]h/hconfig.h/' \
230		${GNUHOSTDIST}/gcc/varray.c >${.TARGET}
231build-varray.lo: ${HH} gtype-desc.h
232
233build-ggc-none.c: ggc-none.c \
234  ${G_GCC_H} gtype-desc.h
235	${_MKTARGET_CREATE}
236	rm -f build-ggc-none.c
237	${TOOL_SED} -e 's/<config[.]h/hconfig.h/' \
238		${GNUHOSTDIST}/gcc/ggc-none.c >${.TARGET}
239build-ggc-none.lo: ${HH}
240
241#
242# The `early' insn-foo generators
243#
244.for f in conditions.c constants.h
245CLEANFILES+=		gen${f:R} insn-${f}
246
247gen${f:R}.lo: gen${f:R}.c ${HH}
248gen${f:R}: gen${f:R}.lo ${EXTRADEPENDSEARLY}
249	${_MKTARGET_LINK}
250	${HOST_LINK.c} -o ${.TARGET} ${.ALLSRC} ${NBCOMPATLIB} ${HOSTLIBIBERTY}
251insn-${f}: gen${f:R} ${G_md_file}
252	${_MKTARGET_CREATE}
253	./gen${f:R} ${G_md_file} >${.TARGET}
254.endfor
255
256#
257# The normal insn-foo generators
258#
259.for f in gensupport.c read-rtl.c dummy-conditions.c
260${f:R}.lo: ${HH}
261.endfor
262
263EXTRADEPENDS=		${G_BUILD_RTL:.o=.lo} ${G_BUILD_SUPPORT:.o=.lo} \
264			${G_BUILD_PRINT:.o=.lo} ${G_BUILD_ERRORS:.o=.lo}
265.for f in attr.h codes.h config.h emit.c extract.c flags.h opinit.c output.c \
266	  peep.c recog.c
267CLEANFILES+=		gen${f:R} insn-${f}
268
269gen${f:R}.lo: ${HH}
270gen${f:R}: gen${f:R}.lo ${EXTRADEPENDS} 
271	${_MKTARGET_LINK}
272	${HOST_LINK.c} -o ${.TARGET} ${.ALLSRC} ${NBCOMPATLIB} ${HOSTLIBIBERTY}
273insn-${f}: gen${f:R} ${G_md_file}
274	${_MKTARGET_CREATE}
275	./gen${f:R} ${G_md_file} >${.TARGET}
276.endfor
277
278#
279# "One of these things is not like the other"
280#
281CLEANFILES+=		genattrtab insn-attrtab.c
282genattrtab.lo: ${HH} gtype-desc.h
283genautomata.lo: ${HH}
284genattrtab: genattrtab.lo genautomata.lo ${EXTRADEPENDS} ${G_BUILD_VARRAY:.o=.lo}
285	${_MKTARGET_LINK}
286	${HOST_LINK.c} -o ${.TARGET} ${.ALLSRC} ${NBCOMPATLIB} ${HOSTLIBIBERTY} -lm
287insn-attrtab.c: genattrtab ${G_md_file}
288	${_MKTARGET_CREATE}
289	./genattrtab ${G_md_file} >${.TARGET}
290
291#
292# Required hard-coded dependancies.
293#
294genextract.lo: insn-config.h
295insn-conditions.lo: insn-constants.h tm_p.h tm-preds.h
296build-ggc-none.lo: gtype-desc.h
297ggc-none.o: gtype-desc.h
298
299insn-attrtab.o: insn-config.h
300insn-extract.o: insn-config.h
301toplev.d toplev.o: options.h
302coverage.d: gcov-iov.h
303gcov-io.h: gcov-iov.h
304
305COPTS+=-Wno-stack-protector
306
307.PATH: ${DIST}/gcc ${DIST}/libiberty ${GCCARCH} ${G_out_file:H} ${DIST}/include
308