1{ lib, stdenv, fetchurl
2, pcre, windows ? null
3, variant ? null
4}:
5
6with lib;
7
8assert elem variant [ null "cpp" "pcre16" "pcre32" ];
9
10let
11 version = "8.44";
12 pname = if (variant == null) then "pcre"
13 else if (variant == "cpp") then "pcre-cpp"
14 else variant;
15
16in stdenv.mkDerivation {
17 name = "${pname}-${version}";
18
19 src = fetchurl {
20 url = "mirror://sourceforge/project/pcre/pcre/${version}/pcre-${version}.tar.bz2";
21 sha256 = "0v9nk51wh55pcbnf2jr36yarz8ayajn6d7ywiq2wagivn9c8c40r";
22 };
23
24 outputs = [ "bin" "dev" "out" "doc" "man" ];
25
26 # Disable jit on Apple Silicon, https://github.com/zherczeg/sljit/issues/51
27 configureFlags = optional (!stdenv.hostPlatform.isRiscV && !(stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64)) "--enable-jit" ++ [
28 "--enable-unicode-properties"
29 "--disable-cpp"
30 ]
31 ++ optional (variant != null) "--enable-${variant}";
32
33 # https://bugs.exim.org/show_bug.cgi?id=2173
34 patches = [ ./stacksize-detection.patch ];
35
36 preCheck = ''
37 patchShebangs RunGrepTest
38 '';
39
40 doCheck = !(with stdenv.hostPlatform; isCygwin || isFreeBSD) && stdenv.hostPlatform == stdenv.buildPlatform;
41 # XXX: test failure on Cygwin
42 # we are running out of stack on both freeBSDs on Hydra
43
44 postFixup = ''
45 moveToOutput bin/pcre-config "$dev"
46 ''
47 + optionalString (variant != null) ''
48 ln -sf -t "$out/lib/" '${pcre.out}'/lib/libpcre{,posix}.{so.*.*.*,*dylib}
49 '';
50
51 meta = {
52 homepage = "http://www.pcre.org/";
53 description = "A library for Perl Compatible Regular Expressions";
54 license = lib.licenses.bsd3;
55
56 longDescription = ''
57 The PCRE library is a set of functions that implement regular
58 expression pattern matching using the same syntax and semantics as
59 Perl 5. PCRE has its own native API, as well as a set of wrapper
60 functions that correspond to the POSIX regular expression API. The
61 PCRE library is free, even for building proprietary software.
62 '';
63
64 platforms = platforms.all;
65 };
66}