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