Makefile revision 1.22 1 # $NetBSD: Makefile,v 1.22 2014/07/06 00:21:24 joerg Exp $
2
3 LIBISPRIVATE= yes
4
5 LIB= backend
6
7 SRCS= ${G_OBJS:.o=.c} ${G_out_file:T}
8
9 BOTH_CPPFLAGS+= -I. -I${GCCARCH} ${G_ALL_CFLAGS:M-D*} ${G_INCLUDES:M-I*:N-I.*}
10 CPPFLAGS+= ${BOTH_CPPFLAGS} -DTARGET_NAME=\"${MACHINE_GNU_PLATFORM}\"
11 HOST_CPPFLAGS+= ${BOTH_CPPFLAGS} -DGENERATOR_FILE
12 DPSRCS+= insn-attr.h insn-codes.h insn-config.h insn-flags.h tree-check.h
13 CPPFLAGS+= -I${DIST}/libgcc
14 CPPFLAGS+= -I${.CURDIR}/../../lib/libgcc/libgcov/arch/${MACHINE_ARCH}
15
16 CPPFLAGS.cppdefault.c+= -DPREFIX=\"/usr\" \
17 -DNATIVE_SYSTEM_HEADER_DIR=\"${G_NATIVE_SYSTEM_HEADER_DIR}\"
18
19 HOSTPROG_CXX= 1
20
21 .include <bsd.lib.mk>
22
23 # Force using C++ for this
24 ORIGHOST_CC:= ${HOST_CC}
25 HOST_CC:= ${HOST_CXX}
26 CC:= ${CXX}
27 CFLAGS:= ${CXXFLAGS}
28
29 # Check PREPROCESSOR_DEFINES for cppbuiltin.c and cppdefault.c
30 CPPFLAGS.cppbuiltin.c+= -DBASEVER="\"${BASEVER}"\"
31
32 #
33 # Independent generation programs.
34 #
35 CLEANFILES+= 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
51 COPTS.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*)
60 HH_NORTL= ${G_tm_file_list} ${G_build_xm_include_list}
61 HH= ${HH_NORTL} genrtl.h insn-modes.h
62
63 #
64 # Generate the various header files we need.
65 #
66 genrtl.h: gengenrtl
67 ${_MKTARGET_CREATE}
68 ./gengenrtl >${.TARGET}
69 gengenrtl.lo: ${HH_NORTL}
70 gengenrtl: gengenrtl.lo build-errors.lo
71 ${_MKTARGET_LINK}
72 ${HOST_LINK.cc} -o ${.TARGET} ${.ALLSRC} ${NBCOMPATLIB} ${HOSTLIBIBERTY}
73
74 insn-preds.c: genpreds ${G_md_file}
75 ${_MKTARGET_CREATE}
76 ./genpreds ${G_md_file} >${.TARGET}
77 tm-preds.h: genpreds ${G_md_file}
78 ${_MKTARGET_CREATE}
79 ./genpreds -h ${G_md_file} >${.TARGET}
80 tm-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.
85 gtyp-input.list.tmp: ${GCCARCH}/gtyp-input.list
86 sed s#SRCDIR#${DIST}# < ${.ALLSRC} > ${.TARGET}
87 CLEANFILES+= gtyp-input.list.tmp
88
89 # XXX
90 CLEANFILES+= gtype-lto.h gtype-objcp.h tm-constrs.h
91
92 gtype-desc.c: gtype-desc.h
93 gtype-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
106 gengtype.lo gengtype-lex.lo gengtype-parse.lo gengtype-state.lo version.lo: ${HH} gtyp-gen.h config.h options.h
107 gengtype: 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
111 gtyp-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
130 insn-modes.c: genmodes
131 ${_MKTARGET_CREATE}
132 ./genmodes >${.TARGET}
133 insn-modes.h: genmodes
134 ${_MKTARGET_CREATE}
135 ./genmodes -h >${.TARGET}
136 min-insn-modes.c: genmodes
137 ${_MKTARGET_CREATE}
138 ./genmodes -m >${.TARGET}
139 genmodes.lo: ${HH_NORTL}
140 genmodes: genmodes.lo build-errors.lo
141 ${_MKTARGET_LINK}
142 ${HOST_LINK.cc} -o ${.TARGET} ${.ALLSRC} ${NBCOMPATLIB} ${HOSTLIBIBERTY}
143
144 gcov-iov.h: gcov-iov
145 ${_MKTARGET_CREATE}
146 ./gcov-iov "${BASEVER}" "${DEVPHASE}" >${.TARGET}
147 gcov-iov.lo: ${HH_NORTL}
148 gcov-iov: gcov-iov.lo
149 ${_MKTARGET_CREATE}
150 ${HOST_LINK.cc} -o ${.TARGET} ${.ALLSRC} ${NBCOMPATLIB} ${HOSTLIBIBERTY}
151
152 tm_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.
165 CLEANFILES+= auto-build.h
166 HOST_CFLAGS+= -I${.OBJDIR}
167 auto-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 --build=`${HOST_SH} ${GNUHOSTDIST}/config.guess` \
180 --host=`${HOST_SH} ${GNUHOSTDIST}/config.guess` \
181 --target=${MACHINE_GNU_PLATFORM} && \
182 mv auto-host.h ../auto-build.h) && \
183 rm -rf .ab
184
185 #
186 # These are copies of files we build for the build host that are used
187 # by the genfoo programs.
188 #
189
190 build-rtl.c: rtl.c \
191 ${G_RTL_H} real.h ${G_GCC_H} errors.h gtype-desc.h
192 ${_MKTARGET_CREATE}
193 rm -f build-rtl.c
194 ${TOOL_SED} -e 's/<config[.]h/hconfig.h/' \
195 ${GNUHOSTDIST}/gcc/rtl.c >${.TARGET}
196 build-rtl.lo: ${HH}
197
198 build-print-rtl.c: print-rtl.c \
199 ${G_RTL_BASE_H} ${G_GTM_H} hard-reg-set.h
200 ${_MKTARGET_CREATE}
201 rm -f build-print-rtl.c
202 ${TOOL_SED} -e 's/<config[.]h/hconfig.h/' \
203 ${GNUHOSTDIST}/gcc/print-rtl.c >${.TARGET}
204 build-print-rtl.lo: ${HH}
205 build/print-rtl.o: print-rtl.c $(BCONFIG_H) $(SYSTEM_H) coretypes.h \
206 $(GTM_H) $(RTL_BASE_H)
207
208
209 build-bitmap.c: bitmap.c \
210 ${G_RTL_H} flags.h ${G_BASIC_BLOCK_H} ${REGS_H} ${G_GCC_H} gtype-desc.h
211 ${_MKTARGET_CREATE}
212 rm -f build-bitmap.c
213 ${TOOL_SED} -e 's/<config[.]h/hconfig.h/' \
214 ${GNUHOSTDIST}/gcc/bitmap.c >${.TARGET}
215 build-bitmap.lo: ${HH}
216
217 build-errors.c: errors.c errors.h
218 ${_MKTARGET_CREATE}
219 rm -f build-errors.c
220 cat ${GNUHOSTDIST}/gcc/errors.c >${.TARGET}
221 build-errors.lo: ${HH_NORTL}
222
223 build-varray.c: varray.c \
224 ${G_RTL_H} ${G_GCC_H} ${TREE_H} bitmap.h errors.h
225 ${_MKTARGET_CREATE}
226 rm -f build-varray.c
227 ${TOOL_SED} -e 's/<config[.]h/hconfig.h/' \
228 ${GNUHOSTDIST}/gcc/varray.c >${.TARGET}
229 build-varray.lo: ${HH} gtype-desc.h
230
231 build-ggc-none.c: ggc-none.c \
232 ${G_GCC_H} gtype-desc.h
233 ${_MKTARGET_CREATE}
234 rm -f build-ggc-none.c
235 ${TOOL_SED} -e 's/<config[.]h/hconfig.h/' \
236 ${GNUHOSTDIST}/gcc/ggc-none.c >${.TARGET}
237 build-ggc-none.lo: ${HH}
238
239 #
240 # The normal insn-foo generators
241 #
242 .for f in gensupport.c read-rtl.c dummy-conditions.c
243 ${f:R}.lo: ${HH}
244 .endfor
245
246 #
247 # There are 5 main classes of generator programs. Ones
248 # that are self contained, ones that use error reporting
249 # mechanisms, ones that use the MD reader, and ones that
250 # use the RTL reader.
251 #
252 GENPROG_ERROR_DEPENDS= ${G_BUILD_ERRORS:.o=.lo}
253 GENPROG_READER_DEPENDS= ${G_BUILD_MD:.o=.lo} ${GENPROG_ERROR_DEPENDS}
254 GENPROG_RTL_DEPENDS= ${G_BUILD_RTL:.o=.lo} ${GENPROG_READER_DEPENDS} ${GENPROG_ERROR_DEPENDS}
255
256 #
257 # First we generate the rules for the generators.
258 #
259 .for f in attr attr-common attrtab automata codes conditions config emit \
260 extract flags opinit output peep preds recog mddump condmd
261 gen${f}.lo: ${HH} gen${f}.c
262 gen${f}: gen${f}.lo ${GENPROG_RTL_DEPENDS}
263 ${_MKTARGET_LINK}
264 ${HOST_LINK.cc} -o ${.TARGET} ${.ALLSRC} ${NBCOMPATLIB} ${HOSTLIBIBERTY} ${LDFLAGS.${.TARGET}}
265 CLEANFILES+= gen${f} gen${f}.lo
266 .endfor
267
268 .for f in mddeps constants enums
269 gen${f}.lo: ${HH} gen${f}.c
270 gen${f}: gen${f}.lo ${GENPROG_READER_DEPENDS}
271 ${_MKTARGET_LINK}
272 ${HOST_LINK.cc} -o ${.TARGET} ${.ALLSRC} ${NBCOMPATLIB} ${HOSTLIBIBERTY} ${LDFLAGS.${.TARGET}}
273 CLEANFILES+= gen${f} gen${f}.lo
274 .endfor
275
276 .for f in check checksum
277 gen${f}.lo: ${HH} gen${f}.c
278 gen${f}: gen${f}.lo
279 ${_MKTARGET_LINK}
280 ${HOST_LINK.cc} -o ${.TARGET} ${.ALLSRC} ${NBCOMPATLIB} ${HOSTLIBIBERTY} ${LDFLAGS.${.TARGET}}
281 CLEANFILES+= gen${f} gen${f}.lo
282 .endfor
283
284 .include "../../Makefile.hooks"
285
286 #
287 # Second we generate the rules for the generated files. There
288 # are 3 main classes: RTL based or not, plus special cases.
289 #
290 # The special cases are: gencheck, genattrtab, genopinit,
291 # gencondmd
292 #
293
294 # RTL based files
295 .for f in attr.h attr-common.h codes.h config.h flags.h \
296 automata.c emit.c extract.c output.c peep.c recog.c
297 insn-${f}: gen${f:R} ${G_md_file} insn-conditions.md
298 ${_MKTARGET_CREATE}
299 ./gen${f:R} ${G_md_file} insn-conditions.md >${.TARGET}
300 CLEANFILES+= insn-${f}
301 .endfor
302
303 # normal files
304 .for f in constants.h enums.c
305 insn-${f}: gen${f:R} ${G_md_file}
306 ${_MKTARGET_CREATE}
307 ./gen${f:R} ${G_md_file} >${.TARGET}
308 CLEANFILES+= insn-${f}
309 .endfor
310
311 # genconditions outputs gencondmd.c
312 gencondmd.c: genconditions ${G_md_file}
313 ${_MKTARGET_CREATE}
314 ./genconditions ${G_md_file} >${.TARGET}
315 CLEANFILES+= gencondmd.c
316
317 # gencheck outputs tree-check.h
318 tree-check.h: gencheck
319 ${_MKTARGET_CREATE}
320 ./gencheck >${.TARGET}
321 CLEANFILES+= tree-check.h
322
323 # Some generators output is not the normal name.
324 BUILDSYMLINKS+= insn-check.h tree-check.h
325
326 # genattrtab has three output files
327 # XXX fix me
328 insn-attrtab.c insn-dfatab.c insn-latencytab.c: genattrtab ${G_md_file} insn-conditions.md
329 ${_MKTARGET_CREATE}
330 ./genattrtab ${G_md_file} insn-conditions.md -Ainsn-attrtab.c -Dinsn-dfatab.c -Linsn-latencytab.c
331 CLEANFILES+= insn-attrtab.c insn-dfatab.c insn-latencytab.c
332
333 # genopinit has two output files
334 insn-opinit.c insn-opinit.h: genopinit ${G_md_file} insn-conditions.md
335 ${_MKTARGET_CREATE}
336 ./genopinit ${G_md_file} insn-conditions.md -hinsn-opinit.h -cinsn-opinit.c
337 CLEANFILES+= insn-opinit.h insn-opinit.c
338
339 LDFLAGS.genautomata+= -lm
340
341 # gencondmd outputs a special .md file
342 insn-conditions.md: gencondmd
343 ./gencondmd >${.TARGET}
344 CLEANFILES+= insn-conditions.md
345
346
347 #
348 # Required hard-coded dependancies.
349 #
350 genextract.lo: insn-config.h
351 gencondmd.lo: tm_p.h tm-constrs.h
352 read-rtl.lo gencodes.lo genattrtab.lo genautomata.lo: insn-constants.h
353 genattr-common.lo gensupport.lo genconditions.lo: insn-constants.h
354 genattr.lo genflags.lo genemit.lo genconfig.lo gencheck.lo: insn-constants.h
355 genopinit.lo genrecog.lo genpreds.lo genoutput.lo genpeep.lo: insn-constants.h
356 build-ggc-none.lo: gtype-desc.h
357 ggc-none.o: gtype-desc.h
358
359 insn-attrtab.o: insn-config.h
360 insn-extract.o: insn-config.h
361 toplev.d toplev.o: options.h
362 coverage.d: gcov-iov.h
363 gcov-io.h: gcov-iov.h
364 alias.d alias.o: insn-constants.h tm_p.h
365 cgraph.d cgraphunit.d cgraphunit.o: gcov-io.h
366 vec.lo: gtype-desc.h
367 gtype-desc.d gtype-desc.o: insn-constants.h
368 insn-emit.d insn-emit.o: tm-constrs.h
369 insn-attr.h: insn-attr-common.h
370 asan.d asan.o: insn-opinit.h
371 data-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
372 data-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
373 gcov-io.h: gcov-iov.h
374 df-scan.d df-scan.o: target-hooks-def.h
375 read-md.d read-md.o read-md.lo: auto-build.h
376
377 # XXX make all hooks generated for now.
378 final.o: target-hooks-def.h c-family/c-target-hooks-def.h common/common-target-hooks-def.h
379
380 .if ${GCC_MACHINE_ARCH} == "alpha"
381 alpha.d alpha.o: tm-constrs.h tm_p.h insn-opinit.h target-hooks-def.h
382 .endif
383
384 .if ${MACHINE_CPU} == "arm"
385 arm.d arm.o: insn-constants.h tm_p.h insn-opinit.h target-hooks-def.h
386 .endif
387
388 .if ${GCC_MACHINE_ARCH} == "i386" || ${GCC_MACHINE_ARCH} == "x86_64"
389 i386.d i386.o: tm-constrs.h
390 .endif
391
392 .if ${GCC_MACHINE_ARCH} == "vax"
393 CPPFLAGS+=-I${.CURDIR}/../../lib/libgcc/libgcov/arch/${GCC_MACHINE_ARCH}
394 COPTS.expmed.c=-O0
395 COPTS.recog.c=-O0
396 .endif
397
398 CFLAGS+= -Wno-stack-protector
399
400 .if ${GCC_MACHINE_ARCH} == "m68000" || ${GCC_MACHINE_ARCH} == "m68k"
401 COPTS.lambda-code.c= -O0
402 COPTS.tree-loop-linear.c= -O0
403 .endif
404
405 COPTS.tree.c= ${${ACTIVE_CC} == "clang" :? -O0 :}
406
407 .PATH: ${DIST}/gcc ${DIST}/libiberty ${GCCARCH} ${G_out_file:H} ${DIST}/include
408 .PATH: ${DIST}/gcc/config
409