summary refs log tree commit diff
path: root/pkgs/stdenv/generic/setup.sh
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/stdenv/generic/setup.sh')
-rw-r--r--pkgs/stdenv/generic/setup.sh283
1 files changed, 120 insertions, 163 deletions
diff --git a/pkgs/stdenv/generic/setup.sh b/pkgs/stdenv/generic/setup.sh
index e91a9ce4dfd..395de988e4c 100644
--- a/pkgs/stdenv/generic/setup.sh
+++ b/pkgs/stdenv/generic/setup.sh
@@ -1,12 +1,6 @@
-set -e
+######################################################################
+# Helper functions that might be useful in setup hooks.
 
-test -z $NIX_GCC && NIX_GCC=@gcc@
-
-if [ -z ${system##*cygwin*} ]; then
-  PATH_DELIMITER=';'
-else
-  PATH_DELIMITER=':'
-fi
 
 addToSearchPathWithCustomDelimiter() {
     local delimiter=$1
@@ -28,6 +22,15 @@ addToSearchPath()
     addToSearchPathWithCustomDelimiter "${PATH_DELIMITER}" "$@"
 }
 
+
+######################################################################
+# Initialisation.
+
+set -e
+
+test -z $NIX_GCC && NIX_GCC=@gcc@
+
+
 # Set up the initial path.
 PATH=
 for i in $NIX_GCC @initialPath@; do
@@ -35,12 +38,13 @@ for i in $NIX_GCC @initialPath@; do
 done
 
 if test "$NIX_DEBUG" = "1"; then
-    echo "Initial path: $PATH"
+    echo "initial path: $PATH"
 fi
 
 
 # Execute the pre-hook.
 export SHELL=@shell@
+PATH_DELIMITER=':'
 if test -z "$shell"; then
     export shell=@shell@
 fi
@@ -49,9 +53,8 @@ param2=@param2@
 param3=@param3@
 param4=@param4@
 param5=@param5@
-if test -n "@preHook@"; then
-    source @preHook@
-fi
+if test -n "@preHook@"; then source @preHook@; fi
+eval "$preHook"
 
 
 # Check that the pre-hook initialised SHELL.
@@ -206,16 +209,16 @@ if test "$useTempPrefix" = "1"; then
 fi
 
 
-# Execute the post-hook.
-if test -n "@postHook@"; then
-    source @postHook@
-fi
-
 PATH=$_PATH${_PATH:+:}$PATH
 if test "$NIX_DEBUG" = "1"; then
-    echo "Final path: $PATH"
+    echo "final path: $PATH"
 fi
 
+
+######################################################################
+# Misc. helper functions.
+
+
 stripDirs() {
     local dirs="$1"
     local stripFlags="$2"
@@ -234,27 +237,17 @@ stripDirs() {
     fi
 }
 
+
 ######################################################################
 # Textual substitution functions.
 
 
-# Some disgusting hackery to escape replacements in Sed substitutions.
-# We should really have a tool that replaces literal values by other
-# literal values, without any need for escaping.
-escapeSed() {
-    local s="$1"
-    # The `tr' hack is to escape newlines.  Sed handles newlines very
-    # badly, so we just replace newlines with the magic character 0xff
-    # (377 octal).  So don't use that character in replacements :-P
-    echo -n "$1" | tr '\012' '\377' | sed -e 's^\\^\\\\^g' -e 's^\xff^\\n^g' -e 's/\^/\\^/g' -e 's/&/\\&/g'
-}
-
-
 substitute() {
     local input="$1"
     local output="$2"
 
     local -a params=("$@")
+    local -a args=()
 
     local sedScript=$NIX_BUILD_TOP/.sedargs
     rm -f $sedScript
@@ -284,12 +277,14 @@ substitute() {
             n=$((n + 2))
         fi
 
-        replacement="$(escapeSed "$replacement")"
-
-        echo "s^$pattern^$replacement^g" >> $sedScript
+        if test ${#args[@]} != 0; then
+            args[${#args[@]}]="-a"
+        fi
+        args[${#args[@]}]="$pattern"
+        args[${#args[@]}]="$replacement"
     done
 
-    sed -f $sedScript < "$input" > "$output".tmp
+    replace-literal -e -s "${args[@]}" < "$input" > "$output".tmp
     if test -x "$output"; then
         chmod +x "$output".tmp
     fi
@@ -427,12 +422,12 @@ stripHash() {
 
 
 unpackFile() {
-    local file=$1
+    local file="$1"
     local cmd
 
     header "unpacking source archive $file" 3
 
-    case $file in
+    case "$file" in
         *.tar)
             tar xvf $file || fail
             ;;
@@ -466,7 +461,7 @@ unpackFile() {
 }
 
 
-unpackW() {
+unpackPhase() {
     if test -n "$unpackPhase"; then
         eval "$unpackPhase"
         return
@@ -536,23 +531,14 @@ unpackW() {
 }
 
 
-unpackPhase() {
-    sourceRoot=. # don't change to user dir homeless shelter if custom unpackSource does'nt set sourceRoot
-    header "unpacking sources"
-    startLog "unpack"
-    unpackW
-    stopLog
-    stopNest
-    cd $sourceRoot
-}
-
-
-patchW() {
+patchPhase() {
     if test -n "$patchPhase"; then
         eval "$patchPhase"
         return
     fi
 
+    if test -z "$patchPhase" -a -z "$patches"; then return; fi
+    
     if test -z "$patchFlags"; then
         patchFlags="-p1"
     fi
@@ -574,23 +560,13 @@ patchW() {
 }
 
 
-patchPhase() {
-    if test -z "$patchPhase" -a -z "$patches"; then return; fi
-    header "patching sources"
-    startLog "patch"
-    patchW
-    stopLog
-    stopNest
-}
-
-
 fixLibtool() {
     sed 's^eval sys_lib_.*search_path=.*^^' < $1 > $1.tmp
     mv $1.tmp $1
 }
 
 
-configureW() {
+configurePhase() {
     if test -n "$configurePhase"; then
         eval "$configurePhase"
         return
@@ -617,6 +593,13 @@ configureW() {
         configureFlags="${prefixKey:---prefix=}$prefix $configureFlags"
     fi
 
+    # Add --disable-dependency-tracking to speed up some builds.
+    if test -z "$dontAddDisableDepTrack"; then
+        if grep -q dependency-tracking $configureScript; then
+            configureFlags="--disable-dependency-tracking ${prefixKey:---prefix=}$prefix $configureFlags"
+        fi
+    fi
+
     echo "configure flags: $configureFlags ${configureFlagsArray[@]}"
     $configureScript $configureFlags"${configureFlagsArray[@]}" || fail
 
@@ -624,16 +607,7 @@ configureW() {
 }
 
 
-configurePhase() {
-    header "configuring"
-    startLog "configure"
-    configureW
-    stopLog
-    stopNest
-}
-
-
-buildW() {
+buildPhase() {
     if test -n "$buildPhase"; then
         eval "$buildPhase"
         return
@@ -641,8 +615,13 @@ buildW() {
 
     eval "$preBuild"
 
+    if ! test -n "$makefile" -o -e "Makefile" -o -e "makefile" -o -e "GNUmakefile"; then
+        echo "no Makefile, doing nothing"
+        return
+    fi
+
     echo "make flags: $makeFlags ${makeFlagsArray[@]} $buildFlags ${buildFlagsArray[@]}"
-    make \
+    make ${makefile:+-f $makefile} \
         $makeFlags "${makeFlagsArray[@]}" \
         $buildFlags "${buildFlagsArray[@]}" || fail
 
@@ -650,19 +629,7 @@ buildW() {
 }
 
 
-buildPhase() {
-    if test "$dontBuild" = 1; then
-        return
-    fi
-    header "building"
-    startLog "build"
-    buildW
-    stopLog
-    stopNest
-}
-
-
-checkW() {
+checkPhase() {
     if test -n "$checkPhase"; then
         eval "$checkPhase"
         return
@@ -673,24 +640,12 @@ checkW() {
     fi
 
     echo "check flags: $makeFlags ${makeFlagsArray[@]} $checkFlags ${checkFlagsArray[@]}"
-    make \
+    make ${makefile:+-f $makefile} \
         $makeFlags "${makeFlagsArray[@]}" \
         $checkFlags "${checkFlagsArray[@]}" $checkTarget || fail
 }
 
 
-checkPhase() {
-    if test "$doCheck" != 1; then
-        return
-    fi
-    header "checking"
-    startLog "check"
-    checkW
-    stopLog
-    stopNest
-}
-
-
 patchELF() {
     # Patch all ELF executables and shared libraries.
     header "patching ELF executables and libraries"
@@ -702,7 +657,7 @@ patchELF() {
 }
 
 
-installW() {
+installPhase() {
     if test -n "$installPhase"; then
         eval "$installPhase"
         return
@@ -717,7 +672,7 @@ installW() {
             installTargets=install
         fi
         echo "install flags: $installTargets $makeFlags ${makeFlagsArray[@]} $installFlags ${installFlagsArray[@]}"
-        make $installTargets \
+        make ${makefile:+-f $makefile} $installTargets \
             $makeFlags "${makeFlagsArray[@]}" \
             $installFlags "${installFlagsArray[@]}" || fail
     else
@@ -728,22 +683,10 @@ installW() {
 }
 
 
-installPhase() {
-    if test "$dontInstall" = 1; then
-        return
-    fi
-    header "installing"
-    startLog "install"
-    installW
-    stopLog
-    stopNest
-}
-
-
 # The fixup phase performs generic, package-independent, Nix-related
 # stuff, like running patchelf and setting the
 # propagated-build-inputs.  It should rarely be overriden.
-fixupW() {
+fixupPhase() {
     if test -n "$fixupPhase"; then
         eval "$fixupPhase"
         return
@@ -751,33 +694,33 @@ fixupW() {
 
     eval "$preFixup"
 
-     forceShare=${forceShare:=man doc info}
-     if test -n "$forceShare"; then
-         for d in $forceShare; do
-             if test -d "$prefix/$d"; then
-                 if test -d "$prefix/share/$d"; then
-                     echo "Both $d/ and share/$d/ exists!"
-                 else
-                    echo Fixing location of $d/ subdirectory
-                     ensureDir $prefix/share
+    # Put man/doc/info under $out/share.
+    forceShare=${forceShare:=man doc info}
+    if test -n "$forceShare"; then
+        for d in $forceShare; do
+            if test -d "$prefix/$d"; then
+                if test -d "$prefix/share/$d"; then
+                    echo "both $d/ and share/$d/ exists!"
+                else
+                    echo "fixing location of $d/ subdirectory"
+                    ensureDir $prefix/share
                     if test -w $prefix/share; then
-                         mv -v $prefix/$d $prefix/share
-                         ln -sv share/$d $prefix
+                        mv -v $prefix/$d $prefix/share
+                        ln -sv share/$d $prefix
                     fi
-                 fi
-            else
-                echo "No $d/ subdirectory, skipping."
-             fi
-         done;
-     fi
-
+                fi
+            fi
+        done;
+    fi
 
-# TODO : strip _only_ ELF executables, and return || fail here...
+    # TODO: strip _only_ ELF executables, and return || fail here...
     if test -z "$dontStrip"; then
-        echo "Stripping debuging symbols from files in"
-        stripDirs "${stripDebugList:-lib}" -S
-        echo "Stripping all symbols from files in"
-        stripDirs "${stripAllList:-bin sbin}" -s
+        stripDebugList=${stripDebugList:-lib}
+        echo "stripping debuging symbols from files in $stripDebugList"
+        stripDirs "$stripDebugList" -S
+        stripAllList=${stripAllList:-bin sbin}
+        echo "stripping all symbols from files in $stripAllList"
+        stripDirs "$stripAllList" -s
     fi
 
     if test "$havePatchELF" = 1 -a -z "$dontPatchELF"; then
@@ -798,19 +741,7 @@ fixupW() {
 }
 
 
-fixupPhase() {
-    if test "$dontFixup" = 1; then
-        return
-    fi
-    header "post-installation fixup"
-    startLog "fixup"
-    fixupW
-    stopLog
-    stopNest
-}
-
-
-distW() {
+distPhase() {
     if test -n "$distPhase"; then
         eval "$distPhase"
         return
@@ -823,7 +754,7 @@ distW() {
     fi
 
     echo "dist flags: $distFlags ${distFlagsArray[@]}"
-    make $distFlags "${distFlagsArray[@]}" $distTarget || fail
+    make ${makefile:+-f $makefile} $distFlags "${distFlagsArray[@]}" $distTarget || fail
 
     if test "$dontCopyDist" != 1; then
         ensureDir "$out/tarballs"
@@ -841,15 +772,18 @@ distW() {
 }
 
 
-distPhase() {
-    if test "$doDist" != 1; then
-        return
-    fi
-    header "creating distribution"
-    startLog "dist"
-    distW
-    stopLog
-    stopNest
+showPhaseHeader() {
+    local phase="$1"
+    case $phase in
+        unpackPhase) header "unpacking sources";;
+        patchPhase) header "patching sources";;
+        configurePhase) header "configuring";;
+        buildPhase) header "building";;
+        checkPhase) header "running tests";;
+        installPhase) header "installing";;
+        fixupPhase) header "post-installation fixup";;
+        *) header "$phase";;
+    esac
 }
 
 
@@ -863,16 +797,39 @@ genericBuild() {
 
     if test -z "$phases"; then
         phases="unpackPhase patchPhase configurePhase buildPhase checkPhase \
-            installPhase fixupPhase distPhase";
-    fi
-
-    for i in $phases; do
+            installPhase fixupPhase distPhase $extraPhases";
+    fi
+
+    for curPhase in $phases; do
+        if test "$curPhase" = buildPhase -a -n "$dontBuild"; then continue; fi
+        if test "$curPhase" = checkPhase -a -z "$doCheck"; then continue; fi
+        if test "$curPhase" = installPhase -a -n "$dontInstall"; then continue; fi
+        if test "$curPhase" = fixupPhase -a -n "$dontFixup"; then continue; fi
+        if test "$curPhase" = distPhase -a -z "$doDist"; then continue; fi
+        
+        showPhaseHeader "$curPhase"
+        startLog "$curPhase"
         dumpVars
-        eval "$i"
+        
+        # Evaluate the variable named $curPhase if it exists, otherwise the
+        # function named $curPhase.
+        eval "${!curPhase:-$curPhase}"
+
+        if test "$curPhase" = unpackPhase; then
+            cd "${sourceRoot:-.}"
+        fi
+        
+        stopLog
+        stopNest
     done
 
     stopNest
 }
 
 
+# Execute the post-hook.
+if test -n "@postHook@"; then source @postHook@; fi
+eval "$postHook"
+
+
 dumpVars