···11-if [ -e .attrs.sh ]; then source .attrs.sh; fi
22-source $stdenv/setup
33-44-55-oldOpts="$(shopt -po nounset)" || true
66-set -euo pipefail
77-88-99-export NIX_FIXINC_DUMMY="$NIX_BUILD_TOP/dummy"
1010-mkdir "$NIX_FIXINC_DUMMY"
1111-1212-1313-if test "$staticCompiler" = "1"; then
1414- EXTRA_LDFLAGS="-static"
1515-else
1616- EXTRA_LDFLAGS="-Wl,-rpath,${!outputLib}/lib"
1717-fi
1818-1919-2020-# GCC interprets empty paths as ".", which we don't want.
2121-if test -z "${CPATH-}"; then unset CPATH; fi
2222-if test -z "${LIBRARY_PATH-}"; then unset LIBRARY_PATH; fi
2323-echo "\$CPATH is \`${CPATH-}'"
2424-echo "\$LIBRARY_PATH is \`${LIBRARY_PATH-}'"
2525-2626-if test "$noSysDirs" = "1"; then
2727-2828- declare \
2929- EXTRA_FLAGS_FOR_BUILD EXTRA_FLAGS EXTRA_FLAGS_FOR_TARGET \
3030- EXTRA_LDFLAGS_FOR_BUILD EXTRA_LDFLAGS_FOR_TARGET
3131-3232- # Extract flags from Bintools Wrappers
3333- for post in '_FOR_BUILD' ''; do
3434- curBintools="NIX_BINTOOLS${post}"
3535-3636- declare -a extraLDFlags=()
3737- if [[ -e "${!curBintools}/nix-support/orig-libc" ]]; then
3838- # Figure out what extra flags when linking to pass to the gcc
3939- # compilers being generated to make sure that they use our libc.
4040- extraLDFlags=($(< "${!curBintools}/nix-support/libc-ldflags") $(< "${!curBintools}/nix-support/libc-ldflags-before" || true))
4141- if [ -e ${!curBintools}/nix-support/ld-set-dynamic-linker ]; then
4242- extraLDFlags=-dynamic-linker=$(< ${!curBintools}/nix-support/dynamic-linker)
4343- fi
4444-4545- # The path to the Libc binaries such as `crti.o'.
4646- libc_libdir="$(< "${!curBintools}/nix-support/orig-libc")/lib"
4747- else
4848- # Hack: support impure environments.
4949- extraLDFlags=("-L/usr/lib64" "-L/usr/lib")
5050- libc_libdir="/usr/lib"
5151- fi
5252- extraLDFlags=("-L$libc_libdir" "-rpath" "$libc_libdir"
5353- "${extraLDFlags[@]}")
5454- for i in "${extraLDFlags[@]}"; do
5555- declare EXTRA_LDFLAGS${post}+=" -Wl,$i"
5656- done
5757- done
5858-5959- # Extract flags from CC Wrappers
6060- for post in '_FOR_BUILD' ''; do
6161- curCC="NIX_CC${post}"
6262- curFIXINC="NIX_FIXINC_DUMMY${post}"
6363-6464- declare -a extraFlags=()
6565- if [[ -e "${!curCC}/nix-support/orig-libc" ]]; then
6666- # Figure out what extra compiling flags to pass to the gcc compilers
6767- # being generated to make sure that they use our libc.
6868- extraFlags=($(< "${!curCC}/nix-support/libc-crt1-cflags") $(< "${!curCC}/nix-support/libc-cflags"))
6969-7070- # The path to the Libc headers
7171- libc_devdir="$(< "${!curCC}/nix-support/orig-libc-dev")"
7272-7373- # Use *real* header files, otherwise a limits.h is generated that
7474- # does not include Libc's limits.h (notably missing SSIZE_MAX,
7575- # which breaks the build).
7676- declare NIX_FIXINC_DUMMY${post}="$libc_devdir/include"
7777- else
7878- # Hack: support impure environments.
7979- extraFlags=("-isystem" "/usr/include")
8080- declare NIX_FIXINC_DUMMY${post}=/usr/include
8181- fi
8282-8383- extraFlags=("-I${!curFIXINC}" "${extraFlags[@]}")
8484-8585- # BOOT_CFLAGS defaults to `-g -O2'; since we override it below, make
8686- # sure to explictly add them so that files compiled with the bootstrap
8787- # compiler are optimized and (optionally) contain debugging information
8888- # (info "(gccinstall) Building").
8989- if test -n "${dontStrip-}"; then
9090- extraFlags=("-O2" "-g" "${extraFlags[@]}")
9191- else
9292- # Don't pass `-g' at all; this saves space while building.
9393- extraFlags=("-O2" "${extraFlags[@]}")
9494- fi
9595-9696- declare EXTRA_FLAGS${post}="${extraFlags[*]}"
9797- done
9898-9999- if test -z "${targetConfig-}"; then
100100- # host = target, so the flags are the same
101101- EXTRA_FLAGS_FOR_TARGET="$EXTRA_FLAGS"
102102- EXTRA_LDFLAGS_FOR_TARGET="$EXTRA_LDFLAGS"
103103- fi
104104-105105- # CFLAGS_FOR_TARGET are needed for the libstdc++ configure script to find
106106- # the startfiles.
107107- # FLAGS_FOR_TARGET are needed for the target libraries to receive the -Bxxx
108108- # for the startfiles.
109109- makeFlagsArray+=(
110110- "BUILD_SYSTEM_HEADER_DIR=$NIX_FIXINC_DUMMY_FOR_BUILD"
111111- "SYSTEM_HEADER_DIR=$NIX_FIXINC_DUMMY_FOR_BUILD"
112112- "NATIVE_SYSTEM_HEADER_DIR=$NIX_FIXINC_DUMMY"
113113-114114- "LDFLAGS_FOR_BUILD=$EXTRA_LDFLAGS_FOR_BUILD"
115115- #"LDFLAGS=$EXTRA_LDFLAGS"
116116- "LDFLAGS_FOR_TARGET=$EXTRA_LDFLAGS_FOR_TARGET"
117117-118118- "CFLAGS_FOR_BUILD=$EXTRA_FLAGS_FOR_BUILD $EXTRA_LDFLAGS_FOR_BUILD"
119119- "CXXFLAGS_FOR_BUILD=$EXTRA_FLAGS_FOR_BUILD $EXTRA_LDFLAGS_FOR_BUILD"
120120- "FLAGS_FOR_BUILD=$EXTRA_FLAGS_FOR_BUILD $EXTRA_LDFLAGS_FOR_BUILD"
121121-122122- # It seems there is a bug in GCC 5
123123- #"CFLAGS=$EXTRA_FLAGS $EXTRA_LDFLAGS"
124124- #"CXXFLAGS=$EXTRA_FLAGS $EXTRA_LDFLAGS"
125125-126126- "CFLAGS_FOR_TARGET=$EXTRA_FLAGS_FOR_TARGET $EXTRA_LDFLAGS_FOR_TARGET"
127127- "CXXFLAGS_FOR_TARGET=$EXTRA_FLAGS_FOR_TARGET $EXTRA_LDFLAGS_FOR_TARGET"
128128- "FLAGS_FOR_TARGET=$EXTRA_FLAGS_FOR_TARGET $EXTRA_LDFLAGS_FOR_TARGET"
129129- )
130130-131131- if test -z "${targetConfig-}"; then
132132- makeFlagsArray+=(
133133- "BOOT_CFLAGS=$EXTRA_FLAGS $EXTRA_LDFLAGS"
134134- "BOOT_LDFLAGS=$EXTRA_FLAGS_FOR_TARGET $EXTRA_LDFLAGS_FOR_TARGET"
135135- )
136136- fi
137137-138138- if test "$withoutTargetLibc" == 1; then
139139- # We don't want the gcc build to assume there will be a libc providing
140140- # limits.h in this stage
141141- makeFlagsArray+=(
142142- 'LIMITS_H_TEST=false'
143143- )
144144- else
145145- makeFlagsArray+=(
146146- 'LIMITS_H_TEST=true'
147147- )
148148- fi
149149-fi
150150-151151-eval "$oldOpts"
152152-153153-providedPreConfigure="$preConfigure";
154154-preConfigure() {
155155- if test -n "$newlibSrc"; then
156156- tar xvf "$newlibSrc" -C ..
157157- ln -s ../newlib-*/newlib newlib
158158- # Patch to get armvt5el working:
159159- sed -i -e 's/ arm)/ arm*)/' newlib/configure.host
160160- fi
161161-162162- # Bug - they packaged zlib
163163- if test -d "zlib"; then
164164- # This breaks the build without-headers, which should build only
165165- # the target libgcc as target libraries.
166166- # See 'configure:5370'
167167- rm -Rf zlib
168168- fi
169169-170170- if test -n "$crossMingw" -a -n "$withoutTargetLibc"; then
171171- mkdir -p ../mingw
172172- # --with-build-sysroot expects that:
173173- cp -R $libcCross/include ../mingw
174174- configureFlags="$configureFlags --with-build-sysroot=`pwd`/.."
175175- fi
176176-177177- # Eval the preConfigure script from nix expression.
178178- eval "$providedPreConfigure"
179179-180180- # Perform the build in a different directory.
181181- mkdir ../build
182182- cd ../build
183183- configureScript=../$sourceRoot/configure
184184-}
185185-186186-187187-postConfigure() {
188188- # Avoid store paths when embedding ./configure flags into gcc.
189189- # Mangled arguments are still useful when reporting bugs upstream.
190190- sed -e "/TOPLEVEL_CONFIGURE_ARGUMENTS=/ s|$NIX_STORE/[a-z0-9]\{32\}-|$NIX_STORE/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-|g" -i Makefile
191191-}
192192-193193-194194-preInstall() {
195195- mkdir -p "$out/${targetConfig}/lib"
196196- mkdir -p "${!outputLib}/${targetConfig}/lib"
197197- # Make ‘lib64’ symlinks to ‘lib’.
198198- if [ -n "$linkLib64toLib" ]; then
199199- ln -s lib "$out/${targetConfig}/lib64"
200200- ln -s lib "${!outputLib}/${targetConfig}/lib64"
201201- fi
202202- # Make ‘lib32’ symlinks to ‘lib’.
203203- if [ -n "$linkLib32toLib" ]; then
204204- ln -s lib "$out/${targetConfig}/lib32"
205205- ln -s lib "${!outputLib}/${targetConfig}/lib32"
206206- fi
207207-}
208208-209209-210210-postInstall() {
211211- # Move runtime libraries to lib output.
212212- moveToOutput "${targetConfig+$targetConfig/}lib/lib*.so*" "${!outputLib}"
213213- moveToOutput "${targetConfig+$targetConfig/}lib/lib*.la" "${!outputLib}"
214214- moveToOutput "${targetConfig+$targetConfig/}lib/lib*.dylib" "${!outputLib}"
215215- moveToOutput "${targetConfig+$targetConfig/}lib/lib*.dll.a" "${!outputLib}"
216216- moveToOutput "share/gcc-*/python" "${!outputLib}"
217217-218218- if [ -z "$enableShared" ]; then
219219- moveToOutput "${targetConfig+$targetConfig/}lib/lib*.a" "${!outputLib}"
220220- fi
221221-222222- for i in "${!outputLib}/${targetConfig}"/lib/*.{la,py}; do
223223- substituteInPlace "$i" --replace "$out" "${!outputLib}"
224224- done
225225-226226- if [ -n "$enableMultilib" ]; then
227227- moveToOutput "${targetConfig+$targetConfig/}lib64/lib*.so*" "${!outputLib}"
228228- moveToOutput "${targetConfig+$targetConfig/}lib64/lib*.la" "${!outputLib}"
229229- moveToOutput "${targetConfig+$targetConfig/}lib64/lib*.dylib" "${!outputLib}"
230230-231231- for i in "${!outputLib}/${targetConfig}"/lib64/*.{la,py}; do
232232- substituteInPlace "$i" --replace "$out" "${!outputLib}"
233233- done
234234- fi
235235-236236- # Remove `fixincl' to prevent a retained dependency on the
237237- # previous gcc.
238238- rm -rf $out/libexec/gcc/*/*/install-tools
239239- rm -rf $out/lib/gcc/*/*/install-tools
240240-241241- # More dependencies with the previous gcc or some libs (gccbug stores the build command line)
242242- rm -rf $out/bin/gccbug
243243-244244- if type "install_name_tool"; then
245245- for i in "${!outputLib}"/lib/*.*.dylib "${!outputLib}"/lib/*.so.[0-9]; do
246246- install_name_tool -id "$i" "$i" || true
247247- for old_path in $(otool -L "$i" | grep "$out" | awk '{print $1}'); do
248248- new_path=`echo "$old_path" | sed "s,$out,${!outputLib},"`
249249- install_name_tool -change "$old_path" "$new_path" "$i" || true
250250- done
251251- done
252252- fi
253253-254254- # Cross-compiler specific:
255255- # --with-headers=$dir option triggers gcc to make a private copy
256256- # of $dir headers and use it later as `-isysroot`. This prevents
257257- # cc-wrapper from overriding libc headers with `-idirafter`.
258258- # It should be safe to drop it and rely solely on the cc-wrapper.
259259- local sysinc_dir=$out/${targetConfig+$targetConfig/}sys-include
260260- if [ -d "$sysinc_dir" ]; then
261261- chmod -R u+w "$out/${targetConfig+$targetConfig/}sys-include"
262262- rm -rfv "$out/${targetConfig+$targetConfig/}sys-include"
263263- fi
264264-265265- # Get rid of some "fixed" header files
266266- rm -rfv $out/lib/gcc/*/*/include-fixed/{root,linux,sys/mount.h,bits/statx.h}
267267-268268- # Replace hard links for i686-pc-linux-gnu-gcc etc. with symlinks.
269269- for i in $out/bin/*-gcc*; do
270270- if cmp -s $out/bin/gcc $i; then
271271- ln -sfn gcc $i
272272- fi
273273- done
274274-275275- for i in $out/bin/c++ $out/bin/*-c++* $out/bin/*-g++*; do
276276- if cmp -s $out/bin/g++ $i; then
277277- ln -sfn g++ $i
278278- fi
279279- done
280280-281281- # Two identical man pages are shipped (moving and compressing is done later)
282282- for i in "$out"/share/man/man1/*g++.1; do
283283- if test -e "$i"; then
284284- man_prefix=`echo "$i" | sed "s,.*/\(.*\)g++.1,\1,"`
285285- ln -sf "$man_prefix"gcc.1 "$i"
286286- fi
287287- done
288288-}
289289-290290-genericBuild
+289
pkgs/development/compilers/gcc/common/builder.nix
···11+{ lib
22+, stdenv
33+, enableMultilib
44+}:
55+66+originalAttrs: (stdenv.mkDerivation (finalAttrs: originalAttrs // {
77+ preUnpack = ''
88+ oldOpts="$(shopt -po nounset)" || true
99+ set -euo pipefail
1010+1111+ export NIX_FIXINC_DUMMY="$NIX_BUILD_TOP/dummy"
1212+ mkdir "$NIX_FIXINC_DUMMY"
1313+1414+ if test "$staticCompiler" = "1"; then
1515+ EXTRA_LDFLAGS="-static"
1616+ else
1717+ EXTRA_LDFLAGS="-Wl,-rpath,''${!outputLib}/lib"
1818+ fi
1919+2020+ # GCC interprets empty paths as ".", which we don't want.
2121+ if test -z "''${CPATH-}"; then unset CPATH; fi
2222+ if test -z "''${LIBRARY_PATH-}"; then unset LIBRARY_PATH; fi
2323+ echo "\$CPATH is \`''${CPATH-}'"
2424+ echo "\$LIBRARY_PATH is \`''${LIBRARY_PATH-}'"
2525+2626+ if test "$noSysDirs" = "1"; then
2727+2828+ declare -g \
2929+ EXTRA_FLAGS_FOR_BUILD EXTRA_FLAGS EXTRA_FLAGS_FOR_TARGET \
3030+ EXTRA_LDFLAGS_FOR_BUILD EXTRA_LDFLAGS_FOR_TARGET
3131+3232+ # Extract flags from Bintools Wrappers
3333+ for post in '_FOR_BUILD' ""; do
3434+ curBintools="NIX_BINTOOLS''${post}"
3535+3636+ declare -a extraLDFlags=()
3737+ if [[ -e "''${!curBintools}/nix-support/orig-libc" ]]; then
3838+ # Figure out what extra flags when linking to pass to the gcc
3939+ # compilers being generated to make sure that they use our libc.
4040+ extraLDFlags=($(< "''${!curBintools}/nix-support/libc-ldflags") $(< "''${!curBintools}/nix-support/libc-ldflags-before" || true))
4141+ if [ -e ''${!curBintools}/nix-support/ld-set-dynamic-linker ]; then
4242+ extraLDFlags=-dynamic-linker=$(< ''${!curBintools}/nix-support/dynamic-linker)
4343+ fi
4444+4545+ # The path to the Libc binaries such as `crti.o'.
4646+ libc_libdir="$(< "''${!curBintools}/nix-support/orig-libc")/lib"
4747+ else
4848+ # Hack: support impure environments.
4949+ extraLDFlags=("-L/usr/lib64" "-L/usr/lib")
5050+ libc_libdir="/usr/lib"
5151+ fi
5252+ extraLDFlags=("-L$libc_libdir" "-rpath" "$libc_libdir"
5353+ "''${extraLDFlags[@]}")
5454+ for i in "''${extraLDFlags[@]}"; do
5555+ declare -g EXTRA_LDFLAGS''${post}+=" -Wl,$i"
5656+ done
5757+ done
5858+5959+ # Extract flags from CC Wrappers
6060+ for post in '_FOR_BUILD' ""; do
6161+ curCC="NIX_CC''${post}"
6262+ curFIXINC="NIX_FIXINC_DUMMY''${post}"
6363+6464+ declare -a extraFlags=()
6565+ if [[ -e "''${!curCC}/nix-support/orig-libc" ]]; then
6666+ # Figure out what extra compiling flags to pass to the gcc compilers
6767+ # being generated to make sure that they use our libc.
6868+ extraFlags=($(< "''${!curCC}/nix-support/libc-crt1-cflags") $(< "''${!curCC}/nix-support/libc-cflags"))
6969+7070+ # The path to the Libc headers
7171+ libc_devdir="$(< "''${!curCC}/nix-support/orig-libc-dev")"
7272+7373+ # Use *real* header files, otherwise a limits.h is generated that
7474+ # does not include Libc's limits.h (notably missing SSIZE_MAX,
7575+ # which breaks the build).
7676+ declare -g NIX_FIXINC_DUMMY''${post}="$libc_devdir/include"
7777+ else
7878+ # Hack: support impure environments.
7979+ extraFlags=("-isystem" "/usr/include")
8080+ declare -g NIX_FIXINC_DUMMY''${post}=/usr/include
8181+ fi
8282+8383+ extraFlags=("-I''${!curFIXINC}" "''${extraFlags[@]}")
8484+8585+ # BOOT_CFLAGS defaults to `-g -O2'; since we override it below, make
8686+ # sure to explictly add them so that files compiled with the bootstrap
8787+ # compiler are optimized and (optionally) contain debugging information
8888+ # (info "(gccinstall) Building").
8989+ if test -n "''${dontStrip-}"; then
9090+ extraFlags=("-O2" "-g" "''${extraFlags[@]}")
9191+ else
9292+ # Don't pass `-g' at all; this saves space while building.
9393+ extraFlags=("-O2" "''${extraFlags[@]}")
9494+ fi
9595+9696+ declare -g EXTRA_FLAGS''${post}="''${extraFlags[*]}"
9797+ done
9898+9999+ if test -z "''${targetConfig-}"; then
100100+ # host = target, so the flags are the same
101101+ EXTRA_FLAGS_FOR_TARGET="$EXTRA_FLAGS"
102102+ EXTRA_LDFLAGS_FOR_TARGET="$EXTRA_LDFLAGS"
103103+ fi
104104+105105+ # CFLAGS_FOR_TARGET are needed for the libstdc++ configure script to find
106106+ # the startfiles.
107107+ # FLAGS_FOR_TARGET are needed for the target libraries to receive the -Bxxx
108108+ # for the startfiles.
109109+ makeFlagsArray+=(
110110+ "BUILD_SYSTEM_HEADER_DIR=$NIX_FIXINC_DUMMY_FOR_BUILD"
111111+ "SYSTEM_HEADER_DIR=$NIX_FIXINC_DUMMY_FOR_BUILD"
112112+ "NATIVE_SYSTEM_HEADER_DIR=$NIX_FIXINC_DUMMY"
113113+114114+ "LDFLAGS_FOR_BUILD=$EXTRA_LDFLAGS_FOR_BUILD"
115115+ #"LDFLAGS=$EXTRA_LDFLAGS"
116116+ "LDFLAGS_FOR_TARGET=$EXTRA_LDFLAGS_FOR_TARGET"
117117+118118+ "CFLAGS_FOR_BUILD=$EXTRA_FLAGS_FOR_BUILD $EXTRA_LDFLAGS_FOR_BUILD"
119119+ "CXXFLAGS_FOR_BUILD=$EXTRA_FLAGS_FOR_BUILD $EXTRA_LDFLAGS_FOR_BUILD"
120120+ "FLAGS_FOR_BUILD=$EXTRA_FLAGS_FOR_BUILD $EXTRA_LDFLAGS_FOR_BUILD"
121121+122122+ # It seems there is a bug in GCC 5
123123+ #"CFLAGS=$EXTRA_FLAGS $EXTRA_LDFLAGS"
124124+ #"CXXFLAGS=$EXTRA_FLAGS $EXTRA_LDFLAGS"
125125+126126+ "CFLAGS_FOR_TARGET=$EXTRA_FLAGS_FOR_TARGET $EXTRA_LDFLAGS_FOR_TARGET"
127127+ "CXXFLAGS_FOR_TARGET=$EXTRA_FLAGS_FOR_TARGET $EXTRA_LDFLAGS_FOR_TARGET"
128128+ "FLAGS_FOR_TARGET=$EXTRA_FLAGS_FOR_TARGET $EXTRA_LDFLAGS_FOR_TARGET"
129129+ )
130130+131131+ if test -z "''${targetConfig-}"; then
132132+ makeFlagsArray+=(
133133+ "BOOT_CFLAGS=$EXTRA_FLAGS $EXTRA_LDFLAGS"
134134+ "BOOT_LDFLAGS=$EXTRA_FLAGS_FOR_TARGET $EXTRA_LDFLAGS_FOR_TARGET"
135135+ )
136136+ fi
137137+138138+ if test "$withoutTargetLibc" == 1; then
139139+ # We don't want the gcc build to assume there will be a libc providing
140140+ # limits.h in this stage
141141+ makeFlagsArray+=(
142142+ 'LIMITS_H_TEST=false'
143143+ )
144144+ else
145145+ makeFlagsArray+=(
146146+ 'LIMITS_H_TEST=true'
147147+ )
148148+ fi
149149+ fi
150150+151151+ eval "$oldOpts"
152152+ '';
153153+154154+ preConfigure = (originalAttrs.preConfigure or "") + ''
155155+ if test -n "$newlibSrc"; then
156156+ tar xvf "$newlibSrc" -C ..
157157+ ln -s ../newlib-*/newlib newlib
158158+ # Patch to get armvt5el working:
159159+ sed -i -e 's/ arm)/ arm*)/' newlib/configure.host
160160+ fi
161161+162162+ # Bug - they packaged zlib
163163+ if test -d "zlib"; then
164164+ # This breaks the build without-headers, which should build only
165165+ # the target libgcc as target libraries.
166166+ # See 'configure:5370'
167167+ rm -Rf zlib
168168+ fi
169169+170170+ if test -n "$crossMingw" -a -n "$withoutTargetLibc"; then
171171+ mkdir -p ../mingw
172172+ # --with-build-sysroot expects that:
173173+ cp -R $libcCross/include ../mingw
174174+ configureFlags="$configureFlags --with-build-sysroot=`pwd`/.."
175175+ fi
176176+177177+ # Perform the build in a different directory.
178178+ mkdir ../build
179179+ cd ../build
180180+ configureScript=../$sourceRoot/configure
181181+ '';
182182+183183+ postConfigure = ''
184184+ # Avoid store paths when embedding ./configure flags into gcc.
185185+ # Mangled arguments are still useful when reporting bugs upstream.
186186+ sed -e "/TOPLEVEL_CONFIGURE_ARGUMENTS=/ s|$NIX_STORE/[a-z0-9]\{32\}-|$NIX_STORE/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-|g" -i Makefile
187187+ '';
188188+189189+ preInstall = ''
190190+ mkdir -p "$out/''${targetConfig}/lib"
191191+ mkdir -p "''${!outputLib}/''${targetConfig}/lib"
192192+ '' +
193193+ # Make `lib64` symlinks to `lib`.
194194+ lib.optionalString (!enableMultilib && stdenv.hostPlatform.is64bit && !stdenv.hostPlatform.isMips64n32) ''
195195+ ln -s lib "$out/''${targetConfig}/lib64"
196196+ ln -s lib "''${!outputLib}/''${targetConfig}/lib64"
197197+ '' +
198198+ # On mips platforms, gcc follows the IRIX naming convention:
199199+ #
200200+ # $PREFIX/lib = mips32
201201+ # $PREFIX/lib32 = mips64n32
202202+ # $PREFIX/lib64 = mips64
203203+ #
204204+ # Make `lib32` symlinks to `lib`.
205205+ lib.optionalString (!enableMultilib && stdenv.targetPlatform.isMips64n32) ''
206206+ ln -s lib "$out/''${targetConfig}/lib32"
207207+ ln -s lib "''${!outputLib}/''${targetConfig}/lib32"
208208+ '';
209209+210210+ postInstall = ''
211211+ # Move runtime libraries to lib output.
212212+ moveToOutput "''${targetConfig+$targetConfig/}lib/lib*.so*" "''${!outputLib}"
213213+ moveToOutput "''${targetConfig+$targetConfig/}lib/lib*.la" "''${!outputLib}"
214214+ moveToOutput "''${targetConfig+$targetConfig/}lib/lib*.dylib" "''${!outputLib}"
215215+ moveToOutput "''${targetConfig+$targetConfig/}lib/lib*.dll.a" "''${!outputLib}"
216216+ moveToOutput "share/gcc-*/python" "''${!outputLib}"
217217+218218+ if [ -z "$enableShared" ]; then
219219+ moveToOutput "''${targetConfig+$targetConfig/}lib/lib*.a" "''${!outputLib}"
220220+ fi
221221+222222+ for i in "''${!outputLib}/''${targetConfig}"/lib/*.{la,py}; do
223223+ substituteInPlace "$i" --replace "$out" "''${!outputLib}"
224224+ done
225225+226226+ if [ -n "$enableMultilib" ]; then
227227+ moveToOutput "''${targetConfig+$targetConfig/}lib64/lib*.so*" "''${!outputLib}"
228228+ moveToOutput "''${targetConfig+$targetConfig/}lib64/lib*.la" "''${!outputLib}"
229229+ moveToOutput "''${targetConfig+$targetConfig/}lib64/lib*.dylib" "''${!outputLib}"
230230+231231+ for i in "''${!outputLib}/''${targetConfig}"/lib64/*.{la,py}; do
232232+ substituteInPlace "$i" --replace "$out" "''${!outputLib}"
233233+ done
234234+ fi
235235+236236+ # Remove `fixincl' to prevent a retained dependency on the
237237+ # previous gcc.
238238+ rm -rf $out/libexec/gcc/*/*/install-tools
239239+ rm -rf $out/lib/gcc/*/*/install-tools
240240+241241+ # More dependencies with the previous gcc or some libs (gccbug stores the build command line)
242242+ rm -rf $out/bin/gccbug
243243+244244+ if type "install_name_tool"; then
245245+ for i in "''${!outputLib}"/lib/*.*.dylib "''${!outputLib}"/lib/*.so.[0-9]; do
246246+ install_name_tool -id "$i" "$i" || true
247247+ for old_path in $(otool -L "$i" | grep "$out" | awk '{print $1}'); do
248248+ new_path=`echo "$old_path" | sed "s,$out,''${!outputLib},"`
249249+ install_name_tool -change "$old_path" "$new_path" "$i" || true
250250+ done
251251+ done
252252+ fi
253253+254254+ # Cross-compiler specific:
255255+ # --with-headers=$dir option triggers gcc to make a private copy
256256+ # of $dir headers and use it later as `-isysroot`. This prevents
257257+ # cc-wrapper from overriding libc headers with `-idirafter`.
258258+ # It should be safe to drop it and rely solely on the cc-wrapper.
259259+ local sysinc_dir=$out/''${targetConfig+$targetConfig/}sys-include
260260+ if [ -d "$sysinc_dir" ]; then
261261+ chmod -R u+w "$out/''${targetConfig+$targetConfig/}sys-include"
262262+ rm -rfv "$out/''${targetConfig+$targetConfig/}sys-include"
263263+ fi
264264+265265+ # Get rid of some "fixed" header files
266266+ rm -rfv $out/lib/gcc/*/*/include-fixed/{root,linux,sys/mount.h,bits/statx.h}
267267+268268+ # Replace hard links for i686-pc-linux-gnu-gcc etc. with symlinks.
269269+ for i in $out/bin/*-gcc*; do
270270+ if cmp -s $out/bin/gcc $i; then
271271+ ln -sfn gcc $i
272272+ fi
273273+ done
274274+275275+ for i in $out/bin/c++ $out/bin/*-c++* $out/bin/*-g++*; do
276276+ if cmp -s $out/bin/g++ $i; then
277277+ ln -sfn g++ $i
278278+ fi
279279+ done
280280+281281+ # Two identical man pages are shipped (moving and compressing is done later)
282282+ for i in "$out"/share/man/man1/*g++.1; do
283283+ if test -e "$i"; then
284284+ man_prefix=`echo "$i" | sed "s,.*/\(.*\)g++.1,\1,"`
285285+ ln -sf "$man_prefix"gcc.1 "$i"
286286+ fi
287287+ done
288288+ '';
289289+}))