summary refs log tree commit diff
path: root/pkgs/stdenv
diff options
context:
space:
mode:
authorFlorian Friesdorf <flo@chaoflow.net>2015-05-26 15:18:49 +0200
committerRok Garbas <rok@garbas.si>2015-05-28 10:53:34 +0200
commit88e58a4fa208a967c4e4bde5beda86e44eca9c12 (patch)
tree49b986667f136d4f49cafb888bad6f04a5b78965 /pkgs/stdenv
parentd2e364c6781359a0fd6ea66b041d37e061b01cef (diff)
downloadnixlib-88e58a4fa208a967c4e4bde5beda86e44eca9c12.tar
nixlib-88e58a4fa208a967c4e4bde5beda86e44eca9c12.tar.gz
nixlib-88e58a4fa208a967c4e4bde5beda86e44eca9c12.tar.bz2
nixlib-88e58a4fa208a967c4e4bde5beda86e44eca9c12.tar.lz
nixlib-88e58a4fa208a967c4e4bde5beda86e44eca9c12.tar.xz
nixlib-88e58a4fa208a967c4e4bde5beda86e44eca9c12.tar.zst
nixlib-88e58a4fa208a967c4e4bde5beda86e44eca9c12.zip
cygwin: stdenv
Diffstat (limited to 'pkgs/stdenv')
-rw-r--r--pkgs/stdenv/cygwin/all-buildinputs-as-runtimedep.sh16
-rw-r--r--pkgs/stdenv/cygwin/rebase-i686.sh21
-rw-r--r--pkgs/stdenv/cygwin/rebase-x86_64.sh21
-rw-r--r--pkgs/stdenv/cygwin/wrap-exes-to-find-dlls.sh74
-rw-r--r--pkgs/stdenv/default.nix2
-rw-r--r--pkgs/stdenv/generic/default.nix3
-rw-r--r--pkgs/stdenv/native/default.nix23
7 files changed, 155 insertions, 5 deletions
diff --git a/pkgs/stdenv/cygwin/all-buildinputs-as-runtimedep.sh b/pkgs/stdenv/cygwin/all-buildinputs-as-runtimedep.sh
new file mode 100644
index 000000000000..7cb6a58f180b
--- /dev/null
+++ b/pkgs/stdenv/cygwin/all-buildinputs-as-runtimedep.sh
@@ -0,0 +1,16 @@
+# On cygwin, automatic runtime dependency detection does not work
+# because the binaries do not contain absolute references to store
+# locations (yet)
+postFixupHooks+=(_cygwinAllBuildInputsAsRuntimeDep)
+
+_cygwinAllBuildInputsAsRuntimeDep() {
+    if [ -n "$buildInputs" ]; then
+        mkdir -p "$out/nix-support"
+        echo "$buildInputs" >> "$out/nix-support/cygwin-buildinputs-as-runtime-deps"
+    fi
+
+    if [ -n "$nativeBuildInputs" ]; then
+        mkdir -p "$out/nix-support"
+        echo "$nativeBuildInputs" >> "$out/nix-support/cygwin-buildinputs-as-runtime-deps"
+    fi
+}
diff --git a/pkgs/stdenv/cygwin/rebase-i686.sh b/pkgs/stdenv/cygwin/rebase-i686.sh
new file mode 100644
index 000000000000..e5695c75a967
--- /dev/null
+++ b/pkgs/stdenv/cygwin/rebase-i686.sh
@@ -0,0 +1,21 @@
+postFixupHooks+=(_cygwinFixAutoImageBase)
+
+_cygwinFixAutoImageBase() {
+    find $out -name "*.dll" | while read DLL; do
+        if [ -f /etc/rebasenix.nextbase ]; then
+            NEXTBASE="$(</etc/rebasenix.nextbase)"
+        fi
+        NEXTBASE=${NEXTBASE:-0x62000000}
+
+        REBASE=(`/bin/rebase -i $DLL`)
+        BASE=${REBASE[2]}
+        SIZE=${REBASE[4]}
+        SKIP=$(((($SIZE>>16)+1)<<16))
+
+        echo "REBASE FIX: $DLL $BASE -> $NEXTBASE"
+        /bin/rebase -b $NEXTBASE $DLL
+        NEXTBASE="0x`printf %x $(($NEXTBASE+$SKIP))`"
+
+        echo $NEXTBASE > /etc/rebasenix.nextbase
+    done
+}
diff --git a/pkgs/stdenv/cygwin/rebase-x86_64.sh b/pkgs/stdenv/cygwin/rebase-x86_64.sh
new file mode 100644
index 000000000000..f782f18dfd15
--- /dev/null
+++ b/pkgs/stdenv/cygwin/rebase-x86_64.sh
@@ -0,0 +1,21 @@
+postFixupHooks+=(_cygwinFixAutoImageBase)
+
+_cygwinFixAutoImageBase() {
+    find $out -name "*.dll" | while read DLL; do
+        if [ -f /etc/rebasenix.nextbase ]; then
+            NEXTBASE="$(</etc/rebasenix.nextbase)"
+        fi
+        NEXTBASE=${NEXTBASE:-0x200000000}
+
+        REBASE=(`/bin/rebase -i $DLL`)
+        BASE=${REBASE[2]}
+        SIZE=${REBASE[4]}
+        SKIP=$(((($SIZE>>16)+1)<<16))
+
+        echo "REBASE FIX: $DLL $BASE -> $NEXTBASE"
+        /bin/rebase -b $NEXTBASE $DLL
+        NEXTBASE="0x`printf %x $(($NEXTBASE+$SKIP))`"
+
+        echo $NEXTBASE > /etc/rebasenix.nextbase
+    done
+}
diff --git a/pkgs/stdenv/cygwin/wrap-exes-to-find-dlls.sh b/pkgs/stdenv/cygwin/wrap-exes-to-find-dlls.sh
new file mode 100644
index 000000000000..d0da8c1b65c2
--- /dev/null
+++ b/pkgs/stdenv/cygwin/wrap-exes-to-find-dlls.sh
@@ -0,0 +1,74 @@
+postFixupHooks+=(_cygwinWrapExesToFindDlls)
+
+_cygwinWrapExesToFindDlls() {
+    find $out -type l | while read LINK; do
+        TARGET="$(readlink "${LINK}")"
+
+        # fix all non .exe links that link explicitly to a .exe
+        if [[ ${TARGET} == *.exe ]] && [[ ${LINK} != *.exe ]]; then
+            mv "${LINK}" "${LINK}.exe"
+            LINK="${LINK}.exe"
+        fi
+
+        # generate complementary filenames
+        if [[ ${LINK} == *.exe ]]; then
+            _LINK="${LINK%.exe}"
+            _TARGET="${TARGET%.exe}"
+        else
+            _LINK="${LINK}.exe"
+            _TARGET="${TARGET}.exe"
+        fi
+
+        # check if sould create complementary link
+        DOLINK=1
+        if [[ ${_TARGET} == *.exe ]]; then
+            # the canonical target has to be a .exe
+            CTARGET="$(readlink -f "${LINK}")"
+            if [[ ${CTARGET} != *.exe ]]; then
+                CTARGET="${CTARGET}.exe"
+            fi
+
+            if [ ! -e "${CTARGET}" ]; then
+                unset DOLINK
+            fi
+        fi
+
+        if [ -e "${_LINK}" ]; then
+            # complementary link seems to exist
+            # but could be cygwin smoke and mirrors
+            INO=$(stat -c%i "${LINK}")
+            _INO=$(stat -c%i "${_LINK}")
+            if [ "${INO}" -ne "${_INO}" ]; then
+                unset DOLINK
+            fi
+        fi
+
+        # create complementary link
+        if [ -n "${DOLINK}" ]; then
+            ln -s "${_TARGET}" "${_LINK}.tmp"
+            mv "${_LINK}.tmp" "${_LINK}"
+        fi
+    done
+
+    find $out -type f -name "*.exe" | while read EXE; do
+        WRAPPER="${EXE%.exe}"
+        if [ -e "${WRAPPER}" ]; then
+            # check if really exists or cygwin smoke and mirrors
+            INO=$(stat -c%i "${EXE}")
+            _INO=$(stat -c%i "${WRAPPER}")
+            if [ "${INO}" -ne "${_INO}" ]; then
+                continue
+            fi
+        fi
+
+        mv "${EXE}" "${EXE}.tmp"
+
+        cat >"${WRAPPER}" <<EOF
+#!/bin/sh
+export PATH=$_PATH${_PATH:+:}\${PATH}
+exec "\$0.exe" "\$@"
+EOF
+        chmod +x "${WRAPPER}"
+        mv "${EXE}.tmp" "${EXE}"
+    done
+}
diff --git a/pkgs/stdenv/default.nix b/pkgs/stdenv/default.nix
index ba87a7aaafbf..545a3d748eb1 100644
--- a/pkgs/stdenv/default.nix
+++ b/pkgs/stdenv/default.nix
@@ -50,5 +50,7 @@ rec {
     if system == "powerpc-linux" then /* stdenvLinux */ stdenvNative else
     if system == "x86_64-darwin" then stdenvDarwin else
     if system == "x86_64-solaris" then stdenvNix else
+    if system == "i686-cygwin" then stdenvNative else
+    if system == "x86_64-cygwin" then stdenvNative else
     stdenvNative;
 }
diff --git a/pkgs/stdenv/generic/default.nix b/pkgs/stdenv/generic/default.nix
index 440e9e6b4d04..cca89487462e 100644
--- a/pkgs/stdenv/generic/default.nix
+++ b/pkgs/stdenv/generic/default.nix
@@ -210,16 +210,19 @@ let
             || system == "i686-gnu"
             || system == "i686-freebsd"
             || system == "i686-openbsd"
+            || system == "i686-cygwin"
             || system == "i386-sunos";
       isx86_64 = system == "x86_64-linux"
               || system == "x86_64-darwin"
               || system == "x86_64-freebsd"
               || system == "x86_64-openbsd"
+              || system == "x86_64-cygwin"
               || system == "x86_64-solaris";
       is64bit = system == "x86_64-linux"
              || system == "x86_64-darwin"
              || system == "x86_64-freebsd"
              || system == "x86_64-openbsd"
+             || system == "x86_64-cygwin"
              || system == "x86_64-solaris"
              || system == "mips64el-linux";
       isMips = system == "mips-linux"
diff --git a/pkgs/stdenv/native/default.nix b/pkgs/stdenv/native/default.nix
index 935af7d4c36b..5390907928de 100644
--- a/pkgs/stdenv/native/default.nix
+++ b/pkgs/stdenv/native/default.nix
@@ -52,16 +52,22 @@ rec {
     shopt -s expand_aliases
   '';
 
+  # prevent libtool from failing to find dynamic libraries
   prehookCygwin = ''
     ${prehookBase}
 
-    if test -z "$cygwinConfigureEnableShared"; then
-      export configureFlags="$configureFlags --disable-shared"
-    fi
-
-    PATH_DELIMITER=';'
+    shopt -s expand_aliases
+    export lt_cv_deplibs_check_method=pass_all
   '';
 
+  extraBuildInputsCygwin = [
+    ../cygwin/all-buildinputs-as-runtimedep.sh
+    ../cygwin/wrap-exes-to-find-dlls.sh
+  ] ++ (if system == "i686-cygwin" then [
+    ../cygwin/rebase-i686.sh
+  ] else if system == "x86_64-cygwin" then [
+    ../cygwin/rebase-x86_64.sh
+  ] else []);
 
   # A function that builds a "native" stdenv (one that uses tools in
   # /usr etc.).
@@ -74,8 +80,15 @@ rec {
         if system == "x86_64-freebsd" then prehookFreeBSD else
         if system == "i686-openbsd" then prehookOpenBSD else
         if system == "i686-netbsd" then prehookNetBSD else
+        if system == "i686-cygwin" then prehookCygwin else
+        if system == "x86_64-cygwin" then prehookCygwin else
         prehookBase;
 
+      extraBuildInputs =
+        if system == "i686-cygwin" then extraBuildInputsCygwin else
+        if system == "x86_64-cygwin" then extraBuildInputsCygwin else
+        [];
+
       initialPath = extraPath ++ path;
 
       fetchurlBoot = fetchurl;