summaryrefslogtreecommitdiffstats
path: root/pkgs/development/skaware-packages/build-skaware-package.nix
blob: 76ec796c5f7ba1c2d07cbe23cdfc30611bf06ad7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
{
  lib,
  stdenv,
  cleanPackaging,
  fetchurl,
  nix-update-script,
  pkg-config,
}:
lib.extendMkDerivation {
  constructDrv = stdenv.mkDerivation;
  excludeDrvArgNames = [
    "sha256"
    "manpages"
  ];
  extendDrvArgs =
    finalAttrs:
    {
      sha256 ? lib.fakeSha256,
      manpages ? null,
      meta ? { },
      outputs ? [
        "bin"
        "lib"
        "dev"
        "doc"
        "out"
      ],
      nativeBuildInputs ? [ ],
      configureFlags,
      passthru ? { },
      ...
    }@args:
    let
      # File globs that can always be deleted
      commonNoiseFiles = [
        ".gitignore"
        "Makefile"
        "INSTALL"
        "configure"
        "patch-for-solaris"
        "src/**/*"
        "tools/**/*"
        "package/**/*"
        "config.mak"
        "*.pc"
      ];
      # File globs that should be moved to $doc
      commonMetaFiles = [
        "COPYING"
        "AUTHORS"
        "NEWS"
        "CHANGELOG"
        "README"
        "README.*"
        "DCO"
        "CONTRIBUTING"
      ];
      libraryOutput = if lib.elem "lib" outputs then "lib" else "out";
    in
    {
      src = fetchurl {
        url = "https://skarnet.org/software/${finalAttrs.pname}/${finalAttrs.pname}-${finalAttrs.version}.tar.gz";
        inherit sha256;
      };
      outputs =
        if manpages == null then
          outputs
        else
          assert (
            lib.assertMsg (!lib.elem "man" outputs)
              "If you pass `manpages` to `skawarePackages.buildPackage`, you cannot have a `man` output already!"
          );
          if lib.length outputs > 0 then
            [
              (lib.head outputs)
              "man"
            ]
            ++ lib.tail outputs
          else
            [ "man" ];
      dontDisableStatic = true;
      enableParallelBuilding = true;
      nativeBuildInputs = [ pkg-config ] ++ nativeBuildInputs;
      configureFlags =
        configureFlags
        ++ [
          "--enable-absolute-paths"
          # We assume every Nix-based cross target has urandom.
          # This might not hold for e.g. BSD.
          "--with-sysdep-devurandom=yes"
          (if stdenv.hostPlatform.isDarwin then "--disable-shared" else "--enable-shared")
          # Use pkg-config
          "--with-pkgconfig=pkg-config"
          "--enable-pkgconfig"
        ]
        # On Darwin, the target triplet from -dumpmachine includes version number,
        # but skarnet.org software uses the triplet to test binary compatibility.
        # Explicitly setting target ensures code can be compiled against a skalibs
        # binary built on a different version of Darwin.
        # http://www.skarnet.org/cgi-bin/archive.cgi?1:mss:623:heiodchokfjdkonfhdph
        ++ (lib.optional stdenv.hostPlatform.isDarwin "--build=${stdenv.hostPlatform.system}");
      makeFlags = lib.optionals stdenv.cc.isClang [
        "AR=${stdenv.cc.targetPrefix}ar"
        "RANLIB=${stdenv.cc.targetPrefix}ranlib"
      ];
      postInstall = ''
        echo "Cleaning & moving common files"
        ${
          cleanPackaging.commonFileActions {
            noiseFiles = commonNoiseFiles;
            docFiles = commonMetaFiles;
          }
        } $doc/share/doc/${finalAttrs.pname}

        ${
          if manpages == null then
            ''echo "no manpages for this package"''
          else
            ''
              echo "copying manpages"
              cp -vr ${manpages} $man
            ''
        }

        ${args.postInstall or ""}
      '';
      postFixup = ''
        if [ -d "$dev/lib/pkgconfig" ]; then
          for pc in "$dev"/lib/pkgconfig/*.pc; do
            sed -i "s|^libdir=.*|libdir=${placeholder libraryOutput}/lib|" "$pc"
            if ! grep -q '^Libs.private:' "$pc"; then
              sed -i "/^Libs:/a Libs.private: -L${placeholder libraryOutput}/lib" "$pc"
            fi
          done
        fi
        ${cleanPackaging.checkForRemainingFiles}
      '';
      passthru = {
        updateScript = nix-update-script {
          extraArgs = [
            "--url"
            "https://github.com/skarnet/${finalAttrs.pname}"
            "--override-filename"
            "pkgs/development/skaware-packages/${finalAttrs.pname}/default.nix"
          ];
        };
      }
      // passthru
      // (if manpages == null then { } else { inherit manpages; });
      meta = {
        homepage = "https://skarnet.org/software/${finalAttrs.pname}/";
        platforms = lib.platforms.all;
        license = lib.licenses.isc;
        maintainers =
          with lib.maintainers;
          [
            pmahoney
            Profpatsch
            qyliss
          ]
          ++ (meta.maintainers or [ ]);
      }
      // meta;
    };
}