@@ -1,23 +1,86 @@
1−{ stdenv, lib, fetchurl }:
2−
1+{ stdenv, lib
2+, build2
3+, fetchurl
4+, fetchpatch
5+, fixDarwinDylibNames
6+, libbutl
7+, libpkgconf
8+, enableShared ? !stdenv.hostPlatform.isStatic
9+, enableStatic ? !enableShared
10+}:
11+let
12+ configSharedStatic = enableShared: enableStatic:
13+ if enableShared && enableStatic then "both"
14+ else if enableShared then "shared"
15+ else if enableStatic then "static"
16+ else throw "neither shared nor static libraries requested";
17+in
318stdenv.mkDerivation rec {
419 pname = "build2";
520 version = "0.13.0";
621
22+ outputs = [ "out" "dev" "doc" "man" ];
23+
24+ setupHook = ./setup-hook.sh;
25+
726 src = fetchurl {
8− url = "https://download.build2.org/${version}/build2-toolchain-${version}.tar.xz";
9− sha256 = "01hmr5y8aa28qchwy9ci8x5q746flwxmlxarmy4w9zay9nmvryms";
27+ url = "https://pkg.cppget.org/1/alpha/build2/build2-${version}.tar.gz";
28+ sha256 = "aff53a87c23534e0232b5cf746e0be4b2aaa840c3de4e668b98e382a3973c45e";
1029 };
1130
12− dontConfigure = true;
13− dontInstall = true;
31+ patches = [
32+ # Remove any build/host config entries which refer to nix store paths
33+ ./remove-config-store-paths.patch
34+ # Pick up sysdirs from NIX_LDFLAGS
35+ ./nix-ldflags-sysdirs.patch
36+ # Fix stray '-l' linker flags in pkg-config files (remove in next release)
37+ (fetchpatch {
38+ url = "https://github.com/build2/build2/commit/d51892e33a0fe69e743e02d9620312133a7ac61d.patch";
39+ sha256 = "0xzm084bxnfi8lqng0cwxvz8ylbfzk0didbr2wf385gssv4fva81";
40+ })
41+ ];
42+
43+ strictDeps = true;
44+ nativeBuildInputs = [
45+ build2
46+ ];
47+ disallowedReferences = [
48+ build2
49+ libbutl.dev
50+ libpkgconf.dev
51+ ];
52+ buildInputs = [
53+ libbutl
54+ libpkgconf
55+ ];
56+
57+ # Build2 uses @rpath on darwin
58+ # https://github.com/build2/build2/issues/166
59+ # N.B. this only adjusts the install_name after all libraries are installed;
60+ # packages containing multiple interdependent libraries may have
61+ # LC_LOAD_DYLIB entries containing @rpath, requiring manual fixup
62+ propagatedBuildInputs = lib.optionals stdenv.targetPlatform.isDarwin [
63+ fixDarwinDylibNames
64+ ];
1465
15− buildPhase = ''
16− runHook preBuild
17− ./build.sh --local --trust yes --install-dir "$out" "$CXX"
18− runHook postBuild
66+ postPatch = ''
67+ patchShebangs --build tests/bash/testscript
1968 '';
2069
70+ build2ConfigureFlags = [
71+ "config.bin.lib=${configSharedStatic enableShared enableStatic}"
72+ "config.cc.poptions+=-I${lib.getDev libpkgconf}/include/pkgconf"
73+ ];
74+
75+ postInstall = lib.optionalString stdenv.isDarwin ''
76+ install_name_tool -add_rpath "''${!outputLib}/lib" "''${!outputBin}/bin/b"
77+ '';
78+
79+ passthru = {
80+ bootstrap = build2;
81+ inherit configSharedStatic;
82+ };
83+
2184 meta = with lib; {
2285 homepage = "https://www.build2.org/";
2386 description = "build2 build system";
@@ -34,6 +97,7 @@ stdenv.mkDerivation rec {
3497 at C/C++ projects as well as mixed-language projects involving
3598 one of these languages (see bash and rust modules, for example).
3699 '';
100+ changelog = "https://git.build2.org/cgit/build2/tree/NEWS";
37101 platforms = platforms.all;
38102 maintainers = with maintainers; [ hiro98 r-burns ];
39103 };