1{ lib, stdenv, buildPackages, fetchurl, bison, m4
2, autoreconfHook, help2man
3}:
4
5# Avoid 'fetchpatch' to allow 'flex' to be used as a possible 'gcc'
6# dependency during bootstrap. Useful when gcc is built from snapshot
7# or from a git tree (flex lexers are not pre-generated there).
8
9stdenv.mkDerivation rec {
10 pname = "flex";
11 version = "2.6.4";
12
13 src = fetchurl {
14 url = "https://github.com/westes/flex/releases/download/v${version}/flex-${version}.tar.gz";
15 sha256 = "15g9bv236nzi665p9ggqjlfn4dwck5835vf0bbw2cz7h5c1swyp8";
16 };
17
18 # Also upstream, will be part of 2.6.5
19 # https://github.com/westes/flex/commit/24fd0551333e
20 patches = [(fetchurl {
21 name = "glibc-2.26.patch";
22 url = "https://raw.githubusercontent.com/lede-project/source/0fb14a2b1ab2f82ce63f4437b062229d73d90516/tools/flex/patches/200-build-AC_USE_SYSTEM_EXTENSIONS-in-configure.ac.patch";
23 sha256 = "0mpp41zdg17gx30kcpj83jl8hssks3adbks0qzbhcz882b9c083r";
24 })];
25
26 postPatch = ''
27 patchShebangs tests
28 '' + lib.optionalString (stdenv.buildPlatform != stdenv.hostPlatform) ''
29 substituteInPlace Makefile.in --replace "tests" " "
30
31 substituteInPlace doc/Makefile.am --replace 'flex.1: $(top_srcdir)/configure.ac' 'flex.1: '
32 '';
33
34 depsBuildBuild = [ buildPackages.stdenv.cc ];
35 nativeBuildInputs = [ autoreconfHook help2man ];
36 buildInputs = [ bison ];
37 propagatedBuildInputs = [ m4 ];
38
39 preConfigure = lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) ''
40 export ac_cv_func_malloc_0_nonnull=yes
41 export ac_cv_func_realloc_0_nonnull=yes
42 '';
43
44 postConfigure = lib.optionalString (stdenv.isDarwin || stdenv.isCygwin) ''
45 sed -i Makefile -e 's/-no-undefined//;'
46 '';
47
48 dontDisableStatic = stdenv.buildPlatform != stdenv.hostPlatform;
49
50 postInstall = ''
51 ln -s $out/bin/flex $out/bin/lex
52 '';
53
54 meta = with lib; {
55 homepage = "https://github.com/westes/flex";
56 description = "A fast lexical analyser generator";
57 license = licenses.bsd2;
58 platforms = platforms.unix;
59 };
60}