···
···
+
# What follows is a horribly cursed hack.
+
# GCC will install its libraries to $out/lib, $out/lib32, $out/lib64,
+
# $out/$targetConfig/lib, $out/$targetConfig/lib32 or $out/$targetConfig/lib64,
+
# depending on whether it's built as native or cross, and the exact target spec.
+
# We can't predict what it's actually going to do, and we also can't just tell it
+
# to always install to $out/lib, but we want everything to end up in $out/lib
+
# for consistency (multilib weirdness aside).
+
# So, we create a bunch of symlinks before we run GCC's install phase,
+
# redirecting every possible directory it may want to write to to the place
+
# we actually want things to be installed.
+
# We will then nuke the symlinks in postInstall.
+
# FIXME: there must be a better way to do this.
+
declare -ga compatibilitySymlinks=()
+
makeCompatibilitySymlink() {
+
for output in "$out" "''${!outputLib}"; do
+
local linkName="$output/$2"
+
echo "Creating compatibility symlink: $linkTarget -> $linkName"
+
mkdir -p "$(dirname "$linkName")"
+
ln -s "$linkTarget" "$linkName"
+
compatibilitySymlinks+=("$linkName")
+
# This will redirect $output/lib{32,64} to $output/lib.
+
# Multilib is special, because it creates $out/lib (for 32-bit)
+
# and $out/lib64 (for 64-bit). No other targets can have both.
+
lib.optionalString (!enableMultilib) ''
+
makeCompatibilitySymlink lib lib32
+
makeCompatibilitySymlink lib lib64
+
# This will redirect $output/$targetConfig/lib{,32,64} to $output/lib.
+
lib.optionalString (with stdenv; targetPlatform.config != hostPlatform.config) ''
+
makeCompatibilitySymlink lib $targetConfig/lib32
+
makeCompatibilitySymlink lib $targetConfig/lib64
+
makeCompatibilitySymlink ../lib $targetConfig/lib
+
# Clean up our compatibility symlinks (see above)
+
for link in "''${compatibilitySymlinks[@]}"; do
+
echo "Removing compatibility symlink: $link"
+
# Move runtime libraries to lib output.
+
moveToOutput "lib/lib*.so*" "''${!outputLib}"
+
moveToOutput "lib/lib*.la" "''${!outputLib}"
+
moveToOutput "lib/lib*.dylib" "''${!outputLib}"
+
moveToOutput "lib/lib*.dll.a" "''${!outputLib}"
+
moveToOutput "lib/lib*.dll" "''${!outputLib}"
+
moveToOutput "share/gcc-*/python" "''${!outputLib}"
+
if [ -z "$enableShared" ]; then
+
moveToOutput "lib/lib*.a" "''${!outputLib}"
+
for i in "''${!outputLib}"/lib/*.{la,py}; do
+
substituteInPlace "$i" --replace "$out" "''${!outputLib}"
+
if [ -n "$enableMultilib" ]; then
+
moveToOutput "lib64/lib*.so*" "''${!outputLib}"
+
moveToOutput "lib64/lib*.la" "''${!outputLib}"
+
moveToOutput "lib64/lib*.dylib" "''${!outputLib}"
+
moveToOutput "lib64/lib*.dll.a" "''${!outputLib}"
+
moveToOutput "lib64/lib*.dll" "''${!outputLib}"
+
for i in "''${!outputLib}"/lib64/*.{la,py}; do
+
substituteInPlace "$i" --replace "$out" "''${!outputLib}"
+
# Remove `fixincl' to prevent a retained dependency on the
+
rm -rf $out/libexec/gcc/*/*/install-tools
+
rm -rf $out/lib/gcc/*/*/install-tools
+
# More dependencies with the previous gcc or some libs (gccbug stores the build command line)
+
if type "install_name_tool"; then
+
for i in "''${!outputLib}"/lib/*.*.dylib "''${!outputLib}"/lib/*.so.[0-9]; do
+
install_name_tool -id "$i" "$i" || true
+
for old_path in $(otool -L "$i" | grep "$out" | awk '{print $1}'); do
+
new_path=`echo "$old_path" | sed "s,$out,''${!outputLib},"`
+
install_name_tool -change "$old_path" "$new_path" "$i" || true
+
# Get rid of some "fixed" header files
+
rm -rfv $out/lib/gcc/*/*/include-fixed/{root,linux,sys/mount.h,bits/statx.h,pthread.h}
+
# Replace hard links for i686-pc-linux-gnu-gcc etc. with symlinks.
+
for i in $out/bin/*-gcc*; do
+
if cmp -s $out/bin/gcc $i; then
+
for i in $out/bin/c++ $out/bin/*-c++* $out/bin/*-g++*; do
+
if cmp -s $out/bin/g++ $i; then
+
# Two identical man pages are shipped (moving and compressing is done later)
+
for i in "$out"/share/man/man1/*g++.1; do
+
man_prefix=`echo "$i" | sed "s,.*/\(.*\)g++.1,\1,"`
+
ln -sf "$man_prefix"gcc.1 "$i"
+
# Recreate the target symlink so GCC can find libgcc_s on non-split builds.
+
lib.optionalString (with stdenv; targetPlatform.config != hostPlatform.config) ''
+
ln -s $lib/lib $lib/$targetConfig/lib