1 { lib, stdenv, fetchurl, makeWrapper, darwin, bootstrap-chicken ? null }:
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
19 url = "https://code.call-cc.org/releases/${version}/chicken-${version}.tar.gz";
20 sha256 = "0hvckhi5gfny3mlva6d7y9pmx7cbwvq0r7mk11k3sdiik9hlkmdd";
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|}' \
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"];
36 "PLATFORM=${platform}" "PREFIX=$(out)"
37 "VARDIR=$(out)/var/lib"
38 ] ++ (lib.optionals stdenv.hostPlatform.isDarwin [
39 "XCODE_TOOL_PATH=${darwin.binutils.bintools}/bin"
41 "POSTINSTALL_PROGRAM=${stdenv.cc.targetPrefix}install_name_tool"
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
52 ] ++ lib.optionals (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64) [
53 darwin.autoSignDarwinBinariesHook
56 buildInputs = lib.optionals (bootstrap-chicken != null) [
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
64 mv buildid buildbranch buildtag.h build-backup
66 # Regenerate eval.c after the patch
67 make spotless $makeFlags
76 --prefix PATH : ${stdenv.cc}/bin
80 # TODO: Assert csi -R files -p '(pathname-file (repository-path))' == binaryVersion
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";
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.