diff --git a/pkgs/baseenv/baseenv-build.sh b/pkgs/baseenv/baseenv-build.sh new file mode 100755 index 00000000000..6c30bb2ff8b --- /dev/null +++ b/pkgs/baseenv/baseenv-build.sh @@ -0,0 +1,28 @@ +#! /bin/sh + +export PATH=/bin:/usr/bin + +mkdir $out || exit 1 +mkdir $out/bin || exit 1 + +sed \ + -e s^@OUT\@^$out^g \ + < $setup > $out/setup || exit 1 + +gcc=/usr/bin/gcc + +sed \ + -e s^@GCC\@^$gcc^g \ + < $gccwrapper > $out/bin/gcc || exit 1 +chmod +x $out/bin/gcc || exit 1 + +ln -s gcc $out/bin/cc + +gplusplus=/usr/bin/g++ + +sed \ + -e s^@GCC\@^$gplusplus^g \ + < $gccwrapper > $out/bin/g++ || exit 1 +chmod +x $out/bin/g++ || exit 1 + +ln -s g++ $out/bin/c++ diff --git a/pkgs/baseenv/baseenv.fix b/pkgs/baseenv/baseenv.fix new file mode 100644 index 00000000000..5efa61d08a0 --- /dev/null +++ b/pkgs/baseenv/baseenv.fix @@ -0,0 +1,8 @@ +Package( + [ ("name", "stdenv-native") + , ("build", Relative("baseenv/baseenv-build.sh")) + + , ("setup", Relative("baseenv/setup.sh")) + , ("gccwrapper", Relative("baseenv/gcc-wrapper.sh")) + ] +) diff --git a/pkgs/stdenv-linux/gcc-wrapper.sh b/pkgs/baseenv/gcc-wrapper.sh similarity index 77% rename from pkgs/stdenv-linux/gcc-wrapper.sh rename to pkgs/baseenv/gcc-wrapper.sh index 9e1b26698bb..4e000169019 100644 --- a/pkgs/stdenv-linux/gcc-wrapper.sh +++ b/pkgs/baseenv/gcc-wrapper.sh @@ -21,12 +21,15 @@ IFS=" " extra=($NIX_CFLAGS) if test "$justcompile" != "1"; then extra=(${extra[@]} $NIX_LDFLAGS) + if test "$NIX_STRIP_DEBUG" == "1"; then + extra=(${extra[@]} -Wl,-s) + fi fi if test "$NIX_DEBUG" == "1"; then - echo "extra gcc flags:" + echo "extra gcc flags:" >&2 for i in ${extra[@]}; do - echo " $i" + echo " $i" >&2 done fi diff --git a/pkgs/baseenv/setup.sh b/pkgs/baseenv/setup.sh new file mode 100644 index 00000000000..3b8263a8df3 --- /dev/null +++ b/pkgs/baseenv/setup.sh @@ -0,0 +1,39 @@ +# Add the directory containing the GCC wrappers to the PATH. +export PATH=@OUT@/bin + +# Recursively add all envpkgs to the relevant environment variables. +addtoenv() +{ + envpkgs="$envpkgs $1" + + if test -d $1/bin; then + export PATH=$1/bin:$PATH + fi + + if test -d $1/lib; then + export NIX_LDFLAGS="-L $1/lib -Wl,-rpath,$1/lib $NIX_LDFLAGS" + fi + + if test -d $1/lib/pkgconfig; then + export PKG_CONFIG_PATH=$1/lib/pkgconfig:$PKG_CONFIG_PATH + fi + + if test -f $1/envpkgs; then + for i in $(cat $1/envpkgs); do + addtoenv $i + done + fi +} + +oldenvpkgs=$envpkgs +envpkgs= + +for i in $oldenvpkgs; do + addtoenv $i +done + +# Add the output as an rpath. +export NIX_LDFLAGS="-Wl,-rpath,$out/lib $NIX_LDFLAGS" + +# Strip debug information by default. +export NIX_STRIP_DEBUG=1 diff --git a/pkgs/coreutils/coreutils-build.sh b/pkgs/coreutils/coreutils-build.sh new file mode 100755 index 00000000000..75308639108 --- /dev/null +++ b/pkgs/coreutils/coreutils-build.sh @@ -0,0 +1,9 @@ +#! /bin/sh + +. $stdenv/setup || exit 1 + +tar xvfj $src || exit 1 +cd coreutils-* || exit 1 +./configure --prefix=$out || exit 1 +make || exit 1 +make install || exit 1 diff --git a/pkgs/coreutils/coreutils.fix b/pkgs/coreutils/coreutils.fix new file mode 100644 index 00000000000..a799619c4eb --- /dev/null +++ b/pkgs/coreutils/coreutils.fix @@ -0,0 +1,13 @@ +Package( + [ ("name", "coreutils-5.0") + + , ("build", Relative("coreutils/coreutils-build.sh")) + + , ("src", Call(IncludeFix("fetchurl/fetchurl.fix"), + [ ("url", "ftp://ftp.nluug.nl/pub/gnu/coreutils/coreutils-5.0.tar.bz2") + , ("md5", "94e5558ee2a65723d4840bfde2d323f0") + ])) + + , ("stdenv", IncludeFix("stdenv-linux/stdenv-nativetools.fix")) + ] +) diff --git a/pkgs/stdenv-linux/setup.sh b/pkgs/stdenv-linux/setup.sh new file mode 100644 index 00000000000..a0f07476a02 --- /dev/null +++ b/pkgs/stdenv-linux/setup.sh @@ -0,0 +1,10 @@ +. @BASEENV@/setup + +export NIX_CFLAGS="-isystem @GLIBC@/include $NIX_CFLAGS" +export NIX_LDFLAGS="-L @GLIBC@/lib -Wl,-dynamic-linker,@GLIBC@/lib/ld-linux.so.2,-rpath,@GLIBC@/lib $NIX_LDFLAGS" + +if test "@NATIVETOOLS@"; then + export PATH=$PATH:/usr/local/bin:/usr/bin:/bin +else + export PATH=@COREUTILS@/bin:$PATH +fi diff --git a/pkgs/stdenv-linux/stdenv-build.sh b/pkgs/stdenv-linux/stdenv-build.sh index 5b5ba436d81..ea03beb55de 100755 --- a/pkgs/stdenv-linux/stdenv-build.sh +++ b/pkgs/stdenv-linux/stdenv-build.sh @@ -3,26 +3,10 @@ export PATH=/bin:/usr/bin mkdir $out || exit 1 -mkdir $out/bin || exit 1 - -echo "export PATH=$out/bin:/bin:/usr/bin" >> $out/setup || exit 1 -echo "export NIX_CFLAGS=\"-isystem $glibc/include \$NIX_CFLAGS\"" >> $out/setup || exit 1 -echo "export NIX_LDFLAGS=\"-L $glibc/lib -Wl,-dynamic-linker,$glibc/lib/ld-linux.so.2,-rpath,$glibc/lib \$NIX_LDFLAGS\"" >> $out/setup || exit 1 - -gcc=/usr/bin/gcc sed \ - -e s^@GCC\@^$gcc^g \ - < $gccwrapper > $out/bin/gcc || exit 1 -chmod +x $out/bin/gcc || exit 1 - -ln -s gcc $out/bin/cc - -gplusplus=/usr/bin/g++ - -sed \ - -e s^@GCC\@^$gplusplus^g \ - < $gccwrapper > $out/bin/g++ || exit 1 -chmod +x $out/bin/g++ || exit 1 - -ln -s g++ $out/bin/c++ + -e s^@GLIBC\@^$glibc^g \ + -e s^@BASEENV\@^$baseenv^g \ + -e s^@NATIVETOOLS\@^$nativeTools^g \ + -e s^@COREUTILS\@^$coreutils^g \ + < $setup > $out/setup || exit 1 diff --git a/pkgs/stdenv-linux/stdenv-generic.fix b/pkgs/stdenv-linux/stdenv-generic.fix new file mode 100644 index 00000000000..ad304c5ebb2 --- /dev/null +++ b/pkgs/stdenv-linux/stdenv-generic.fix @@ -0,0 +1,16 @@ +Function(["nativeTools"], + + Package( + [ ("name", "stdenv-linux") + , ("build", Relative("stdenv-linux/stdenv-build.sh")) + + , ("nativeTools", Var("nativeTools")) + + , ("setup", Relative("stdenv-linux/setup.sh")) + , ("baseenv", IncludeFix("baseenv/baseenv.fix")) + , ("glibc", IncludeFix("glibc/glibc.fix")) + + , ("coreutils", If(Var("nativeTools"), "", IncludeFix("coreutils/coreutils.fix"))) + ] + ) +) diff --git a/pkgs/stdenv-linux/stdenv-nativetools.fix b/pkgs/stdenv-linux/stdenv-nativetools.fix new file mode 100644 index 00000000000..a29278a3841 --- /dev/null +++ b/pkgs/stdenv-linux/stdenv-nativetools.fix @@ -0,0 +1 @@ +Call(IncludeFix("stdenv-linux/stdenv-generic.fix"), [("nativeTools", True)]) \ No newline at end of file diff --git a/pkgs/stdenv-linux/stdenv.fix b/pkgs/stdenv-linux/stdenv.fix index 050095de48d..ceef50c6eca 100644 --- a/pkgs/stdenv-linux/stdenv.fix +++ b/pkgs/stdenv-linux/stdenv.fix @@ -1,9 +1 @@ -Package( - [ ("name", "stdenv-linux") - , ("build", Relative("stdenv-linux/stdenv-build.sh")) - - , ("gccwrapper", Relative("stdenv-linux/gcc-wrapper.sh")) - - , ("glibc", IncludeFix("glibc/glibc.fix")) - ] -) +Call(IncludeFix("stdenv-linux/stdenv-generic.fix"), [("nativeTools", False)]) \ No newline at end of file