diff options
Diffstat (limited to 'scripts/build')
-rw-r--r-- | scripts/build/cc/gcc.sh | 84 | ||||
-rw-r--r-- | scripts/build/companion_libs/100-gmp.sh | 9 | ||||
-rw-r--r-- | scripts/build/companion_libs/340-picolibc.sh (renamed from scripts/build/libc/picolibc.sh) | 81 |
3 files changed, 156 insertions, 18 deletions
diff --git a/scripts/build/cc/gcc.sh b/scripts/build/cc/gcc.sh index a3f3af1f..b96bb89b 100644 --- a/scripts/build/cc/gcc.sh +++ b/scripts/build/cc/gcc.sh @@ -279,7 +279,8 @@ do_cc_core_pass_2() { # build_manuals : whether to build manuals or not : bool : no # cflags : cflags to use : string : (empty) # ldflags : ldflags to use : string : (empty) -# build_step : build step 'core1', 'core2', 'gcc_build' +# build_step : build step 'core1', 'core2', 'gcc_build', +# 'libstdcxx' # or 'gcc_host' : string : (none) # Usage: do_gcc_core_backend mode=[static|shared|baremetal] build_libgcc=[yes|no] build_staticlinked=[yes|no] do_gcc_core_backend() { @@ -291,6 +292,7 @@ do_gcc_core_backend() { local build_manuals=no local host local prefix + local enable_optspace local complibs local lang_list local cflags cflags_for_build cflags_for_target @@ -298,6 +300,9 @@ do_gcc_core_backend() { local build_step local log_txt local tmp + local exec_prefix + local header_dir + local libstdcxx_name local -a host_libstdcxx_flags local -a extra_config local -a core_LDFLAGS @@ -327,11 +332,30 @@ do_gcc_core_backend() { # to inhibit the libiberty and libgcc tricks later on build_libgcc=no ;; + libstdcxx) + CT_DoLog EXTRA "Configuring libstdc++ for ${libstdcxx_name}" + if [ "${header_dir}" = "" ]; then + header_dir="${CT_PREFIX_DIR}/${libstdcxx_name}/include" + fi + if [ "${exec_prefix}" = "" ]; then + exec_prefix="${CT_PREFIX_DIR}/${libstdcxx_name}" + fi + extra_config+=( "${CT_CC_SYSROOT_ARG[@]}" ) + extra_config+=( "--with-headers=${header_dir}" ) + extra_user_config=( "${CT_CC_GCC_EXTRA_CONFIG_ARRAY[@]}" ) + log_txt="libstdc++ ${libstdcxx_name} library" + # to inhibit the libiberty and libgcc tricks later on + build_libgcc=no + ;; *) - CT_Abort "Internal Error: 'build_step' must be one of: 'core1', 'core2', 'gcc_build' or 'gcc_host', not '${build_step:-(empty)}'" + CT_Abort "Internal Error: 'build_step' must be one of: 'core1', 'core2', 'gcc_build', 'gcc_host' or 'libstdcxx', not '${build_step:-(empty)}'" ;; esac + if [ "${exec_prefix}" = "" ]; then + exec_prefix="${prefix}" + fi + case "${mode}" in static) extra_config+=("--with-newlib") @@ -394,6 +418,10 @@ do_gcc_core_backend() { extra_config+=(--disable-libquadmath-support) fi + if [ "${build_libstdcxx}" = "no" ]; then + extra_config+=(--disable-libstdcxx) + fi + core_LDFLAGS+=("${ldflags}") # *** WARNING ! *** @@ -452,7 +480,8 @@ do_gcc_core_backend() { extra_config+=("--with-host-libstdcxx=${host_libstdcxx_flags[*]}") fi - if [ "${CT_CC_GCC_ENABLE_TARGET_OPTSPACE}" = "y" ]; then + if [ "${CT_CC_GCC_ENABLE_TARGET_OPTSPACE}" = "y" ] || \ + [ "${enable_optspace}" = "yes" ]; then extra_config+=("--enable-target-optspace") fi if [ "${CT_CC_GCC_DISABLE_PCH}" = "y" ]; then @@ -600,6 +629,7 @@ do_gcc_core_backend() { --host=${host} \ --target=${CT_TARGET} \ --prefix="${prefix}" \ + --exec_prefix="${exec_prefix}" \ --with-local-prefix="${CT_SYSROOT_DIR}" \ "${extra_config[@]}" \ --enable-languages="${lang_list}" \ @@ -683,6 +713,11 @@ do_gcc_core_backend() { core_targets_all=all core_targets_install=install ;; + libstdcxx) + core_targets=( target-libstdc++-v3 ) + core_targets_all="${core_targets[@]/#/all-}" + core_targets_install="${core_targets[@]/#/install-}" + ;; esac CT_DoLog EXTRA "Building ${log_txt}" @@ -759,7 +794,9 @@ do_cc_for_build() { # lack of such a compiler, but better safe than sorry... build_final_opts+=( "mode=baremetal" ) build_final_opts+=( "build_libgcc=yes" ) - build_final_opts+=( "build_libstdcxx=yes" ) + if [ "${CT_LIBC_NONE}" != "y" ]; then + build_final_opts+=( "build_libstdcxx=yes" ) + fi build_final_opts+=( "build_libgfortran=yes" ) if [ "${CT_STATIC_TOOLCHAIN}" = "y" ]; then build_final_opts+=( "build_staticlinked=yes" ) @@ -848,7 +885,9 @@ do_cc_for_host() { if [ "${CT_BARE_METAL}" = "y" ]; then final_opts+=( "mode=baremetal" ) final_opts+=( "build_libgcc=yes" ) - final_opts+=( "build_libstdcxx=yes" ) + if [ "${CT_LIBC_NONE}" != "y" ]; then + final_opts+=( "build_libstdcxx=yes" ) + fi final_opts+=( "build_libgfortran=yes" ) if [ "${CT_STATIC_TOOLCHAIN}" = "y" ]; then final_opts+=( "build_staticlinked=yes" ) @@ -881,20 +920,27 @@ do_cc_for_host() { # Parameter : Definition : Type : Default # host : the host we run onto : tuple : (none) # prefix : the runtime prefix : dir : (none) +# exec_prefix : prefix for executables : dir : (none) # complibs : the companion libraries prefix : dir : (none) # cflags : cflags to use : string : (empty) # ldflags : ldflags to use : string : (empty) # lang_list : the list of languages to build : string : (empty) # build_manuals : whether to build manuals or not : bool : no +# build_step : build step 'gcc_build', 'gcc_host' +# or 'libstdcxx' : string : (none) do_gcc_backend() { local host local prefix + local exec_prefix local complibs local lang_list local cflags local cflags_for_build local ldflags local build_manuals + local exec_prefix + local header_dir + local libstdcxx_name local -a host_libstdcxx_flags local -a extra_config local -a final_LDFLAGS @@ -905,7 +951,24 @@ do_gcc_backend() { eval "${arg// /\\ }" done - CT_DoLog EXTRA "Configuring final gcc compiler" + if [ "${exec_prefix}" = "" ]; then + exec_prefix="${prefix}" + fi + + # This function gets called for final gcc and libstdcxx. + case "${build_step}" in + gcc_build|gcc_host) + log_txt="final gcc compiler" + ;; + libstdcxx) + log_txt="libstdc++ library for ${libstdcxx_name}" + ;; + *) + CT_Abort "Internal Error: 'build_step' must be one of: 'gcc_build', 'gcc_host' or 'libstdcxx', not '${build_step:-(empty)}'" + ;; + esac + + CT_DoLog EXTRA "Configuring ${log_txt}" # Enable selected languages extra_config+=("--enable-languages=${lang_list}") @@ -979,6 +1042,10 @@ do_gcc_backend() { fi fi + if [ "${build_libstdcxx}" = "no" ]; then + extra_config+=(--disable-libstdcxx) + fi + final_LDFLAGS+=("${ldflags}") # *** WARNING ! *** @@ -1048,9 +1115,11 @@ do_gcc_backend() { fi fi - if [ "${CT_CC_GCC_ENABLE_TARGET_OPTSPACE}" = "y" ]; then + if [ "${CT_CC_GCC_ENABLE_TARGET_OPTSPACE}" = "y" ] || \ + [ "${enable_optspace}" = "yes" ]; then extra_config+=("--enable-target-optspace") fi + if [ "${CT_CC_GCC_DISABLE_PCH}" = "y" ]; then extra_config+=("--disable-libstdcxx-pch") fi @@ -1166,6 +1235,7 @@ do_gcc_backend() { --host=${host} \ --target=${CT_TARGET} \ --prefix="${prefix}" \ + --exec_prefix="${exec_prefix}" \ ${CT_CC_SYSROOT_ARG} \ "${extra_config[@]}" \ --with-local-prefix="${CT_SYSROOT_DIR}" \ diff --git a/scripts/build/companion_libs/100-gmp.sh b/scripts/build/companion_libs/100-gmp.sh index 4e8c12fb..eafe2dd7 100644 --- a/scripts/build/companion_libs/100-gmp.sh +++ b/scripts/build/companion_libs/100-gmp.sh @@ -87,6 +87,15 @@ do_gmp_backend() { extra_config+=("--enable-mpbsd") fi + # To avoind “illegal text-relocation” linking error against + # the static library, see: + # https://github.com/Homebrew/homebrew-core/pull/25470 + case "${host}" in + *darwin*) + extra_config+=("--with-pic") + ;; + esac + # FIXME: GMP's configure script doesn't respect the host parameter # when not cross-compiling, ie when build == host. CT_DoExecLog CFG \ diff --git a/scripts/build/libc/picolibc.sh b/scripts/build/companion_libs/340-picolibc.sh index 152125c1..525497ae 100644 --- a/scripts/build/libc/picolibc.sh +++ b/scripts/build/companion_libs/340-picolibc.sh @@ -5,22 +5,74 @@ # Edited by Keith Packard <keithp@keithp.com> # -picolibc_start_files() -{ - CT_DoStep INFO "Installing C library headers & start files" - CT_DoExecLog ALL cp -a "${CT_SRC_DIR}/picolibc/newlib/libc/include/." \ - "${CT_HEADERS_DIR}" - CT_EndStep +do_picolibc_get() { :; } +do_picolibc_extract() { :; } +do_picolibc_for_build() { :; } +do_picolibc_for_host() { :; } +do_picolibc_for_target() { :; } + +if [ "${CT_COMP_LIBS_PICOLIBC}" = "y" ]; then + +# Download picolibc +do_picolibc_get() { + CT_Fetch PICOLIBC } -picolibc_main() +do_picolibc_extract() { + CT_ExtractPatch PICOLIBC +} + +#------------------------------------------------------------------------------ +# Build an additional target libstdc++ with "-Os" (optimise for speed) option +# flag for libstdc++ "picolibc" variant. +do_cc_libstdcxx_picolibc() { + local -a final_opts + local final_backend + + if [ "${CT_LIBC_PICOLIBC_GCC_LIBSTDCXX}" = "y" ]; then + final_opts+=( "host=${CT_HOST}" ) + final_opts+=( "libstdcxx_name=picolibc" ) + final_opts+=( "prefix=${CT_PREFIX_DIR}" ) + final_opts+=( "complibs=${CT_HOST_COMPLIBS_DIR}" ) + final_opts+=( "cflags=${CT_CFLAGS_FOR_HOST}" ) + final_opts+=( "ldflags=${CT_LDFLAGS_FOR_HOST}" ) + final_opts+=( "lang_list=c,c++" ) + final_opts+=( "build_step=libstdcxx" ) + final_opts+=( "extra_config+=('--enable-stdio=stdio_pure')" ) + if [ "${CT_LIBC_PICOLIBC_ENABLE_TARGET_OPTSPACE}" = "y" ]; then + final_opts+=( "enable_optspace=yes" ) + fi + + if [ "${CT_BARE_METAL}" = "y" ]; then + final_opts+=( "mode=baremetal" ) + final_opts+=( "build_libgcc=yes" ) + final_opts+=( "build_libstdcxx=yes" ) + final_opts+=( "build_libgfortran=yes" ) + if [ "${CT_STATIC_TOOLCHAIN}" = "y" ]; then + final_opts+=( "build_staticlinked=yes" ) + fi + final_backend=do_gcc_core_backend + else + final_backend=do_gcc_backend + fi + + CT_DoStep INFO "Installing libstdc++ picolibc" + CT_mkdir_pushd "${CT_BUILD_DIR}/build-cc-libstdcxx-picolibc" + "${final_backend}" "${final_opts[@]}" + CT_Popd + + CT_EndStep + fi +} + +do_picolibc_for_target() { local -a picolibc_opts local cflags_for_target - CT_DoStep INFO "Installing C library" + CT_DoStep INFO "Installing Picolibc library" - CT_mkdir_pushd "${CT_BUILD_DIR}/build-libc" + CT_mkdir_pushd "${CT_BUILD_DIR}/build-picolibc-build-${CT_BUILD}" CT_DoLog EXTRA "Configuring Picolibc library" @@ -91,11 +143,14 @@ c_args = [ ${meson_cflags} '-nostdlib', '-fno-common', '-ftls-model=local-exec' needs_exe_wrapper = true skip_sanity_check = true EOF + CT_DoExecLog CFG \ meson \ --cross-file picolibc-cross.txt \ - --prefix=${CT_SYSROOT_DIR} \ - -Dspecsdir=${CT_SYSROOT_DIR}/lib \ + --prefix="${CT_PREFIX_DIR}" \ + -Dincludedir=picolibc/include \ + -Dlibdir=picolibc/${CT_TARGET}/lib \ + -Dspecsdir="${CT_SYSROOT_DIR}"/lib \ "${CT_SRC_DIR}/picolibc" \ "${picolibc_opts[@]}" \ "${CT_LIBC_PICOLIBC_EXTRA_CONFIG_ARRAY[@]}" @@ -108,4 +163,8 @@ EOF CT_Popd CT_EndStep + + do_cc_libstdcxx_picolibc } + +fi |