about summary refs log tree commit diff
path: root/nixpkgs/pkgs/development/skaware-packages/build-skaware-package.nix
blob: 56bbe6bec51b3241cd7a27a5306cf15158a79438 (plain) (blame)
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
{ lib, stdenv, cleanPackaging, fetchurl }:
{
  # : string
  pname
  # : string
, version
  # : string
, sha256 ? lib.fakeSha256
  # : drv | null
, manpages ? null
  # : string
, description
  # : list Platform
, platforms ? lib.platforms.all
  # : list string
, outputs ? [ "bin" "lib" "dev" "doc" "out" ]
  # TODO(Profpatsch): automatically infer most of these
  # : list string
, configureFlags
  # : string
, postConfigure ? null
  # mostly for moving and deleting files from the build directory
  # : lines
, postInstall
  # : list Maintainer
, maintainers ? [ ]
  # : passthru arguments (e.g. tests)
, passthru ? { }

}:

let

  # File globs that can always be deleted
  commonNoiseFiles = [
    ".gitignore"
    "Makefile"
    "INSTALL"
    "configure"
    "patch-for-solaris"
    "src/**/*"
    "tools/**/*"
    "package/**/*"
    "config.mak"
  ];

  # File globs that should be moved to $doc
  commonMetaFiles = [
    "COPYING"
    "AUTHORS"
    "NEWS"
    "CHANGELOG"
    "README"
    "README.*"
    "DCO"
    "CONTRIBUTING"
  ];

in
stdenv.mkDerivation {
  inherit pname version;

  src = fetchurl {
    url = "https://skarnet.org/software/${pname}/${pname}-${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!");
    # insert as early as posible, but keep the first element
    if lib.length outputs > 0
    then [(lib.head outputs) "man"] ++ lib.tail outputs
    else ["man"];

  dontDisableStatic = true;
  enableParallelBuilding = true;

  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.isDarwin
    then "--disable-shared"
    else "--enable-shared")
  ]
    # 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.isDarwin
    "--build=${stdenv.hostPlatform.system}");

  inherit postConfigure;

  makeFlags = lib.optionals stdenv.cc.isClang [ "AR=${stdenv.cc.targetPrefix}ar" "RANLIB=${stdenv.cc.targetPrefix}ranlib" ];

  # TODO(Profpatsch): ensure that there is always a $doc output!
  postInstall = ''
    echo "Cleaning & moving common files"
    ${cleanPackaging.commonFileActions {
       noiseFiles = commonNoiseFiles;
       docFiles = commonMetaFiles;
     }} $doc/share/doc/${pname}

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

    ${postInstall}
  '';

  postFixup = ''
    ${cleanPackaging.checkForRemainingFiles}
  '';

  passthru = passthru // (if manpages == null then {} else { inherit manpages; });

  meta = {
    homepage = "https://skarnet.org/software/${pname}/";
    inherit description platforms;
    license = lib.licenses.isc;
    maintainers = with lib.maintainers;
      [ pmahoney Profpatsch qyliss ] ++ maintainers;
  };

}