1{
2 lib,
3 stdenv,
4 fetchurl,
5 removeReferencesTo,
6 runtimeShellPackage,
7 texinfo,
8 interactive ? false,
9 readline,
10 autoreconfHook, # no-pma fix
11
12 /*
13 Test suite broke on:
14 stdenv.hostPlatform.isCygwin # XXX: `test-dup2' segfaults on Cygwin 6.1
15 || stdenv.hostPlatform.isDarwin # XXX: `locale' segfaults
16 || stdenv.hostPlatform.isSunOS # XXX: `_backsmalls1' fails, locale stuff?
17 || stdenv.hostPlatform.isFreeBSD
18 */
19 doCheck ? (interactive && stdenv.hostPlatform.isLinux),
20 glibcLocales ? null,
21 locale ? null,
22}:
23
24assert (doCheck && stdenv.hostPlatform.isLinux) -> glibcLocales != null;
25
26stdenv.mkDerivation rec {
27 pname = "gawk" + lib.optionalString interactive "-interactive";
28 version = "5.3.2";
29
30 src = fetchurl {
31 url = "mirror://gnu/gawk/gawk-${version}.tar.xz";
32 hash = "sha256-+MNIZQnecFGSE4sA7ywAu73Q6Eww1cB9I/xzqdxMycw=";
33 };
34
35 # PIE is incompatible with the "persistent malloc" ("pma") feature.
36 # While build system attempts to pass -no-pie to gcc. nixpkgs' `ld`
37 # wrapped still passes `-pie` flag to linker and breaks linkage.
38 # Let's disable "pie" until `ld` is fixed to do the right thing.
39 hardeningDisable = [ "pie" ];
40
41 # When we do build separate interactive version, it makes sense to always include man.
42 outputs = [
43 "out"
44 "info"
45 ]
46 ++ lib.optional (!interactive) "man";
47
48 strictDeps = true;
49
50 # no-pma fix
51 nativeBuildInputs = [
52 autoreconfHook
53 texinfo
54 ]
55 ++ lib.optionals interactive [
56 removeReferencesTo
57 ]
58 ++ lib.optionals (doCheck && stdenv.hostPlatform.isLinux) [
59 glibcLocales
60 ];
61
62 buildInputs =
63 lib.optionals interactive [
64 runtimeShellPackage
65 readline
66 ]
67 ++ lib.optionals stdenv.hostPlatform.isDarwin [
68 locale
69 ];
70
71 configureFlags = [
72 (if interactive then "--with-readline=${readline.dev}" else "--without-readline")
73 ];
74
75 env = lib.optionalAttrs stdenv.hostPlatform.isDarwin {
76 # TODO: figure out a better way to unbreak _NSGetExecutablePath invocations
77 NIX_CFLAGS_COMPILE = "-Wno-implicit-function-declaration";
78 };
79
80 makeFlags = [
81 "AR=${stdenv.cc.targetPrefix}ar"
82 ];
83
84 inherit doCheck;
85
86 postInstall =
87 (
88 if interactive then
89 ''
90 remove-references-to -t "$NIX_CC" "$out"/bin/gawkbug
91 patchShebangs --host "$out"/bin/gawkbug
92 ''
93 else
94 ''
95 rm "$out"/bin/gawkbug
96 ''
97 )
98 + ''
99 rm "$out"/bin/gawk-*
100 ln -s gawk.1 "''${!outputMan}"/share/man/man1/awk.1
101 '';
102
103 meta = {
104 homepage = "https://www.gnu.org/software/gawk/";
105 description = "GNU implementation of the Awk programming language";
106 longDescription = ''
107 Many computer users need to manipulate text files: extract and then
108 operate on data from parts of certain lines while discarding the rest,
109 make changes in various text files wherever certain patterns appear,
110 and so on. To write a program to do these things in a language such as
111 C or Pascal is a time-consuming inconvenience that may take many lines
112 of code. The job is easy with awk, especially the GNU implementation:
113 Gawk.
114
115 The awk utility interprets a special-purpose programming language that
116 makes it possible to handle many data-reformatting jobs with just a few
117 lines of code.
118 '';
119 license = lib.licenses.gpl3Plus;
120 platforms = lib.platforms.unix ++ lib.platforms.windows;
121 teams = [ lib.teams.helsinki-systems ];
122 mainProgram = "gawk";
123 };
124}