summary refs log tree commit diff
path: root/pkgs/development/compilers/djgpp/default.nix
blob: d6f645f3a31a7ec149217632d21a015f18432e7b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
{ bison
, buildPackages
, curl
, fetchFromGitHub
, fetchurl
, file
, flex
, targetArchitecture ? "i586"
, lib
, makeWrapper
, perl
, stdenv
, texinfo
, unzip
, which }:

let
  s = import ./sources.nix { inherit fetchurl fetchFromGitHub; };
in
assert lib.elem targetArchitecture [ "i586" "i686" ];
stdenv.mkDerivation rec {
  pname = "djgpp";
  version = s.gccVersion;
  src = s.src;

  patchPhase = ''
    runHook prePatch
    for f in "build-djgpp.sh" "script/${version}" "setenv/copyfile.sh"; do
      substituteInPlace "$f" --replace '/usr/bin/env' '${buildPackages.coreutils}/bin/env'
    done
  ''
  # i686 patches from https://github.com/andrewwutw/build-djgpp/issues/45#issuecomment-1484010755
  # The build script unpacks some files so we can't patch ahead of time, instead patch the script
  # to patch after it extracts

  + lib.optionalString (targetArchitecture == "i686") ''
    sed -i 's/i586/i686/g' setenv/setenv script/${version}
    sed -i '/Building DXE tools./a sed -i "s/i586/i686/g" src/makefile.def src/dxe/makefile.dxe' script/${version}
  ''
  + ''
    runHook postPatch
  '';

  nativeBuildInputs = [
    makeWrapper
  ];

  buildInputs = [
    bison
    curl
    file
    flex
    perl
    texinfo
    unzip
    which
  ];

  hardeningDisable = [ "format" ];

  buildPhase = ''
    runHook preBuild
    mkdir download; pushd download
    ln -s "${s.autoconf}"   "${s.autoconf.name}"
    ln -s "${s.automake}"   "${s.automake.name}"
    ln -s "${s.binutils}"   "${s.binutils.name}"
    ln -s "${s.djcrossgcc}" "${s.djcrossgcc.name}"
    ln -s "${s.djcrx}"      "${s.djcrx.name}"
    ln -s "${s.djdev}"      "${s.djdev.name}"
    ln -s "${s.djlsr}"      "${s.djlsr.name}"
    ln -s "${s.gcc}"        "${s.gcc.name}"
    ln -s "${s.gmp}"        "${s.gmp.name}"
    ln -s "${s.mpc}"        "${s.mpc.name}"
    ln -s "${s.mpfr}"       "${s.mpfr.name}"
    popd
    DJGPP_PREFIX=$out ./build-djgpp.sh ${version}
    runHook postBuild
  '';

  postInstall = ''
    for f in dxegen dxe3gen dxe3res exe2coff stubify; do
      cp -v "$out/${targetArchitecture}-pc-msdosdjgpp/bin/$f" "$out/bin"
    done

    for f in dxegen dxe3gen; do
      wrapProgram $out/bin/$f --set DJDIR $out
    done
  '';

  meta = {
    description = "A complete 32-bit GNU-based development system for Intel x86 PCs running DOS";
    homepage = "https://www.delorie.com/djgpp/";
    license = lib.licenses.gpl2Plus;
    maintainers = with lib.maintainers; [ hughobrien ];
    platforms = lib.platforms.linux ++ lib.platforms.darwin;
  };
}