18 # We use Gambit, that works 10x better with GCC than Clang. See ../gambit/build.nix
23 stdenv.mkDerivation rec {
28 buildInputs_libraries = [
34 # TODO: either fix all of Gerbil's dependencies to provide static libraries,
35 # or give up and delete all tentative support for static libraries.
36 #buildInputs_staticLibraries = map makeStaticLibraries buildInputs_libraries;
38 buildInputs = buildInputs_libraries;
42 grep -Fl '#!/usr/bin/env' `find . -type f -executable` | while read f ; do
43 substituteInPlace "$f" --replace '#!/usr/bin/env' '#!${coreutils}/bin/env' ;
46 gerbil_stamp_version=v${git-version}
47 gambit_stamp_version=v${gambit-git-version}
48 gambit_stamp_ymd=${gambit-stampYmd}
49 gambit_stamp_hms=${gambit-stampHms}
51 for f in src/bootstrap/gerbil/compiler/driver__0.scm \
52 src/build/build-libgerbil.ss \
53 src/gerbil/compiler/driver.ss ; do
54 substituteInPlace "$f" --replace '"gcc"' '"${gccStdenv.cc}/bin/${gccStdenv.cc.targetPrefix}gcc"' ;
58 ## TODO: make static compilation work.
59 ## For that, get all the packages below to somehow expose static libraries,
60 ## so we can offer users the option to statically link them into Gambit and/or Gerbil.
61 ## Then add the following to the postPatch script above:
62 # cat > etc/gerbil_static_libraries.sh <<EOF
63 # OPENSSL_LIBCRYPTO=${makeStaticLibraries openssl}/lib/libcrypto.a # MISSING!
64 # OPENSSL_LIBSSL=${makeStaticLibraries openssl}/lib/libssl.a # MISSING!
65 # ZLIB=${makeStaticLibraries zlib}/lib/libz.a
66 # SQLITE=${makeStaticLibraries sqlite}/lib/sqlite.a # MISSING!
70 "--prefix=$out/gerbil"
74 "--enable-march=" # Avoid non-portable invalid instructions. Use =native if local build only.
78 export CC=${gccStdenv.cc}/bin/${gccStdenv.cc.targetPrefix}gcc \
79 CXX=${gccStdenv.cc}/bin/${gccStdenv.cc.targetPrefix}g++ \
80 CPP=${gccStdenv.cc}/bin/${gccStdenv.cc.targetPrefix}cpp \
81 CXXCPP=${gccStdenv.cc}/bin/${gccStdenv.cc.targetPrefix}cpp \
82 LD=${gccStdenv.cc}/bin/${gccStdenv.cc.targetPrefix}ld \
83 XMKMF=${coreutils}/bin/false
84 unset CFLAGS LDFLAGS LIBS CPPFLAGS CXXFLAGS
85 ./configure ${builtins.concatStringsSep " " configureFlags}
90 "-L${openssl.out}/lib"
97 # gxprof testing uses $HOME/.cache/gerbil/gxc
99 export GERBIL_BUILD_CORES=$NIX_BUILD_CORES
100 export GERBIL_GXC=$PWD/bin/gxc
101 export GERBIL_BASE=$PWD
102 export GERBIL_PREFIX=$PWD
103 export GERBIL_PATH=$PWD/lib
104 export PATH=$PWD/bin:$PATH
105 ${gambit-support.export-gambopt gambit-params}
107 # Build, replacing make by build.sh
108 ( cd src && sh build.sh )
110 f=build/lib/libgerbil.so.ldd ; [ -f $f ] && :
111 substituteInPlace "$f" --replace '(' \
112 '(${lib.strings.concatStrings (map (x: "\"${x}\" ") extraLdOptions)}'
120 mkdir -p $out/gerbil $out/bin
122 (cd $out/bin ; ln -s ../gerbil/bin/* .)
125 + lib.optionalString stdenv.hostPlatform.isDarwin ''
126 libgerbil="$(realpath "$out/gerbil/lib/libgerbil.so")"
127 install_name_tool -id "$libgerbil" "$libgerbil"
133 description = "Gerbil Scheme";
134 homepage = "https://github.com/vyzo/gerbil";
135 license = lib.licenses.lgpl21Only; # dual, also asl20, like Gambit
136 # NB regarding platforms: regularly tested on Linux and on macOS.
137 # Please report success and/or failure to fare.
138 platforms = lib.platforms.unix;
139 maintainers = with lib.maintainers; [ fare ];
142 outputsToInstall = [ "out" ];