summaryrefslogtreecommitdiffstats
path: root/pkgs/development/compilers/fpc/default.nix
blob: 4d7b8870b5769478823815f4e8bb9c616c87e5f1 (plain)
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
{
  lib,
  stdenv,
  fetchurl,
  gawk,
  fetchpatch,
  undmg,
  cpio,
  xar,
  libiconv,
}:

let
  startFPC = import ./binary.nix {
    inherit
      stdenv
      fetchurl
      undmg
      cpio
      xar
      lib
      ;
  };
in

stdenv.mkDerivation rec {
  version = "3.2.2";
  pname = "fpc";

  src = fetchurl {
    url = "mirror://sourceforge/freepascal/fpcbuild-${version}.tar.gz";
    sha256 = "85ef993043bb83f999e2212f1bca766eb71f6f973d362e2290475dbaaf50161f";
  };

  buildInputs = [
    startFPC
    gawk
  ];

  glibc = stdenv.cc.libc.out;

  # Patch paths for linux systems. Other platforms will need their own patches.
  patches = [
    ./mark-paths.patch # mark paths for later substitution in postPatch
  ]
  ++ lib.optional stdenv.hostPlatform.isAarch64 (fetchpatch {
    # backport upstream patch for aarch64 glibc 2.34
    url = "https://gitlab.com/freepascal.org/fpc/source/-/commit/a20a7e3497bccf3415bf47ccc55f133eb9d6d6a0.patch";
    hash = "sha256-xKTBwuOxOwX9KCazQbBNLhMXCqkuJgIFvlXewHY63GM=";
    stripLen = 1;
    extraPrefix = "fpcsrc/";
  });

  postPatch = ''
    # substitute the markers set by the mark-paths patch
    substituteInPlace fpcsrc/compiler/systems/t_linux.pas --subst-var-by dynlinker-prefix "${glibc}"
    substituteInPlace fpcsrc/compiler/systems/t_linux.pas --subst-var-by syslibpath "${glibc}/lib"

    substituteInPlace fpcsrc/compiler/systems/t_darwin.pas \
      --replace-fail "LibrarySearchPath.AddLibraryPath(sysrootpath,'=/usr/lib',true)" "LibrarySearchPath.AddLibraryPath(sysrootpath,'$SDKROOT/usr/lib',true)"

    # Replace the `codesign --remove-signature` command with a custom script, since `codesign` is not available
    # in nixpkgs
    # Remove the -no_uuid strip flag which does not work on llvm-strip, only
    # Apple strip.
    substituteInPlace fpcsrc/compiler/Makefile \
      --replace \
        "\$(CODESIGN) --remove-signature" \
        "${./remove-signature.sh}" \
      --replace "ifneq (\$(CODESIGN),)" "ifeq (\$(OS_TARGET), darwin)" \
      --replace "-no_uuid" ""
  '';

  preConfigure = lib.optionalString stdenv.hostPlatform.isDarwin ''
    NIX_LDFLAGS="-syslibroot $SDKROOT -L${lib.getLib libiconv}/lib"
  '';

  makeFlags = [
    "NOGDB=1"
    "FPC=${startFPC}/bin/fpc"
  ];

  installFlags = [ "INSTALL_PREFIX=\${out}" ];

  postInstall = ''
    for i in $out/lib/fpc/*/ppc*; do
      ln -fs $i $out/bin/$(basename $i)
    done
    mkdir -p $out/lib/fpc/etc/
    $out/lib/fpc/*/samplecfg $out/lib/fpc/${version} $out/lib/fpc/etc/

    # Generate config files in /etc since on darwin, ppc* does not follow symlinks
    # to resolve the location of /etc
    mkdir -p $out/etc
    $out/lib/fpc/*/samplecfg $out/lib/fpc/${version} $out/etc
  '';

  passthru = {
    bootstrap = startFPC;
  };

  meta = {
    description = "Free Pascal Compiler from a source distribution";
    homepage = "https://www.freepascal.org";
    maintainers = [ lib.maintainers.raskin ];
    license = with lib.licenses; [
      gpl2
      lgpl2
    ];
    platforms = lib.platforms.unix;
    # See:
    # * <https://gitlab.com/freepascal.org/fpc/source/-/issues/41045>
    # * <https://gitlab.com/freepascal.org/fpc/source/-/merge_requests/887>
    broken = stdenv.cc.isClang && stdenv.hostPlatform.isx86_64;
  };
}