sqlite_orm: 1.9 -> 1.9.1 (#379250)
[NixPkgs.git] / pkgs / development / compilers / gerbil / build.nix
blob26808377b1ac50338a01ec77041de461a509ffa8
2   gccStdenv,
3   lib,
4   coreutils,
5   openssl,
6   zlib,
7   sqlite,
8   version,
9   git-version,
10   src,
11   gambit-support,
12   gambit-git-version,
13   gambit-stampYmd,
14   gambit-stampHms,
15   gambit-params,
18 # We use Gambit, that works 10x better with GCC than Clang. See ../gambit/build.nix
19 let
20   stdenv = gccStdenv;
23 stdenv.mkDerivation rec {
24   pname = "gerbil";
25   inherit version;
26   inherit src;
28   buildInputs_libraries = [
29     openssl
30     zlib
31     sqlite
32   ];
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;
40   postPatch = ''
41     patchShebangs . ;
42     grep -Fl '#!/usr/bin/env' `find . -type f -executable` | while read f ; do
43       substituteInPlace "$f" --replace '#!/usr/bin/env' '#!${coreutils}/bin/env' ;
44     done ;
45     cat > MANIFEST <<EOF
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}
50     EOF
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"' ;
55     done
56   '';
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!
67   # EOF
69   configureFlags = [
70     "--prefix=$out/gerbil"
71     "--enable-zlib"
72     "--enable-sqlite"
73     "--enable-shared"
74     "--enable-march=" # Avoid non-portable invalid instructions. Use =native if local build only.
75   ];
77   configurePhase = ''
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}
86   '';
88   extraLdOptions = [
89     "-L${zlib}/lib"
90     "-L${openssl.out}/lib"
91     "-L${sqlite.out}/lib"
92   ];
94   buildPhase = ''
95     runHook preBuild
97     # gxprof testing uses $HOME/.cache/gerbil/gxc
98     export HOME=$PWD
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)}'
114     runHook postBuild
115   '';
117   installPhase =
118     ''
119       runHook preInstall
120       mkdir -p $out/gerbil $out/bin
121       ./install.sh
122       (cd $out/bin ; ln -s ../gerbil/bin/* .)
123       runHook postInstall
124     ''
125     + lib.optionalString stdenv.hostPlatform.isDarwin ''
126       libgerbil="$(realpath "$out/gerbil/lib/libgerbil.so")"
127       install_name_tool -id "$libgerbil" "$libgerbil"
128     '';
130   dontStrip = true;
132   meta = {
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 ];
140   };
142   outputsToInstall = [ "out" ];