#!/bin/sh # $NetBSD: mknative-gcc.old,v 1.11 2023/07/28 08:05:29 mrg Exp $ # # Shell script for generating all the constants needed for a native # platform build of gcc. # # This version is for GCC 10.3 # initialise _TMPDIR=$2 _TOP=$3 _SRC=$4 _PLATFORM=$5 _MACHINE_ARCH=$6 _DESTDIR=$7 _TOOLDIR=$8 _VPATH=`grep VPATH ${_TMPDIR}/Makefile | sed 's,^.*=[ ]*,,'` _GNU_DIST=`cd ${_VPATH}; pwd` if [ -z "$_DESTDIR" ]; then echo "\$_DESTDIR is empty" 2>&1 exit 1 fi . $_TOP/tools/gcc/mknative.common case $0 in *mknative-gcc.old) _OUTDIRBASE="external/gpl3/gcc.old" ;; *) _OUTDIRBASE="external/gpl3/gcc" ;; esac _OUTDIR="$_TOP/$_OUTDIRBASE" sanitise_includes () { sed \ -e "s,-I$_DESTDIR/usr/include,,g" \ -e "s,-I$_SRC/external/lgpl3/mpfr/dist/src,,g" \ -e "s,-I$_SRC/external/lgpl3/mpc/dist/src,,g" \ -e "s,-I$_SRC/external/lgpl3/gmp/lib/libgmp/arch/[a-z_0-9-]*,,g" \ -e "s,-I$_TOOLDIR/include,,g" \ -e "s,-I/usr/include/[^ ]*,," } ##### lib/libg2c ##### get_libg2c () { mkdir -p $_OUTDIR/lib/libg2c3/arch/$_MACHINE_ARCH write_c $_OUTDIRBASE/lib/libg2c3/arch/$_MACHINE_ARCH/config.h <$_TMPDIR/$_PLATFORM/libf2c/libU77/config.h write_c $_OUTDIRBASE/lib/libg2c3/arch/$_MACHINE_ARCH/g2c.h <$_TMPDIR/$_PLATFORM/libf2c/g2c.h { getvars $_PLATFORM/libf2c/Makefile \ F2CEXT getvars $_PLATFORM/libf2c/libF77/Makefile \ ALL_CFLAGS OBJS getvars $_PLATFORM/libf2c/libI77/Makefile \ ALL_CFLAGS OBJS | sed 's,=,+=,' getvars $_PLATFORM/libf2c/libU77/Makefile \ ALL_CFLAGS OBJS | sed 's,=,+=,' } | write_mk $_OUTDIRBASE/lib/libg2c3/arch/$_MACHINE_ARCH/defs.mk } ##### lib/libgcc ##### get_libgcc () { _subdir="$1" mkdir -p $_OUTDIR/lib/lib$_subdir/arch # DPBIT, FPBIT only used on mn10[23]00, we don't need them. # XXX we should probably grab everything Just In Case for # the future. mkdir -p $_OUTDIR/lib/lib$_subdir/arch/$_MACHINE_ARCH cd $_TMPDIR/$_PLATFORM/libgcc { getvars $_PLATFORM/libgcc/Makefile \ INCLUDES \ INTERNAL_CFLAGS \ LIB2ADD LIB2ADDEH LIB2ADD_ST \ LIB1ASMFUNCS LIB1ASMSRC \ LIB2_DIVMOD_FUNCS LIB2FUNCS_ST \ LIB2FUNCS_EXTRA \ LIBGCC2_CFLAGS \ SHLIB_MKMAP SHLIB_MKMAP_OPTS \ SHLIB_MAPFILES SHLIB_NM_FLAGS getvars gcc/Makefile \ NOEXCEPTION_FLAGS EXTRA_HEADERS } | sanitise_includes \ | write_mk $_OUTDIRBASE/lib/lib$_subdir/arch/$_MACHINE_ARCH/defs.mk cd $_TMPDIR/$_PLATFORM/libgcc { getvars $_PLATFORM/libgcc/Makefile \ enable_execute_stack \ unwind_header md_unwind_header \ sfp_machine_header thread_header } | sanitise_includes \ | write_mk $_OUTDIRBASE/lib/lib$_subdir/arch/$_MACHINE_ARCH/gthr-defs.mk if [ "${_MACHINE_ARCH}" = "m68000" ] then ex <<__EOF__ $_OUTDIR/lib/lib$_subdir/arch/$_MACHINE_ARCH/defs.mk /G_LIBGCC2_CFLAGS/ s/-fPIC// wq __EOF__ fi for f in auto-target.h; do write_c $_OUTDIRBASE/lib/lib$_subdir/arch/$_MACHINE_ARCH/$f \ <$_TMPDIR/$_PLATFORM/libgcc/$f done } ##### lib/libgcov ##### get_libgcov () { _subdir="$1" _mf="$2" mkdir -p $_OUTDIR/lib/lib$_subdir/libgcov/arch/$_MACHINE_ARCH { getvars $_mf \ LIBGCOV_MERGE \ LIBGCOV_PROFILER \ LIBGCOV_INTERFACE \ LIBGCOV_DRIVER } | write_mk $_OUTDIRBASE/lib/lib$_subdir/libgcov/arch/$_MACHINE_ARCH/defs.mk write_c $_OUTDIRBASE/lib/lib$_subdir/libgcov/arch/$_MACHINE_ARCH/gcov-iov.h \ <$_TMPDIR/gcc/gcov-iov.h } ##### lib/libiberty ##### get_gcc_libiberty () { _subdir="$1" _libibertydir="lib/libiberty" mkdir -p $_OUTDIR/$_libibertydir/arch/$_MACHINE_ARCH getvars libiberty/Makefile \ ALLOCA EXTRA_OFILES LIBOBJS REQUIRED_OFILES \ | write_mk $_OUTDIRBASE/$_libibertydir/defs.mk write_c $_OUTDIRBASE/$_libibertydir/arch/$_MACHINE_ARCH/config.h \ <$_TMPDIR/libiberty/config.h } ##### lib/libdecnumber ##### get_libdecnumber () { _subdir="$1" mkdir -p $_OUTDIR/usr.bin/$_subdir/arch/$_MACHINE_ARCH write_c $_OUTDIRBASE/usr.bin/$_subdir/arch/$_MACHINE_ARCH/config.h \ <$_TMPDIR/libdecnumber/config.h } ##### lib/libgomp ##### get_libgomp () { _subdir="$1" mkdir -p $_OUTDIR/lib/$_subdir/arch/$_MACHINE_ARCH getvars $_PLATFORM/libgomp/Makefile \ libgomp_la_SOURCES \ | write_mk $_OUTDIRBASE/lib/$_subdir/defs.mk write_c $_OUTDIRBASE/lib/$_subdir/arch/$_MACHINE_ARCH/config.h \ <$_TMPDIR/$_PLATFORM/libgomp/config.h write_c $_OUTDIRBASE/lib/$_subdir/arch/$_MACHINE_ARCH/libgomp_f.h \ <$_TMPDIR/$_PLATFORM/libgomp/libgomp_f.h write_mk $_OUTDIRBASE/lib/$_subdir/arch/$_MACHINE_ARCH/libgomp.spec \ <$_TMPDIR/$_PLATFORM/libgomp/libgomp.spec write_c $_OUTDIRBASE/lib/$_subdir/arch/$_MACHINE_ARCH/omp.h \ <$_TMPDIR/$_PLATFORM/libgomp/omp.h } ##### lib/libbacktrace ##### get_libbacktrace () { _subdir="$1" mkdir -p $_OUTDIR/lib/$_subdir/arch/$_MACHINE_ARCH write_c $_OUTDIRBASE/lib/$_subdir/arch/$_MACHINE_ARCH/config.h \ <$_TMPDIR/$_PLATFORM/$_subdir/config.h write_c $_OUTDIRBASE/lib/$_subdir/arch/$_MACHINE_ARCH/backtrace-supported.h \ <$_TMPDIR/$_PLATFORM/$_subdir/backtrace-supported.h } ##### lib/libobjc ##### get_libobjc () { _subdir="$1/arch/$_MACHINE_ARCH" _options="ALL_OPT_FILES" mkdir -p $_OUTDIR/lib/$_subdir { if [ -n "$_options" ]; then getvars gcc/Makefile $_options fi getvars $_PLATFORM/libobjc/Makefile \ ALL_CFLAGS INCLUDES OBJC_SOURCE_FILES C_SOURCE_FILES OBJC_H \ | sed "s,$_GNU_DIST,\${GNUHOSTDIST},g" } | sanitise_includes \ | write_mk $_OUTDIRBASE/lib/$_subdir/defs.mk write_c $_OUTDIRBASE/lib/$_subdir/config.h \ <$_TMPDIR/$_PLATFORM/libobjc/config.h } ##### lib/libstdc++-v3 ##### get_libstdcxx_v3 () { _subdir="$1" _ver="$2" mkdir -p $_OUTDIR/lib/$_subdir/arch/$_MACHINE_ARCH _build_headers="c++config.h cxxabi_tweaks.h" _headers1="backward_headers c_base_headers_extra" _headers1="$_headers1 c_base_headers_extra_install" _headers1="$_headers1 tr1_headers tr2_headers" _headers1="$_headers1 decimal_headers c_compatibility_headers_install" _headers1="$_headers1 debug_headers parallel_headers" _headers1="$_headers1 pb_headers1 pb_headers2 pb_headers3 pb_headers4" _headers1="$_headers1 pb_headers5 pb_headers6 pb_headers7" _headers1="$_headers1 bits_headers ext_headers host_headers" _headers1="$_headers1 pstl_headers" _headers1="$_headers1 profile_headers profile_impl_headers" _headers1="$_headers1 experimental_headers experimental_bits_headers" _headers1="$_headers1 ext_host_headers" # build files for h in $_build_headers; do write_c $_OUTDIRBASE/lib/$_subdir/arch/$_MACHINE_ARCH/$h \ <$_TMPDIR/$_PLATFORM/libstdc++-v3/include/$_PLATFORM/bits/$h done write_c $_OUTDIRBASE/lib/$_subdir/arch/$_MACHINE_ARCH/gstdint.h \ <$_TMPDIR/$_PLATFORM/libstdc++-v3/include/gstdint.h write_c $_OUTDIRBASE/lib/$_subdir/arch/$_MACHINE_ARCH/symver-config.h \ <$_TMPDIR/$_PLATFORM/libstdc++-v3/config.h { getvars $_PLATFORM/libstdc++-v3/Makefile \ port_specific_symbol_files getvars $_PLATFORM/libstdc++-v3/src/Makefile \ cxx17_sources \ cxx11_sources \ cxx98_sources # libsupc++ getvars $_PLATFORM/libstdc++-v3/libsupc++/Makefile \ sources | sed 's/^G_sources=/G_LIBSUPCXX_SOURCES=/' getvars $_PLATFORM/libstdc++-v3/libsupc++/Makefile \ c_sources | sed 's/^G_c_sources=/G_LIBSUPCXX_C_SOURCES=/' # includes getvars $_PLATFORM/libstdc++-v3/include/Makefile \ c_base_headers std_headers | sed -e 's#/[^ ][^ ]*/##g' -e 's/\${GNUHOSTDIST}//g' # src getvars $_PLATFORM/libstdc++-v3/src/Makefile \ libstdc___la_SOURCES | sed 's/^G_libstdc___la_SOURCES=/G_SRC_SOURCES=/' getvars $_PLATFORM/libstdc++-v3/src/c++17/Makefile \ libc__17convenience_la_SOURCES | \ sed -e 's/^G_libc__17convenience_la_SOURCES=/G_CPP17_SOURCES=/' getvars $_PLATFORM/libstdc++-v3/src/c++11/Makefile \ libc__11convenience_la_SOURCES | \ sed -e 's/^G_libc__11convenience_la_SOURCES=/G_CPP11_SOURCES=/' getvars $_PLATFORM/libstdc++-v3/src/c++98/Makefile \ GLIBCXX_ABI_FLAGS libc__98convenience_la_SOURCES | \ sed -e 's/^G_libc__98convenience_la_SOURCES=/G_CPP98_SOURCES=/' getvars $_PLATFORM/libstdc++-v3/src/filesystem/Makefile \ libstdc__fs_la_SOURCES | \ sed -e 's/^G_libstdc__fs_la_SOURCES=/G_FILESYSTEM_SOURCES=/' getvars $_PLATFORM/libstdc++-v3/Makefile ATOMICITY_SRCDIR \ BASIC_FILE_CC CLOCALE_CC CCODECVT_CC CCOLLATE_CC \ CCTYPE_CC CMESSAGES_CC CMONEY_CC CNUMERIC_CC CTIME_CC \ CPU_OPT_BITS_RANDOM # includes getvars $_PLATFORM/libstdc++-v3/include/Makefile \ $_headers1 | \ sed -e 's#\${GNUHOSTDIST}/libstdc++-v3/include/##g' \ -e 's#\${GNUHOSTDIST}/libstdc++-v3/config/##g' getvars $_PLATFORM/libstdc++-v3/include/Makefile \ BASIC_FILE_H ALLOCATOR_H CSTDIO_H CLOCALE_H CMESSAGES_H CTIME_H } | sanitise_includes \ | write_mk $_OUTDIRBASE/lib/$_subdir/arch/$_MACHINE_ARCH/defs.mk } ##### lib/libsanitizer ##### get_libsanitizer () { _subdir="$1" mkdir -p $_OUTDIR/lib/$_subdir/arch/$_MACHINE_ARCH { getvars $_PLATFORM/libsanitizer/asan/Makefile \ asan_files getvars $_PLATFORM/libsanitizer/lsan/Makefile \ lsan_files getvars $_PLATFORM/libsanitizer/tsan/Makefile \ tsan_files getvars $_PLATFORM/libsanitizer/ubsan/Makefile \ ubsan_files getvars $_PLATFORM/libsanitizer/interception/Makefile \ interception_files } | sanitise_includes \ | write_mk $_OUTDIRBASE/lib/$_subdir/arch/$_MACHINE_ARCH/defs.mk } ##### usr.bin/gcc* ##### get_gcc_bootstrap () { _subdir="$1" mkdir -p $_OUTDIR/usr.bin/$_subdir/arch/$_MACHINE_ARCH for f in auto-host tm config; do write_c $_OUTDIRBASE/usr.bin/$_subdir/arch/$_MACHINE_ARCH/$f.h <$_TMPDIR/gcc/$f.h done # XXXGCC5 don't really want to copy insn-modes as we build # it but libgcc needs to too early yet for f in insn-modes; do write_c $_OUTDIRBASE/usr.bin/$_subdir/arch/$_MACHINE_ARCH/$f.h <$_TMPDIR/gcc/$f.h done } get_gcc () { _subdir="$1" mkdir -p $_OUTDIR/usr.bin/$_subdir/arch/$_MACHINE_ARCH mkdir -p $_OUTDIR/usr.bin/libcpp/arch/$_MACHINE_ARCH mkdir -p $_OUTDIR/usr.bin/include/arch mkdir -p $_OUTDIR/usr.bin/common-target/arch _buildname="BUILD_" _libcppsubdir="" _extravars="TM_H ALL_OPT_FILES" _hconfig_h="" _extravars2="tm_file_list build_xm_include_list" _extravars3="tm_p_include_list" { getvars gcc/Makefile \ ${_buildname}EARLY_SUPPORT ${_buildname}ERRORS ${_buildname}PRINT \ ${_buildname}RTL ${_buildname}SUPPORT ${_buildname}VARRAY \ ${_buildname}MD | \ sed -e 's#build/errors.o#build-errors.o#g' \ -e 's#build/print-rtl.o#build-print-rtl.o#g' \ -e 's#build/rtl.o#build-rtl.o#g' \ -e 's#build/varray.o#build-varray.o#g' \ -e 's#build/ggc-none.o#build-ggc-none.o#g' \ -e 's#build/##g' getvars gcc/Makefile \ ALL_CFLAGS ALL_CPPFLAGS C_AND_OBJC_OBJS C_OBJS CCCP_OBJS \ GCC_OBJS GCOV_OBJS GCOV_DUMP_OBJS GXX_OBJS GTM_H PROTO_OBJS ${_extravars1} \ INCLUDES md_file OBJC_OBJS OBJS out_file version \ BUILD_PREFIX RTL_H RTL_BASE_H TREE_H ${_hconfig_h} BASIC_BLOCK_H GCC_H \ D_TARGET_DEF \ GTFILES_SRCDIR GTFILES_FILES_FILES GTFILES_FILES_LANGS \ GTFILES GTFILES_LANG_DIR_NAMES HASH_TABLE_H \ NOEXCEPTION_FLAGS NATIVE_SYSTEM_HEADER_DIR \ tm_defines host_xm_file host_xm_defines tm_p_file \ target_cpu_default ${_extravars} ${_extravars2} \ lang_specs_files ${_extravars3} \ common_out_file \ | sanitise_includes getvars gcc/Makefile \ LIB2ADDEHDEP | sed 's/unwind.inc//' getvars gcc/Makefile \ CXX_OBJS CXX_C_OBJS | sed 's/cp\///g' getvars gcc/Makefile \ F77_OBJS | sed 's/f\///g' getvars libcpp/Makefile \ libcpp_a_OBJS getvars gcc/Makefile \ ENABLE_SHARED echo G_SHLIB_LINK="$CC -shared" echo G_SHLIB_MULTILIB=. } | write_mk $_OUTDIRBASE/usr.bin/$_subdir/arch/$_MACHINE_ARCH/defs.mk getvars gcc/Makefile \ EXTRA_HEADERS \ | write_mk $_OUTDIRBASE/usr.bin/include/arch/$_MACHINE_ARCH.mk getvars gcc/Makefile \ OBJS-libcommon \ | write_mk $_OUTDIRBASE/usr.bin/common/defs.mk getvars gcc/Makefile \ OBJS-libcommon-target \ | write_mk $_OUTDIRBASE/usr.bin/common-target/arch/$_MACHINE_ARCH.mk write_c $_OUTDIRBASE/usr.bin/libcpp/arch/$_MACHINE_ARCH/config.h <$_TMPDIR/libcpp/config.h hfiles='auto-host configargs config bconfig bversion plugin-version multilib tm omp-device-properties' for f in $hfiles; do write_c $_OUTDIRBASE/usr.bin/$_subdir/arch/$_MACHINE_ARCH/$f.h <$_TMPDIR/gcc/$f.h if [ "${_MACHINE_ARCH}" = "powerpc" -a "${f}" = "configargs" ] then ex <<__EOF__ $_OUTDIR/usr.bin/$_subdir/arch/$_MACHINE_ARCH/$f.h /configuration_arguments/ s/$// ya i #ifdef _SOFT_FLOAT . pu s/";$/ -with-float=soft";/ a #else #endif . . m +1 /configure_default_options/ s/{ NULL.*$// a #ifdef _SOFT_FLOAT { "float", "soft" }, #endif { NULL, NULL } }; . wq __EOF__ fi if [ "${f}" = "configargs" ] then _srcquoted=$(echo "$_SRC" | sed 's/\//\\\//g') sed -i -E -e "s,$_srcquoted,/usr/src,g" \ -e 's/--build=[^ ]+ --host=([^ ]+)/--build=\1 --host=\1/' \ $_OUTDIR/usr.bin/$_subdir/arch/$_MACHINE_ARCH/$f.h fi done # keep identical for f in all-tree.def; do cp $_TMPDIR/gcc/$f $_OUTDIR/usr.bin/$_subdir/arch/$_MACHINE_ARCH/$f done # special transforms for f in gtyp-input.list; do sed -e "s@^.*$_OUTDIRBASE/dist@SRCDIR@" < $_TMPDIR/gcc/$f > $_OUTDIR/usr.bin/$_subdir/arch/$_MACHINE_ARCH/$f done # special platforms if [ "${_MACHINE_ARCH}" = "sh3el" -o "${_MACHINE_ARCH}" = "sh3eb" ]; then write_c $_OUTDIRBASE/usr.bin/$_subdir/arch/$_MACHINE_ARCH/sysroot-suffix.h <$_TMPDIR/gcc/sysroot-suffix.h fi if [ "${_MACHINE_ARCH}" = "i386" -o "${_MACHINE_ARCH}" = "x86_64" ]; then write_c $_OUTDIRBASE/usr.bin/$_subdir/arch/$_MACHINE_ARCH/i386-builtin-types.inc <$_TMPDIR/gcc/i386-builtin-types.inc fi case "${_MACHINE_ARCH}" in (*arm*) d=$_OUTDIRBASE/usr.bin/$_subdir/arch/${_MACHINE_ARCH} for f in arm-cpu.h arm-cpu-cdata.h arm-cpu-data.h arm-isa.h; do write_c $d/$f <$_TMPDIR/gcc/$f done ;; esac } ##### main ##### case "$1" in # .mk and .h files for libgcc bootstrap (from host build) libgcc*-bootstrap) get_libgcc gcc get_libgcov gcc $_PLATFORM/libgcc/Makefile get_gcc_bootstrap gcc exit 0 ;; libstdc++-bootstrap) get_libstdcxx_v3 libstdc++-v3 gcc exit 0 ;; gcc*) get_gcc gcc get_libgcc gcc get_libgcov gcc $_PLATFORM/libgcc/Makefile get_gcc_bootstrap gcc get_gcc_libiberty gcc get_libobjc libobjc get_libstdcxx_v3 libstdc++-v3 gcc # wants libstdc++-v3 built # get_libsanitizer libsanitizer get_libdecnumber libdecnumber get_libgomp libgomp get_libbacktrace libbacktrace exit 0 ;; *) echo invalid arguments; exit 1 ;; esac