gcc: Modernize builder.sh for Cross

Instead of `NIX_CC` vs `NIX_CC_CROSS` spagetti, unconditionally use
`NIX_BUILD_CC` and `NIX_CC` in a consistent manner.
This commit is contained in:
John Ericson 2017-12-01 16:21:54 -05:00
parent aeffc007fb
commit d4595b38e9
8 changed files with 134 additions and 142 deletions

View file

@ -274,6 +274,8 @@ stdenv.mkDerivation ({
)
)
}
${optionalString (!(crossMingw && crossStageStatic))
"--with-native-system-header-dir=${getDev (stdenv.ccCross or stdenv.cc).libc}/include"}
${ # Trick that should be taken out once we have a mips64el-linux not loongson2f
if targetPlatform == hostPlatform && stdenv.system == "mips64el-linux" then "--with-arch=loongson2f" else ""}
${if langAda then " --enable-libada" else ""}
@ -325,11 +327,12 @@ stdenv.mkDerivation ({
STRIP_FOR_TARGET = "${targetPlatform.config}-strip";
CC_FOR_TARGET = "${targetPlatform.config}-gcc";
CXX_FOR_TARGET = "${targetPlatform.config}-g++";
# If we are making a cross compiler, cross != null
NIX_CC_CROSS = if targetPlatform == hostPlatform then "${stdenv.ccCross}" else "";
dontStrip = true;
};
NIX_BUILD_CC = stdenv.cc;
NIX_CC_CROSS = stdenv.ccCross or null;
# Needed for the cross compilation to work
AR = "ar";

View file

@ -338,11 +338,8 @@ stdenv.mkDerivation ({
)
)
}
${if targetPlatform == hostPlatform
then if hostPlatform.isDarwin
then " --with-native-system-header-dir=${darwin.usr-include}"
else " --with-native-system-header-dir=${getDev stdenv.cc.libc}/include"
else ""}
${optionalString (!(crossMingw && crossStageStatic))
"--with-native-system-header-dir=${getDev (stdenv.ccCross or stdenv.cc).libc}/include"}
${if langAda then " --enable-libada" else ""}
${if targetPlatform == hostPlatform && targetPlatform.isi686 then "--with-arch=i686" else ""}
${if targetPlatform != hostPlatform then crossConfigureFlags else ""}
@ -402,12 +399,13 @@ stdenv.mkDerivation ({
STRIP_FOR_TARGET = "${targetPlatform.config}-strip";
CC_FOR_TARGET = "${targetPlatform.config}-gcc";
CXX_FOR_TARGET = "${targetPlatform.config}-g++";
# If we are making a cross compiler, cross != null
NIX_CC_CROSS = if targetPlatform == hostPlatform then "${stdenv.ccCross}" else "";
dontStrip = true;
buildFlags = "";
};
NIX_BUILD_CC = stdenv.cc;
NIX_CC_CROSS = stdenv.ccCross or null;
# Needed for the cross compilation to work
AR = "ar";

View file

@ -344,11 +344,8 @@ stdenv.mkDerivation ({
)
)
}
${if targetPlatform == hostPlatform
then if hostPlatform.isDarwin
then " --with-native-system-header-dir=${darwin.usr-include}"
else " --with-native-system-header-dir=${getDev stdenv.cc.libc}/include"
else ""}
${optionalString (!(crossMingw && crossStageStatic))
"--with-native-system-header-dir=${getDev (stdenv.ccCross or stdenv.cc).libc}/include"}
${if langAda then " --enable-libada" else ""}
${if targetPlatform == hostPlatform && targetPlatform.isi686 then "--with-arch=i686" else ""}
${if targetPlatform != hostPlatform then crossConfigureFlags else ""}
@ -408,12 +405,13 @@ stdenv.mkDerivation ({
STRIP_FOR_TARGET = "${targetPlatform.config}-strip";
CC_FOR_TARGET = "${targetPlatform.config}-gcc";
CXX_FOR_TARGET = "${targetPlatform.config}-g++";
# If we are making a cross compiler, cross != null
NIX_CC_CROSS = if targetPlatform == hostPlatform then "${stdenv.ccCross}" else "";
dontStrip = true;
buildFlags = "";
};
NIX_BUILD_CC = stdenv.cc;
NIX_CC_CROSS = stdenv.ccCross or null;
# Needed for the cross compilation to work
AR = "ar";

View file

@ -359,11 +359,8 @@ stdenv.mkDerivation ({
)
)
}
${if targetPlatform == hostPlatform
then if hostPlatform.isDarwin
then " --with-native-system-header-dir=${darwin.usr-include}"
else " --with-native-system-header-dir=${getDev stdenv.cc.libc}/include"
else ""}
${optionalString (!(crossMingw && crossStageStatic))
"--with-native-system-header-dir=${getDev (stdenv.ccCross or stdenv.cc).libc}/include"}
${if langAda then " --enable-libada" else ""}
${if targetPlatform == hostPlatform && targetPlatform.isi686 then "--with-arch=i686" else ""}
${if targetPlatform != hostPlatform then crossConfigureFlags else ""}
@ -423,12 +420,13 @@ stdenv.mkDerivation ({
STRIP_FOR_TARGET = "${targetPlatform.config}-strip";
CC_FOR_TARGET = "${targetPlatform.config}-gcc";
CXX_FOR_TARGET = "${targetPlatform.config}-g++";
# If we are making a cross compiler, cross != null
NIX_CC_CROSS = if targetPlatform == hostPlatform then "${stdenv.ccCross}" else "";
dontStrip = true;
buildFlags = "";
};
NIX_BUILD_CC = stdenv.cc;
NIX_CC_CROSS = stdenv.ccCross or null;
# Needed for the cross compilation to work
AR = "ar";

View file

@ -341,11 +341,8 @@ stdenv.mkDerivation ({
)
)
}
${if targetPlatform == hostPlatform
then if hostPlatform.isDarwin
then " --with-native-system-header-dir=${darwin.usr-include}"
else " --with-native-system-header-dir=${getDev stdenv.cc.libc}/include"
else ""}
${optionalString (!(crossMingw && crossStageStatic))
"--with-native-system-header-dir=${getDev (stdenv.ccCross or stdenv.cc).libc}/include"}
${if langAda then " --enable-libada" else ""}
${if targetPlatform == hostPlatform && targetPlatform.isi686 then "--with-arch=i686" else ""}
${if targetPlatform != hostPlatform then crossConfigureFlags else ""}
@ -405,12 +402,13 @@ stdenv.mkDerivation ({
STRIP_FOR_TARGET = "${targetPlatform.config}-strip";
CC_FOR_TARGET = "${targetPlatform.config}-gcc";
CXX_FOR_TARGET = "${targetPlatform.config}-g++";
# If we are making a cross compiler, cross != null
NIX_CC_CROSS = if targetPlatform == hostPlatform then "${stdenv.ccCross}" else "";
dontStrip = true;
buildFlags = "";
};
NIX_BUILD_CC = stdenv.cc;
NIX_CC_CROSS = stdenv.ccCross or null;
# Needed for the cross compilation to work
AR = "ar";

View file

@ -342,11 +342,8 @@ stdenv.mkDerivation ({
)
)
}
${if targetPlatform == hostPlatform
then if hostPlatform.isDarwin
then " --with-native-system-header-dir=${darwin.usr-include}"
else " --with-native-system-header-dir=${getDev stdenv.cc.libc}/include"
else ""}
${optionalString (!(crossMingw && crossStageStatic))
"--with-native-system-header-dir=${getDev (stdenv.ccCross or stdenv.cc).libc}/include"}
${if langAda then " --enable-libada" else ""}
${if targetPlatform == hostPlatform && targetPlatform.isi686 then "--with-arch=i686" else ""}
${if targetPlatform != hostPlatform then crossConfigureFlags else ""}
@ -406,12 +403,13 @@ stdenv.mkDerivation ({
STRIP_FOR_TARGET = "${targetPlatform.config}-strip";
CC_FOR_TARGET = "${targetPlatform.config}-gcc";
CXX_FOR_TARGET = "${targetPlatform.config}-g++";
# If we are making a cross compiler, targetPlatform != hostPlatform
NIX_CC_CROSS = if targetPlatform == hostPlatform then "${stdenv.ccCross}" else "";
dontStrip = true;
buildFlags = "";
};
NIX_BUILD_CC = stdenv.cc;
NIX_CC_CROSS = stdenv.ccCross or null;
# Needed for the cross compilation to work
AR = "ar";

View file

@ -1,8 +1,17 @@
source $stdenv/setup
export NIX_FIXINC_DUMMY=$NIX_BUILD_TOP/dummy
mkdir $NIX_FIXINC_DUMMY
oldOpts="$(shopt -po nounset)" || true
set -euo pipefail
if test -n "${NIX_CC_CROSS-}"; then
export NIX_CC="$NIX_CC_CROSS"
fi
export NIX_FIXINC_DUMMY="$NIX_BUILD_TOP/dummy"
mkdir "$NIX_FIXINC_DUMMY"
if test "$staticCompiler" = "1"; then
@ -20,134 +29,126 @@ echo "\$LIBRARY_PATH is \`$LIBRARY_PATH'"
if test "$noSysDirs" = "1"; then
if test -e $NIX_CC/nix-support/orig-libc; then
declare \
EXTRA_BUILD_FLAGS EXTRA_FLAGS EXTRA_TARGET_FLAGS \
EXTRA_BUILD_LDFLAGS EXTRA_TARGET_LDFLAGS
# Figure out what extra flags to pass to the gcc compilers
# being generated to make sure that they use our glibc.
extraFlags="$(cat $NIX_CC/nix-support/libc-cflags)"
extraLDFlags="$(cat $NIX_CC/nix-support/libc-ldflags) $(cat $NIX_CC/nix-support/libc-ldflags-before || true)"
for pre in 'BUILD_' ''; do
curCC="NIX_${pre}CC"
curFIXINC="NIX_${pre}FIXINC_DUMMY"
# Use *real* header files, otherwise a limits.h is generated
# that does not include Glibc's limits.h (notably missing
# SSIZE_MAX, which breaks the build).
export NIX_FIXINC_DUMMY=$libc_dev/include
declare -a extraFlags=() extraLDFlags=()
if [[ -e "${!curCC}/nix-support/orig-libc" ]]; then
# Figure out what extra flags to pass to the gcc compilers being
# generated to make sure that they use our glibc.
extraFlags=($(cat "${!curCC}/nix-support/libc-cflags"))
extraLDFlags=($(cat "${!curCC}/nix-support/libc-ldflags") $(cat "${!curCC}/nix-support/libc-ldflags-before" || true))
# The path to the Glibc binaries such as `crti.o'.
glibc_libdir="$(cat $NIX_CC/nix-support/orig-libc)/lib"
glibc_libdir="$(cat "${!curCC}/nix-support/orig-libc")/lib"
glibc_devdir="$(cat "${!curCC}/nix-support/orig-libc-dev")"
# Use *real* header files, otherwise a limits.h is generated that
# does not include Glibc's limits.h (notably missing SSIZE_MAX,
# which breaks the build).
declare NIX_${pre}FIXINC_DUMMY="$glibc_devdir/include"
else
# Hack: support impure environments.
extraFlags="-isystem /usr/include"
extraLDFlags="-L/usr/lib64 -L/usr/lib"
extraFlags=("-isystem" "/usr/include")
extraLDFlags=("-L/usr/lib64" "-L/usr/lib")
glibc_libdir="/usr/lib"
export NIX_FIXINC_DUMMY=/usr/include
declare NIX_${pre}FIXINC_DUMMY=/usr/include
fi
extraFlags="-I$NIX_FIXINC_DUMMY $extraFlags"
extraLDFlags="-L$glibc_libdir -rpath $glibc_libdir $extraLDFlags"
extraFlags=("-I${!curFIXINC}"
"${extraFlags[@]}")
extraLDFlags=("-L$glibc_libdir" "-rpath" "$glibc_libdir"
"${extraLDFlags[@]}")
# BOOT_CFLAGS defaults to `-g -O2'; since we override it below,
# make sure to explictly add them so that files compiled with the
# bootstrap compiler are optimized and (optionally) contain
# debugging information (info "(gccinstall) Building").
if test -n "$dontStrip"; then
extraFlags="-O2 -g $extraFlags"
# BOOT_CFLAGS defaults to `-g -O2'; since we override it below, make
# sure to explictly add them so that files compiled with the bootstrap
# compiler are optimized and (optionally) contain debugging information
# (info "(gccinstall) Building").
if test -n "${dontStrip-}"; then
extraFlags=("-O2" "-g" "${extraFlags[@]}")
else
# Don't pass `-g' at all; this saves space while building.
extraFlags="-O2 $extraFlags"
extraFlags=("-O2" "${extraFlags[@]}")
fi
EXTRA_FLAGS="$extraFlags"
for i in $extraLDFlags; do
EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,$i"
declare EXTRA_${pre}FLAGS="${extraFlags[*]}"
for i in "${extraLDFlags[@]}"; do
declare EXTRA_${pre}LDFLAGS+=" -Wl,$i"
done
done
if test -n "$targetConfig"; then
# Cross-compiling, we need gcc not to read ./specs in order to build
# the g++ compiler (after the specs for the cross-gcc are created).
# Having LIBRARY_PATH= makes gcc read the specs from ., and the build
if test -n "${targetConfig-}"; then
# Cross-compiling, we need gcc not to read ./specs in order to build the
# g++ compiler (after the specs for the cross-gcc are created). Having
# LIBRARY_PATH= makes gcc read the specs from ., and the build
# breaks. Having this variable comes from the default.nix code to bring
# gcj in.
unset LIBRARY_PATH
unset CPATH
else
if test -z "$NIX_CC_CROSS"; then
EXTRA_TARGET_CFLAGS="$EXTRA_FLAGS"
EXTRA_TARGET_CXXFLAGS="$EXTRA_FLAGS"
# host = target, so the flags are the same
EXTRA_TARGET_FLAGS="$EXTRA_FLAGS"
EXTRA_TARGET_LDFLAGS="$EXTRA_LDFLAGS"
else
# This the case of cross-building the gcc.
# We need special flags for the target, different than those of the build
# Assertion:
test -e $NIX_CC_CROSS/nix-support/orig-libc
# Figure out what extra flags to pass to the gcc compilers
# being generated to make sure that they use our glibc.
extraFlags="$(cat $NIX_CC_CROSS/nix-support/libc-cflags)"
extraLDFlags="$(cat $NIX_CC_CROSS/nix-support/libc-ldflags) $(cat $NIX_CC_CROSS/nix-support/libc-ldflags-before)"
# The path to the Glibc binaries such as `crti.o'.
glibc_dir="$(cat $NIX_CC_CROSS/nix-support/orig-libc)"
glibc_libdir="$glibc_dir/lib"
glibc_devdir="$(cat $NIX_CC_CROSS/nix-support/orig-libc-dev)"
configureFlags="$configureFlags --with-native-system-header-dir=$glibc_devdir/include"
# Use *real* header files, otherwise a limits.h is generated
# that does not include Glibc's limits.h (notably missing
# SSIZE_MAX, which breaks the build).
NIX_FIXINC_DUMMY_CROSS="$glibc_devdir/include"
extraFlags="-I$NIX_FIXINC_DUMMY_CROSS $extraFlags"
extraLDFlags="-L$glibc_libdir -rpath $glibc_libdir $extraLDFlags"
EXTRA_TARGET_CFLAGS="$extraFlags"
for i in $extraLDFlags; do
EXTRA_TARGET_LDFLAGS="$EXTRA_TARGET_LDFLAGS -Wl,$i"
done
fi
fi
# CFLAGS_FOR_TARGET are needed for the libstdc++ configure script to find
# the startfiles.
# FLAGS_FOR_TARGET are needed for the target libraries to receive the -Bxxx
# for the startfiles.
makeFlagsArray+=( \
NATIVE_SYSTEM_HEADER_DIR="$NIX_FIXINC_DUMMY" \
SYSTEM_HEADER_DIR="$NIX_FIXINC_DUMMY" \
CFLAGS_FOR_BUILD="$EXTRA_FLAGS $EXTRA_LDFLAGS" \
CXXFLAGS_FOR_BUILD="$EXTRA_FLAGS $EXTRA_LDFLAGS" \
CFLAGS_FOR_TARGET="$EXTRA_TARGET_CFLAGS $EXTRA_TARGET_LDFLAGS" \
CXXFLAGS_FOR_TARGET="$EXTRA_TARGET_CFLAGS $EXTRA_TARGET_LDFLAGS" \
FLAGS_FOR_TARGET="$EXTRA_TARGET_CFLAGS $EXTRA_TARGET_LDFLAGS" \
LDFLAGS_FOR_BUILD="$EXTRA_FLAGS $EXTRA_LDFLAGS" \
LDFLAGS_FOR_TARGET="$EXTRA_TARGET_LDFLAGS $EXTRA_TARGET_LDFLAGS" \
makeFlagsArray+=(
"BUILD_SYSTEM_HEADER_DIR=$NIX_BUILD_FIXINC_DUMMY"
"SYSTEM_HEADER_DIR=$NIX_BUILD_FIXINC_DUMMY"
"NATIVE_SYSTEM_HEADER_DIR=$NIX_FIXINC_DUMMY"
"LDFLAGS_FOR_BUILD=$EXTRA_BUILD_LDFLAGS"
#"LDFLAGS=$EXTRA_LDFLAGS"
"LDFLAGS_FOR_TARGET=$EXTRA_TARGET_LDFLAGS"
"CFLAGS_FOR_BUILD=$EXTRA_BUILD_FLAGS $EXTRA_BUILD_LDFLAGS"
"CXXFLAGS_FOR_BUILD=$EXTRA_BUILD_FLAGS $EXTRA_BUILD_LDFLAGS"
"FLAGS_FOR_BUILD=$EXTRA_BUILD_FLAGS $EXTRA_BUILD_LDFLAGS"
# It seems there is a bug in GCC 5
#"CFLAGS=$EXTRA_FLAGS $EXTRA_LDFLAGS"
#"CXXFLAGS=$EXTRA_FLAGS $EXTRA_LDFLAGS"
"CFLAGS_FOR_TARGET=$EXTRA_TARGET_FLAGS $EXTRA_TARGET_LDFLAGS"
"CXXFLAGS_FOR_TARGET=$EXTRA_TARGET_FLAGS $EXTRA_TARGET_LDFLAGS"
"FLAGS_FOR_TARGET=$EXTRA_TARGET_FLAGS $EXTRA_TARGET_LDFLAGS"
)
if test -z "$targetConfig"; then
makeFlagsArray+=( \
BOOT_CFLAGS="$EXTRA_FLAGS $EXTRA_LDFLAGS" \
BOOT_LDFLAGS="$EXTRA_TARGET_CFLAGS $EXTRA_TARGET_LDFLAGS" \
if test -z "${targetConfig-}"; then
makeFlagsArray+=(
"BOOT_CFLAGS=$EXTRA_FLAGS $EXTRA_LDFLAGS"
"BOOT_LDFLAGS=$EXTRA_TARGET_FLAGS $EXTRA_TARGET_LDFLAGS"
)
fi
if test -n "$targetConfig" -a "$crossStageStatic" == 1; then
if test -n "${targetConfig-}" -a "$crossStageStatic" == 1; then
# We don't want the gcc build to assume there will be a libc providing
# limits.h in this stagae
makeFlagsArray+=( \
LIMITS_H_TEST=false \
makeFlagsArray+=(
'LIMITS_H_TEST=false'
)
else
makeFlagsArray+=( \
LIMITS_H_TEST=true \
makeFlagsArray+=(
'LIMITS_H_TEST=true'
)
fi
fi
if test -n "$targetConfig"; then
if test -n "${targetConfig-}"; then
# The host strip will destroy some important details of the objects
dontStrip=1
fi
eval "$oldOpts"
providedPreConfigure="$preConfigure";
preConfigure() {
if test -n "$newlibSrc"; then

View file

@ -342,11 +342,8 @@ stdenv.mkDerivation ({
)
)
}
${if targetPlatform == hostPlatform
then if hostPlatform.isDarwin
then " --with-native-system-header-dir=${darwin.usr-include}"
else " --with-native-system-header-dir=${getDev stdenv.cc.libc}/include"
else ""}
${optionalString (!(crossMingw && crossStageStatic))
"--with-native-system-header-dir=${getDev (stdenv.ccCross or stdenv.cc).libc}/include"}
${if langAda then " --enable-libada" else ""}
${if targetPlatform == hostPlatform && targetPlatform.isi686 then "--with-arch=i686" else ""}
${if targetPlatform != hostPlatform then crossConfigureFlags else ""}
@ -406,12 +403,13 @@ stdenv.mkDerivation ({
STRIP_FOR_TARGET = "${targetPlatform.config}-strip";
CC_FOR_TARGET = "${targetPlatform.config}-gcc";
CXX_FOR_TARGET = "${targetPlatform.config}-g++";
# If we are making a cross compiler, cross != null
NIX_CC_CROSS = if targetPlatform == hostPlatform then "${stdenv.ccCross}" else "";
dontStrip = true;
buildFlags = "";
};
NIX_BUILD_CC = stdenv.cc;
NIX_CC_CROSS = stdenv.ccCross or null;
# Needed for the cross compilation to work
AR = "ar";