diff options
Diffstat (limited to 'scripts/build')
-rw-r--r-- | scripts/build/arch.sh | 68 | ||||
-rw-r--r-- | scripts/build/arch/arm.sh | 81 | ||||
-rw-r--r-- | scripts/build/arch/m68k.sh | 6 | ||||
-rw-r--r-- | scripts/build/arch/microblaze.sh | 6 | ||||
-rw-r--r-- | scripts/build/arch/mips.sh | 55 | ||||
-rw-r--r-- | scripts/build/arch/nios2.sh | 1 | ||||
-rw-r--r-- | scripts/build/arch/powerpc.sh | 62 | ||||
-rw-r--r-- | scripts/build/arch/s390.sh | 31 | ||||
-rw-r--r-- | scripts/build/arch/sh.sh | 45 | ||||
-rw-r--r-- | scripts/build/arch/sparc.sh | 74 | ||||
-rw-r--r-- | scripts/build/arch/x86.sh | 161 | ||||
-rw-r--r-- | scripts/build/arch/xtensa.sh | 6 | ||||
-rw-r--r-- | scripts/build/binutils/binutils.sh | 5 | ||||
-rw-r--r-- | scripts/build/cc/100-gcc.sh | 294 | ||||
-rw-r--r-- | scripts/build/debug/300-gdb.sh | 34 | ||||
-rw-r--r-- | scripts/build/internals.sh | 19 | ||||
-rw-r--r-- | scripts/build/libc/avr-libc.sh | 4 | ||||
-rw-r--r-- | scripts/build/libc/glibc.sh | 291 | ||||
-rw-r--r-- | scripts/build/libc/mingw.sh | 31 | ||||
-rw-r--r-- | scripts/build/libc/musl.sh | 113 | ||||
-rw-r--r-- | scripts/build/libc/newlib.sh | 4 | ||||
-rw-r--r-- | scripts/build/libc/none.sh | 4 | ||||
-rw-r--r-- | scripts/build/libc/uClibc.sh | 544 |
23 files changed, 1348 insertions, 591 deletions
diff --git a/scripts/build/arch.sh b/scripts/build/arch.sh new file mode 100644 index 00000000..5c5edc9f --- /dev/null +++ b/scripts/build/arch.sh @@ -0,0 +1,68 @@ +# This file provides the default implementations of arch-specific functions. + +# Set up the target tuple +CT_DoArchTupleValues() { + :; +} + +# Multilib: change the target triplet according to CFLAGS +# Usage: CT_DoArchGlibcAdjustTuple <variable-name> <CFLAGS> +CT_DoArchMultilibTarget() { + :; +} + +# Multilib: Adjust target tuple for GLIBC +# Usage: CT_DoArchGlibcAdjustTuple <variable-name> +CT_DoArchGlibcAdjustTuple() { + :; +} + +# Helper for uClibc configurators: select the architecture +# Usage: CT_DoArchUClibcSelectArch <config-file> <architecture> +CT_DoArchUClibcSelectArch() { + local cfg="${1}" + local arch="${2}" + + ${sed} -i -r -e '/^TARGET_.*/d' "${cfg}" + CT_KconfigEnableOption "TARGET_${arch}" "${cfg}" + CT_KconfigSetOption "TARGET_ARCH" "${arch}" "${cfg}" +} + +# uClibc: Adjust configuration file according to the CT-NG configuration +# Usage: CT_DoArchUClibcConfig <config-file> +CT_DoArchUClibcConfig() { + CT_DoLog WARN "Support for '${CT_ARCH}' is not implemented in uClibc config tweaker." + CT_DoLog WARN "Exact configuration file must be provided." +} + +# Multilib/uClibc: Adjust configuration file for given CFLAGS +# Usage: CT_DoArchUClibcCflags <config-file> <cflags> +CT_DoArchUClibcCflags() { + local cfg="${1}" + local cflags="${2}" + + # Likely, any non-default cflags need to be reflected into the config. + # It may work if we just pass them into EXTRA_CFLAGS, but we have no + # idea as they might interact with the CFLAGS inferred by uClibc from + # the configuration file. + if [ "${cflags}" != "" ]; then + CT_DoLog WARN "Multilib configuration not supported for uClibc/${CT_ARCH}" + fi +} + +# Multilib/uClibc: Adjust header installation path for given CFLAGS +# Usage: CT_DoArchUClibcHeaderDir <path-variable> <cflags> +CT_DoArchUClibcHeaderDir() { + # Only needed if a given architecture may select different uClibc architectures. + :; +} + +# Multilib/MUSL: Adjust header installation path for given CFLAGS +# Usage: CT_DoArchMUSLHeaderDir <path-variable> <cflags> +CT_DoArchMUSLHeaderDir() { + # Only needed if a given architecture may select different MUSL architectures. + :; +} + +# Override from the actual arch implementation as needed. +. "${CT_LIB_DIR}/scripts/build/arch/${CT_ARCH}.sh" diff --git a/scripts/build/arch/arm.sh b/scripts/build/arch/arm.sh index 5f6ce2fc..b728311e 100644 --- a/scripts/build/arch/arm.sh +++ b/scripts/build/arch/arm.sh @@ -27,7 +27,6 @@ CT_DoArchTupleValues() { thumb) CT_ARCH_CC_CORE_EXTRA_CONFIG="--with-mode=thumb" CT_ARCH_CC_EXTRA_CONFIG="--with-mode=thumb" -# CT_ARCH_TARGET_CFLAGS="-mthumb" ;; esac @@ -38,4 +37,84 @@ CT_DoArchTupleValues() { if [ "${CT_ARCH_ARM_TUPLE_USE_EABIHF}" = "y" ]; then CT_TARGET_SYS="${CT_TARGET_SYS}hf" fi + + # If building multilib, zero out any WITH_*/*_CFLAG - GCC on ARM does not allow + # any of them with multilib. + if [ "${CT_MULTILIB}" = "y" ]; then + CT_ARCH_WITH_ARCH= + CT_ARCH_WITH_ABI= + CT_ARCH_WITH_CPU= + CT_ARCH_WITH_TUNE= + CT_ARCH_WITH_FPU= + CT_ARCH_WITH_FLOAT= + CT_ARCH_ARCH_CFLAG= + CT_ARCH_ABI_CFLAG= + CT_ARCH_CPU_CFLAG= + CT_ARCH_TUNE_CFLAG= + CT_ARCH_FPU_CFLAG= + CT_ARCH_FLOAT_CFLAG= + fi +} + +CT_DoArchUClibcConfig() { + local cfg="${1}" + + CT_DoArchUClibcSelectArch "${cfg}" "arm" + + case "${CT_ARCH_ARM_MODE}" in + arm) + CT_KconfigDisableOption "COMPILE_IN_THUMB_MODE" "${cfg}" + ;; + thumb) + CT_KconfigEnableOption "COMPILE_IN_THUMB_MODE" "${cfg}" + ;; + esac + + # FIXME: CONFIG_ARM_OABI does not exist in neither uClibc/uClibc-ng + # FIXME: CONFIG_ARM_EABI does not seem to affect anything in either of them, too + # (both check the compiler's built-in define, __ARM_EABI__ instead) except for + # a check for match between toolchain configuration and uClibc-ng in + # uClibc_arch_features.h + if [ "${CT_ARCH_ARM_EABI}" = "y" ]; then + CT_KconfigDisableOption "CONFIG_ARM_OABI" "${cfg}" + CT_KconfigEnableOption "CONFIG_ARM_EABI" "${cfg}" + else + CT_KconfigDisableOption "CONFIG_ARM_EABI" "${cfg}" + CT_KconfigEnableOption "CONFIG_ARM_OABI" "${cfg}" + fi +} + +CT_DoArchUClibcCflags() { + local cfg="${1}" + local cflags="${2}" + local f + + for f in ${cflags}; do + case "${f}" in + -mthumb) + CT_KconfigEnableOption "COMPILE_IN_THUMB_MODE" "${cfg}" + ;; + -marm) + CT_KconfigDisableOption "COMPILE_IN_THUMB_MODE" "${cfg}" + ;; + -mlittle-endian) + CT_KconfigDisableOption "ARCH_BIG_ENDIAN" "${cfg}" + CT_KconfigDisableOption "ARCH_WANTS_BIG_ENDIAN" "${cfg}" + CT_KconfigEnableOption "ARCH_LITTLE_ENDIAN" "${cfg}" + CT_KconfigEnableOption "ARCH_WANTS_LITTLE_ENDIAN" "${cfg}" + ;; + -mbig-endian) + CT_KconfigEnableOption "ARCH_BIG_ENDIAN" "${cfg}" + CT_KconfigEnableOption "ARCH_WANTS_BIG_ENDIAN" "${cfg}" + CT_KconfigDisableOption "ARCH_LITTLE_ENDIAN" "${cfg}" + CT_KconfigDisableOption "ARCH_WANTS_LITTLE_ENDIAN" "${cfg}" + ;; + -mhard-float|-mfloat-abi=hard|-mfloat-abi=softfp) + CT_KconfigEnableOption "UCLIBC_HAS_FPU" "${cfg}" + ;; + -msoft-float|-mfloat-abi=soft) + CT_KconfigDisableOption "UCLIBC_HAS_FPU" "${cfg}" + ;; + esac + done } diff --git a/scripts/build/arch/m68k.sh b/scripts/build/arch/m68k.sh index bf26d1b2..3cba76c6 100644 --- a/scripts/build/arch/m68k.sh +++ b/scripts/build/arch/m68k.sh @@ -1,5 +1,7 @@ # Compute M68k-specific values -CT_DoArchTupleValues() { - : +CT_DoArchUClibcConfig() { + local cfg="${1}" + + CT_DoArchUClibcSelectArch "${cfg}" "m68k" } diff --git a/scripts/build/arch/microblaze.sh b/scripts/build/arch/microblaze.sh index 456a6e3a..e9d98114 100644 --- a/scripts/build/arch/microblaze.sh +++ b/scripts/build/arch/microblaze.sh @@ -19,3 +19,9 @@ CT_DoArchTupleValues () { esac } + +CT_DoArchUClibcConfig() { + local cfg="${1}" + + CT_DoArchUClibcSelectArch "${cfg}" "microblaze" +} diff --git a/scripts/build/arch/mips.sh b/scripts/build/arch/mips.sh index 4d732be9..6097c89f 100644 --- a/scripts/build/arch/mips.sh +++ b/scripts/build/arch/mips.sh @@ -14,3 +14,58 @@ CT_DoArchTupleValues() { CT_ARCH_ABI_CFLAG="-mabi=${CT_ARCH_mips_ABI}" CT_ARCH_WITH_ABI="--with-abi=${CT_ARCH_mips_ABI}" } + +CT_DoArchUClibcConfig() { + local cfg="${1}" + + CT_DoArchUClibcSelectArch "${cfg}" "${CT_ARCH}" + + CT_KconfigDisableOption "CONFIG_MIPS_O32_ABI" "${cfg}" + CT_KconfigDisableOption "CONFIG_MIPS_N32_ABI" "${cfg}" + CT_KconfigDisableOption "CONFIG_MIPS_N64_ABI" "${cfg}" + case "${CT_ARCH_mips_ABI}" in + 32) + CT_KconfigEnableOption "CONFIG_MIPS_O32_ABI" "${cfg}" + ;; + n32) + CT_KconfigEnableOption "CONFIG_MIPS_N32_ABI" "${cfg}" + ;; + 64) + CT_KconfigEnableOption "CONFIG_MIPS_N64_ABI" "${cfg}" + ;; + esac + + # FIXME: uClibc (!ng) allows to select ISA in the config; should + # match from the selected ARCH_ARCH level... For now, delete and + # fall back to default. + CT_KconfigDeleteOption "CONFIG_MIPS_ISA_1" "${cfg}" + CT_KconfigDeleteOption "CONFIG_MIPS_ISA_2" "${cfg}" + CT_KconfigDeleteOption "CONFIG_MIPS_ISA_3" "${cfg}" + CT_KconfigDeleteOption "CONFIG_MIPS_ISA_4" "${cfg}" + CT_KconfigDeleteOption "CONFIG_MIPS_ISA_MIPS32" "${cfg}" + CT_KconfigDeleteOption "CONFIG_MIPS_ISA_MIPS32R2" "${cfg}" + CT_KconfigDeleteOption "CONFIG_MIPS_ISA_MIPS64" "${cfg}" + CT_KconfigDeleteOption "CONFIG_MIPS_ISA_MIPS64R2" "${cfg}" +} + +CT_DoArchUClibcCflags() { + local cfg="${1}" + local cflags="${2}" + local f + + for f in ${cflags}; do + case "${f}" in + -mabi=*) + CT_KconfigDisableOption "CONFIG_MIPS_O32_ABI" "${cfg}" + CT_KconfigDisableOption "CONFIG_MIPS_N32_ABI" "${cfg}" + CT_KconfigDisableOption "CONFIG_MIPS_N64_ABI" "${cfg}" + case "${f#-mabi=}" in + 32) CT_KconfigEnableOption "CONFIG_MIPS_O32_ABI" "${cfg}";; + n32) CT_KconfigEnableOption "CONFIG_MIPS_N32_ABI" "${cfg}";; + 64) CT_KconfigEnableOption "CONFIG_MIPS_N64_ABI" "${cfg}";; + *) CT_Abort "Unsupported ABI: ${f#-mabi=}";; + esac + ;; + esac + done +} diff --git a/scripts/build/arch/nios2.sh b/scripts/build/arch/nios2.sh index 8c7d4451..24c556bf 100644 --- a/scripts/build/arch/nios2.sh +++ b/scripts/build/arch/nios2.sh @@ -9,5 +9,4 @@ CT_DoArchTupleValues() { CT_ARCH_WITH_FPU= CT_ARCH_WITH_FLOAT= CT_TARGET_SYS=elf - } diff --git a/scripts/build/arch/powerpc.sh b/scripts/build/arch/powerpc.sh index fbc3120f..52f3f8bb 100644 --- a/scripts/build/arch/powerpc.sh +++ b/scripts/build/arch/powerpc.sh @@ -26,3 +26,65 @@ CT_DoArchTupleValues () { CT_ARCH_CC_EXTRA_CONFIG="--enable-e500_double" fi } + +#------------------------------------------------------------------------------ +# Get multilib architecture-specific target +# Usage: CT_DoArchMultilibTarget "target variable" "multilib flags" +CT_DoArchMultilibTarget () +{ + local target_var="${1}"; shift + local -a multi_flags=( "$@" ) + local target_ + + local m32=false + local m64=false + local mlittle=false + local mbig=false + + for m in "${multi_flags[@]}"; do + case "$m" in + -m32) m32=true ;; + -m64) m64=true ;; + -mbig) mbig=true ;; + -mlittle) mlittle=true ;; + esac + done + + eval target_=\"\${${target_var}}\" + + # Fix up bitness + case "${target_}" in + powerpc-*) $m64 && target_=${target_/#powerpc-/powerpc64-} ;; + powerpcle-*) $m64 && target_=${target_/#powerpcle-/powerpc64le-} ;; + powerpc64-*) $m32 && target_=${target_/#powerpc64-/powerpc-} ;; + powerpc64le-*) $m32 && target_=${target_/#powerpc64le-/powerpcle-} ;; + esac + + # Fix up endianness + case "${target_}" in + powerpc-*) $mlittle && target_=${target_/#powerpc-/powerpcle-} ;; + powerpcle-*) $mbig && target_=${target_/#powerpcle-/powerpc-} ;; + powerpc64-*) $mlittle && target_=${target_/#powerpc64-/powerpc64le-} ;; + powerpc64le-*) $mbig && target_=${target_/#powerpc64le-/powerpc64-} ;; + esac + + # Set the target variable + eval ${target_var}=\"${target_}\" +} + +CT_DoArchUClibcConfig() { + local cfg="${1}" + + CT_DoArchUClibcSelectArch "${cfg}" "powerpc" + + CT_KconfigDisableOption "CONFIG_E500" "${cfg}" + CT_KconfigDisableOption "CONFIG_CLASSIC" "${cfg}" + CT_KconfigDeleteOption "TARGET_SUBARCH" "${cfg}" + if [ "${CT_ARCH_powerpc_ABI}" = "spe" ]; then + CT_KconfigEnableOption "CONFIG_E500" "${cfg}" + CT_KconfigSetOption "TARGET_SUBARCH" "e500" "${cfg}" + else + CT_KconfigEnableOption "CONFIG_CLASSIC" "${cfg}" + CT_KconfigSetOption "TARGET_SUBARCH" "classic" "${cfg}" + fi +} diff --git a/scripts/build/arch/s390.sh b/scripts/build/arch/s390.sh index b4b8078c..dff86a0c 100644 --- a/scripts/build/arch/s390.sh +++ b/scripts/build/arch/s390.sh @@ -6,3 +6,34 @@ CT_DoArchTupleValues() { CT_TARGET_ARCH="s390x${CT_ARCH_SUFFIX}" fi } + +#------------------------------------------------------------------------------ +# Get multilib architecture-specific target +# Usage: CT_DoArchMultilibTarget "target variable" "multilib flags" +CT_DoArchMultilibTarget () +{ + local target_var="${1}"; shift + local -a multi_flags=( "$@" ) + local target_ + + local m31=false + local m64=false + + for m in "${multi_flags[@]}"; do + case "${multi_flags}" in + -m64) m64=true ;; + -m31) m31=true ;; + esac + done + + eval target_=\"\${${target_var}}\" + + # Fix bitness + case "${target_}" in + s390-*) $m64 && target_=${target_/#s390-/s390x-} ;; + s390x-*) $m31 && target_=${target_/#s390x-/s390-} ;; + esac + + # Set the target variable + eval ${target_var}=\"${target_}\" +} diff --git a/scripts/build/arch/sh.sh b/scripts/build/arch/sh.sh index 7780e40f..6761435d 100644 --- a/scripts/build/arch/sh.sh +++ b/scripts/build/arch/sh.sh @@ -35,3 +35,48 @@ CT_DoArchTupleValues () { esac CT_ARCH_FLOAT_CFLAG= } + +CT_DoArchUClibcConfig() { + local cfg="${1}" + + # FIXME: uclibc (!ng) seems to support sh64 (sh5), too + CT_DoArchUClibcSelectArch "${cfg}" "sh" + CT_KconfigDisableOption "CONFIG_SH3" "${cfg}" + CT_KconfigDisableOption "CONFIG_SH4" "${cfg}" + CT_KconfigDisableOption "CONFIG_SH4A" "${cfg}" + case "${CT_ARCH_SH_VARIANT}" in + sh3) CT_KconfigEnableOption "CONFIG_SH3" "${cfg}";; + sh4) CT_KconfigEnableOption "CONFIG_SH4" "${cfg}";; + sh4a) CT_KconfigEnableOption "CONFIG_SH4A" "${cfg}";; + esac +} + +CT_DoArchUClibcCflags() { + local cfg="${1}" + local cflags="${2}" + local f + + for f in ${cflags}; do + case "${f}" in + -m3) + CT_KconfigEnableOption "CONFIG_SH3" "${cfg}" + ;; + -m4) + CT_KconfigEnableOption "CONFIG_SH4" "${cfg}" + CT_KconfigEnableOption "UCLIBC_HAS_FPU" "${cfg}" + ;; + -m4-nofpu) + CT_KconfigEnableOption "CONFIG_SH4" "${cfg}" + CT_KconfigDisableOption "UCLIBC_HAS_FPU" "${cfg}" + ;; + -m4a) + CT_KconfigEnableOption "CONFIG_SH4A" "${cfg}" + CT_KconfigEnableOption "UCLIBC_HAS_FPU" "${cfg}" + ;; + -m4a-nofpu) + CT_KconfigEnableOption "CONFIG_SH4A" "${cfg}" + CT_KconfigDisableOption "UCLIBC_HAS_FPU" "${cfg}" + ;; + esac + done +} diff --git a/scripts/build/arch/sparc.sh b/scripts/build/arch/sparc.sh index e3e74913..74f6f785 100644 --- a/scripts/build/arch/sparc.sh +++ b/scripts/build/arch/sparc.sh @@ -2,4 +2,78 @@ CT_DoArchTupleValues() { # That's the only thing to override CT_TARGET_ARCH="sparc${target_bits_64}${CT_ARCH_SUFFIX}" + + # By default, sparc64-*-linux is configured with -mcpu=v9. However, + # according to https://sourceware.org/ml/libc-alpha/2005-12/msg00027.html, + # "There is no Linux sparc64 port that runs on non-UltraSPARC-I+ ISA CPUs." + # There is a patch that would change the default to -mcpu=ultrasparc for + # sparc64-*-linux configuration: https://patchwork.ozlabs.org/patch/409424/ + # but that patch has not been integrated (yet). One concern raised about + # this patch was that -mcpu=ultrasparc can suboptimally schedule instructions + # for newer SPARC CPUs. So, override to -mcpu=ultrasparc and warn the user. + if [ "${CT_KERNEL}" = "linux" -a "${CT_ARCH_64}" = "y" -a -z "${CT_ARCH_CPU}" ]; then + CT_DoLog WARN "Setting CPU to UltraSPARC-I for sparc64-linux. Set CT_ARCH_CPU if a different CPU is desired." + CT_ARCH_WITH_CPU="--with-cpu=ultrasparc" + fi +} + +#------------------------------------------------------------------------------ +# Get multilib architecture-specific target +# Usage: CT_DoArchMultilibTarget "target variable" "multilib flags" +CT_DoArchMultilibTarget () +{ + local target_var="${1}"; shift + local -a multi_flags=( "$@" ) + local target_ + + local m32=false + local m64=false + + for m in "${multi_flags[@]}"; do + case "$m" in + -m32) m32=true ;; + -m64) m64=true ;; + esac + done + + eval target_=\"\${${target_var}}\" + + # Fix up bitness + case "${target_}" in + sparc-*) $m64 && target_=${target_/#sparc-/sparc64-} ;; + sparc64-*) $m32 && target_=${target_/#sparc64-/sparc-} ;; + esac + + # Set the target variable + eval ${target_var}=\"${target_}\" +} + +# Special tuple adjustment for glibc. +CT_DoArchGlibcAdjustTuple() { + local target_var="${1}" + local target_ + + eval target_=\"\${${target_var}}\" + + case "${target_}" in + # SPARC quirk: glibc 2.23 and newer dropped support for SPARCv8 and + # earlier (corresponding pthread barrier code is missing). Until this + # support is reintroduced, configure as sparcv9. + sparc-*) + if [ "${CT_LIBC_GLIBC_2_23_or_later}" = y ]; then + CT_DoLog WARN "GLIBC 2.23 only supports SPARCv9" + target_=${target_/#sparc-/sparcv9-} + fi + ;; + esac + + # Set the target variable + eval ${target_var}=\"${target_}\" +} + +CT_DoArchUClibcConfig() { + local cfg="${1}" + + CT_DoArchUClibcSelectArch "${cfg}" "${CT_ARCH}" + # FIXME: select CONFIG_SPARC_V7/V8/V9/V9B according to the CPU selector } diff --git a/scripts/build/arch/x86.sh b/scripts/build/arch/x86.sh index 69407db9..2c8a2267 100644 --- a/scripts/build/arch/x86.sh +++ b/scripts/build/arch/x86.sh @@ -15,9 +15,168 @@ CT_DoArchTupleValues() { winchip*) CT_TARGET_ARCH=i486;; pentium|pentium-mmx|c3*) CT_TARGET_ARCH=i586;; pentiumpro|pentium*|athlon*) CT_TARGET_ARCH=i686;; - prescott) CT_TARGET_ARCH=i686;; + core2|atom) CT_TARGET_ARCH=i686;; + prescott|nocona) CT_TARGET_ARCH=i686;; + k8*|opteron*) CT_TARGET_ARCH=i686;; *) CT_TARGET_ARCH=i586;; esac fi CT_TARGET_ARCH="${CT_TARGET_ARCH}${CT_ARCH_SUFFIX}" + + # Shouldn't be possible to specify this (CT_TARGET_SYS is not specified by the user, + # it is computed by scripts/functions from libc choices). But trap if such invalid + # values ever come from the caller: + case "${CT_TARGET_ARCH}-${CT_TARGET_SYS}" in + i[34567]86-gnux32) + CT_DoLog ERROR "Invalid CT_TARGET: i[34567]86-<vendor>-<os>-gnux32 is invalid." + CT_DoLog ERROR "CT_TARGET: ${CT_TARGET}" + CT_Abort "Go read: https://wiki.debian.org/Multiarch/Tuples" + ;; + esac +} + +#------------------------------------------------------------------------------ +# Get multilib architecture-specific target +# Usage: CT_DoArchMultilibTarget "target variable" "multilib flags" +CT_DoArchMultilibTarget () +{ + local target_var="${1}"; shift + local -a multi_flags=( "$@" ) + local target_ + + local bit32=false + local bit64=false + local abi_dflt=false + local abi_x32=false + + for m in "${multi_flags[@]}"; do + case "$m" in + -m32) bit32=true; abi_dflt=true;; + -m64) bit64=true; abi_dflt=true;; + -mx32) bit64=true; abi_x32=true;; + esac + done + + eval target_=\"\${${target_var}}\" + + # Fix up architecture. + case "${target_}" in + x86_64-*) $bit32 && target_=${target_/#x86_64-/i386-} ;; + i[34567]86-*) $bit64 && target_=${target_/#i[34567]86-/x86_64-} ;; + esac + + # Fix up the ABI part. + case "${target_}" in + *x32) $abi_dflt && target_=${target_/%x32} ;; + *) $abi_x32 && target_=${target_}x32 ;; + esac + + # Set the target variable + eval ${target_var}=\"${target_}\" +} + +# Adjust target tuple for GLIBC +CT_DoArchGlibcAdjustTuple() { + local target_var="${1}" + local target_ + + eval target_=\"\${${target_var}}\" + + case "${target_}" in + # x86 quirk: architecture name is i386, but glibc expects i[4567]86 - to + # indicate the desired optimization. If it was a multilib variant of x86_64, + # then it targets at least NetBurst a.k.a. i786, but we'll follow the model + # above # and set the optimization to i686. Otherwise, replace with the most + # conservative choice, i486. + i386-*) + if [ "${CT_TARGET_ARCH}" = "x86_64" ]; then + target_=${target_/#i386-/i686-} + elif [ "${CT_TARGET_ARCH}" != "i386" ]; then + target_=${target_/#i386-/${CT_TARGET_ARCH}-} + else + target_=${target_/#i386-/i486-} + fi + ;; + esac + + # Set the target variable + eval ${target_var}=\"${target_}\" +} + +CT_DoArchUClibcConfig() { + local cfg="${1}" + + if [ "${CT_ARCH_BITNESS}" = 64 ]; then + CT_DoArchUClibcSelectArch "${cfg}" "x86_64" + else + CT_DoArchUClibcSelectArch "${cfg}" "i386" + fi + + # FIXME This doesn't cover all cases of x86_32 on uClibc (!ng) + CT_KconfigDisableOption "CONFIG_386" "${cfg}" + CT_KconfigDisableOption "CONFIG_486" "${cfg}" + CT_KconfigDisableOption "CONFIG_586" "${cfg}" + CT_KconfigDisableOption "CONFIG_686" "${cfg}" + case ${CT_TARGET_ARCH} in + i386) + CT_KconfigEnableOption "CONFIG_386" "${cfg}" + ;; + i486) + CT_KconfigEnableOption "CONFIG_486" "${cfg}" + ;; + i586) + CT_KconfigEnableOption "CONFIG_586" "${cfg}" + ;; + i686) + CT_KconfigEnableOption "CONFIG_686" "${cfg}" + ;; + esac +} + +CT_DoArchUClibcCflags() { + local cfg="${1}" + local cflags="${2}" + local f + + for f in ${cflags}; do + case "${f}" in + -m64) + CT_DoArchUClibcSelectArch "${cfg}" "x86_64" + ;; + -m32) + # Since it's a part of multilib with 64-bit flavor, default + # to new architecture (i686). + CT_DoArchUClibcSelectArch "${cfg}" "i386" + CT_KconfigDisableOption "CONFIG_386" "${cfg}" + CT_KconfigDisableOption "CONFIG_486" "${cfg}" + CT_KconfigDisableOption "CONFIG_586" "${cfg}" + CT_KconfigEnableOption "CONFIG_686" "${cfg}" + ;; + -mx32) + CT_Abort "uClibc does not support x32 ABI" + ;; + esac + done +} + +CT_DoArchUClibcHeaderDir() { + local dir_var="${1}" + local cflags="${2}" + + # If it is non-default multilib, add a suffix with architecture (reported by gcc) + # to the headers installation path. + if [ -n "${cflags}" ]; then + eval "${dir_var}="$( ${CT_TARGET}-gcc -print-multiarch ${cflags} ) + fi +} + +CT_DoArchMUSLHeaderDir() { + local dir_var="${1}" + local cflags="${2}" + + # If it is non-default multilib, add a suffix with architecture (reported by gcc) + # to the headers installation path. + if [ -n "${cflags}" ]; then + eval "${dir_var}="$( ${CT_TARGET}-gcc -print-multiarch ${cflags} ) + fi } diff --git a/scripts/build/arch/xtensa.sh b/scripts/build/arch/xtensa.sh index c7bd4320..a3010c69 100644 --- a/scripts/build/arch/xtensa.sh +++ b/scripts/build/arch/xtensa.sh @@ -70,3 +70,9 @@ CT_ConfigureXtensa() { CT_Popd } + +CT_DoArchUClibcConfig() { + local cfg="${1}" + + CT_DoArchUClibcSelectArch "${cfg}" "xtensa" +} diff --git a/scripts/build/binutils/binutils.sh b/scripts/build/binutils/binutils.sh index edaf8187..c1e490d9 100644 --- a/scripts/build/binutils/binutils.sh +++ b/scripts/build/binutils/binutils.sh @@ -25,7 +25,7 @@ do_binutils_get() { CT_GetCustom "elf2flt" "${CT_ELF2FLT_CUSTOM_VERSION}" \ "${CT_ELF2FLT_CUSTOM_LOCATION}" else - CT_GetGit elf2flt "${CT_ELF2FLT_GIT_CSET}" http://cgit.openadk.org/cgi/cgit/elf2flt.git + CT_GetGit elf2flt "${CT_ELF2FLT_GIT_CSET}" https://github.com/uclinux-dev/elf2flt.git fi fi } @@ -132,7 +132,7 @@ do_binutils_for_host() { mkdir -p "${CT_BUILDTOOLS_PREFIX_DIR}/bin" for t in "${binutils_tools[@]}"; do CT_DoExecLog ALL ln -sv \ - "${CT_PREFIX_DIR}/bin/${CT_TARGET}-${t}" \ + "${CT_PREFIX_DIR}/${CT_TARGET}/bin/${t}" \ "${CT_BUILDTOOLS_PREFIX_DIR}/${CT_TARGET}/bin/${t}" CT_DoExecLog ALL ln -sv \ "${CT_PREFIX_DIR}/bin/${CT_TARGET}-${t}" \ @@ -309,6 +309,7 @@ do_elf2flt_backend() { --with-binutils-include-dir=${binutils_src}/include \ --with-libbfd=${binutils_bld}/bfd/libbfd.a \ --with-libiberty=${binutils_bld}/libiberty/libiberty.a \ + --disable-werror \ ${elf2flt_opts} \ "${CT_ELF2FLT_EXTRA_CONFIG_ARRAY[@]}" diff --git a/scripts/build/cc/100-gcc.sh b/scripts/build/cc/100-gcc.sh index 7085a904..0e0f8ed5 100644 --- a/scripts/build/cc/100-gcc.sh +++ b/scripts/build/cc/100-gcc.sh @@ -85,6 +85,169 @@ cc_gcc_lang_list() { } #------------------------------------------------------------------------------ +# Return a value of a requested GCC spec +cc_gcc_get_spec() { + local spec=$1 + local cc_and_cflags=$2 + + # GCC does not provide a facility to request a value of a spec string. + # The only way to do that I found was to augment the spec file with + # some dummy suffix handler that does nothing except printing it. + touch temp-input.spec_eval + { + echo ".spec_eval:" + echo "echo %(${spec})" + } > "tmp-specs-${spec}" + ${cc_and_cflags} -specs="tmp-specs-${spec}" -E temp-input.spec_eval +} + +#------------------------------------------------------------------------------ +# Report the type of a GCC option +cc_gcc_classify_opt() { + # Options present in multiple architectures + case "${1}" in + -march=*) echo "arch"; return;; + -mabi=*) echo "abi"; return;; + -mcpu=*|-mmcu=*) echo "cpu"; return;; + -mtune=*) echo "tune"; return;; + -mfpu=*) echo "fpu"; return;; + -mhard-float|-msoft-float|-mno-soft-float|-mno-float|-mfloat-abi=*|\ + -mfpu|-mno-fpu) echo "float"; return;; + -EB|-EL|-mbig-endian|-mlittle-endian|-mbig|-mlittle|-meb|-mel|-mb|-ml) echo "endian"; return;; + -mthumb|-marm) echo "mode"; return;; + esac + + # Arch-specific options and aliases + case "${CT_ARCH}" in + m68k) + case "${1}" in + -m68881) echo "float"; return;; + -m5[234]*|-mcfv4e) echo "cpu"; return;; + -m68*|-mc68*) echo "arch"; return;; + esac + ;; + mips) + case "${1}" in + -mips[1234]|-mips32|-mips32r*|-mips64|-mips64r*) echo "cpu"; return;; + esac + ;; + sh) + case "${1}" in + -m[12345]*) echo "cpu"; return;; + esac + esac + + # All tried and failed + echo "unknown" +} + +#------------------------------------------------------------------------------ +# This function lists the multilibs configured in the compiler (even if multilib +# is disabled - so that it lists the default GCC/OS directory, which may differ +# from the default 'lib'). It then performs a few multilib checks/quirks: +# +# 1. On SuperH target, configuring with default CPU (e.g. by supplying the target +# name as 'sh4', which is what CT-NG does) results in the compiler being unable to +# run if that same switch is passed to the resulting gcc (e.g. 'gcc -m4'). The reason +# for this behavior is that the script that determines the sysroot suffix is not +# aware of the default multilib selection, so it generates <sysroot>/m4 as the +# suffixed sysroot. But the main driver, knowing that -m4 is the default, does not +# even attempt to fall back to the non-suffixed sysroot (as it does with non-default +# multilibs) - as a result, gcc fails to find any library if invoked with -m4. +# The right solution would be to drop the default CPU from the multilib list +# completely, or make the print-sysroot-suffix.sh script aware of the defaults +# (which is not easy, as the defaults are not in tmake_file, but rather in tm_file...) +# +# 2. On MIPS target, gcc (or rather, ld, which it invokes under the hood) chokes +# if supplied with two -mabi=* options. I.e., 'gcc -mabi=n32' and 'gcc -mabi=32' both +# work, but 'gcc -mabi=32 -mabi=n32' produces an internal error in ld. Thus we do +# not supply target's CFLAGS in multilib builds - and after compiling pass-1 gcc, +# attempt to determine which CFLAGS need to be filtered out. +cc_gcc_multilib_housekeeping() { + local cc host + local flags osdir dir multilibs i f + local multilib_defaults + local suffix sysroot base lnk + local ml_arch ml_abi ml_cpu ml_tune ml_fpu ml_float ml_endian ml_mode ml_unknown ml + local new_cflags + + for arg in "$@"; do + eval "${arg// /\\ }" + done + + if [ \( "${CT_CANADIAN}" = "y" -o "${CT_CROSS_NATIVE}" = "y" \) -a "${host}" = "${CT_HOST}" ]; then + CT_DoLog EXTRA "Canadian Cross/Cross-native unable to confirm multilibs configuration "\ + "directly; will use build-compiler for housekeeping." + # Since we cannot run the desired compiler, substitute build-CC with the assumption + # that the host-CC is configured in the same way. + cc="${CT_BUILDTOOLS_PREFIX_DIR}/bin/${CT_TARGET}-gcc" + fi + + # sed: prepend dashes or do nothing if default is empty string + multilib_defaults=( $( cc_gcc_get_spec multilib_defaults "${cc}" | \ + ${sed} 's/\(^\|[[:space:]]\+\)\([^[:space:]]\)/ -\2/g' ) ) + CT_DoLog EXTRA "gcc default flags: '${multilib_defaults}'" + + multilibs=( $( "${cc}" -print-multi-lib ) ) + if [ ${#multilibs[@]} -ne 0 ]; then + CT_DoLog EXTRA "gcc configured with these multilibs (including the default):" + for i in "${multilibs[@]}"; do + dir="lib/${i%%;*}" + flags="${i#*;}" + flags=${flags//@/ -} + flags=$( echo ${flags} ) + osdir="lib/"$( "${cc}" -print-multi-os-directory ${flags} ) + CT_SanitizeVarDir dir osdir + CT_DoLog EXTRA " '${flags}' --> ${dir} (gcc) ${osdir} (os)" + for f in ${flags}; do + eval ml_`cc_gcc_classify_opt ${f}`=seen + done + done + else + CT_DoLog WARN "no multilib configuration: GCC unusable?" + fi + + # Filtering out some of the options provided in CT-NG config. Then *prepend* + # them to CT_TARGET_CFLAGS, like scripts/crosstool-NG.sh does. Zero out + # the stashed MULTILIB flags so that we don't process them again in the passes + # that follow. + CT_DoLog DEBUG "Configured target CFLAGS: '${CT_ARCH_TARGET_CFLAGS_MULTILIB}'" + ml_unknown= # Pass through anything we don't know about + for f in ${CT_ARCH_TARGET_CFLAGS_MULTILIB}; do + eval ml=\$ml_`cc_gcc_classify_opt ${f}` + if [ "${ml}" != "seen" ]; then + new_cflags="${new_cflags} ${f}" + fi + done + CT_DoLog DEBUG "Filtered target CFLAGS: '${new_cflags}'" + CT_EnvModify CT_TARGET_CFLAGS "${new_cflags} ${CT_TARGET_CFLAGS}" + CT_EnvModify CT_ARCH_TARGET_CFLAGS_MULTILIB "" + + # Currently, the only LDFLAGS are endianness-related + CT_DoLog DEBUG "Configured target LDFLAGS: '${CT_ARCH_TARGET_LDFLAGS_MULTILIB}'" + if [ "${ml_endian}" != "seen" ]; then + CT_EnvModify CT_TARGET_LDFLAGS "${CT_ARCH_TARGET_LDFLAGS_MULTILIB} ${CT_TARGET_LDFLAGS}" + CT_EnvModify CT_ARCH_TARGET_LDFLAGS_MULTILIB "" + fi + CT_DoLog DEBUG "Filtered target LDFLAGS: '${CT_ARCH_TARGET_LDFLAGS_MULTILIB}'" + + # Sysroot suffix fixup for the multilib default. + suffix=$( cc_gcc_get_spec sysroot_suffix_spec "${cc} ${multilib_defaults}" ) + if [ -n "${suffix}" ]; then + base=${suffix%/*} + sysroot=$( "${cc}" -print-sysroot ) + if [ -n "${base}" ]; then + CT_DoExecLog ALL mkdir -p "${sysroot}${base}" + lnk=$( echo "${base#/}" | ${sed} -e 's,[^/]*,..,g' ) + else + lnk=. + fi + CT_DoExecLog ALL rm -f "${sysroot}${suffix}" + CT_DoExecLog ALL ln -sfv "${lnk}" "${sysroot}${suffix}" + fi +} + +#------------------------------------------------------------------------------ # Core gcc pass 1 do_gcc_core_pass_1() { local -a core_opts @@ -273,6 +436,7 @@ do_gcc_core_backend() { extra_config+=(--disable-libgomp) extra_config+=(--disable-libmudflap) + extra_config+=(--disable-libmpx) if [ "${CT_CC_GCC_LIBSSP}" = "y" ]; then extra_config+=(--enable-libssp) @@ -403,10 +567,20 @@ do_gcc_core_backend() { extra_config+=("--with-system-zlib") fi - # Some versions of gcc have a deffective --enable-multilib. - # Since that's the default, only pass --disable-multilib. + # Some versions of gcc have a defective --enable-multilib. + # Since that's the default, only pass --disable-multilib. For multilib, + # also enable multiarch. Without explicit --enable-multiarch, pass-1 + # compiler is configured as multilib/no-multiarch and pass-2/final + # are multilib/multiarch (because gcc autodetects multiarch based on + # multiple instances of crt*.o in the install directory - which do + # not exist in pass-1). if [ "${CT_MULTILIB}" != "y" ]; then extra_config+=("--disable-multilib") + else + extra_config+=("--enable-multiarch") + if [ -n "${CT_CC_GCC_MULTILIB_LIST}" ]; then + extra_config+=("--with-multilib-list=${CT_CC_GCC_MULTILIB_LIST}") + fi fi CT_DoLog DEBUG "Extra config passed: '${extra_config[*]}'" @@ -522,14 +696,22 @@ do_gcc_core_backend() { CT_DoLog EXTRA "Building ${log_txt}" CT_DoExecLog ALL ${make} ${JOBSFLAGS} ${core_targets_all} + # Do not pass ${JOBSFLAGS} here: recent GCC builds have been failing + # in parallel 'make install' at random locations: libitm, libcilk, + # always for the files that are installed more than once to the same + # location (such as libitm.info). + # The symptom is that the install command fails with "File exists" + # error; running the same command manually succeeds. It looks like + # attempts to remove the destination and re-create it, but another + # install gets in the way. CT_DoLog EXTRA "Installing ${log_txt}" - CT_DoExecLog ALL ${make} ${JOBSFLAGS} ${core_targets_install} + CT_DoExecLog ALL ${make} ${core_targets_install} # Remove the libtool "pseudo-libraries": having them in the installed # tree makes the libtoolized utilities that are built next assume # that, for example, libsupc++ is an "accessory library", and not include # -lsupc++ to the link flags. That breaks ltrace, for example. - CT_DoLog EXTRA "Housekeeping for final gcc compiler" + CT_DoLog EXTRA "Housekeeping for core gcc compiler" CT_Pushd "${prefix}" find . -type f -name "*.la" -exec rm {} \; |CT_DoLog ALL CT_Popd @@ -550,25 +732,8 @@ do_gcc_core_backend() { CT_DoExecLog ALL ln -sfv "${CT_TARGET}-gcc${ext}" "${prefix}/bin/${CT_TARGET}-cc${ext}" fi - if [ "${CT_MULTILIB}" = "y" ]; then - if [ "${CT_CANADIAN}" = "y" -a "${mode}" = "baremetal" \ - -a "${host}" = "${CT_HOST}" ]; then - CT_DoLog WARN "Canadian Cross unable to confirm multilibs configured correctly" - else - multilibs=( $( "${prefix}/bin/${CT_TARGET}-gcc" -print-multi-lib \ - |tail -n +2 ) ) - if [ ${#multilibs[@]} -ne 0 ]; then - CT_DoLog EXTRA "gcc configured with these multilibs (besides the default):" - for i in "${multilibs[@]}"; do - dir="${i%%;*}" - flags="${i#*;}" - CT_DoLog EXTRA " ${flags//@/ -} --> ${dir}/" - done - else - CT_DoLog WARN "gcc configured for multilib, but none available" - fi - fi - fi + cc_gcc_multilib_housekeeping cc="${prefix}/bin/${CT_TARGET}-gcc" \ + host="${host}" } #------------------------------------------------------------------------------ @@ -613,6 +778,35 @@ do_gcc_for_build() { CT_EndStep } +gcc_movelibs() { + local multi_flags multi_dir multi_os_dir multi_root multi_index multi_count + local gcc_dir + + for arg in "$@"; do + eval "${arg// /\\ }" + done + + # Move only files, directories are for other multilibs + gcc_dir="${CT_PREFIX_DIR}/${CT_TARGET}/lib/${multi_os_dir}" + if [ ! -d "${gcc_dir}" ]; then + # GCC didn't install anything outside of sysroot + return + fi + ls "${gcc_dir}" | while read f; do + case "${f}" in + *.ld) + # Linker scripts remain in GCC's directory; elf2flt insists on + # finding them there. + continue + ;; + esac + if [ -f "${gcc_dir}/${f}" ]; then + CT_DoExecLog ALL mkdir -p "${multi_root}/lib/${multi_os_dir}" + CT_DoExecLog ALL mv "${gcc_dir}/${f}" "${multi_root}/lib/${multi_os_dir}/${f}" + fi + done +} + #------------------------------------------------------------------------------ # Build final gcc to run on host do_gcc_for_host() { @@ -644,10 +838,18 @@ do_gcc_for_host() { CT_DoStep INFO "Installing final gcc compiler" CT_mkdir_pushd "${CT_BUILD_DIR}/build-cc-gcc-final" - "${final_backend}" "${final_opts[@]}" - CT_Popd + + # GCC installs stuff (including libgcc) into its own /lib dir, + # outside of sysroot, breaking linking with -static-libgcc. + # Fix up by moving the libraries into the sysroot. + if [ "${CT_USE_SYSROOT}" = "y" ]; then + CT_mkdir_pushd "${CT_BUILD_DIR}/build-cc-gcc-final-movelibs" + CT_IterateMultilibs gcc_movelibs movelibs + CT_Popd + fi + CT_EndStep } @@ -748,6 +950,14 @@ do_gcc_backend() { fi fi + if [ "${CT_CC_GCC_HAS_LIBMPX}" = "y" ]; then + if [ "${CT_CC_GCC_LIBMPX}" = "y" ]; then + extra_config+=(--enable-libmpx) + else + extra_config+=(--disable-libmpx) + fi + fi + final_LDFLAGS+=("${ldflags}") # *** WARNING ! *** @@ -880,10 +1090,15 @@ do_gcc_backend() { extra_config+=("--with-system-zlib") fi - # Some versions of gcc have a deffective --enable-multilib. + # Some versions of gcc have a defective --enable-multilib. # Since that's the default, only pass --disable-multilib. if [ "${CT_MULTILIB}" != "y" ]; then extra_config+=("--disable-multilib") + else + extra_config+=("--enable-multiarch") + if [ -n "${CT_CC_GCC_MULTILIB_LIST}" ]; then + extra_config+=("--with-multilib-list=${CT_CC_GCC_MULTILIB_LIST}") + fi fi CT_DoLog DEBUG "Extra config passed: '${extra_config[*]}'" @@ -921,11 +1136,12 @@ do_gcc_backend() { CT_DoLog EXTRA "Building final gcc compiler" CT_DoExecLog ALL ${make} ${JOBSFLAGS} all + # See the note on issues with parallel 'make install' in GCC above. CT_DoLog EXTRA "Installing final gcc compiler" if [ "${CT_STRIP_TARGET_TOOLCHAIN_EXECUTABLES}" = "y" ]; then - CT_DoExecLog ALL ${make} ${JOBSFLAGS} install-strip + CT_DoExecLog ALL ${make} install-strip else - CT_DoExecLog ALL ${make} ${JOBSFLAGS} install + CT_DoExecLog ALL ${make} install fi # Remove the libtool "pseudo-libraries": having them in the installed @@ -950,25 +1166,9 @@ do_gcc_backend() { file="$( ls -1 "${CT_PREFIX_DIR}/bin/${CT_TARGET}-gcc."* 2>/dev/null || true )" [ -z "${file}" ] || ext=".${file##*.}" if [ -f "${CT_PREFIX_DIR}/bin/${CT_TARGET}-gcc${ext}" ]; then - CT_DoExecLog ALL ln -sfv "${CT_TARGET}-gcc${ext}" "${CT_PREFIX_DIR}/bin/${CT_TARGET}-cc${ext}" + CT_DoExecLog ALL ln -sfv "${CT_TARGET}-gcc${ext}" "${prefix}/bin/${CT_TARGET}-cc${ext}" fi - if [ "${CT_MULTILIB}" = "y" ]; then - if [ "${CT_CANADIAN}" = "y" ]; then - CT_DoLog WARN "Canadian Cross unable to confirm multilibs configured correctly" - else - multilibs=( $( "${prefix}/bin/${CT_TARGET}-gcc" -print-multi-lib \ - |tail -n +2 ) ) - if [ ${#multilibs[@]} -ne 0 ]; then - CT_DoLog EXTRA "gcc configured with these multilibs (besides the default):" - for i in "${multilibs[@]}"; do - dir="${i%%;*}" - flags="${i#*;}" - CT_DoLog EXTRA " ${flags//@/ -} --> ${dir}/" - done - else - CT_DoLog WARN "gcc configured for multilib, but none available" - fi - fi - fi + cc_gcc_multilib_housekeeping cc="${prefix}/bin/${CT_TARGET}-gcc" \ + host="${host}" } diff --git a/scripts/build/debug/300-gdb.sh b/scripts/build/debug/300-gdb.sh index 418e85c6..ee4753ef 100644 --- a/scripts/build/debug/300-gdb.sh +++ b/scripts/build/debug/300-gdb.sh @@ -69,7 +69,11 @@ do_debug_gdb_build() { cross_extra_config=("${extra_config[@]}") cross_extra_config+=("--with-expat") - cross_extra_config+=("--with-libexpat-prefix=${CT_HOST_COMPLIBS_DIR}") + # NOTE: DO NOT USE --with-libexpat-prefix (until GDB configure is smarter)!!! + # It conflicts with a static build: GDB's configure script will find the shared + # version of expat and will attempt to link that, despite the -static flag. + # The link will fail, and configure will abort with "expat missing or unusable" + # message. case "${CT_THREADS}" in none) cross_extra_config+=("--disable-threads");; *) cross_extra_config+=("--enable-threads");; @@ -88,17 +92,24 @@ do_debug_gdb_build() { cross_extra_config+=("--disable-nls") fi - CC_for_gdb= - LD_for_gdb= + CC_for_gdb="${CT_HOST}-gcc ${CT_CFLAGS_FOR_HOST} ${CT_LDFLAGS_FOR_HOST}" + LD_for_gdb="${CT_HOST}-ld ${CT_LDFLAGS_FOR_HOST}" if [ "${CT_GDB_CROSS_STATIC}" = "y" ]; then - CC_for_gdb="${CT_HOST}-gcc -static" - LD_for_gdb="${CT_HOST}-ld -static" + CC_for_gdb+=" -static" + LD_for_gdb+=" -static" fi - # Disable binutils options when building from the binutils-gdb repo. - cross_extra_config+=("--disable-binutils") - cross_extra_config+=("--disable-ld") - cross_extra_config+=("--disable-gas") + # Fix up whitespace. Some older GDB releases (e.g. 6.8a) get confused if there + # are multiple consecutive spaces: sub-configure scripts replace them with a + # single space and then complain that $CC value changed from that in + # the master directory. + CC_for_gdb=`echo $CC_for_gdb` + LD_for_gdb=`echo $LD_for_gdb` + + # Disable binutils options when building from the binutils-gdb repo. + cross_extra_config+=("--disable-binutils") + cross_extra_config+=("--disable-ld") + cross_extra_config+=("--disable-gas") CT_DoLog DEBUG "Extra config passed: '${cross_extra_config[*]}'" @@ -162,6 +173,11 @@ do_debug_gdb_build() { fi native_extra_config+=("--with-expat") + # NOTE: DO NOT USE --with-libexpat-prefix (until GDB configure is smarter)!!! + # It conflicts with a static build: GDB's configure script will find the shared + # version of expat and will attempt to link that, despite the -static flag. + # The link will fail, and configure will abort with "expat missing or unusable" + # message. CT_DoLog EXTRA "Configuring native gdb" diff --git a/scripts/build/internals.sh b/scripts/build/internals.sh index a2351acd..3f0260e8 100644 --- a/scripts/build/internals.sh +++ b/scripts/build/internals.sh @@ -8,6 +8,7 @@ do_finish() { local _type local strip_args local gcc_version + local exe_suffix CT_DoStep INFO "Cleaning-up the toolchain's directory" @@ -20,13 +21,21 @@ do_finish() { strip_args="--strip-all -v" ;; esac + case "$CT_TARGET" in + *mingw*) + exe_suffix=".exe" + ;; + *) + exe_suffix="" + ;; + esac CT_DoLog INFO "Stripping all toolchain executables" CT_Pushd "${CT_PREFIX_DIR}" # Strip gdbserver if [ "${CT_GDB_GDBSERVER}" = "y" ]; then CT_DoExecLog ALL "${CT_TARGET}-strip" ${strip_args} \ - "${CT_TARGET}/debug-root/usr/bin/gdbserver" + "${CT_TARGET}/debug-root/usr/bin/gdbserver${exe_suffix}" fi if [ "${CT_CC_gcc}" = "y" ]; then # We can not use the version in CT_CC_GCC_VERSION because @@ -64,6 +73,7 @@ do_finish() { CT_DoLog EXTRA "Installing the populate helper" ${sed} -r -e 's|@@CT_TARGET@@|'"${CT_TARGET}"'|g;' \ -e 's|@@CT_install@@|'"${install}"'|g;' \ + -e 's|@@CT_awk@@|'"${awk}"'|g;' \ -e 's|@@CT_bash@@|'"${bash}"'|g;' \ -e 's|@@CT_grep@@|'"${grep}"'|g;' \ -e 's|@@CT_make@@|'"${make}"'|g;' \ @@ -118,12 +128,5 @@ do_finish() { CT_DoForceRmdir "${CT_DEBUGROOT_DIR}/"{,usr/}{,share/}{man,info} fi - # Remove the lib* symlinks, now: - # The symlinks are needed only during the build process. - # The final gcc will still search those dirs, but will also search - # the standard lib/ dirs, so we can get rid of the symlinks - CT_DoExecLog ALL rm -f "${CT_PREFIX_DIR}/lib32" - CT_DoExecLog ALL rm -f "${CT_PREFIX_DIR}/lib64" - CT_EndStep } diff --git a/scripts/build/libc/avr-libc.sh b/scripts/build/libc/avr-libc.sh index b73f990b..3dc91a42 100644 --- a/scripts/build/libc/avr-libc.sh +++ b/scripts/build/libc/avr-libc.sh @@ -18,10 +18,6 @@ do_libc_extract() { CT_Patch "avr-libc" "${CT_LIBC_VERSION}" } -do_libc_check_config() { - : -} - do_libc_configure() { CT_DoLog EXTRA "Configuring C library" diff --git a/scripts/build/libc/glibc.sh b/scripts/build/libc/glibc.sh index 0a09cbd1..5067455f 100644 --- a/scripts/build/libc/glibc.sh +++ b/scripts/build/libc/glibc.sh @@ -30,7 +30,8 @@ do_libc_get() { do_libc_extract() { CT_Extract "${CT_LIBC}-${CT_LIBC_VERSION}" CT_Pushd "${CT_SRC_DIR}/${CT_LIBC}-${CT_LIBC_VERSION}" - # Attempt CT_PATCH only if NOT custom + # Custom glibc won't get patched, because CT_GetCustom + # marks custom glibc as patched. CT_Patch nochdir "${CT_LIBC}" "${CT_LIBC_VERSION}" # The configure files may be older than the configure.in files @@ -41,10 +42,6 @@ do_libc_extract() { CT_Popd } -do_libc_check_config() { - : -} - # Build and install headers and start files do_libc_start_files() { # Start files and Headers should be configured the same way as the @@ -68,13 +65,6 @@ do_libc_post_cc() { # libc_mode : 'startfiles' or 'final' : string : (none) do_libc_backend() { local libc_mode - local -a multilibs - local multilib - local multi_dir - local multi_flags - local extra_dir - local libc_headers libc_startfiles libc_full - local hdr local arg for arg in "$@"; do @@ -84,136 +74,77 @@ do_libc_backend() { case "${libc_mode}" in startfiles) CT_DoStep INFO "Installing C library headers & start files" - hdr=y - libc_startfiles=y - libc_full= ;; final) CT_DoStep INFO "Installing C library" - hdr= - libc_startfiles= - libc_full=y ;; - *) CT_Abort "Unsupported (or unset) libc_mode='${libc_mode}'";; + *) + CT_Abort "Unsupported (or unset) libc_mode='${libc_mode}'" + ;; esac - # If gcc is not configured for multilib, it still prints - # a single line for the default settings - multilibs=( $("${CT_TARGET}-gcc" -print-multi-lib 2>/dev/null) ) - for multilib in "${multilibs[@]}"; do - multi_dir="${multilib%%;*}" - if [ "${multi_dir}" != "." ]; then - CT_DoStep INFO "Building for multilib subdir='${multi_dir}'" - - extra_flags="$( echo "${multilib#*;}" \ - |${sed} -r -e 's/@/ -/g;' \ - )" - extra_dir="/${multi_dir}" - - # glibc install its files in ${extra_dir}/{usr/,}lib - # while gcc expects them in {,usr/}lib/${extra_dir}. - # Prepare some symlinks so glibc installs in fact in - # the proper place - # We do it in the start-files step, so it is not needed - # to do it in the final step, as the symlinks will - # already exist - if [ "${libc_mode}" = "startfiles" ]; then - CT_Pushd "${CT_SYSROOT_DIR}" - CT_DoExecLog ALL mkdir -p "lib/${multi_dir}" \ - "usr/lib/${multi_dir}" \ - "${multi_dir}" \ - "${multi_dir}/usr" - CT_DoExecLog ALL ln -sf "../lib/${multi_dir}" "${multi_dir}/lib" - CT_DoExecLog ALL ln -sf "../../usr/lib/${multi_dir}" "${multi_dir}/usr/lib" - CT_Popd - fi - libc_headers= - else - extra_dir= - extra_flags= - libc_headers="${hdr}" - fi - - CT_mkdir_pushd "${CT_BUILD_DIR}/build-libc-${libc_mode}${extra_dir//\//_}" - - do_libc_backend_once extra_dir="${extra_dir}" \ - extra_flags="${extra_flags}" \ - libc_headers="${libc_headers}" \ - libc_startfiles="${libc_startfiles}" \ - libc_full="${libc_full}" - - CT_Popd - - if [ "${multi_dir}" != "." ]; then - if [ "${libc_mode}" = "final" ]; then - CT_DoLog EXTRA "Fixing up multilib location" - - # rewrite the library multiplexers - for d in "lib/${multi_dir}" "usr/lib/${multi_dir}"; do - for l in libc libpthread libgcc_s; do - if [ -f "${CT_SYSROOT_DIR}/${d}/${l}.so" \ - -a ! -L ${CT_SYSROOT_DIR}/${d}/${l}.so ] - then - CT_DoExecLog DEBUG ${sed} -r -i \ - -e "s:/lib/:/lib/${multi_dir}/:g;" \ - "${CT_SYSROOT_DIR}/${d}/${l}.so" - fi - done - done - # Remove the multi_dir now it is no longer useful - CT_DoExecLog DEBUG rm -rf "${CT_SYSROOT_DIR}/${multi_dir}" - fi # libc_mode == final - - CT_EndStep - fi - done - + CT_mkdir_pushd "${CT_BUILD_DIR}/build-libc-${libc_mode}" + CT_IterateMultilibs do_libc_backend_once multilib libc_mode="${libc_mode}" + CT_Popd CT_EndStep } # This backend builds the C library once # Usage: do_libc_backend_once param=value [...] -# Parameter : Definition : Type : Default -# libc_headers : Build libc headers : bool : n -# libc_startfiles : Build libc start-files : bool : n -# libc_full : Build full libc : bool : n -# extra_flags : Extra CFLAGS to use (for multilib) : string : (empty) -# extra_dir : Extra subdir for multilib : string : (empty) +# Parameter : Definition : Type +# libc_mode : 'startfiles' or 'final' : string : (empty) +# multi_* : as defined in CT_IterateMultilibs : (varies) : do_libc_backend_once() { - local libc_headers - local libc_startfiles - local libc_full - local extra_flags - local extra_dir + local multi_flags multi_dir multi_os_dir multi_root multi_index multi_count + local startfiles_dir local src_dir="${CT_SRC_DIR}/${CT_LIBC}-${CT_LIBC_VERSION}" - local extra_cc_args local -a extra_config local -a extra_make_args local glibc_cflags - local float_extra - local endian_extra - local arg + local arg opt for arg in "$@"; do eval "${arg// /\\ }" done + CT_DoStep INFO "Building for multilib ${multi_index}/${multi_count}: '${multi_flags}'" + + # Ensure sysroot (with suffix, if applicable) exists + CT_DoExecLog ALL mkdir -p "${multi_root}" + + # Adjust target tuple according GLIBC quirks + CT_DoArchGlibcAdjustTuple multi_target + + # Glibc seems to be smart enough to know about the cases that can coexist + # in the same root and installs them into proper multilib-os directory; all + # we need is to point to the right root. We do need to handle multilib-os + # here, though, for the first pass where we install crt*.o and a dummy + # libc.so; we therefore install it to the most specific location of + # <sysroot>/<suffix>/usr/lib/<multilib-os> where it is least likely to clash + # with other multilib variants. We then remove these temporary files at + # the beginning of the libc-final step and allow glibc to install them + # where it thinks is proper. + startfiles_dir="${multi_root}/usr/lib/${multi_os_dir}" + CT_SanitizeVarDir startfiles_dir + + if [ "${libc_mode}" = "final" ]; then + CT_DoLog EXTRA "Cleaning up start files" + CT_DoExecLog ALL rm -f "${startfiles_dir}/crt1.o" \ + "${startfiles_dir}/crti.o" \ + "${startfiles_dir}/crtn.o" \ + "${startfiles_dir}/libc.so" + fi + CT_DoLog EXTRA "Configuring C library" - case "${CT_LIBC}" in - glibc) - # glibc can't be built without -O2 (reference needed!) - OPTIMIZE=-O2 - # Also, if those two are missing, iconv build breaks - extra_config+=( --disable-debug --disable-sanity-checks ) - ;; - esac + # Also, if those two are missing, iconv build breaks + extra_config+=( --disable-debug --disable-sanity-checks ) # always include rpc, the user can still override it with TI-RPC extra_config+=( --enable-obsolete-rpc ) # Add some default glibc config options if not given by user. - # We don't need to be conditional on wether the user did set different + # We don't need to be conditional on whether the user did set different # values, as they CT_LIBC_GLIBC_EXTRA_CONFIG_ARRAY is passed after # extra_config @@ -235,21 +166,6 @@ do_libc_backend_once() { *) extra_config+=("--disable-shared");; esac - float_extra="$( echo "${extra_flags}" \ - |${sed} -r -e '/^(.*[[:space:]])?-m(hard|soft)-float([[:space:]].*)?$/!d;' \ - -e 's//\2/;' \ - )" - case "${float_extra}" in - hard) extra_config+=("--with-fp");; - soft) extra_config+=("--without-fp");; - "") - case "${CT_ARCH_FLOAT}" in - hard|softfp) extra_config+=("--with-fp");; - soft) extra_config+=("--without-fp");; - esac - ;; - esac - if [ "${CT_LIBC_DISABLE_VERSIONING}" = "y" ]; then extra_config+=("--disable-versioning") fi @@ -266,24 +182,6 @@ do_libc_backend_once() { extra_config+=("--with-pkgversion=${CT_PKGVERSION}") [ -n "${CT_TOOLCHAIN_BUGURL}" ] && extra_config+=("--with-bugurl=${CT_TOOLCHAIN_BUGURL}") - # Extract the endianness options if any - # This should cover all possible endianness options - # in gcc, but it is prone to bit-rot... :-( - endian_extra="$( echo "${extra_flags}" \ - |${sed} -r -e '/^(.*[[:space:]])?-(E[BL]|m((big|little)(-endian)?|e?[bl]))([[:space:]].*)?$/!d;' \ - -e 's//\2/;' \ - )" - case "${endian_extra}" in - EB|mbig-endian|mbig|meb|mb) - extra_cc_args="${extra_cc_args} ${endian_extra}" - ;; - EL|mlittle-endian|mlittle|mel|ml) - extra_cc_args="${extra_cc_args} ${endian_extra}" - ;; - "") extra_cc_args="${extra_cc_args} ${CT_ARCH_ENDIAN_OPT}" - ;; - esac - touch config.cache if [ "${CT_LIBC_GLIBC_FORCE_UNWIND}" = "y" ]; then echo "libc_cv_forced_unwind=yes" >>config.cache @@ -293,14 +191,30 @@ do_libc_backend_once() { # Pre-seed the configparms file with values from the config option printf "%s\n" "${CT_LIBC_GLIBC_CONFIGPARMS}" > configparms - cross_cc=$(CT_Which "${CT_TARGET}-gcc") - extra_cc_args+=" ${extra_flags}" + # glibc can't be built without -O2 (reference needed!) + glibc_cflags+=" -O2" case "${CT_LIBC_ENABLE_FORTIFIED_BUILD}" in y) ;; *) glibc_cflags+=" -U_FORTIFY_SOURCE";; esac - glibc_cflags+=" ${CT_TARGET_CFLAGS} ${OPTIMIZE} ${CT_LIBC_GLIBC_EXTRA_CFLAGS}" + + # In the order of increasing precedence. Flags common to compiler and linker. + glibc_cflags+=" ${CT_TARGET_CFLAGS}" + glibc_cflags+=" ${CT_LIBC_GLIBC_EXTRA_CFLAGS}" + glibc_cflags+=" ${multi_flags}" + + # Analyze the resulting options for any extra configure switches to throw in. + for opt in ${glibc_cflags}; do + case ${opt} in + -mhard-float|-mfloat-abi=hard|-mfloat-abi=softfp|-mno-soft-float|-mfpu) + extra_config+=("--with-fp") + ;; + -msoft-float|-mfloat-abi=soft|-mno-float|-mno-fpu) + extra_config+=("--without-fp") + ;; + esac + done # ./configure is mislead by our tools override wrapper for bash # so just tell it where the real bash is _on_the_target_! @@ -317,31 +231,35 @@ do_libc_backend_once() { # Configure with --prefix the way we want it on the target... # There are a whole lot of settings here. You'll probably want - # to read up on what they all mean, and customize a bit, possibly by setting GLIBC_EXTRA_CONFIG_ARRAY - # Compare these options with the ones used when installing the glibc headers above - they're different. - # Adding "--without-gd" option to avoid error "memusagestat.c:36:16: gd.h: No such file or directory" + # to read up on what they all mean, and customize a bit, possibly + # by setting GLIBC_EXTRA_CONFIG_ARRAY. + # Compare these options with the ones used when installing + # the glibc headers above - they're different. + # Adding "--without-gd" option to avoid error "memusagestat.c:36:16: + # gd.h: No such file or directory" # See also http://sources.redhat.com/ml/libc-alpha/2000-07/msg00024.html. # Set BUILD_CC, or we won't be able to build datafiles # Run explicitly through CONFIG_SHELL, or the build breaks badly (loop-of-death) # when the shell is not bash... Sigh... :-( - CT_DoLog DEBUG "Using gcc for target : '${cross_cc}'" - CT_DoLog DEBUG "Configuring with addons : '$(do_libc_add_ons_list ,)'" - CT_DoLog DEBUG "Extra config args passed: '${extra_config[*]}'" - CT_DoLog DEBUG "Extra CC args passed : '${glibc_cflags}'" - CT_DoLog DEBUG "Extra flags (multilib) : '${extra_flags}'" + CT_DoLog DEBUG "Configuring with addons : '$(do_libc_add_ons_list ,)'" + CT_DoLog DEBUG "Extra config args passed : '${extra_config[*]}'" + CT_DoLog DEBUG "Extra CFLAGS passed : '${glibc_cflags}'" + CT_DoLog DEBUG "Placing startfiles into : '${startfiles_dir}'" + CT_DoLog DEBUG "Configuring with --host : '${multi_target}'" + # CFLAGS are only applied when compiling .c files. .S files are compiled with ASFLAGS, + # but they are not passed by configure. Thus, pass everything in CC instead. CT_DoExecLog CFG \ - BUILD_CC="${CT_BUILD}-gcc" \ - CFLAGS="${glibc_cflags}" \ - CC="${CT_TARGET}-gcc ${CT_LIBC_EXTRA_CC_ARGS} ${extra_cc_args}" \ + BUILD_CC=${CT_BUILD}-gcc \ + CC="${CT_TARGET}-gcc ${glibc_cflags}" \ AR=${CT_TARGET}-ar \ RANLIB=${CT_TARGET}-ranlib \ "${CONFIG_SHELL}" \ "${src_dir}/configure" \ --prefix=/usr \ --build=${CT_BUILD} \ - --host=${CT_TARGET} \ + --host=${multi_target} \ --cache-file="$(pwd)/config.cache" \ --without-cvs \ --disable-profile \ @@ -377,13 +295,14 @@ do_libc_backend_once() { ;; esac - if [ "${libc_headers}" = "y" ]; then + if [ "${libc_mode}" = "startfiles" -a ! -r "${multi_root}/.libc_headers_installed" ]; then CT_DoLog EXTRA "Installing C library headers" + CT_DoExecLog ALL touch "${multi_root}/.libc_headers_installed" # use the 'install-headers' makefile target to install the # headers CT_DoExecLog ALL ${make} ${JOBSFLAGS} \ - install_root=${CT_SYSROOT_DIR}${extra_dir} \ + install_root=${multi_root} \ install-bootstrap-headers=yes \ "${extra_make_args[@]}" \ install-headers @@ -424,46 +343,52 @@ do_libc_backend_once() { ;; esac fi - fi # libc_headers == y + elif [ "${libc_mode}" = "final" -a -r "${multi_root}/.libc_headers_installed" ]; then + CT_DoExecLog ALL rm -f "${multi_root}/.libc_headers_installed" + fi # installing headers - if [ "${libc_startfiles}" = "y" ]; then + if [ "${libc_mode}" = "startfiles" ]; then if [ "${CT_THREADS}" = "nptl" ]; then CT_DoLog EXTRA "Installing C library start files" # there are a few object files needed to link shared libraries, # which we build and install by hand - CT_DoExecLog ALL mkdir -p "${CT_SYSROOT_DIR}${extra_dir}/usr/lib" + CT_DoExecLog ALL mkdir -p "${startfiles_dir}" CT_DoExecLog ALL ${make} ${JOBSFLAGS} \ - "${extra_make_args[@]}" \ + "${extra_make_args[@]}" \ csu/subdir_lib CT_DoExecLog ALL cp csu/crt1.o csu/crti.o csu/crtn.o \ - "${CT_SYSROOT_DIR}${extra_dir}/usr/lib" + "${startfiles_dir}" # Finally, 'libgcc_s.so' requires a 'libc.so' to link against. # However, since we will never actually execute its code, # it doesn't matter what it contains. So, treating '/dev/null' # as a C source file, we produce a dummy 'libc.so' in one step - CT_DoExecLog ALL "${cross_cc}" -nostdlib \ - -nostartfiles \ - -shared \ - -x c /dev/null \ - -o "${CT_SYSROOT_DIR}${extra_dir}/usr/lib/libc.so" + CT_DoExecLog ALL "${CT_TARGET}-gcc" ${multi_flags} \ + -nostdlib \ + -nostartfiles \ + -shared \ + -x c /dev/null \ + -o "${startfiles_dir}/libc.so" fi # threads == nptl - fi # libc_headers == y + fi # libc_mode = startfiles - if [ "${libc_full}" = "y" ]; then + if [ "${libc_mode}" = "final" ]; then CT_DoLog EXTRA "Building C library" CT_DoExecLog ALL ${make} ${JOBSFLAGS} \ "${extra_make_args[@]}" \ all CT_DoLog EXTRA "Installing C library" - CT_DoExecLog ALL ${make} ${JOBSFLAGS} \ - "${extra_make_args[@]}" \ - install_root="${CT_SYSROOT_DIR}${extra_dir}" \ + CT_DoExecLog ALL ${make} ${JOBSFLAGS} \ + "${extra_make_args[@]}" \ + install_root="${multi_root}" \ install - if [ "${CT_BUILD_MANUALS}" = "y" ]; then + if [ "${CT_BUILD_MANUALS}" = "y" -a "${multi_index}" = "${multi_count}" ]; then + # We only need to build the manuals once. Only build them on the + # last multilib target. If it's not multilib, it will happen on the + # only target. CT_DoLog EXTRA "Building and installing the C library manual" # Omit JOBSFLAGS as GLIBC has problems building the # manuals in parallel @@ -474,10 +399,12 @@ do_libc_backend_once() { ${CT_PREFIX_DIR}/share/doc fi - if [ "${CT_LIBC_LOCALES}" = "y" ]; then + if [ "${CT_LIBC_LOCALES}" = "y" -a "${multi_index}" = "${multi_count}" ]; then do_libc_locales fi - fi # libc_full == y + fi # libc_mode = final + + CT_EndStep } # Build up the addons list, separated with $1 diff --git a/scripts/build/libc/mingw.sh b/scripts/build/libc/mingw.sh index 964a11d9..e2b781db 100644 --- a/scripts/build/libc/mingw.sh +++ b/scripts/build/libc/mingw.sh @@ -23,10 +23,6 @@ do_libc_extract() { CT_Popd } -do_libc_check_config() { - : -} - do_set_mingw_install_prefix(){ MINGW_INSTALL_PREFIX=/usr/${CT_TARGET} if [[ ${CT_WINAPI_VERSION} == 2* ]]; then @@ -114,8 +110,35 @@ do_libc() { CT_DoExecLog ALL ${make} install DESTDIR=${CT_SYSROOT_DIR} CT_EndStep + + if [ "${CT_THREADS}" = "posix" ]; then + do_pthreads + fi } do_libc_post_cc() { : } + +do_pthreads() { + CT_DoStep INFO "Building mingw-w64-winpthreads files" + + CT_DoLog EXTRA "Configuring mingw-w64-winpthreads" + + CT_mkdir_pushd "${CT_BUILD_DIR}/build-mingw-w64-winpthreads" + + CT_DoExecLog CFG \ + "${CT_SRC_DIR}/mingw-w64-${CT_WINAPI_VERSION_DOWNLOADED}/mingw-w64-libraries/winpthreads/configure" \ + --with-sysroot=${CT_SYSROOT_DIR} \ + --prefix=${MINGW_INSTALL_PREFIX} \ + --build=${CT_BUILD} \ + --host=${CT_TARGET} \ + + CT_DoLog EXTRA "Building mingw-w64-winpthreads" + CT_DoExecLog ALL ${make} ${JOBSFLAGS} + + CT_DoLog EXTRA "Installing mingw-w64-winpthreads" + CT_DoExecLog ALL ${make} install DESTDIR=${CT_SYSROOT_DIR} + + CT_EndStep +} diff --git a/scripts/build/libc/musl.sh b/scripts/build/libc/musl.sh index 2699d795..2a0c04fd 100644 --- a/scripts/build/libc/musl.sh +++ b/scripts/build/libc/musl.sh @@ -16,10 +16,6 @@ do_libc_extract() { CT_Patch "musl" "${CT_LIBC_VERSION}" } -do_libc_check_config() { - : -} - # Build and install headers and start files do_libc_start_files() { # Start files and Headers should be configured the same way as the @@ -36,36 +32,51 @@ do_libc_post_cc() { : } +do_libc_backend() { + local libc_mode + local arg + + for arg in "$@"; do + eval "${arg// /\\ }" + done + + case "${libc_mode}" in + startfiles) CT_DoStep INFO "Installing C library headers & start files";; + final) CT_DoStep INFO "Installing C library";; + *) CT_Abort "Unsupported (or unset) libc_mode='${libc_mode}'";; + esac + + CT_mkdir_pushd "${CT_BUILD_DIR}/build-libc-${libc_mode}" + CT_IterateMultilibs do_libc_backend_once multilib libc_mode="${libc_mode}" + CT_Popd + CT_EndStep +} + # This backend builds the C library # Usage: do_libc_backend param=value [...] # Parameter : Definition : Type : Default # libc_mode : 'startfiles' or 'final' : string : (none) -do_libc_backend() { +do_libc_backend_once() { local libc_mode local -a extra_cflags local -a extra_config local src_dir="${CT_SRC_DIR}/${CT_LIBC}-${CT_LIBC_VERSION}" - local libc_headers libc_startfiles libc_full + local multi_dir multi_os_dir multi_root multi_flags multi_index multi_count + local multilib_dir + local hdr_install_subdir + local arg f l for arg in "$@"; do eval "${arg// /\\ }" done - case "${libc_mode}" in - startfiles) - CT_DoStep INFO "Installing C library headers & start files" - libc_headers=y - libc_startfiles=y - libc_full= - ;; - final) - CT_DoStep INFO "Installing C library" - libc_headers= - libc_startfiles= - libc_full=y - ;; - *) CT_Abort "Unsupported (or unset) libc_mode='${libc_mode}'";; - esac + CT_DoStep INFO "Building for multilib ${multi_index}/${multi_count}: '${multi_flags}'" + + multilib_dir="/usr/lib/${multi_os_dir}" + CT_SanitizeVarDir multilib_dir + CT_DoExecLog ALL mkdir -p "${multi_root}${multilib_dir}" + + extra_cflags=( ${multi_flags} ) # From buildroot: # gcc constant folding bug with weak aliases workaround @@ -84,42 +95,64 @@ do_libc_backend() { extra_config+=( "--enable-optimize=${CT_LIBC_MUSL_OPTIMIZE}" ) - CT_mkdir_pushd "${CT_BUILD_DIR}/build-libc-${libc_mode}" + # Same problem as with uClibc: different variants sometimes have + # incompatible headers. + CT_DoArchMUSLHeaderDir hdr_install_subdir "${multi_flags}" + if [ -n "${hdr_install_subdir}" ]; then + extra_config+=( "--includedir=/usr/include/${hdr_install_subdir}" ) + fi # NOTE: musl handles the build/host/target a little bit differently # then one would expect: # build : not used - # host : the machine building musl + # host : same as --target # target : the machine musl runs on - CT_DoExecLog CFG \ - CFLAGS="${extra_cflags[@]}" \ - CROSS_COMPILE="${CT_TARGET}-" \ - ${src_dir}/configure \ - --host="${CT_TARGET}" \ - --target="${CT_TARGET}" \ - --prefix="/usr" \ - --disable-gcc-wrapper \ + CT_DoExecLog CFG \ + CFLAGS="${extra_cflags[*]}" \ + CROSS_COMPILE="${CT_TARGET}-" \ + ${src_dir}/configure \ + --host="${multi_target}" \ + --target="${multi_target}" \ + --prefix="/usr" \ + --libdir="${multilib_dir}" \ + --disable-gcc-wrapper \ "${extra_config[@]}" - if [ "${libc_headers}" = "y" ]; then + if [ "${libc_mode}" = "startfiles" ]; then CT_DoLog EXTRA "Installing C library headers" - CT_DoExecLog ALL ${make} DESTDIR="${CT_SYSROOT_DIR}" install-headers - fi - if [ "${libc_startfiles}" = "y" ]; then + CT_DoExecLog ALL ${make} DESTDIR="${multi_root}" install-headers CT_DoLog EXTRA "Building C library start files" - CT_DoExecLog ALL ${make} DESTDIR="${CT_SYSROOT_DIR}" \ + CT_DoExecLog ALL ${make} DESTDIR="${multi_root}" \ obj/crt/crt1.o obj/crt/crti.o obj/crt/crtn.o CT_DoLog EXTRA "Installing C library start files" - CT_DoExecLog ALL cp -av obj/crt/crt*.o "${CT_SYSROOT_DIR}/usr/lib" + CT_DoExecLog ALL cp -av obj/crt/crt*.o "${multi_root}${multilib_dir}" CT_DoExecLog ALL ${CT_TARGET}-gcc -nostdlib \ - -nostartfiles -shared -x c /dev/null -o "${CT_SYSROOT_DIR}/usr/lib/libc.so" + -nostartfiles -shared -x c /dev/null -o "${multi_root}${multilib_dir}/libc.so" fi - if [ "${libc_full}" = "y" ]; then + if [ "${libc_mode}" = "final" ]; then + CT_DoLog EXTRA "Cleaning up start files" + CT_DoExecLog ALL rm -f "${multi_root}${multilib_dir}/crt1.o" \ + "${multi_root}${multilib_dir}/crti.o" \ + "${multi_root}${multilib_dir}/crtn.o" \ + "${multi_root}${multilib_dir}/libc.so" + CT_DoLog EXTRA "Building C library" CT_DoExecLog ALL ${make} ${JOBSFLAGS} CT_DoLog EXTRA "Installing C library" - CT_DoExecLog ALL ${make} DESTDIR="${CT_SYSROOT_DIR}" install + CT_DoExecLog ALL ${make} DESTDIR="${multi_root}" install + + # Convert /lib/ld-* symlinks to relative paths so that they are valid + # both on the host and on the target. + for f in ${multi_root}/ld-musl-*; do + [ -L "${f}" ] || continue + l=$( readlink ${f} ) + case "${l}" in + ${multilib_dir}/*) + CT_DoExecLog ALL ln -sf "../${l}" "${f}" + ;; + esac + done fi CT_EndStep diff --git a/scripts/build/libc/newlib.sh b/scripts/build/libc/newlib.sh index e70b6690..d9bda06f 100644 --- a/scripts/build/libc/newlib.sh +++ b/scripts/build/libc/newlib.sh @@ -38,10 +38,6 @@ do_libc_extract() { fi } -do_libc_check_config() { - : -} - do_libc_start_files() { CT_DoStep INFO "Installing C library headers & start files" CT_DoExecLog ALL cp -a "${CT_SRC_DIR}/newlib-${CT_LIBC_VERSION}/newlib/libc/include/." \ diff --git a/scripts/build/libc/none.sh b/scripts/build/libc/none.sh index d4bf7dcb..8537a8ea 100644 --- a/scripts/build/libc/none.sh +++ b/scripts/build/libc/none.sh @@ -10,10 +10,6 @@ do_libc_extract() { : } -do_libc_check_config() { - : -} - do_libc_start_files() { : } diff --git a/scripts/build/libc/uClibc.sh b/scripts/build/libc/uClibc.sh index 422412c9..be8d6bf2 100644 --- a/scripts/build/libc/uClibc.sh +++ b/scripts/build/libc/uClibc.sh @@ -5,7 +5,7 @@ # This is a constant because it does not change very often. # We're in 2010, and are still using data from 7 years ago. uclibc_locales_version=030818 -uclibc_local_tarball="uClibc-locale-${uclibc_locales_version}" +uclibc_locale_tarball="uClibc-locale-${uclibc_locales_version}" if [ "${CT_LIBC_UCLIBC_NG}" = "y" ]; then uclibc_name="uClibc-ng" @@ -26,7 +26,7 @@ do_libc_get() { fi # uClibc locales if [ "${CT_LIBC_UCLIBC_LOCALES_PREGEN_DATA}" = "y" ]; then - CT_GetFile "${uclibc_local_tarball}" ${libc_src} + CT_GetFile "${uclibc_locale_tarball}" ${libc_src} fi return 0 @@ -41,196 +41,207 @@ do_libc_extract() { # Extracting pregen locales ourselves is kinda # broken, so just link it in place... if [ "${CT_LIBC_UCLIBC_LOCALES_PREGEN_DATA}" = "y" \ - -a ! -f "${CT_SRC_DIR}/.${uclibc_local_tarball}.extracted" ]; then + -a ! -f "${CT_SRC_DIR}/.${uclibc_locale_tarball}.extracted" ]; then CT_Pushd "${CT_SRC_DIR}/${uclibc_name}-${CT_LIBC_VERSION}/extra/locale" - CT_DoExecLog ALL ln -s "${CT_TARBALLS_DIR}/${uclibc_local_tarball}.tgz" . + CT_DoExecLog ALL ln -s "${CT_TARBALLS_DIR}/${uclibc_locale_tarball}.tgz" . CT_Popd - touch "${CT_SRC_DIR}/.${uclibc_local_tarball}.extracted" + touch "${CT_SRC_DIR}/.${uclibc_locale_tarball}.extracted" fi return 0 } -# Check that uClibc has been previously configured -do_libc_check_config() { - CT_DoStep INFO "Checking C library configuration" +# Build and install headers and start files +do_libc_start_files() { + # Start files and Headers should be configured the same way as the + # final libc, but built and installed differently. + do_libc_backend libc_mode=startfiles +} - # Use the default config if the user did not provide one. - if [ -z "${CT_LIBC_UCLIBC_CONFIG_FILE}" ]; then - CT_LIBC_UCLIBC_CONFIG_FILE="${CT_LIB_DIR}/contrib/uClibc-defconfigs/${uclibc_name}.config" - fi +# This function builds and install the full C library +do_libc() { + do_libc_backend libc_mode=final +} - if ${grep} -E '^KERNEL_SOURCE=' "${CT_LIBC_UCLIBC_CONFIG_FILE}" >/dev/null 2>&1; then - CT_DoLog WARN "Your uClibc version refers to the kernel _sources_, which is bad." - CT_DoLog WARN "I can't guarantee that our little hack will work. Please try to upgrade." - fi +# Common backend for 1st and 2nd passes. +do_libc_backend() { + local libc_mode + local arg + + for arg in "$@"; do + eval "${arg// /\\ }" + done + + case "${libc_mode}" in + startfiles) CT_DoStep INFO "Installing C library headers & start files";; + final) CT_DoStep INFO "Installing C library";; + *) CT_Abort "Unsupported (or unset) libc_mode='${libc_mode}'";; + esac - CT_DoLog EXTRA "Manage uClibc configuration" - manage_uClibc_config "${CT_LIBC_UCLIBC_CONFIG_FILE}" "${CT_CONFIG_DIR}/uClibc.config" + CT_mkdir_pushd "${CT_BUILD_DIR}/build-libc-${libc_mode}" + CT_IterateMultilibs do_libc_backend_once multilib libc_mode="${libc_mode}" + + CT_Popd CT_EndStep } -# Build and install headers and start files -do_libc_start_files() { - local cross +# Common backend for 1st and 2nd passes, once per multilib. +do_libc_backend_once() { + local libc_mode + local multi_dir multi_os_dir multi_root multi_flags multi_index multi_count + local multilib_dir startfiles_dir + local jflag=${CT_LIBC_UCLIBC_PARALLEL:+${JOBSFLAGS}} + local -a make_args + local extra_cflags f cfg_cflags cf + local hdr_install_subdir + + for arg in "$@"; do + eval "${arg// /\\ }" + done - CT_DoStep INFO "Installing C library headers" + CT_DoStep INFO "Building for multilib ${multi_index}/${multi_count}: '${multi_flags}'" # Simply copy files until uClibc has the ability to build out-of-tree CT_DoLog EXTRA "Copying sources to build dir" - CT_DoExecLog ALL cp -av "${CT_SRC_DIR}/${uclibc_name}-${CT_LIBC_VERSION}" \ - "${CT_BUILD_DIR}/build-libc-headers" - cd "${CT_BUILD_DIR}/build-libc-headers" - - # Retrieve the config file - CT_DoExecLog ALL cp "${CT_CONFIG_DIR}/uClibc.config" .config - - # uClibc uses the CROSS environment variable as a prefix to the - # compiler tools to use. Setting it to the empty string forces - # use of the native build host tools, which we need at this - # stage, as we don't have target tools yet. - # BUT! With NPTL, we need a cross-compiler (and we have it) - if [ "${CT_THREADS}" = "nptl" ]; then - cross="${CT_TARGET}-" - fi + CT_DoExecLog ALL cp -aT "${CT_SRC_DIR}/${uclibc_name}-${CT_LIBC_VERSION}" . + + multilib_dir="lib/${multi_os_dir}" + startfiles_dir="${multi_root}/usr/${multilib_dir}" + CT_SanitizeVarDir multilib_dir startfiles_dir + + # Construct make arguments: + # - uClibc uses the CROSS environment variable as a prefix to the compiler + # tools to use. Since it requires core pass-1, thusly named compiler is + # already available. + # - Note about CFLAGS: In uClibc, CFLAGS are generated by Rules.mak, + # depending on the configuration of the library. That is, they are tailored + # to best fit the target. So it is useless and seems to be a bad thing to + # use LIBC_EXTRA_CFLAGS here. + # - We do _not_ want to strip anything for now, in case we specifically + # asked for a debug toolchain, thus the STRIPTOOL= assignment. + make_args=( CROSS_COMPILE="${CT_TARGET}-" \ + PREFIX="${multi_root}/" \ + MULTILIB_DIR="${multilib_dir}" \ + LOCALE_DATA_FILENAME="${uclibc_locale_tarball}.tgz" \ + STRIPTOOL=true \ + ${CT_LIBC_UCLIBC_VERBOSITY} \ + ) # Force the date of the pregen locale data, as the # newer ones that are referenced are not available CT_DoLog EXTRA "Applying configuration" - CT_DoYes "" |CT_DoExecLog ALL \ - ${make} CROSS_COMPILE="${cross}" \ - UCLIBC_EXTRA_CFLAGS="-pipe" \ - PREFIX="${CT_SYSROOT_DIR}/" \ - LOCALE_DATA_FILENAME="${uclibc_local_tarball}.tgz" \ - oldconfig - - CT_DoLog EXTRA "Building headers" - CT_DoExecLog ALL \ - ${make} ${CT_LIBC_UCLIBC_VERBOSITY} \ - CROSS_COMPILE="${cross}" \ - UCLIBC_EXTRA_CFLAGS="-pipe" \ - PREFIX="${CT_SYSROOT_DIR}/" \ - LOCALE_DATA_FILENAME="${uclibc_local_tarball}.tgz" \ - headers - - CT_DoLog EXTRA "Installing headers" - CT_DoExecLog ALL \ - ${make} ${CT_LIBC_UCLIBC_VERBOSITY} \ - CROSS_COMPILE="${cross}" \ - UCLIBC_EXTRA_CFLAGS="-pipe" \ - PREFIX="${CT_SYSROOT_DIR}/" \ - LOCALE_DATA_FILENAME="${uclibc_local_tarball}.tgz" \ - install_headers - - if [ "${CT_THREADS}" = "nptl" ]; then - CT_DoLog EXTRA "Building start files" - CT_DoExecLog ALL \ - ${make} ${CT_LIBC_UCLIBC_PARALLEL:+${JOBSFLAGS}} \ - CROSS_COMPILE="${cross}" \ - UCLIBC_EXTRA_CFLAGS="-pipe" \ - PREFIX="${CT_SYSROOT_DIR}/" \ - STRIPTOOL=true \ - ${CT_LIBC_UCLIBC_VERBOSITY} \ - LOCALE_DATA_FILENAME="${uclibc_local_tarball}.tgz" \ - lib/crt1.o lib/crti.o lib/crtn.o - - # From: http://git.openembedded.org/cgit.cgi/openembedded/commit/?id=ad5668a7ac7e0436db92e55caaf3fdf782b6ba3b - # libm.so is needed for ppc, as libgcc is linked against libm.so - # No problem to create it for other archs. - CT_DoLog EXTRA "Building dummy shared libs" - CT_DoExecLog ALL "${cross}gcc" -nostdlib \ - -nostartfiles \ - -shared \ - -x c /dev/null \ - -o libdummy.so - - CT_DoLog EXTRA "Installing start files" - CT_DoExecLog ALL ${install} -m 0644 lib/crt1.o lib/crti.o lib/crtn.o \ - "${CT_SYSROOT_DIR}/usr/lib" - - CT_DoLog EXTRA "Installing dummy shared libs" - CT_DoExecLog ALL ${install} -m 0755 libdummy.so "${CT_SYSROOT_DIR}/usr/lib/libc.so" - CT_DoExecLog ALL ${install} -m 0755 libdummy.so "${CT_SYSROOT_DIR}/usr/lib/libm.so" - fi # CT_THREADS == nptl - CT_EndStep -} + # Use the default config if the user did not provide one. + if [ -z "${CT_LIBC_UCLIBC_CONFIG_FILE}" ]; then + CT_LIBC_UCLIBC_CONFIG_FILE="${CT_LIB_DIR}/contrib/uClibc-defconfigs/${uclibc_name}.config" + fi -# This function build and install the full uClibc -do_libc() { - CT_DoStep INFO "Installing C library" + manage_uClibc_config "${CT_LIBC_UCLIBC_CONFIG_FILE}" .config "${multi_flags}" + CT_DoYes | CT_DoExecLog ALL ${make} "${make_args[@]}" oldconfig + + # Now filter the multilib flags. manage_uClibc_config did the opposite of + # what Rules.mak in uClibc would do: by the multilib's CFLAGS, it determined + # the applicable configuration options. We don't want to pass the same options + # in the UCLIBC_EXTRA_CFLAGS again (on some targets, the options do not correctly + # override each other). On the other hand, we do not want to lose the options + # that are not reflected in the .config. + extra_cflags="-pipe" + { echo "include Rules.mak"; echo "show-cpu-flags:"; printf '\t@echo $(CPU_CFLAGS)\n'; } \ + > .show-cpu-cflags.mk + cfg_cflags=$( ${make} "${make_args[@]}" \ + --no-print-directory -f .show-cpu-cflags.mk show-cpu-flags ) + CT_DoExecLog ALL rm -f .show-cpu-cflags.mk + CT_DoLog DEBUG "CPU_CFLAGS detected by uClibc: ${cfg_cflags[@]}" + for f in ${multi_flags}; do + for cf in ${cfg_cflags}; do + if [ "${f}" = "${cf}" ]; then + f= + break + fi + done + if [ -n "${f}" ]; then + extra_cflags+=" ${f}" + fi + done + CT_DoLog DEBUG "Filtered multilib CFLAGS: ${extra_cflags}" + make_args+=( UCLIBC_EXTRA_CFLAGS="${extra_cflags}" ) + + # uClibc does not have a way to select the installation subdirectory for headers, + # it is always $(DEVEL_PREFIX)/include. Also, we're reinstalling the headers + # at the final stage (see the note below), we may already have the subdirectory + # in /usr/include. + CT_DoArchUClibcHeaderDir hdr_install_subdir "${multi_flags}" + if [ -n "${hdr_install_subdir}" ]; then + CT_DoExecLog ALL cp -a "${multi_root}/usr/include" "${multi_root}/usr/include.saved" + fi - # Simply copy files until uClibc has the ability to build out-of-tree - CT_DoLog EXTRA "Copying sources to build dir" - CT_DoExecLog ALL cp -av "${CT_SRC_DIR}/${uclibc_name}-${CT_LIBC_VERSION}" \ - "${CT_BUILD_DIR}/build-libc" - cd "${CT_BUILD_DIR}/build-libc" - - # Retrieve the config file - CT_DoExecLog ALL cp "${CT_CONFIG_DIR}/uClibc.config" .config - - # uClibc uses the CROSS environment variable as a prefix to the compiler - # tools to use. The newly built tools should be in our path, so we need - # only give the correct name for them. - # Note about CFLAGS: In uClibc, CFLAGS are generated by Rules.mak, - # depending on the configuration of the library. That is, they are tailored - # to best fit the target. So it is useless and seems to be a bad thing to - # use LIBC_EXTRA_CFLAGS here. - CT_DoLog EXTRA "Applying configuration" - CT_DoYes "" |CT_DoExecLog CFG \ - ${make} CROSS_COMPILE=${CT_TARGET}- \ - UCLIBC_EXTRA_CFLAGS="-pipe" \ - PREFIX="${CT_SYSROOT_DIR}/" \ - LOCALE_DATA_FILENAME="${uclibc_local_tarball}.tgz" \ - oldconfig - - # We do _not_ want to strip anything for now, in case we specifically - # asked for a debug toolchain, thus the STRIPTOOL= assignment - # /Old/ versions can not build in // - CT_DoLog EXTRA "Building C library" - CT_DoExecLog ALL \ - ${make} -j1 \ - CROSS_COMPILE=${CT_TARGET}- \ - UCLIBC_EXTRA_CFLAGS="-pipe" \ - PREFIX="${CT_SYSROOT_DIR}/" \ - STRIPTOOL=true \ - ${CT_LIBC_UCLIBC_VERBOSITY} \ - LOCALE_DATA_FILENAME="${uclibc_local_tarball}.tgz" \ - pregen - CT_DoExecLog ALL \ - ${make} ${CT_LIBC_UCLIBC_PARALLEL:+${JOBSFLAGS}} \ - CROSS_COMPILE=${CT_TARGET}- \ - UCLIBC_EXTRA_CFLAGS="-pipe" \ - PREFIX="${CT_SYSROOT_DIR}/" \ - STRIPTOOL=true \ - ${CT_LIBC_UCLIBC_VERBOSITY} \ - LOCALE_DATA_FILENAME="${uclibc_local_tarball}.tgz" \ - all - - # YEM-FIXME: - # - we want to install 'runtime' files, eg. lib*.{a,so*}, crti.o and - # such files, except the headers as they already are installed - # - "make install_dev" installs the headers, the crti.o... and the - # static libs, but not the dynamic libs - # - "make install_runtime" installs the dynamic libs only - # - "make install" calls install_runtime and install_dev - # - so we're left with re-installing the headers... Sigh... - # - # We do _not_ want to strip anything for now, in case we specifically - # asked for a debug toolchain, hence the STRIPTOOL= assignment - # - # Note: JOBSFLAGS is not usefull for installation. - # - CT_DoLog EXTRA "Installing C library" - CT_DoExecLog ALL \ - ${make} CROSS_COMPILE=${CT_TARGET}- \ - UCLIBC_EXTRA_CFLAGS="-pipe" \ - PREFIX="${CT_SYSROOT_DIR}/" \ - STRIPTOOL=true \ - ${CT_LIBC_UCLIBC_VERBOSITY} \ - LOCALE_DATA_FILENAME="${uclibc_local_tarball}.tgz" \ - install + if [ "${libc_mode}" = "startfiles" ]; then + CT_DoLog EXTRA "Building headers" + CT_DoExecLog ALL ${make} "${make_args[@]}" headers + + # Ensure the directory for installing multilib-specific binaries exists. + CT_DoExecLog ALL mkdir -p "${startfiles_dir}" + + CT_DoLog EXTRA "Installing headers" + CT_DoExecLog ALL ${make} "${make_args[@]}" install_headers + + # The check might look bogus, but it is the same condition as is used + # by GCC build script to enable/disable shared library support. + if [ "${CT_THREADS}" = "nptl" ]; then + CT_DoLog EXTRA "Building start files" + CT_DoExecLog ALL ${make} ${jflag} "${make_args[@]}" \ + lib/crt1.o lib/crti.o lib/crtn.o + + # From: http://git.openembedded.org/cgit.cgi/openembedded/commit/?id=ad5668a7ac7e0436db92e55caaf3fdf782b6ba3b + # libm.so is needed for ppc, as libgcc is linked against libm.so + # No problem to create it for other archs. + CT_DoLog EXTRA "Building dummy shared libs" + CT_DoExecLog ALL "${CT_TARGET}-gcc" -nostdlib -nostartfiles \ + -shared ${multi_flags} -x c /dev/null -o libdummy.so + + CT_DoLog EXTRA "Installing start files" + CT_DoExecLog ALL ${install} -m 0644 lib/crt1.o lib/crti.o lib/crtn.o \ + "${startfiles_dir}" + + CT_DoLog EXTRA "Installing dummy shared libs" + CT_DoExecLog ALL ${install} -m 0755 libdummy.so "${startfiles_dir}/libc.so" + CT_DoExecLog ALL ${install} -m 0755 libdummy.so "${startfiles_dir}/libm.so" + fi # CT_THREADS == nptl + fi # libc_mode == startfiles + + if [ "${libc_mode}" = "final" ]; then + CT_DoLog EXTRA "Cleaning up startfiles" + CT_DoExecLog ALL rm -f "${startfiles_dir}/crt1.o" \ + "${startfiles_dir}/crti.o" \ + "${startfiles_dir}/crtn.o" \ + "${startfiles_dir}/libc.so" \ + "${startfiles_dir}/libm.so" + + CT_DoLog EXTRA "Building C library" + CT_DoExecLog ALL ${make} "${make_args[@]}" pregen + CT_DoExecLog ALL ${make} ${jflag} "${make_args[@]}" all + + # YEM-FIXME: + # - we want to install 'runtime' files, eg. lib*.{a,so*}, crti.o and + # such files, except the headers as they already are installed + # - "make install_dev" installs the headers, the crti.o... and the + # static libs, but not the dynamic libs + # - "make install_runtime" installs the dynamic libs only + # - "make install" calls install_runtime and install_dev + # - so we're left with re-installing the headers... Sigh... + CT_DoLog EXTRA "Installing C library" + CT_DoExecLog ALL ${make} "${make_args[@]}" install install_utils + fi # libc_mode == final + + # Now, if installing headers into a subdirectory, put everything in its place. + # Remove the header subdirectory if it existed already. + if [ -n "${hdr_install_subdir}" ]; then + CT_DoExecLog ALL mv "${multi_root}/usr/include" "${multi_root}/usr/include.new" + CT_DoExecLog ALL mv "${multi_root}/usr/include.saved" "${multi_root}/usr/include" + CT_DoExecLog ALL rm -rf "${multi_root}/usr/include/${hdr_install_subdir}" + CT_DoExecLog ALL mv "${multi_root}/usr/include.new" "${multi_root}/usr/include/${hdr_install_subdir}" + fi CT_EndStep } @@ -241,98 +252,11 @@ do_libc() { manage_uClibc_config() { src="$1" dst="$2" + flags="$3" # Start with fresh files - CT_DoExecLog ALL rm -f "${dst}" - CT_DoExecLog ALL mkdir -p "$(dirname ${dst})" CT_DoExecLog ALL cp "${src}" "${dst}" - # Hack our target in the config file. - case "${CT_ARCH}:${CT_ARCH_BITNESS}" in - x86:32) arch=i386;; - x86:64) arch=x86_64;; - sh:32) arch="sh";; - *) arch="${CT_ARCH}";; - esac - # Also remove stripping: its the responsibility of the - # firmware builder to strip or not. - ${sed} -i -r -e '/^TARGET_.*/d' "${dst}" - CT_KconfigEnableOption "TARGET_${arch}" "${dst}" - CT_KconfigSetOption "TARGET_ARCH" "${arch}" "${dst}" - CT_KconfigDisableOption "DOSTRIP" "${dst}" - - # Ah. We may one day need architecture-specific handler here... - case "${arch}" in - arm*) - if [ "${CT_ARCH_ARM_EABI}" = "y" ]; then - CT_KconfigDisableOption "CONFIG_ARM_OABI" "${dst}" - CT_KconfigEnableOption "CONFIG_ARM_EABI" "${dst}" - else - CT_KconfigDisableOption "CONFIG_ARM_EABI" "${dst}" - CT_KconfigEnableOption "CONFIG_ARM_OABI" "${dst}" - fi - ;; - i386) - # FIXME This doesn't cover all cases of x86_32... - case ${CT_TARGET_ARCH} in - i386) - CT_KconfigEnableOption "CONFIG_386" "${dst}" - ;; - i486) - CT_KconfigEnableOption "CONFIG_486" "${dst}" - ;; - i586) - CT_KconfigEnableOption "CONFIG_586" "${dst}" - ;; - i686) - CT_KconfigEnableOption "CONFIG_686" "${dst}" - ;; - esac - ;; - mips*) - CT_KconfigDisableOption "CONFIG_MIPS_O32_ABI" "${dst}" - CT_KconfigDisableOption "CONFIG_MIPS_N32_ABI" "${dst}" - CT_KconfigDisableOption "CONFIG_MIPS_N64_ABI" "${dst}" - CT_KconfigDeleteOption "CONFIG_MIPS_ISA_1" "${dst}" - CT_KconfigDeleteOption "CONFIG_MIPS_ISA_2" "${dst}" - CT_KconfigDeleteOption "CONFIG_MIPS_ISA_3" "${dst}" - CT_KconfigDeleteOption "CONFIG_MIPS_ISA_4" "${dst}" - CT_KconfigDeleteOption "CONFIG_MIPS_ISA_MIPS32" "${dst}" - CT_KconfigDeleteOption "CONFIG_MIPS_ISA_MIPS32R2" "${dst}" - CT_KconfigDeleteOption "CONFIG_MIPS_ISA_MIPS64" "${dst}" - CT_KconfigDeleteOption "CONFIG_MIPS_ISA_MIPS64R2" "${dst}" - case "${CT_ARCH_mips_ABI}" in - 32) - CT_KconfigEnableOption "CONFIG_MIPS_O32_ABI" "${dst}" - ;; - n32) - CT_KconfigEnableOption "CONFIG_MIPS_N32_ABI" "${dst}" - ;; - 64) - CT_KconfigEnableOption "CONFIG_MIPS_N64_ABI" "${dst}" - ;; - esac - ;; - powerpc*) - CT_KconfigDisableOption "CONFIG_E500" "${dst}" - CT_KconfigDisableOption "CONFIG_CLASSIC" "${dst}" - CT_KconfigDeleteOption "TARGET_SUBARCH" "${dst}" - if [ "${CT_ARCH_powerpc_ABI}" = "spe" ]; then - CT_KconfigEnableOption "CONFIG_E500" "${dst}" - CT_KconfigSetOption "TARGET_SUBARCH" "e500" "${dst}" - else - CT_KconfigEnableOption "CONFIG_CLASSIC" "${dst}" - CT_KconfigSetOption "TARGET_SUBARCH" "classic" "${dst}" - fi - ;; - sh) - # all we really support right now is sh4:32 - CT_KconfigEnableOption "CONFIG_SH4" "${dst}" - ;; - esac - - # Accomodate for old and new uClibc versions, where the - # way to select between big/little endian has changed case "${CT_ARCH_ENDIAN}" in big) CT_KconfigDisableOption "ARCH_LITTLE_ENDIAN" "${dst}" @@ -348,14 +272,18 @@ manage_uClibc_config() { ;; esac - # Accomodate for old and new uClibc versions, where the - # MMU settings has different config knobs if [ "${CT_ARCH_USE_MMU}" = "y" ]; then CT_KconfigEnableOption "ARCH_USE_MMU" "${dst}" else CT_KconfigDisableOption "ARCH_USE_MMU" "${dst}" fi + if [ "${CT_SHARED_LIBS}" = "y" ]; then + CT_KconfigEnableOption "HAVE_SHARED" "${dst}" + else + CT_KconfigDisableOption "HAVE_SHARED" "${dst}" + fi + # Accomodate for old and new uClibc version, where the # way to select between hard/soft float has changed case "${CT_ARCH_FLOAT}" in @@ -382,7 +310,6 @@ manage_uClibc_config() { # which is the correct value of ${PREFIX}/${TARGET}. CT_KconfigSetOption "DEVEL_PREFIX" "\"/usr/\"" "${dst}" CT_KconfigSetOption "RUNTIME_PREFIX" "\"/\"" "${dst}" - CT_KconfigSetOption "SHARED_LIB_LOADER_PREFIX" "\"/lib/\"" "${dst}" CT_KconfigSetOption "KERNEL_HEADERS" "\"${CT_HEADERS_DIR}\"" "${dst}" # Locales support @@ -443,29 +370,28 @@ manage_uClibc_config() { fi # Push the threading model + CT_KconfigDisableOption "UCLIBC_HAS_THREADS" "${dst}" + CT_KconfigDisableOption "LINUXTHREADS_OLD" "${dst}" + CT_KconfigDisableOption "LINUXTHREADS_NEW" "${dst}" + CT_KconfigDisableOption "UCLIBC_HAS_THREADS_NATIVE" "${dst}" case "${CT_THREADS}:${CT_LIBC_UCLIBC_LNXTHRD}" in none:) - CT_KconfigDisableOption "UCLIBC_HAS_THREADS" "${dst}" - CT_KconfigDisableOption "LINUXTHREADS_OLD" "${dst}" - CT_KconfigDisableOption "LINUXTHREADS_NEW" "${dst}" - CT_KconfigDisableOption "UCLIBC_HAS_THREADS_NATIVE" "${dst}" + ;; + linuxthreads:) + # Newer version of uClibc-ng, no old/new dichotomy + CT_KconfigEnableOption "UCLIBC_HAS_THREADS" "${dst}" + CT_KconfigEnableOption "UCLIBC_HAS_LINUXTHREADS" "${dst}" ;; linuxthreads:old) CT_KconfigEnableOption "UCLIBC_HAS_THREADS" "${dst}" CT_KconfigEnableOption "LINUXTHREADS_OLD" "${dst}" - CT_KconfigDisableOption "LINUXTHREADS_NEW" "${dst}" - CT_KconfigDisableOption "UCLIBC_HAS_THREADS_NATIVE" "${dst}" ;; linuxthreads:new) CT_KconfigEnableOption "UCLIBC_HAS_THREADS" "${dst}" - CT_KconfigDisableOption "LINUXTHREADS_OLD" "${dst}" CT_KconfigEnableOption "LINUXTHREADS_NEW" "${dst}" - CT_KconfigDisableOption "UCLIBC_HAS_THREADS_NATIVE" "${dst}" ;; nptl:) CT_KconfigEnableOption "UCLIBC_HAS_THREADS" "${dst}" - CT_KconfigDisableOption "LINUXTHREADS_OLD" "${dst}" - CT_KconfigDisableOption "LINUXTHREADS_NEW" "${dst}" CT_KconfigEnableOption "UCLIBC_HAS_THREADS_NATIVE" "${dst}" ;; *) @@ -477,29 +403,22 @@ manage_uClibc_config() { CT_KconfigEnableOption "PTHREADS_DEBUG_SUPPORT" "${dst}" # Force on debug options if asked for + CT_KconfigDisableOption "DODEBUG" "${dst}" + CT_KconfigDisableOption "DODEBUG_PT" "${dst}" + CT_KconfigDisableOption "DOASSERTS" "${dst}" + CT_KconfigDisableOption "SUPPORT_LD_DEBUG" "${dst}" + CT_KconfigDisableOption "SUPPORT_LD_DEBUG_EARLY" "${dst}" + CT_KconfigDisableOption "UCLIBC_MALLOC_DEBUGGING" "${dst}" case "${CT_LIBC_UCLIBC_DEBUG_LEVEL}" in 0) - CT_KconfigDisableOption "DODEBUG" "${dst}" - CT_KconfigDisableOption "DODEBUG_PT" "${dst}" - CT_KconfigDisableOption "DOASSERTS" "${dst}" - CT_KconfigDisableOption "SUPPORT_LD_DEBUG" "${dst}" - CT_KconfigDisableOption "SUPPORT_LD_DEBUG_EARLY" "${dst}" - CT_KconfigDisableOption "UCLIBC_MALLOC_DEBUGGING" "${dst}" ;; 1) CT_KconfigEnableOption "DODEBUG" "${dst}" - CT_KconfigDisableOption "DODEBUG_PT" "${dst}" - CT_KconfigDisableOption "DOASSERTS" "${dst}" - CT_KconfigDisableOption "SUPPORT_LD_DEBUG" "${dst}" - CT_KconfigDisableOption "SUPPORT_LD_DEBUG_EARLY" "${dst}" - CT_KconfigDisableOption "UCLIBC_MALLOC_DEBUGGING" "${dst}" ;; 2) CT_KconfigEnableOption "DODEBUG" "${dst}" - CT_KconfigDisableOption "DODEBUG_PT" "${dst}" CT_KconfigEnableOption "DOASSERTS" "${dst}" CT_KconfigEnableOption "SUPPORT_LD_DEBUG" "${dst}" - CT_KconfigDisableOption "SUPPORT_LD_DEBUG_EARLY" "${dst}" CT_KconfigEnableOption "UCLIBC_MALLOC_DEBUGGING" "${dst}" ;; 3) @@ -511,8 +430,69 @@ manage_uClibc_config() { CT_KconfigEnableOption "UCLIBC_MALLOC_DEBUGGING" "${dst}" ;; esac + + # Remove stripping: its the responsibility of the + # firmware builder to strip or not. + CT_KconfigDisableOption "DOSTRIP" "${dst}" + + # Now allow architecture to tweak as it wants + CT_DoArchUClibcConfig "${dst}" + CT_DoArchUClibcCflags "${dst}" "${flags}" } do_libc_post_cc() { - : + # uClibc and GCC disagree where the dynamic linker lives. uClibc always + # places it in the MULTILIB_DIR, while gcc does that for *some* variants + # and expects it in /lib for the other. So, create a symlink from lib + # to the actual location, but only if that will not override the actual + # file in /lib. Thus, need to do this after all the variants are built. + # Moreover, need to do this after the final compiler is built: on targets + # that use elf2flt, the core compilers cannot find ld when running elf2flt. + CT_DoStep INFO "Checking dynamic linker symlinks" + CT_mkdir_pushd "${CT_BUILD_DIR}/build-libc-post_cc" + echo "int main(void) { return 0; }" > test-ldso.c + CT_IterateMultilibs do_libc_ldso_fixup ldso_fixup + CT_Popd + CT_EndStep +} + +do_libc_ldso_fixup() { + local multi_dir multi_os_dir multi_root multi_flags multi_index multi_count + local binary + local ldso ldso_f ldso_d multilib_dir + + for arg in "$@"; do + eval "${arg// /\\ }" + done + + CT_DoLog EXTRA "Checking dynamic linker for multilib '${multi_flags}'" + + multilib_dir="/lib/${multi_os_dir}" + CT_SanitizeVarDir multilib_dir + + CT_DoExecLog ALL "${CT_TARGET}-gcc" -o test-ldso ../test-ldso.c ${multi_flags} + if [ -r "test-ldso.gdb" ]; then + binary="test-ldso.gdb" + else + binary="test-ldso" + fi + if ${CT_TARGET}-readelf -Wl "${binary}" | grep -q 'Requesting program interpreter: '; then + ldso=$( ${CT_TARGET}-readelf -Wl "${binary}" | \ + grep 'Requesting program interpreter: ' | \ + sed -e 's,.*: ,,' -e 's,\].*,,' ) + fi + CT_DoLog DEBUG "Detected dynamic linker for multilib '${multi_flags}': '${ldso}'" + + ldso_d="${ldso%/ld*.so.*}" + ldso_f="${ldso##*/}" + # Create symlink if GCC produced an executable, dynamically linked, it was requesting + # a linker not in the current directory, and there is no such file in the expected + # ldso dir. + if [ -n "${ldso}" -a "${ldso_d}" != "${multilib_dir}" -a ! -r "${multi_root}${ldso}" ]; then + # Convert ldso_d to "how many levels we need to go up" and remove + # leading slash. + ldso_d=$( echo "${ldso_d#/}" | sed 's,[^/]\+,..,g' ) + CT_DoExecLog ALL ln -sf "${ldso_d}${multilib_dir}/${ldso_f}" \ + "${multi_root}${ldso}" + fi } |