summaryrefslogtreecommitdiffstats
path: root/pkgs/by-name/pr/procmail/package.nix
blob: 19041cefc29f046104e3671589e6c3d9d890f8fc (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
{
  lib,
  stdenv,
  gcc14Stdenv,
  fetchurl,
  fetchpatch,
  buildPackages,
}@args:

let
  stdenv = if args.stdenv.cc.isGNU then gcc14Stdenv else args.stdenv;
in

stdenv.mkDerivation (finalAttrs: {
  pname = "procmail";
  version = "3.24";

  src = fetchurl {
    url = "https://github.com/BuGlessRB/procmail/archive/refs/tags/v${finalAttrs.version}.tar.gz";
    sha256 = "UU6kMzOXg+ld+TIeeUdx5Ih7mCOsVf2yRpcCz2m9OYk=";
  };

  patches = [
    # Avoid benchmarking the build machine to determine compilation results
    # https://build.opensuse.org/projects/server:mail/packages/procmail/files/reproducible.patch?expand=1
    ./reproducible.patch
    # Fix clang-16 and gcc-14 build failures:
    #   https://github.com/BuGlessRB/procmail/pull/7
    (fetchpatch {
      name = "clang-16.patch";
      url = "https://github.com/BuGlessRB/procmail/commit/8cfd570fd14c8fb9983859767ab1851bfd064b64.patch";
      hash = "sha256-CaQeDKwF0hNOrxioBj7EzkCdJdsq44KwkfA9s8xK88g=";
    })
  ];

  # getline is defined differently in glibc now. So rename it.
  # Without the .PHONY target "make install" won't install anything on Darwin.
  postPatch = ''
    sed -i Makefile \
      -e "s%^RM.*$%#%" \
      -e "s%^BASENAME.*%\BASENAME=$out%" \
      -e "s%^LIBS=.*%LIBS=-lm%"
    sed -e "s%getline%thisgetline%g" -i src/*.c src/*.h
    sed -e "3i\
    .PHONY: install
    " -i Makefile
  ''
  + lib.optionalString (!stdenv.buildPlatform.canExecute stdenv.hostPlatform) ''
    substituteInPlace src/Makefile.0 \
      --replace-fail '@./_autotst' '@${stdenv.hostPlatform.emulator buildPackages} ./_autotst'
    sed -e '3i\
    _autotst() { ${stdenv.hostPlatform.emulator buildPackages} ./_autotst "$@"; } \
    _locktst() { ${stdenv.hostPlatform.emulator buildPackages} ./_locktst "$@"; } \
    ' -i src/autoconf
  '';

  # default target is binaries + manpages; manpages don't cross compile without more work.
  makeFlags = lib.optionals (!stdenv.buildPlatform.canExecute stdenv.hostPlatform) [ "bins" ];
  installTargets = lib.optionals (!stdenv.buildPlatform.canExecute stdenv.hostPlatform) [
    "install.bin"
  ];

  meta = {
    description = "Mail processing and filtering utility";
    homepage = "https://github.com/BuGlessRB/procmail/";
    license = lib.licenses.gpl2;
    platforms = lib.platforms.unix;
    maintainers = [ ];
  };
})