about summary refs log tree commit diff
path: root/pkgs/development/compilers/ghc/ghc-wrapper/default.nix
blob: 9cff8095c65f0f22c182ad6d6d0fcd8d3fadbd0f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
args: with args; with lib;

stdenv.mkDerivation {
  inherit suffix name ghc readline ncurses;

  buildInputs = (libraries ++ [ghcPkgUtil]);
  tags = if installSourceAndTags then
          map (x :  sourceWithTagsDerivation (sourceWithTagsFromDerivation x)) 
          ( uniqList { inputList= filter annotatedWithSourceAndTagInfo libraries; } )
        else [];

  phases="installPhase";

  installPhase="
    set -e
    ensureDir \$out/bin
    if test -n \"\$ghcPackagedLibs\"; then
       g=:\$(echo \$ghc/lib/ghc-*/package.conf)
    fi

    for a in ghc ghci ghc-pkg; do
      app=$(ls -al $ghc/bin/$a | sed -n 's%.*-> \\(.*\\)%\\1%p');
cat > \"\$out/bin/\$a$suffix\" << EOF
#!`type -f sh | gawk '{ print $3; }'`
export LIBRARY_PATH=\$readline/lib:\$ncurses/lib
GHC_PACKAGE_PATH=\${GHC_PACKAGE_PATH}\${g} \$ghc/bin/$app \"\\\$@\"
EOF
      chmod +x \"\$out/bin/\$a$suffix\"
    done

    ensureDir \$out/src
    for i in \$tags; do
        ln -s \$i/src/* \$out/src
    done

    ensureDir \$out/bin
    for i in `echo $GHC_PACKAGE_PATH | sed 's/:/ /g'`; do
      o=\${i/lib*/}
      o=\${i/nix-support*/}
      for j in \$ghc/bin/* `find \${o}bin/ -type f 2>/dev/null` `find \${o}usr/local/bin/ -type f 2>/dev/null`; do
        b=`basename \$j`
        if [ \$b == sh ]; then continue; fi
        if [ \$b == bash ]; then continue; fi
        if [ \$b == bashbug ]; then continue; fi
        if [ \$b == bashbug ]; then continue; fi
        if [ -e \$out/bin/\$b ]; then continue; fi
        ln -s \$j \$out/bin/;
      done
    done
";
}