lol
1{ pkgs, gccStdenv, lib, coreutils,
2 openssl, zlib, sqlite,
3 version, git-version, src,
4 gambit-support,
5 gambit-git-version,
6 gambit-stampYmd,
7 gambit-stampHms,
8 gambit-params }:
9
10# We use Gambit, that works 10x better with GCC than Clang. See ../gambit/build.nix
11let stdenv = gccStdenv; in
12
13stdenv.mkDerivation rec {
14 pname = "gerbil";
15 inherit version;
16 inherit src;
17
18 buildInputs_libraries = [ openssl zlib sqlite ];
19
20 # TODO: either fix all of Gerbil's dependencies to provide static libraries,
21 # or give up and delete all tentative support for static libraries.
22 #buildInputs_staticLibraries = map makeStaticLibraries buildInputs_libraries;
23
24 buildInputs = buildInputs_libraries;
25
26 postPatch = ''
27 echo '(define (gerbil-version-string) "v${git-version}")' > src/gerbil/runtime/gx-version.scm ;
28 patchShebangs . ;
29 grep -Fl '#!/usr/bin/env' `find . -type f -executable` | while read f ; do
30 substituteInPlace "$f" --replace '#!/usr/bin/env' '#!${coreutils}/bin/env' ;
31 done ;
32 substituteInPlace ./configure --replace 'set -e' 'set -e ; git () { echo "v${git-version}" ;}' ;
33 substituteInPlace ./src/build/build-version.scm --replace "with-exception-catcher" '(lambda _ "v${git-version}")' ;
34 #rmdir src/gambit
35 #cp -a ${pkgs.gambit-unstable.src} ./src/gambit
36 chmod -R u+w ./src/gambit
37 ( cd src/gambit ; ${gambit-params.fixStamp gambit-git-version gambit-stampYmd gambit-stampHms} )
38 for f in src/bootstrap/gerbil/compiler/driver__0.scm \
39 src/build/build-libgerbil.ss \
40 src/gerbil/compiler/driver.ss ; do
41 substituteInPlace "$f" --replace '"gcc"' '"${gccStdenv.cc}/bin/${gccStdenv.cc.targetPrefix}gcc"' ;
42 done
43 '';
44
45## TODO: make static compilation work.
46## For that, get all the packages below to somehow expose static libraries,
47## so we can offer users the option to statically link them into Gambit and/or Gerbil.
48## Then add the following to the postPatch script above:
49# cat > etc/gerbil_static_libraries.sh <<EOF
50# OPENSSL_LIBCRYPTO=${makeStaticLibraries openssl}/lib/libcrypto.a # MISSING!
51# OPENSSL_LIBSSL=${makeStaticLibraries openssl}/lib/libssl.a # MISSING!
52# ZLIB=${makeStaticLibraries zlib}/lib/libz.a
53# SQLITE=${makeStaticLibraries sqlite}/lib/sqlite.a # MISSING!
54# EOF
55
56 configureFlags = [
57 "--prefix=$out/gerbil"
58 "--enable-zlib"
59 "--enable-sqlite"
60 "--enable-shared"
61 "--disable-deprecated"
62 "--enable-march=" # Avoid non-portable invalid instructions
63 ];
64
65 configurePhase = ''
66 export CC=${gccStdenv.cc}/bin/${gccStdenv.cc.targetPrefix}gcc \
67 CXX=${gccStdenv.cc}/bin/${gccStdenv.cc.targetPrefix}g++ \
68 CPP=${gccStdenv.cc}/bin/${gccStdenv.cc.targetPrefix}cpp \
69 CXXCPP=${gccStdenv.cc}/bin/${gccStdenv.cc.targetPrefix}cpp \
70 LD=${gccStdenv.cc}/bin/${gccStdenv.cc.targetPrefix}ld \
71 XMKMF=${coreutils}/bin/false
72 unset CFLAGS LDFLAGS LIBS CPPFLAGS CXXFLAGS
73 (cd src/gambit ; ${gambit-params.fixStamp gambit-git-version gambit-stampYmd gambit-stampHms})
74 ./configure ${builtins.concatStringsSep " " configureFlags}
75 (cd src/gambit ;
76 substituteInPlace config.status \
77 ${lib.optionalString (gccStdenv.isDarwin && !gambit-params.stable)
78 ''--replace "/usr/local/opt/openssl@1.1" "${lib.getLib openssl}"''} \
79 --replace "/usr/local/opt/openssl" "${lib.getLib openssl}"
80 ./config.status
81 )
82 '';
83
84 extraLdOptions = [
85 "-L${zlib}/lib"
86 "-L${openssl.out}/lib"
87 "-L${sqlite.out}/lib"
88 ];
89
90 buildPhase = ''
91 runHook preBuild
92
93 # gxprof testing uses $HOME/.cache/gerbil/gxc
94 export HOME=$PWD
95 export GERBIL_BUILD_CORES=$NIX_BUILD_CORES
96 export GERBIL_GXC=$PWD/bin/gxc
97 export GERBIL_BASE=$PWD
98 export GERBIL_PREFIX=$PWD
99 export GERBIL_PATH=$PWD/lib
100 export PATH=$PWD/bin:$PATH
101 ${gambit-support.export-gambopt gambit-params}
102
103 # Build, replacing make by build.sh
104 ( cd src && sh build.sh )
105
106 f=build/lib/libgerbil.so.ldd ; [ -f $f ] && :
107 substituteInPlace "$f" --replace '(' \
108 '(${lib.strings.concatStrings (map (x: "\"${x}\" " ) extraLdOptions)}'
109
110 runHook postBuild
111 '';
112
113 installPhase = ''
114 runHook preInstall
115 mkdir -p $out/gerbil $out/bin
116 ./install.sh
117 (cd $out/bin ; ln -s ../gerbil/bin/* .)
118 runHook postInstall
119 '';
120
121 dontStrip = true;
122
123 meta = {
124 description = "Gerbil Scheme";
125 homepage = "https://github.com/vyzo/gerbil";
126 license = lib.licenses.lgpl21Only; # dual, also asl20, like Gambit
127 # NB regarding platforms: regularly tested on Linux and on macOS.
128 # Please report success and/or failure to fare.
129 platforms = lib.platforms.unix;
130 maintainers = with lib.maintainers; [ fare ];
131 };
132
133 outputsToInstall = [ "out" ];
134}