2021-03-12 07:09:13 +00:00
|
|
|
{ pkgs, gccStdenv, lib, coreutils,
|
2023-10-19 13:55:26 +00:00
|
|
|
openssl, zlib, sqlite,
|
|
|
|
version, git-version, src,
|
2020-05-29 06:06:01 +00:00
|
|
|
gambit-support,
|
2023-10-19 13:55:26 +00:00
|
|
|
gambit-git-version,
|
|
|
|
gambit-stampYmd,
|
|
|
|
gambit-stampHms,
|
|
|
|
gambit-params }:
|
2020-05-29 06:06:01 +00:00
|
|
|
|
|
|
|
# We use Gambit, that works 10x better with GCC than Clang. See ../gambit/build.nix
|
|
|
|
let stdenv = gccStdenv; in
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
stdenv.mkDerivation rec {
|
|
|
|
pname = "gerbil";
|
|
|
|
inherit version;
|
|
|
|
inherit src;
|
|
|
|
|
2023-10-19 13:55:26 +00:00
|
|
|
buildInputs_libraries = [ openssl zlib sqlite ];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2020-05-29 06:06:01 +00:00
|
|
|
# TODO: either fix all of Gerbil's dependencies to provide static libraries,
|
|
|
|
# or give up and delete all tentative support for static libraries.
|
|
|
|
#buildInputs_staticLibraries = map makeStaticLibraries buildInputs_libraries;
|
|
|
|
|
2023-10-19 13:55:26 +00:00
|
|
|
buildInputs = buildInputs_libraries;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
postPatch = ''
|
2020-05-29 06:06:01 +00:00
|
|
|
patchShebangs . ;
|
2020-04-24 23:36:52 +00:00
|
|
|
grep -Fl '#!/usr/bin/env' `find . -type f -executable` | while read f ; do
|
2020-05-29 06:06:01 +00:00
|
|
|
substituteInPlace "$f" --replace '#!/usr/bin/env' '#!${coreutils}/bin/env' ;
|
|
|
|
done ;
|
2024-01-02 11:29:13 +00:00
|
|
|
cat > MANIFEST <<EOF
|
|
|
|
gerbil_stamp_version=v${git-version}
|
|
|
|
gambit_stamp_version=v${gambit-git-version}
|
|
|
|
gambit_stamp_ymd=${gambit-stampYmd}
|
|
|
|
gambit_stamp_hms=${gambit-stampHms}
|
|
|
|
EOF
|
2023-10-19 13:55:26 +00:00
|
|
|
for f in src/bootstrap/gerbil/compiler/driver__0.scm \
|
|
|
|
src/build/build-libgerbil.ss \
|
|
|
|
src/gerbil/compiler/driver.ss ; do
|
|
|
|
substituteInPlace "$f" --replace '"gcc"' '"${gccStdenv.cc}/bin/${gccStdenv.cc.targetPrefix}gcc"' ;
|
|
|
|
done
|
2023-08-10 07:59:29 +00:00
|
|
|
'';
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
## TODO: make static compilation work.
|
|
|
|
## For that, get all the packages below to somehow expose static libraries,
|
|
|
|
## so we can offer users the option to statically link them into Gambit and/or Gerbil.
|
|
|
|
## Then add the following to the postPatch script above:
|
|
|
|
# cat > etc/gerbil_static_libraries.sh <<EOF
|
|
|
|
# OPENSSL_LIBCRYPTO=${makeStaticLibraries openssl}/lib/libcrypto.a # MISSING!
|
|
|
|
# OPENSSL_LIBSSL=${makeStaticLibraries openssl}/lib/libssl.a # MISSING!
|
|
|
|
# ZLIB=${makeStaticLibraries zlib}/lib/libz.a
|
|
|
|
# SQLITE=${makeStaticLibraries sqlite}/lib/sqlite.a # MISSING!
|
|
|
|
# EOF
|
|
|
|
|
2023-10-19 13:55:26 +00:00
|
|
|
configureFlags = [
|
|
|
|
"--prefix=$out/gerbil"
|
|
|
|
"--enable-zlib"
|
|
|
|
"--enable-sqlite"
|
|
|
|
"--enable-shared"
|
2024-01-02 11:29:13 +00:00
|
|
|
"--enable-march=" # Avoid non-portable invalid instructions. Use =native if local build only.
|
2023-10-19 13:55:26 +00:00
|
|
|
];
|
|
|
|
|
2020-05-29 06:06:01 +00:00
|
|
|
configurePhase = ''
|
2023-10-19 13:55:26 +00:00
|
|
|
export CC=${gccStdenv.cc}/bin/${gccStdenv.cc.targetPrefix}gcc \
|
|
|
|
CXX=${gccStdenv.cc}/bin/${gccStdenv.cc.targetPrefix}g++ \
|
|
|
|
CPP=${gccStdenv.cc}/bin/${gccStdenv.cc.targetPrefix}cpp \
|
|
|
|
CXXCPP=${gccStdenv.cc}/bin/${gccStdenv.cc.targetPrefix}cpp \
|
|
|
|
LD=${gccStdenv.cc}/bin/${gccStdenv.cc.targetPrefix}ld \
|
|
|
|
XMKMF=${coreutils}/bin/false
|
|
|
|
unset CFLAGS LDFLAGS LIBS CPPFLAGS CXXFLAGS
|
|
|
|
./configure ${builtins.concatStringsSep " " configureFlags}
|
2020-05-29 06:06:01 +00:00
|
|
|
'';
|
|
|
|
|
2023-10-19 13:55:26 +00:00
|
|
|
extraLdOptions = [
|
|
|
|
"-L${zlib}/lib"
|
|
|
|
"-L${openssl.out}/lib"
|
|
|
|
"-L${sqlite.out}/lib"
|
|
|
|
];
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
buildPhase = ''
|
|
|
|
runHook preBuild
|
|
|
|
|
|
|
|
# gxprof testing uses $HOME/.cache/gerbil/gxc
|
2020-05-29 06:06:01 +00:00
|
|
|
export HOME=$PWD
|
|
|
|
export GERBIL_BUILD_CORES=$NIX_BUILD_CORES
|
|
|
|
export GERBIL_GXC=$PWD/bin/gxc
|
|
|
|
export GERBIL_BASE=$PWD
|
2023-10-19 13:55:26 +00:00
|
|
|
export GERBIL_PREFIX=$PWD
|
2020-05-29 06:06:01 +00:00
|
|
|
export GERBIL_PATH=$PWD/lib
|
|
|
|
export PATH=$PWD/bin:$PATH
|
|
|
|
${gambit-support.export-gambopt gambit-params}
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
# Build, replacing make by build.sh
|
|
|
|
( cd src && sh build.sh )
|
|
|
|
|
2023-10-19 13:55:26 +00:00
|
|
|
f=build/lib/libgerbil.so.ldd ; [ -f $f ] && :
|
|
|
|
substituteInPlace "$f" --replace '(' \
|
|
|
|
'(${lib.strings.concatStrings (map (x: "\"${x}\" " ) extraLdOptions)}'
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
runHook postBuild
|
|
|
|
'';
|
|
|
|
|
|
|
|
installPhase = ''
|
|
|
|
runHook preInstall
|
2020-05-29 06:06:01 +00:00
|
|
|
mkdir -p $out/gerbil $out/bin
|
2023-10-19 13:55:26 +00:00
|
|
|
./install.sh
|
2020-05-29 06:06:01 +00:00
|
|
|
(cd $out/bin ; ln -s ../gerbil/bin/* .)
|
2020-04-24 23:36:52 +00:00
|
|
|
runHook postInstall
|
2024-01-02 11:29:13 +00:00
|
|
|
'' + lib.optionalString stdenv.isDarwin ''
|
|
|
|
libgerbil="$(realpath "$out/gerbil/lib/libgerbil.so")"
|
|
|
|
install_name_tool -id "$libgerbil" "$libgerbil"
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
dontStrip = true;
|
|
|
|
|
|
|
|
meta = {
|
|
|
|
description = "Gerbil Scheme";
|
|
|
|
homepage = "https://github.com/vyzo/gerbil";
|
2023-08-10 07:59:29 +00:00
|
|
|
license = lib.licenses.lgpl21Only; # dual, also asl20, like Gambit
|
|
|
|
# NB regarding platforms: regularly tested on Linux and on macOS.
|
2020-04-24 23:36:52 +00:00
|
|
|
# Please report success and/or failure to fare.
|
2020-05-29 06:06:01 +00:00
|
|
|
platforms = lib.platforms.unix;
|
|
|
|
maintainers = with lib.maintainers; [ fare ];
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
2023-10-19 13:55:26 +00:00
|
|
|
|
|
|
|
outputsToInstall = [ "out" ];
|
2020-04-24 23:36:52 +00:00
|
|
|
}
|