1{ lib, stdenv, buildPackages, fetchurl, tcl, makeWrapper, autoreconfHook, fetchpatch, substituteAll }:
2
3tcl.mkTclDerivation rec {
4 pname = "expect";
5 version = "5.45.4";
6
7 src = fetchurl {
8 url = "mirror://sourceforge/expect/Expect/${version}/expect${version}.tar.gz";
9 hash = "sha256-Safag7C92fRtBKBN7sGcd2e7mjI+QMR4H4nK92C5LDQ=";
10 };
11
12 patches = [
13 (fetchpatch {
14 url = "https://raw.githubusercontent.com/buildroot/buildroot/c05e6aa361a4049eabd8b21eb64a34899ef83fc7/package/expect/0001-enable-cross-compilation.patch";
15 hash = "sha256-yyzE0Jjac5qaj7Svn4VpMiAqSNLYrw7VZbtFqgMVncs=";
16 })
17 (substituteAll {
18 src = ./fix-cross-compilation.patch;
19 tcl = "${buildPackages.tcl}/bin/tclsh";
20 })
21 # The following patches fix compilation with clang 15+
22 (fetchpatch {
23 url = "https://sourceforge.net/p/expect/patches/24/attachment/0001-Add-prototype-to-function-definitions.patch";
24 hash = "sha256-X2Vv6VVM3KjmBHo2ukVWe5YTVXRmqe//Kw2kr73OpZs=";
25 })
26 (fetchpatch {
27 url = "https://sourceforge.net/p/expect/patches/_discuss/thread/b813ca9895/6759/attachment/expect-configure-c99.patch";
28 hash = "sha256-PxQQ9roWgVXUoCMxkXEgu+it26ES/JuzHF6oML/nk54=";
29 })
30 # Include `sys/ioctl.h` and `util.h` on Darwin, which are required for `ioctl` and `openpty`.
31 ./fix-darwin-clang16.patch
32 ];
33
34 postPatch = ''
35 sed -i "s,/bin/stty,$(type -p stty),g" configure.in
36 '';
37
38 nativeBuildInputs = [ autoreconfHook makeWrapper ];
39
40 strictDeps = true;
41 hardeningDisable = [ "format" ];
42
43 postInstall = ''
44 tclWrapperArgs+=(--prefix PATH : ${lib.makeBinPath [ tcl ]})
45 ${lib.optionalString stdenv.isDarwin "tclWrapperArgs+=(--prefix DYLD_LIBRARY_PATH : $out/lib/expect${version})"}
46 '';
47
48 outputs = [ "out" "dev" ];
49
50 meta = with lib; {
51 description = "A tool for automating interactive applications";
52 homepage = "https://expect.sourceforge.net/";
53 license = licenses.publicDomain;
54 platforms = platforms.unix;
55 mainProgram = "expect";
56 maintainers = with maintainers; [ SuperSandro2000 ];
57 };
58}