xref: /minix/external/gpl3/gcc/usr.bin/backend/Makefile (revision 0a6a1f1d)
1#	$NetBSD: Makefile,v 1.24 2015/02/01 17:47:00 chs Exp $
2
3LIBISPRIVATE=	yes
4
5LIB=		backend
6
7SRCS=		${G_OBJS:.o=.c} ${G_out_file:T}
8
9BOTH_CPPFLAGS+=	-I. -I${GCCARCH} ${G_ALL_CFLAGS:M-D*} ${G_INCLUDES:M-I*:N-I.*}
10CPPFLAGS+=	${BOTH_CPPFLAGS} -DTARGET_NAME=\"${MACHINE_GNU_PLATFORM}\"
11HOST_CPPFLAGS+=	${BOTH_CPPFLAGS} -DGENERATOR_FILE
12DPSRCS+=	insn-attr.h insn-codes.h insn-config.h insn-flags.h tree-check.h
13CPPFLAGS+=	-I${DIST}/libgcc
14CPPFLAGS+=	-I${.CURDIR}/../../lib/libgcc/libgcov/arch/${MACHINE_ARCH}
15
16CPPFLAGS.cppdefault.c+=	-DPREFIX=\"/usr\" \
17			-DNATIVE_SYSTEM_HEADER_DIR=\"${G_NATIVE_SYSTEM_HEADER_DIR}\"
18
19HOSTPROG_CXX=	1
20
21.include <bsd.lib.mk>
22
23# Force using C++ for this
24ORIGHOST_CC:=	${HOST_CC}
25HOST_CC:=	${HOST_CXX}
26CC:=		${CXX}
27CFLAGS:=	${CXXFLAGS}
28
29# Check PREPROCESSOR_DEFINES for cppbuiltin.c and cppdefault.c
30CPPFLAGS.cppbuiltin.c+=	-DBASEVER="\"${BASEVER}"\"
31
32#
33# Independent generation programs.
34#
35CLEANFILES+=	gengenrtl genrtl.h \
36		gengtype gtyp-gen.h gtype-desc.c gtype-desc.h \
37		gtype-c.h gtype-cp.h gtype-f.h gtype-objc.h \
38		genflags genflags.h \
39		gencheck tree-check.h \
40		insn-preds.c genpreds tm-preds.h tm_p.h cs-tm_p.h \
41		genmodes insn-modes.c insn-modes.h min-insn-modes.c \
42		auto-host.h build-print-rtl.c \
43		build-rtl.c build-errors.c build-varray.c \
44		build-bitmap.c build-ggc-none.c \
45		gt-*.h *.o *.lo \
46		cs-config.h \
47		gcov-iov gcov-iov.h \
48		gtype-go.h gtype.state
49
50# XXX
51COPTS.varasm.c=			-Wno-error
52
53# XXX Override the normal rule to use HOST_COMPILE.cc
54.c.lo:
55	${_MKTARGET_COMPILE}
56	${HOST_COMPILE.cc} -o ${.TARGET}.o ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC}
57	mv ${.TARGET}.o ${.TARGET}
58
59# Headers that host objects depend on (except gen*rtl*)
60HH_NORTL=	${G_tm_file_list} ${G_build_xm_include_list}
61HH=		${HH_NORTL} genrtl.h insn-modes.h
62
63#
64# Generate the various header files we need.
65#
66genrtl.h: gengenrtl
67	${_MKTARGET_CREATE}
68	./gengenrtl >${.TARGET}
69gengenrtl.lo: ${HH_NORTL}
70gengenrtl: gengenrtl.lo build-errors.lo
71	${_MKTARGET_LINK}
72	${HOST_LINK.cc} -o ${.TARGET} ${.ALLSRC} ${NBCOMPATLIB} ${HOSTLIBIBERTY}
73
74insn-preds.c: genpreds ${G_md_file}
75	${_MKTARGET_CREATE}
76	./genpreds ${G_md_file} >${.TARGET}
77tm-preds.h: genpreds ${G_md_file}
78	${_MKTARGET_CREATE}
79	./genpreds -h ${G_md_file} >${.TARGET}
80tm-constrs.h: genpreds ${G_md_file}
81	${_MKTARGET_CREATE}
82	./genpreds -c ${G_md_file} >${.TARGET}
83
84# be nice to generate this entirely; but difficult.
85gtyp-input.list.tmp: ${GCCARCH}/gtyp-input.list
86	sed s#SRCDIR#${DIST}# < ${.ALLSRC} > ${.TARGET}
87CLEANFILES+=	gtyp-input.list.tmp
88
89# XXX
90CLEANFILES+=	gtype-lto.h gtype-objcp.h tm-constrs.h
91
92gtype-desc.c: gtype-desc.h
93gtype-desc.h: gengtype gtyp-input.list.tmp
94	${_MKTARGET_CREATE}
95	rm -f auto-host.h
96	ln -s ${.CURDIR}/../gcc/arch/${GCC_MACHINE_ARCH}/auto-host.h .
97	if [ -f ${.CURDIR}/../gcc/arch/${GCC_MACHINE_ARCH}/sysroot-suffix.h ]; then \
98	  rm -f sysroot-suffix.h; \
99	  ln -s ${.CURDIR}/../gcc/arch/${GCC_MACHINE_ARCH}/sysroot-suffix.h ; \
100	fi
101	./gengtype -S ${DIST}/gcc -I gtyp-input.list.tmp -w gtype.state
102	./gengtype -r gtype.state
103	# GCC 4.8 installs gtype-state and gengtype as a plugin
104
105# gengtype is the real need for options.h
106gengtype.lo gengtype-lex.lo gengtype-parse.lo gengtype-state.lo version.lo: ${HH} gtyp-gen.h config.h options.h
107gengtype: gengtype.lo gengtype-lex.lo gengtype-parse.lo gengtype-state.lo build-errors.lo version.lo
108	${_MKTARGET_LINK}
109	${HOST_LINK.cc} -o ${.TARGET} ${.ALLSRC} ${NBCOMPATLIB} ${HOSTLIBIBERTY}
110
111gtyp-gen.h: Makefile
112	${_MKTARGET_CREATE}
113	(\
114	unset empty							; \
115	echo "static const char *srcdir = \"$(G_GTFILES_SRCDIR)\";"	; \
116	echo "static const char *lang_files[] = {"			; \
117	for f in $$empty $(G_GTFILES_FILES_FILES); do echo "\"$$f\", "; done ; \
118	echo "NULL };"							; \
119	echo "static const char *langs_for_lang_files[] = {"		; \
120	for f in $$empty $(G_GTFILES_FILES_LANGS); do echo "\"$$f\", "; done ; \
121	echo "NULL };"							; \
122	echo "static const char *all_files[] = {"			; \
123	for f in $$empty $(G_GTFILES); do echo "\"$$f\", "; done	; \
124	echo " NULL };"							; \
125	echo "static const char *lang_dir_names[] = {"			; \
126	for f in c $(G_GTFILES_LANG_DIR_NAMES); do echo "\"$$f\", "; done ; \
127	echo "NULL };"							; \
128	) >${.TARGET}
129
130insn-modes.c: genmodes
131	${_MKTARGET_CREATE}
132	./genmodes >${.TARGET}
133insn-modes.h: genmodes
134	${_MKTARGET_CREATE}
135	./genmodes -h >${.TARGET}
136min-insn-modes.c: genmodes
137	${_MKTARGET_CREATE}
138	./genmodes -m >${.TARGET}
139genmodes.lo: ${HH_NORTL}
140genmodes: genmodes.lo build-errors.lo
141	${_MKTARGET_LINK}
142	${HOST_LINK.cc} -o ${.TARGET} ${.ALLSRC} ${NBCOMPATLIB} ${HOSTLIBIBERTY}
143
144gcov-iov.h: gcov-iov
145	${_MKTARGET_CREATE}
146	./gcov-iov "${BASEVER}" "${DEVPHASE}" >${.TARGET}
147gcov-iov.lo: ${HH_NORTL}
148gcov-iov: gcov-iov.lo
149	${_MKTARGET_CREATE}
150	${HOST_LINK.cc} -o ${.TARGET} ${.ALLSRC} ${NBCOMPATLIB} ${HOSTLIBIBERTY}
151
152tm_p.h: Makefile tm-preds.h
153	${_MKTARGET_CREATE}
154	TARGET_CPU_DEFAULT="" \
155	HEADERS="$(G_tm_p_include_list)" DEFINES="" \
156	${HOST_SH} ${GNUHOSTDIST}/gcc/mkconfig.sh ${.TARGET}
157
158${G_OBJS} ${G_OBJS:.o=.d}:	tm_p.h		# XXX crude
159
160.include "../Makefile.options"
161
162# Yuck, we have to run configure to generate this one...
163# We use ORIGHOST_CC here because GCC's ./configure expects (and
164# depends upon) it.
165CLEANFILES+=	auto-build.h
166HOST_CFLAGS+= -I${.OBJDIR}
167auto-build.h: gmp.h Makefile
168	${_MKTARGET_CREATE}
169	rm -rf .ab && \
170	mkdir .ab && \
171	(cd .ab && \
172		AWK=${TOOL_AWK:Q} \
173		CC=${ORIGHOST_CC:Q} CFLAGS=${HOST_CFLAGS:Q} \
174		MAKE=${MAKE:Q} \
175		CONFIG_SHELL=${HOST_SH:Q} \
176		gcc_cv_ld=${LD} \
177		gcc_cv_as=${AS} \
178		${HOST_SH} ${GNUHOSTDIST}/gcc/configure \
179			--enable-lto \
180			--build=`${HOST_SH} ${GNUHOSTDIST}/config.guess` \
181			--host=`${HOST_SH} ${GNUHOSTDIST}/config.guess` \
182			--target=${MACHINE_GNU_PLATFORM} && \
183		mv auto-host.h ../auto-build.h) && \
184	rm -rf .ab
185
186#
187# These are copies of files we build for the build host that are used
188# by the genfoo programs.
189#
190
191build-rtl.c: rtl.c \
192  ${G_RTL_H} real.h ${G_GCC_H} errors.h gtype-desc.h
193	${_MKTARGET_CREATE}
194	rm -f build-rtl.c
195	${TOOL_SED} -e 's/<config[.]h/hconfig.h/' \
196		${GNUHOSTDIST}/gcc/rtl.c >${.TARGET}
197build-rtl.lo: ${HH}
198
199build-print-rtl.c: print-rtl.c \
200  ${G_RTL_BASE_H} ${G_GTM_H} hard-reg-set.h
201	${_MKTARGET_CREATE}
202	rm -f build-print-rtl.c
203	${TOOL_SED} -e 's/<config[.]h/hconfig.h/' \
204		${GNUHOSTDIST}/gcc/print-rtl.c >${.TARGET}
205build-print-rtl.lo: ${HH}
206build/print-rtl.o: print-rtl.c $(BCONFIG_H) $(SYSTEM_H) coretypes.h     \
207  $(GTM_H) $(RTL_BASE_H)
208
209
210build-bitmap.c: bitmap.c \
211  ${G_RTL_H} flags.h ${G_BASIC_BLOCK_H} ${REGS_H} ${G_GCC_H} gtype-desc.h
212	${_MKTARGET_CREATE}
213	rm -f build-bitmap.c
214	${TOOL_SED} -e 's/<config[.]h/hconfig.h/' \
215		${GNUHOSTDIST}/gcc/bitmap.c >${.TARGET}
216build-bitmap.lo: ${HH}
217
218build-errors.c: errors.c errors.h
219	${_MKTARGET_CREATE}
220	rm -f build-errors.c
221	cat ${GNUHOSTDIST}/gcc/errors.c >${.TARGET}
222build-errors.lo: ${HH_NORTL}
223
224build-varray.c: varray.c \
225  ${G_RTL_H} ${G_GCC_H} ${TREE_H} bitmap.h errors.h
226	${_MKTARGET_CREATE}
227	rm -f build-varray.c
228	${TOOL_SED} -e 's/<config[.]h/hconfig.h/' \
229		${GNUHOSTDIST}/gcc/varray.c >${.TARGET}
230build-varray.lo: ${HH} gtype-desc.h
231
232build-ggc-none.c: ggc-none.c \
233  ${G_GCC_H} gtype-desc.h
234	${_MKTARGET_CREATE}
235	rm -f build-ggc-none.c
236	${TOOL_SED} -e 's/<config[.]h/hconfig.h/' \
237		${GNUHOSTDIST}/gcc/ggc-none.c >${.TARGET}
238build-ggc-none.lo: ${HH}
239
240#
241# The normal insn-foo generators
242#
243.for f in gensupport.c read-rtl.c dummy-conditions.c
244${f:R}.lo: ${HH}
245.endfor
246
247#
248# There are 5 main classes of generator programs.  Ones
249# that are self contained, ones that use error reporting
250# mechanisms, ones that use the MD reader, and ones that
251# use the RTL reader.
252#
253GENPROG_ERROR_DEPENDS=	${G_BUILD_ERRORS:.o=.lo}
254GENPROG_READER_DEPENDS=	${G_BUILD_MD:.o=.lo} ${GENPROG_ERROR_DEPENDS}
255GENPROG_RTL_DEPENDS=	${G_BUILD_RTL:.o=.lo} ${GENPROG_READER_DEPENDS} ${GENPROG_ERROR_DEPENDS}
256
257#
258# First we generate the rules for the generators.
259#
260.for f in attr attr-common attrtab automata codes conditions config emit \
261	  extract flags opinit output peep preds recog mddump condmd
262gen${f}.lo: ${HH} gen${f}.c
263gen${f}: gen${f}.lo ${GENPROG_RTL_DEPENDS}
264	${_MKTARGET_LINK}
265	${HOST_LINK.cc} -o ${.TARGET} ${.ALLSRC} ${NBCOMPATLIB} ${HOSTLIBIBERTY} ${LDFLAGS.${.TARGET}}
266CLEANFILES+=	gen${f} gen${f}.lo
267.endfor
268
269.for f in mddeps constants enums
270gen${f}.lo: ${HH} gen${f}.c
271gen${f}: gen${f}.lo ${GENPROG_READER_DEPENDS}
272	${_MKTARGET_LINK}
273	${HOST_LINK.cc} -o ${.TARGET} ${.ALLSRC} ${NBCOMPATLIB} ${HOSTLIBIBERTY} ${LDFLAGS.${.TARGET}}
274CLEANFILES+=	gen${f} gen${f}.lo
275.endfor
276
277.for f in check checksum
278gen${f}.lo: ${HH} gen${f}.c
279gen${f}: gen${f}.lo
280	${_MKTARGET_LINK}
281	${HOST_LINK.cc} -o ${.TARGET} ${.ALLSRC} ${NBCOMPATLIB} ${HOSTLIBIBERTY} ${LDFLAGS.${.TARGET}}
282CLEANFILES+=	gen${f} gen${f}.lo
283.endfor
284
285.include "../../Makefile.hooks"
286
287#
288# Second we generate the rules for the generated files.  There
289# are 3 main classes:  RTL based or not, plus special cases.
290#
291# The special cases are:  gencheck, genattrtab, genopinit,
292# gencondmd
293#
294
295# RTL based files
296.for f in attr.h attr-common.h codes.h config.h flags.h \
297	  automata.c emit.c extract.c output.c peep.c recog.c
298insn-${f}: gen${f:R} ${G_md_file} insn-conditions.md
299	${_MKTARGET_CREATE}
300	./gen${f:R} ${G_md_file} insn-conditions.md >${.TARGET}
301CLEANFILES+=	insn-${f}
302.endfor
303
304# normal files
305.for f in constants.h enums.c
306insn-${f}: gen${f:R} ${G_md_file}
307	${_MKTARGET_CREATE}
308	./gen${f:R} ${G_md_file} >${.TARGET}
309CLEANFILES+=	insn-${f}
310.endfor
311
312# genconditions outputs gencondmd.c
313gencondmd.c: genconditions ${G_md_file}
314	${_MKTARGET_CREATE}
315	./genconditions ${G_md_file} >${.TARGET}
316CLEANFILES+=	gencondmd.c
317
318# gencheck outputs tree-check.h
319tree-check.h: gencheck
320	${_MKTARGET_CREATE}
321	./gencheck >${.TARGET}
322CLEANFILES+=	tree-check.h
323
324# Some generators output is not the normal name.
325BUILDSYMLINKS+= insn-check.h tree-check.h
326
327# genattrtab has three output files
328# XXX fix me
329insn-attrtab.c insn-dfatab.c insn-latencytab.c: genattrtab ${G_md_file} insn-conditions.md
330	${_MKTARGET_CREATE}
331	./genattrtab ${G_md_file} insn-conditions.md -Ainsn-attrtab.c -Dinsn-dfatab.c -Linsn-latencytab.c
332CLEANFILES+=	insn-attrtab.c insn-dfatab.c insn-latencytab.c
333
334# genopinit has two output files
335insn-opinit.c insn-opinit.h: genopinit ${G_md_file} insn-conditions.md
336	${_MKTARGET_CREATE}
337	./genopinit ${G_md_file} insn-conditions.md -hinsn-opinit.h -cinsn-opinit.c
338CLEANFILES+=	insn-opinit.h insn-opinit.c
339
340LDFLAGS.genautomata+=	-lm
341
342# gencondmd outputs a special .md file
343insn-conditions.md: gencondmd
344	./gencondmd >${.TARGET}
345CLEANFILES+=	insn-conditions.md
346
347
348#
349# Required hard-coded dependancies.
350#
351genextract.lo: insn-config.h
352gencondmd.lo: tm_p.h tm-constrs.h
353read-rtl.lo gencodes.lo genattrtab.lo genautomata.lo: insn-constants.h
354genattr-common.lo gensupport.lo genconditions.lo: insn-constants.h
355genattr.lo genflags.lo genemit.lo genconfig.lo gencheck.lo: insn-constants.h
356genopinit.lo genrecog.lo genpreds.lo genoutput.lo genpeep.lo: insn-constants.h
357build-ggc-none.lo: gtype-desc.h
358ggc-none.o: gtype-desc.h
359
360insn-attrtab.o: insn-config.h
361insn-extract.o: insn-config.h
362toplev.d toplev.o: options.h
363coverage.d: gcov-iov.h
364gcov-io.h: gcov-iov.h
365alias.d alias.o: insn-constants.h tm_p.h
366cgraph.d cgraphunit.d cgraphunit.o: gcov-io.h
367vec.lo: gtype-desc.h
368gtype-desc.d gtype-desc.o: insn-constants.h
369insn-emit.d insn-emit.o: tm-constrs.h
370insn-attr.h: insn-attr-common.h
371asan.d asan.o: insn-opinit.h
372data-streamer.d data-streamer-out.d coverage.d gcov-dump.d gcov-io.d gcov-iov.d gcov.d libgcov.d lto-cgraph.d mcf.d modulo-sched.d profile.d value-prof.d: gcov-io.h
373data-streamer.o data-streamer-out.o coverage.o gcov-dump.o gcov-io.o gcov-iov.o gcov.o libgcov.o lto-cgraph.o mcf.o modulo-sched.o profile.o value-prof.o: gcov-io.h
374gcov-io.h: gcov-iov.h
375df-scan.d df-scan.o: target-hooks-def.h
376read-md.d read-md.o read-md.lo: auto-build.h
377
378# XXX make all hooks generated for now.
379final.o: target-hooks-def.h c-family/c-target-hooks-def.h common/common-target-hooks-def.h
380
381.if ${GCC_MACHINE_ARCH} == "alpha"
382alpha.d alpha.o: tm-constrs.h tm_p.h insn-opinit.h target-hooks-def.h
383.endif
384
385.if ${MACHINE_CPU} == "arm"
386arm.d arm.o: insn-constants.h tm_p.h insn-opinit.h target-hooks-def.h
387.endif
388
389.if ${GCC_MACHINE_ARCH} == "i386" || ${GCC_MACHINE_ARCH} == "x86_64"
390i386.d i386.o: tm-constrs.h
391.endif
392
393.if ${GCC_MACHINE_ARCH} == "vax"
394CPPFLAGS+=-I${.CURDIR}/../../lib/libgcc/libgcov/arch/${GCC_MACHINE_ARCH}
395COPTS.expmed.c=-O0
396COPTS.recog.c=-O0
397.endif
398
399CFLAGS+=	-Wno-stack-protector
400
401.if ${GCC_MACHINE_ARCH} == "m68000" || ${GCC_MACHINE_ARCH} == "m68k" || \
402	${GCC_MACHINE_ARCH} == "coldfire"
403COPTS.tree-loop-distribution.c=	-O2
404.endif
405
406COPTS.tree.c=	${${ACTIVE_CC} == "clang" :? -O0 :}
407
408.PATH: ${DIST}/gcc ${DIST}/libiberty ${GCCARCH} ${G_out_file:H} ${DIST}/include
409.PATH: ${DIST}/gcc/config
410