From 758e85cfac62ba09893f83205e379ce83497319a Mon Sep 17 00:00:00 2001
From: Peter Simons <simons@cryp.to>
Date: Fri, 8 Jul 2011 22:45:23 +0000
Subject: [PATCH] texlive: fixed erroneous forwarder scripts

 - Generate a forwarder scripts only for executable files. This change
   removes the broken 'man' script, for example.

 - Run the real binaries with 'exec'.

 - Use $SHELL to interpret the forwarder scripts rather than /bin/sh.

 - Indent consistently with blanks.

 - Removed some debug output from the build expression.

svn path=/nixpkgs/trunk/; revision=27679
---
 pkgs/misc/tex/texlive/aggregate.nix | 28 ++++++++++++++--------------
 pkgs/misc/tex/texlive/default.nix   | 27 +++++++++++++--------------
 2 files changed, 27 insertions(+), 28 deletions(-)

diff --git a/pkgs/misc/tex/texlive/aggregate.nix b/pkgs/misc/tex/texlive/aggregate.nix
index 2ea57445eb6..1723f481906 100644
--- a/pkgs/misc/tex/texlive/aggregate.nix
+++ b/pkgs/misc/tex/texlive/aggregate.nix
@@ -12,20 +12,20 @@ rec {
         echo Symlinking "$currentPath"
         find $currentPath/share/info $currentPath/share/man $(echo $currentPath/texmf*/) ! -type d | while read; do
             REPLY="''${REPLY#$currentPath}"
-	    ensureDir $out/"$(dirname "$REPLY")"
-	    ln -fs $currentPath/"$REPLY" $out/"$REPLY"
-	    echo
+            ensureDir $out/"$(dirname "$REPLY")"
+            ln -fs $currentPath/"$REPLY" $out/"$REPLY"
+            echo
         done | while read; do head -n 99 >/dev/null; echo -n .; done
 
-        for i in $currentPath/bin/* :; do #*/
-            test "$i" = : && continue;
-            echo -ne "#! /bin/sh\\n$i \"\$@\"" > "$out/bin/$(basename "$i")" && \
+        for i in "$currentPath/bin/"* :; do
+            test "$i" != : || continue
+            echo -ne "#! $SHELL\\nexec $i \"\$@\"" > "$out/bin/$(basename "$i")" && \
             chmod a+x "$out/bin/$(basename "$i")"
         done
 
-	echo
+        echo
 
-	cp -Trfp $currentPath/libexec $out/libexec || true
+        cp -Trfp $currentPath/libexec $out/libexec || true
     done
 
     ln -s $out/texmf* $out/share/
@@ -39,8 +39,8 @@ rec {
     for i in $out/libexec/*/* :; do
         test "$i" = : && continue;
         test -f "$i" && \
-	test -x "$i" && \
-	echo -ne "#! /bin/sh\\n$i \"\$@\"" >$out/bin/$(basename $i) && \
+        test -x "$i" && \
+        echo -ne "#! $SHELL\\nexec $i \"\$@\"" >$out/bin/$(basename $i) && \
         chmod a+x $out/bin/$(basename $i)
     done
 
@@ -58,12 +58,12 @@ rec {
   meta = {
     description = "TeX distribution directory";
     longDescription = ''
-      Here all the files from different TeX-related 
-      packages are collected in one directory. Of 
-      course, mktexlsr is called. Later placed 
+      Here all the files from different TeX-related
+      packages are collected in one directory. Of
+      course, mktexlsr is called. Later placed
       directories take precedence. It is supposed that
       share and libexec are symlinked, and bin is
-      recreated with wrappers for libexec-located 
+      recreated with wrappers for libexec-located
       linked binaries.
     '';
   };
diff --git a/pkgs/misc/tex/texlive/default.nix b/pkgs/misc/tex/texlive/default.nix
index e72d9112daa..69fb5d7e415 100644
--- a/pkgs/misc/tex/texlive/default.nix
+++ b/pkgs/misc/tex/texlive/default.nix
@@ -1,11 +1,11 @@
-args : with args; 
+args : with args;
 rec {
-  src = fetchurl { 
+  src = fetchurl {
     url = mirror://debian/pool/main/t/texlive-bin/texlive-bin_2009.orig.tar.gz;
     sha256 = "0ywc8h4jnig53fs0bji2ivw5f9j6zlgdy477jqw7xvpc7migjpw7";
   };
-  
-  texmfSrc = fetchurl { 
+
+  texmfSrc = fetchurl {
     url = mirror://debian/pool/main/t/texlive-base/texlive-base_2009.orig.tar.gz;
     sha256 = "130z907xcxr10yrzbbmp9l8a00dabvi4bi702s5jxamjzav17cmf";
   };
@@ -19,7 +19,7 @@ rec {
 
   doMainBuild = fullDepEntry (''
     ensureDir $out
-    ensureDir $out/nix-support 
+    ensureDir $out/nix-support
     cp ${setupHook} $out/nix-support/setup-hook.sh
     ensureDir $out/share
     tar xf ${texmfSrc} -C $out --strip-components=1
@@ -32,7 +32,7 @@ rec {
     sed -e 's@\<env python@${python}/bin/python@' -i $(grep 'env python' -rl . )
 
     sed -e '/ubidi_open/i#include <unicode/urename.h>' -i $(find . -name configure)
-    sed -e s@ncurses/curses.h@curses.h@g -i $(grep ncurses/curses.h -rl . ) 
+    sed -e s@ncurses/curses.h@curses.h@g -i $(grep ncurses/curses.h -rl . )
     sed -e '1i\#include <string.h>\n\#include <stdlib.h>' -i $( find libs/teckit -name '*.cpp' -o -name '*.c' )
 
     NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -I${freetype}/include/freetype2"
@@ -47,12 +47,13 @@ rec {
     mv $out/bin $out/libexec
     ensureDir $out/bin
     for i in "$out/libexec/"*"/"*; do
-        echo -ne "#! /bin/sh\\n$i \"\$@\"" >$out/bin/$(basename $i)
+        test \( \! -d "$i" \) -a -x "$i" || continue
+        echo -ne "#! $SHELL\\nexec $i \"\$@\"" >$out/bin/$(basename $i)
         chmod a+x $out/bin/$(basename $i)
     done
     [ -d $out/texmf-config ] || ln -s $out/texmf $out/texmf-config
     ln -s "$out/"*texmf* "$out/share/"
-    
+
     sed -e 's/.*pyhyph.*/=&/' -i $out/texmf-config/tex/generic/config/language.dat
 
     PATH=$PATH:$out/bin mktexlsr $out/texmf*
@@ -76,18 +77,16 @@ rec {
 
   buildInputs = [
     zlib bzip2 ncurses libpng flex bison libX11 libICE
-    xproto freetype t1lib gd libXaw icu ghostscript ed 
-    libXt libXpm libXmu libXext xextproto perl libSM 
+    xproto freetype t1lib gd libXaw icu ghostscript ed
+    libXt libXpm libXmu libXext xextproto perl libSM
     ruby expat curl libjpeg python fontconfig
   ];
 
-  configureFlags = [ "--with-x11" 
+  configureFlags = [ "--with-x11"
     "--enable-ipc" "--with-mktexfmt"
   ];
 
-  phaseNames = ["addInputs" (doDump "0") "doMainBuild" 
-    (doDump "1")
-    "doMakeInstall" "doPostInstall"];
+  phaseNames = ["addInputs" "doMainBuild" "doMakeInstall" "doPostInstall"];
 
   name = "texlive-core-2009";
   meta = {