1{
2 lib,
3 stdenv,
4 gprbuild-boot,
5 which,
6 gnat,
7 xmlada,
8}:
9
10stdenv.mkDerivation {
11 pname = "gprbuild";
12
13 # See ./boot.nix for an explanation of the gprbuild setupHook,
14 # our custom knowledge base entry and the situation wrt a
15 # (future) gprbuild wrapper.
16 inherit (gprbuild-boot)
17 version
18 src
19 setupHooks
20 meta
21 ;
22
23 nativeBuildInputs = [
24 gnat
25 gprbuild-boot
26 which
27 ];
28
29 propagatedBuildInputs = [
30 xmlada
31 ];
32
33 makeFlags =
34 [
35 "ENABLE_SHARED=${if stdenv.hostPlatform.isStatic then "no" else "yes"}"
36 "PROCESSORS=$(NIX_BUILD_CORES)"
37 # confusingly, for gprbuild --target is autoconf --host
38 "TARGET=${stdenv.hostPlatform.config}"
39 "prefix=${placeholder "out"}"
40 ]
41 ++ lib.optionals (!stdenv.hostPlatform.isStatic) [
42 "LIBRARY_TYPE=relocatable"
43 ];
44
45 env = lib.optionalAttrs stdenv.hostPlatform.isDarwin {
46 # Ensure that there is enough space for the `fixDarwinDylibNames` hook to
47 # update the install names of the output dylibs.
48 NIX_LDFLAGS = "-headerpad_max_install_names";
49 };
50
51 # Fixes gprbuild being linked statically always. Based on the AUR's patch:
52 # https://aur.archlinux.org/cgit/aur.git/plain/0001-Makefile-build-relocatable-instead-of-static-binary.patch?h=gprbuild&id=bac524c76cd59c68fb91ef4dfcbe427357b9f850
53 patches = lib.optionals (!stdenv.hostPlatform.isStatic) [
54 ./gprbuild-relocatable-build.patch
55 ];
56
57 buildFlags = [
58 "all"
59 "libgpr.build"
60 ];
61
62 installFlags = [
63 "all"
64 "libgpr.install"
65 ];
66
67 # link gprconfig_kb db from gprbuild-boot into build dir,
68 # the install process copies its contents to $out
69 preInstall = ''
70 # Use PATH to discover spliced gprbuild-boot from buildPackages,
71 # since path interpolation would give us gprbuild-boot from pkgsHostTarget
72 gprbuild_boot="$(dirname "$(type -p gprbuild)")/.."
73 ln -sf "$gprbuild_boot/share/gprconfig" share/gprconfig
74 '';
75
76 # no need for the install script
77 postInstall = ''
78 rm $out/doinstall
79 '';
80}