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