lol
1{ lib, stdenv, buildPackages, fetchurl, fetchpatch, autoreconfHook, which, pkg-config, perl, guile_2_2, libxml2 }:
2
3stdenv.mkDerivation rec {
4 pname = "autogen";
5 version = "5.18.16";
6
7 src = fetchurl {
8 url = "mirror://gnu/autogen/rel${version}/autogen-${version}.tar.xz";
9 sha256 = "16mlbdys8q4ckxlvxyhwkdnh1ay9f6g0cyp1kylkpalgnik398gq";
10 };
11
12 patches = let
13 dp = { ver ? "1%255.18.16-5", name, sha256 }: fetchurl {
14 url = "https://salsa.debian.org/debian/autogen/-/raw/debian/${ver}"
15 + "/debian/patches/${name}?inline=false";
16 inherit name sha256;
17 };
18 in [
19 (dp {
20 name = "20_no_Werror.diff";
21 sha256 = "08z4s2ifiqyaacjpd9pzr59w8m4j3548kkaq1bwvp2gjn29m680x";
22 })
23 (dp {
24 name = "30_ag_macros.m4_syntax_error.diff";
25 sha256 = "1z8vmbwbkz3505wd33i2xx91mlf8rwsa7klndq37nw821skxwyh3";
26 })
27 (dp {
28 name = "31_allow_overriding_AGexe_for_crossbuild.diff";
29 sha256 = "0h9wkc9bqb509knh8mymi43hg6n6sxg2lixvjlchcx7z0j7p8xkf";
30 })
31 (dp {
32 name = "40_suse_01-autogen-catch-race-error.patch";
33 sha256 = "1cfkym2zds1f85md1m74snxzqmzlj7wd5jivgmyl342856848xav";
34 })
35 (dp {
36 name = "40_suse_03-gcc9-fix-wrestrict.patch";
37 sha256 = "1ifdwi6gf96jc78jw7q4bfi5fgdldlf2nl55y20h6xb78kv0pznd";
38 })
39 (dp {
40 name = "40_suse_05-sprintf-overflow.patch";
41 sha256 = "136m62k68w1h5k7iapynvbyipidw35js6pq21lsc6rpxvgp0n469";
42 })
43 (dp {
44 name = "40_suse_06-autogen-avoid-GCC-code-analysis-bug.patch";
45 sha256 = "1d65zygzw2rpa00s0jy2y1bg29vkbhnjwlb5pv22rfv87zbk6z9q";
46 })
47 # Next upstream release will contain guile-3 support. We apply non-invasive
48 # patch meanwhile.
49 (fetchpatch {
50 name = "guile-3.patch";
51 url = "https://gitweb.gentoo.org/repo/gentoo.git/plain/sys-devel/autogen/files/autogen-5.18.16-guile-3.patch?id=43bcc61c56a5a7de0eaf806efec7d8c0e4c01ae7";
52 sha256 = "18d7y1f6164dm1wlh7rzbacfygiwrmbc35a7qqsbdawpkhydm5lr";
53 })
54 ];
55
56 outputs = [ "bin" "dev" "lib" "out" "man" "info" ];
57
58 nativeBuildInputs = [
59 which pkg-config perl autoreconfHook/*patches applied*/
60 ] ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
61 # autogen needs a build autogen when cross-compiling
62 buildPackages.buildPackages.autogen buildPackages.texinfo
63 ];
64 buildInputs = [
65 guile_2_2 libxml2
66 ];
67
68 preConfigure = ''
69 export MAN_PAGE_DATE=$(date '+%Y-%m-%d' -d "@$SOURCE_DATE_EPOCH")
70 '';
71
72 configureFlags = [
73 "--with-libxml2=${libxml2.dev}"
74 "--with-libxml2-cflags=-I${libxml2.dev}/include/libxml2"
75 # Make sure to use a static value for the timeout. If we do not set a value
76 # here autogen will select one based on the execution time of the configure
77 # phase which is not really reproducible.
78 #
79 # If you are curious about the number 78, it has been cargo-culted from
80 # Debian: https://salsa.debian.org/debian/autogen/-/blob/master/debian/rules#L21
81 "--enable-timeout=78"
82 ] ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
83 # the configure check for regcomp wants to run a host program
84 "libopts_cv_with_libregex=yes"
85 #"MAKEINFO=${buildPackages.texinfo}/bin/makeinfo"
86 ]
87 # See: https://sourceforge.net/p/autogen/bugs/187/
88 ++ lib.optionals stdenv.isDarwin [ "ac_cv_func_utimensat=no" ];
89
90 #doCheck = true; # not reliable
91
92 postInstall = ''
93 mkdir -p $dev/bin
94 mv $bin/bin/autoopts-config $dev/bin
95
96 for f in $lib/lib/autogen/tpl-config.tlib $out/share/autogen/tpl-config.tlib; do
97 sed -e "s|$dev/include|/no-such-autogen-include-path|" -i $f
98 sed -e "s|$bin/bin|/no-such-autogen-bin-path|" -i $f
99 sed -e "s|$lib/lib|/no-such-autogen-lib-path|" -i $f
100 done
101
102 '' + lib.optionalString (!stdenv.hostPlatform.isDarwin) ''
103 # remove build directory (/build/**, or /tmp/nix-build-**) from RPATHs
104 for f in "$bin"/bin/*; do
105 local nrp="$(patchelf --print-rpath "$f" | sed -E 's@(:|^)'$NIX_BUILD_TOP'[^:]*:@\1@g')"
106 patchelf --set-rpath "$nrp" "$f"
107 done
108 '';
109
110 meta = with lib; {
111 description = "Automated text and program generation tool";
112 license = with licenses; [ gpl3Plus lgpl3Plus ];
113 homepage = "https://www.gnu.org/software/autogen/";
114 platforms = platforms.all;
115 maintainers = [ ];
116 };
117}