1{
2 bison,
3 buildPackages,
4 curl,
5 fetchFromGitHub,
6 fetchurl,
7 file,
8 flex,
9 targetArchitecture ? "i586",
10 lib,
11 makeWrapper,
12 perl,
13 stdenv,
14 texinfo,
15 unzip,
16 which,
17}:
18
19let
20 s = import ./sources.nix { inherit fetchurl fetchFromGitHub; };
21in
22assert lib.elem targetArchitecture [
23 "i586"
24 "i686"
25];
26stdenv.mkDerivation rec {
27 pname = "djgpp";
28 version = s.gccVersion;
29 src = s.src;
30
31 patchPhase =
32 ''
33 runHook prePatch
34 for f in "build-djgpp.sh" "script/${version}" "setenv/copyfile.sh"; do
35 substituteInPlace "$f" --replace '/usr/bin/env' '${buildPackages.coreutils}/bin/env'
36 done
37 ''
38 # i686 patches from https://github.com/andrewwutw/build-djgpp/issues/45#issuecomment-1484010755
39 # The build script unpacks some files so we can't patch ahead of time, instead patch the script
40 # to patch after it extracts
41
42 + lib.optionalString (targetArchitecture == "i686") ''
43 sed -i 's/i586/i686/g' setenv/setenv script/${version}
44 sed -i '/Building DXE tools./a sed -i "s/i586/i686/g" src/makefile.def src/dxe/makefile.dxe' script/${version}
45 ''
46 + ''
47 runHook postPatch
48 '';
49
50 nativeBuildInputs = [
51 makeWrapper
52 ];
53
54 buildInputs = [
55 bison
56 curl
57 file
58 flex
59 perl
60 texinfo
61 unzip
62 which
63 ];
64
65 hardeningDisable = [ "format" ];
66
67 # stripping breaks static libs, causing this when you attempt to compile a binary:
68 # error adding symbols: Archive has no index; run ranlib to add one
69 dontStrip = true;
70
71 buildPhase = ''
72 runHook preBuild
73 mkdir download; pushd download
74 ln -s "${s.autoconf}" "${s.autoconf.name}"
75 ln -s "${s.automake}" "${s.automake.name}"
76 ln -s "${s.binutils}" "${s.binutils.name}"
77 ln -s "${s.djcrossgcc}" "${s.djcrossgcc.name}"
78 ln -s "${s.djcrx}" "${s.djcrx.name}"
79 ln -s "${s.djdev}" "${s.djdev.name}"
80 ln -s "${s.djlsr}" "${s.djlsr.name}"
81 ln -s "${s.gcc}" "${s.gcc.name}"
82 ln -s "${s.gmp}" "${s.gmp.name}"
83 ln -s "${s.mpc}" "${s.mpc.name}"
84 ln -s "${s.mpfr}" "${s.mpfr.name}"
85 popd
86 DJGPP_PREFIX=$out ./build-djgpp.sh ${version}
87 runHook postBuild
88 '';
89
90 postInstall = ''
91 for f in dxegen dxe3gen dxe3res exe2coff stubify; do
92 cp -v "$out/${targetArchitecture}-pc-msdosdjgpp/bin/$f" "$out/bin"
93 done
94
95 for f in dxegen dxe3gen; do
96 wrapProgram $out/bin/$f --set DJDIR $out
97 done
98 '';
99
100 meta = {
101 description = "Complete 32-bit GNU-based development system for Intel x86 PCs running DOS";
102 homepage = "https://www.delorie.com/djgpp/";
103 license = lib.licenses.gpl2Plus;
104 maintainers = with lib.maintainers; [ hughobrien ];
105 platforms = lib.platforms.linux ++ lib.platforms.darwin;
106 };
107}