btrbk: add mainProgram (#356350)
[NixPkgs.git] / pkgs / development / compilers / chicken / 4 / chicken.nix
bloba36ef4569e3051fc4a6a010bc24e2e10570cd212
1 { lib, stdenv, fetchurl, makeWrapper, darwin, bootstrap-chicken ? null }:
3 let
4   version = "4.13.0";
5   platform = with stdenv;
6     if isDarwin then "macosx"
7     else if isCygwin then "cygwin"
8     else if (isFreeBSD || isOpenBSD) then "bsd"
9     else if isSunOS then "solaris"
10     else "linux"; # Should be a sane default
12 stdenv.mkDerivation {
13   pname = "chicken";
14   inherit version;
16   binaryVersion = 8;
18   src = fetchurl {
19     url = "https://code.call-cc.org/releases/${version}/chicken-${version}.tar.gz";
20     sha256 = "0hvckhi5gfny3mlva6d7y9pmx7cbwvq0r7mk11k3sdiik9hlkmdd";
21   };
23   postPatch = lib.optionalString stdenv.hostPlatform.isDarwin ''
24     # There is not enough space in the load command to accomodate a full path to the store,
25     # so use `@executable_path` to specify a relative path to chicken’s lib folder.
26     sed -e '/POSTINSTALL_PROGRAM_FLAGS = /{s|$(LIBDIR)|@executable_path/../lib|}' \
27       -i Makefile.macosx
28   '';
30   setupHook = lib.optional (bootstrap-chicken != null) ./setup-hook.sh;
32   # -fno-strict-overflow is not a supported argument in clang on darwin
33   hardeningDisable = lib.optionals stdenv.hostPlatform.isDarwin ["strictoverflow"];
35   makeFlags = [
36     "PLATFORM=${platform}" "PREFIX=$(out)"
37     "VARDIR=$(out)/var/lib"
38   ] ++ (lib.optionals stdenv.hostPlatform.isDarwin [
39     "XCODE_TOOL_PATH=${darwin.binutils.bintools}/bin"
40     "C_COMPILER=$(CC)"
41     "POSTINSTALL_PROGRAM=${stdenv.cc.targetPrefix}install_name_tool"
42   ]);
44   # We need a bootstrap-chicken to regenerate the c-files after
45   # applying a patch to add support for CHICKEN_REPOSITORY_EXTRA
46   patches = lib.optionals (bootstrap-chicken != null) [
47     ./0001-Introduce-CHICKEN_REPOSITORY_EXTRA.patch
48   ];
50   nativeBuildInputs = [
51     makeWrapper
52   ] ++ lib.optionals (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64) [
53     darwin.autoSignDarwinBinariesHook
54   ];
56   buildInputs = lib.optionals (bootstrap-chicken != null) [
57     bootstrap-chicken
58   ];
60   preBuild = lib.optionalString (bootstrap-chicken != null) ''
61     # Backup the build* files - those are generated from hostname,
62     # git-tag, etc. and we don't need/want that
63     mkdir -p build-backup
64     mv buildid buildbranch buildtag.h build-backup
66     # Regenerate eval.c after the patch
67     make spotless $makeFlags
69     mv build-backup/* .
70   '';
72   postInstall = ''
73     for f in $out/bin/*
74     do
75       wrapProgram $f \
76         --prefix PATH : ${stdenv.cc}/bin
77     done
78   '';
80   # TODO: Assert csi -R files -p '(pathname-file (repository-path))' == binaryVersion
82   meta = {
83     homepage = "http://www.call-cc.org/";
84     license = lib.licenses.bsd3;
85     maintainers = with lib.maintainers; [ corngood ];
86     platforms = lib.platforms.linux ++ lib.platforms.darwin; # Maybe other Unix
87     description = "Portable compiler for the Scheme programming language";
88     longDescription = ''
89       CHICKEN is a compiler for the Scheme programming language.
90       CHICKEN produces portable and efficient C, supports almost all
91       of the R5RS Scheme language standard, and includes many
92       enhancements and extensions. CHICKEN runs on Linux, macOS,
93       Windows, and many Unix flavours.
94     '';
95   };