mknative-gcc revision 1.88
1#!/bin/sh
2#	$NetBSD: mknative-gcc,v 1.88 2016/10/05 14:16:12 christos Exp $
3#
4# Shell script for generating all the constants needed for a native
5# platform build of gcc.
6#
7# This version is for GCC 5.3
8
9# initialise
10
11_TMPDIR=$2
12_TOP=$3
13_SRC=$4
14_PLATFORM=$5
15_DESTDIR=$6
16_TOOLDIR=$7
17_VPATH=`grep VPATH ${_TMPDIR}/Makefile | sed 's,^.*=[ 	]*,,'`
18_GNU_DIST=`cd ${_VPATH}; pwd`
19
20if [ -z "$_DESTDIR" ]; then
21	echo "\$_DESTDIR is empty" 2>&1
22	exit 1
23fi
24
25. $_TOP/tools/gcc/mknative.common
26
27_OUTDIR="$_TOP/external/gpl3/gcc"
28_OUTDIRBASE="external/gpl3/gcc"
29
30sanitise_includes () {
31	sed \
32		-e "s,-I$_DESTDIR/usr/include,,g" \
33		-e "s,-I$_SRC/external/lgpl3/mpfr/dist/src,,g" \
34		-e "s,-I$_SRC/external/lgpl3/mpc/dist/src,,g" \
35		-e "s,-I$_SRC/external/lgpl3/gmp/lib/libgmp/arch/[a-z_0-9-]*,,g" \
36		-e "s,-I$_TOOLDIR/include,,g" \
37		-e "s,-I/usr/include/[^ 	]*,,"
38}
39
40##### lib/libg2c #####
41
42get_libg2c () {
43	mkdir -p $_OUTDIR/lib/libg2c3/arch/$MACHINE_ARCH
44
45	write_c $_OUTDIRBASE/lib/libg2c3/arch/$MACHINE_ARCH/config.h <$_TMPDIR/$_PLATFORM/libf2c/libU77/config.h
46	write_c $_OUTDIRBASE/lib/libg2c3/arch/$MACHINE_ARCH/g2c.h <$_TMPDIR/$_PLATFORM/libf2c/g2c.h
47
48	{
49		getvars $_PLATFORM/libf2c/Makefile \
50			F2CEXT
51		getvars $_PLATFORM/libf2c/libF77/Makefile \
52			ALL_CFLAGS OBJS
53		getvars $_PLATFORM/libf2c/libI77/Makefile \
54			ALL_CFLAGS OBJS | sed 's,=,+=,'
55		getvars $_PLATFORM/libf2c/libU77/Makefile \
56			ALL_CFLAGS OBJS | sed 's,=,+=,'
57	} | write_mk $_OUTDIRBASE/lib/libg2c3/arch/$MACHINE_ARCH/defs.mk
58}
59
60##### lib/libgcc #####
61
62skipsoftfloat() {
63	sed -e 's@${GNUHOSTDIST}/libgcc/soft-fp/[a-z0-9]*.c@@g' -e 's@ @@g'
64}
65
66get_libgcc () {
67	_subdir="$1"
68	mkdir -p $_OUTDIR/lib/lib$_subdir/arch
69
70	# DPBIT, FPBIT only used on mn10[23]00, we don't need them.
71	# XXX we should probably grab everything Just In Case for
72	# the future.
73
74	mkdir -p $_OUTDIR/lib/lib$_subdir/arch/$MACHINE_ARCH
75	cd $_TMPDIR/$_PLATFORM/libgcc
76	{
77		getvars $_PLATFORM/libgcc/Makefile \
78			INCLUDES LIB2ADDEH LIB2ADD_ST \
79			LIB1ASMFUNCS LIB1ASMSRC \
80			LIB2_DIVMOD_FUNCS LIB2FUNCS_ST \
81			LIB2FUNCS_EXTRA \
82			LIBGCC2_CFLAGS \
83			SHLIB_MKMAP SHLIB_MKMAP_OPTS \
84			SHLIB_MAPFILES SHLIB_NM_FLAGS
85		getvars $_PLATFORM/libgcc/Makefile LIB2ADD | skipsoftfloat
86		getvars gcc/Makefile \
87			NOEXCEPTION_FLAGS EXTRA_HEADERS
88		getlinks config.status libgcc
89	}	| sanitise_includes \
90		| write_mk $_OUTDIRBASE/lib/lib$_subdir/arch/$MACHINE_ARCH/defs.mk
91
92	if [ "${MACHINE_ARCH}" = "m68000" ]
93	then
94		ex <<__EOF__ $_OUTDIR/lib/lib$_subdir/arch/$MACHINE_ARCH/defs.mk
95/G_LIBGCC2_CFLAGS/ s/-fPIC//
96wq
97__EOF__
98	fi
99
100	for f in auto-target.h; do
101		write_c $_OUTDIRBASE/lib/lib$_subdir/arch/$MACHINE_ARCH/$f \
102		    <$_TMPDIR/$_PLATFORM/libgcc/$f
103	done
104}
105
106##### lib/libgcov #####
107
108get_libgcov () {
109	_subdir="$1"
110	_mf="$2"
111
112	mkdir -p $_OUTDIR/lib/lib$_subdir/libgcov/arch/$MACHINE_ARCH
113
114	{
115		getvars $_mf \
116			LIBGCOV_MERGE \
117			LIBGCOV_PROFILER \
118			LIBGCOV_INTERFACE \
119			LIBGCOV_DRIVER
120	} | write_mk $_OUTDIRBASE/lib/lib$_subdir/libgcov/arch/$MACHINE_ARCH/defs.mk
121
122	write_c $_OUTDIRBASE/lib/lib$_subdir/libgcov/arch/$MACHINE_ARCH/gcov-iov.h \
123	   <$_TMPDIR/gcc/gcov-iov.h
124
125}
126
127##### lib/libiberty #####
128
129get_gcc_libiberty () {
130	_subdir="$1"
131	_libibertydir="lib/libiberty"
132	mkdir -p $_OUTDIR/$_libibertydir/arch/$MACHINE_ARCH
133
134	getvars libiberty/Makefile \
135		ALLOCA EXTRA_OFILES LIBOBJS REQUIRED_OFILES \
136		| write_mk $_OUTDIRBASE/$_libibertydir/defs.mk
137
138	write_c $_OUTDIRBASE/$_libibertydir/arch/$MACHINE_ARCH/config.h \
139		<$_TMPDIR/libiberty/config.h
140}
141
142##### lib/libdecnumber #####
143
144get_libdecnumber () {
145	_subdir="$1"
146
147	mkdir -p $_OUTDIR/usr.bin/$_subdir/arch/$MACHINE_ARCH
148	write_c $_OUTDIRBASE/usr.bin/$_subdir/arch/$MACHINE_ARCH/config.h \
149		<$_TMPDIR/libdecnumber/config.h
150}
151
152##### lib/libgomp #####
153
154get_libgomp () {
155	_subdir="$1"
156
157	mkdir -p $_OUTDIR/lib/$_subdir/arch/$MACHINE_ARCH
158	write_c $_OUTDIRBASE/lib/$_subdir/arch/$MACHINE_ARCH/config.h \
159		<$_TMPDIR/$_PLATFORM/libgomp/config.h
160	write_c $_OUTDIRBASE/lib/$_subdir/arch/$MACHINE_ARCH/libgomp_f.h \
161		<$_TMPDIR/$_PLATFORM/libgomp/libgomp_f.h
162	write_mk $_OUTDIRBASE/lib/$_subdir/arch/$MACHINE_ARCH/libgomp.spec \
163		<$_TMPDIR/$_PLATFORM/libgomp/libgomp.spec
164	write_c $_OUTDIRBASE/lib/$_subdir/arch/$MACHINE_ARCH/omp.h \
165		<$_TMPDIR/$_PLATFORM/libgomp/omp.h
166}
167
168##### lib/libbacktrace #####
169
170get_libbacktrace () {
171	_subdir="$1"
172
173	mkdir -p $_OUTDIR/lib/$_subdir/arch/$MACHINE_ARCH
174	write_c $_OUTDIRBASE/lib/$_subdir/arch/$MACHINE_ARCH/config.h \
175		<$_TMPDIR/$_subdir/config.h
176	write_c $_OUTDIRBASE/lib/$_subdir/arch/$MACHINE_ARCH/backtrace-supported.h \
177		<$_TMPDIR/$_subdir/backtrace-supported.h
178}
179
180##### lib/libobjc #####
181
182get_libobjc () {
183	_subdir="$1/arch/$MACHINE_ARCH"
184	_options="ALL_OPT_FILES"
185
186	mkdir -p $_OUTDIR/lib/$_subdir
187
188	{
189		if [ -n "$_options" ]; then
190			getvars gcc/Makefile $_options
191		fi
192		getvars $_PLATFORM/libobjc/Makefile \
193			ALL_CFLAGS INCLUDES OBJC_SOURCE_FILES C_SOURCE_FILES OBJC_H \
194			| sed "s,$_GNU_DIST,\${GNUHOSTDIST},g"
195		getlinks $_TMPDIR/$_PLATFORM/libgcc/config.status libgcc
196	} | sanitise_includes \
197	  | write_mk $_OUTDIRBASE/lib/$_subdir/defs.mk
198
199	write_c $_OUTDIRBASE/lib/$_subdir/config.h \
200		<$_TMPDIR/$_PLATFORM/libobjc/config.h
201}
202
203##### lib/libstdc++-v3 #####
204
205get_libstdcxx_v3 () {
206	_subdir="$1"
207	_ver="$2"
208
209	mkdir -p $_OUTDIR/lib/$_subdir/arch/$MACHINE_ARCH
210
211	_build_headers="c++config.h cxxabi_tweaks.h gthr-posix.h gthr-single.h gthr.h"
212	_headers1="c_base_headers_extra_install"
213	_headers1="$_headers1 tr1_headers tr2_headers decimal_headers c_compatibility_headers_install"
214	_headers1="$_headers1 debug_headers parallel_headers"
215	_headers2="host_headers thread_host_headers"
216	_pf_headers="profile_headers profile_impl_headers"
217	_pb_headers="pb_headers1 pb_headers2 pb_headers3 pb_headers4 pb_headers5 pb_headers6 pb_headers7"
218
219	# build files
220	for h in $_build_headers; do
221		write_c $_OUTDIRBASE/lib/$_subdir/arch/$MACHINE_ARCH/$h \
222			<$_TMPDIR/$_PLATFORM/libstdc++-v3/include/$_PLATFORM/bits/$h
223	done
224
225	write_c $_OUTDIRBASE/lib/$_subdir/arch/$MACHINE_ARCH/gstdint.h \
226		<$_TMPDIR/$_PLATFORM/libstdc++-v3/include/gstdint.h
227
228	{
229		# libsupc++
230		getvars $_PLATFORM/libstdc++-v3/libsupc++/Makefile \
231			sources | sed 's/^G_sources=/G_LIBSUPCXX_SOURCES=/'
232		getvars $_PLATFORM/libstdc++-v3/libsupc++/Makefile \
233			c_sources | sed 's/^G_c_sources=/G_LIBSUPCXX_C_SOURCES=/'
234
235		# includes
236		getvars $_PLATFORM/libstdc++-v3/include/Makefile \
237			c_base_headers std_headers | sed -e 's#/[^ 	][^ 	]*/##g' -e 's/\${GNUHOSTDIST}//g'
238
239		# src
240		getvars $_PLATFORM/libstdc++-v3/src/Makefile \
241			libstdc___la_SOURCES | sed 's/^G_libstdc___la_SOURCES=/G_SRC_SOURCES=/'
242		getvars $_PLATFORM/libstdc++-v3/src/c++11/Makefile \
243			libc__11convenience_la_SOURCES | \
244			sed -e 's/^G_libc__11convenience_la_SOURCES=/G_CPP11_SOURCES=/' \
245			    -e 's/codecvt.cc/c11-codecvt.cc/'
246		getvars $_PLATFORM/libstdc++-v3/src/c++98/Makefile \
247			GLIBCXX_ABI_FLAGS libc__98convenience_la_SOURCES | \
248			sed -e 's/^G_libc__98convenience_la_SOURCES=/G_CPP98_SOURCES=/' \
249			    -e 's/codecvt.cc/c98-codecvt.cc/'
250		getvars $_PLATFORM/libstdc++-v3/Makefile ATOMICITY_SRCDIR \
251			BASIC_FILE_CC CLOCALE_CC CCODECVT_CC CCOLLATE_CC \
252			CCTYPE_CC  CMESSAGES_CC CMONEY_CC CNUMERIC_CC CTIME_CC \
253			CPU_OPT_BITS_RANDOM
254
255		# includes
256		getvars $_PLATFORM/libstdc++-v3/include/Makefile \
257			backward_headers c_base_headers_extra $_headers1 $_pb_headers | \
258				sed -e 's#\${GNUHOSTDIST}/libstdc++-v3/include/##g'
259		getvars $_PLATFORM/libstdc++-v3/include/Makefile \
260			bits_headers ext_headers $_headers2 | \
261				sed -e 's#\${GNUHOSTDIST}/libstdc++-v3/include/##g' -e 's#\${GNUHOSTDIST}/libstdc++-v3/config/##g'
262		getvars $_PLATFORM/libstdc++-v3/include/Makefile \
263			$_pf_headers | sed -e 's#\${GNUHOSTDIST}/libstdc++-v3/include/profile/##g'
264		getvars $_PLATFORM/libstdc++-v3/include/Makefile \
265			BASIC_FILE_H ALLOCATOR_H CSTDIO_H CLOCALE_H CMESSAGES_H CTIME_H
266		getlinks $_TMPDIR/$_PLATFORM/libgcc/config.status libgcc
267	} | sanitise_includes \
268	  | write_mk $_OUTDIRBASE/lib/$_subdir/arch/$MACHINE_ARCH/defs.mk
269}
270
271##### usr.bin/gcc* #####
272
273get_gcc_bootstrap () {
274	_subdir="$1"
275	mkdir -p $_OUTDIR/usr.bin/$_subdir/arch/$MACHINE_ARCH
276	for f in auto-host tm config; do
277		write_c $_OUTDIRBASE/usr.bin/$_subdir/arch/$MACHINE_ARCH/$f.h <$_TMPDIR/gcc/$f.h
278	done
279	# XXXGCC5 don't really want to copy insn-modes as we build
280	# it but libgcc needs to too early yet
281	for f in insn-modes; do
282		write_c $_OUTDIRBASE/usr.bin/$_subdir/arch/$MACHINE_ARCH/$f.h <$_TMPDIR/gcc/$f.h
283	done
284}
285
286get_gcc () {
287	_subdir="$1"
288	mkdir -p $_OUTDIR/usr.bin/$_subdir/arch/$MACHINE_ARCH
289	mkdir -p $_OUTDIR/usr.bin/libcpp/arch/$MACHINE_ARCH
290	mkdir -p $_OUTDIR/usr.bin/include/arch
291	_buildname="BUILD_"
292	_libcppsubdir=""
293	_extravars="TM_H ALL_OPT_FILES"
294	_hconfig_h=""
295	_extravars2="tm_file_list build_xm_include_list"
296	_extravars3="tm_p_include_list"
297
298	{
299		getvars gcc/Makefile \
300			${_buildname}EARLY_SUPPORT ${_buildname}ERRORS ${_buildname}PRINT \
301			${_buildname}RTL ${_buildname}SUPPORT ${_buildname}VARRAY \
302			${_buildname}MD | \
303		    sed -e 's#build/errors.o#build-errors.o#g' \
304			-e 's#build/print-rtl.o#build-print-rtl.o#g' \
305			-e 's#build/rtl.o#build-rtl.o#g' \
306			-e 's#build/varray.o#build-varray.o#g' \
307			-e 's#build/ggc-none.o#build-ggc-none.o#g' \
308			-e 's#build/##g'
309		getvars gcc/Makefile \
310			ALL_CFLAGS ALL_CPPFLAGS C_AND_OBJC_OBJS C_OBJS CCCP_OBJS \
311			GCC_OBJS GCOV_OBJS GXX_OBJS GTM_H PROTO_OBJS ${_extravars1} \
312			INCLUDES md_file OBJC_OBJS OBJS out_file version \
313			BUILD_PREFIX RTL_H RTL_BASE_H TREE_H ${_hconfig_h} BASIC_BLOCK_H GCC_H \
314			GGC_H \
315			GTFILES_SRCDIR GTFILES_FILES_FILES GTFILES_FILES_LANGS \
316			GTFILES GTFILES_LANG_DIR_NAMES NOEXCEPTION_FLAGS \
317			NATIVE_SYSTEM_HEADER_DIR \
318			tm_defines host_xm_file host_xm_defines tm_p_file \
319			target_cpu_default ${_extravars} ${_extravars2} \
320			lang_specs_files ${_extravars3} \
321			common_out_file \
322				| sanitise_includes
323		getvars gcc/Makefile \
324			LIB2ADDEHDEP | sed 's/unwind.inc//'
325		getvars gcc/Makefile \
326			CXX_OBJS CXX_C_OBJS | sed 's/cp\///g'
327		getvars gcc/Makefile \
328			F77_OBJS | sed 's/f\///g'
329		getvars libcpp/Makefile \
330			libcpp_a_OBJS
331		getvars gcc/Makefile \
332			ENABLE_SHARED
333		echo G_SHLIB_LINK="$CC -shared"
334		echo G_SHLIB_MULTILIB=.
335	} | write_mk $_OUTDIRBASE/usr.bin/$_subdir/arch/$MACHINE_ARCH/defs.mk
336
337	getvars gcc/Makefile \
338		EXTRA_HEADERS \
339			| write_mk $_OUTDIRBASE/usr.bin/include/arch/$MACHINE_ARCH.mk
340
341	write_c $_OUTDIRBASE/usr.bin/libcpp/arch/$MACHINE_ARCH/config.h <$_TMPDIR/libcpp/config.h
342	hfiles='auto-host configargs config bconfig bversion plugin-version multilib tm'
343	for f in $hfiles; do
344		write_c $_OUTDIRBASE/usr.bin/$_subdir/arch/$MACHINE_ARCH/$f.h <$_TMPDIR/gcc/$f.h
345		if [ "${MACHINE_ARCH}" = "powerpc" -a "${f}" = "configargs" ]
346		then
347			ex <<__EOF__ $_OUTDIR/usr.bin/$_subdir/arch/$MACHINE_ARCH/$f.h
348/configuration_arguments/ s/$//
349ya
350i
351#ifdef _SOFT_FLOAT
352.
353pu
354s/";$/ -with-float=soft";/
355a
356#else
357#endif
358.
359. m +1
360/configure_default_options/ s/{ NULL.*$//
361a
362#ifdef _SOFT_FLOAT
363  { "float", "soft" },
364#endif
365  { NULL, NULL }
366};
367.
368wq
369__EOF__
370		fi
371		if [ "${f}" = "configargs" ]
372		then
373			_srcquoted=$(echo "$_SRC" | sed 's/\//\\\//g')
374			ex <<__EOF__ $_OUTDIR/usr.bin/$_subdir/arch/$MACHINE_ARCH/$f.h
375/static const char configuration_arguments/ s/$_srcquoted/\/usr\/src/g
376wq
377__EOF__
378		fi
379	done
380
381	# keep identical
382	for f in all-tree.def; do
383		cp $_TMPDIR/gcc/$f $_OUTDIR/usr.bin/$_subdir/arch/$MACHINE_ARCH/$f
384	done
385
386	# special transforms
387	for f in gtyp-input.list; do
388		sed -e 's/^.*external\/gpl3\/gcc\/dist/SRCDIR/' < $_TMPDIR/gcc/$f > $_OUTDIR/usr.bin/$_subdir/arch/$MACHINE_ARCH/$f
389	done
390
391	# special platforms
392	if [ "${MACHINE_ARCH}" = "sh3el" -o "${MACHINE_ARCH}" = "sh3eb" ]; then
393		write_c $_OUTDIRBASE/usr.bin/$_subdir/arch/$MACHINE_ARCH/sysroot-suffix.h <$_TMPDIR/gcc/sysroot-suffix.h
394	fi
395
396	if [ "${MACHINE_ARCH}" = "i386" -o "${MACHINE_ARCH}" = "x86_64" ]; then
397		write_c $_OUTDIRBASE/usr.bin/$_subdir/arch/$MACHINE_ARCH/i386-builtin-types.inc <$_TMPDIR/gcc/i386-builtin-types.inc
398	fi
399}
400
401##### main #####
402
403case "$1" in
404# .mk and .h files for libgcc bootstrap (from host build)
405
406libgcc*-bootstrap)
407	get_libgcc gcc
408	get_libgcov gcc $_PLATFORM/libgcc/Makefile
409	get_gcc_bootstrap gcc
410	exit 0
411	;;
412
413libstdc++-bootstrap)
414	get_libstdcxx_v3 libstdc++-v3 gcc
415	exit 0
416	;;
417
418gcc*)
419	get_gcc gcc
420	get_libgcc gcc
421	get_libgcov gcc $_PLATFORM/libgcc/Makefile
422	get_gcc_bootstrap gcc
423	get_gcc_libiberty gcc
424	get_libobjc libobjc
425	get_libstdcxx_v3 libstdc++-v3 gcc
426	get_libdecnumber libdecnumber
427	get_libgomp libgomp
428	get_libbacktrace libbacktrace
429	exit 0
430	;;
431
432
433*)
434	echo invalid arguments;
435	exit 1
436	;;
437esac
438