1{
2 lib,
3 stdenv,
4 fetchurl,
5 gawk,
6 fetchpatch,
7 undmg,
8 cpio,
9 xar,
10 libiconv,
11}:
12
13let
14 startFPC = import ./binary.nix {
15 inherit
16 stdenv
17 fetchurl
18 undmg
19 cpio
20 xar
21 lib
22 ;
23 };
24in
25
26stdenv.mkDerivation rec {
27 version = "3.2.2";
28 pname = "fpc";
29
30 src = fetchurl {
31 url = "mirror://sourceforge/freepascal/fpcbuild-${version}.tar.gz";
32 sha256 = "85ef993043bb83f999e2212f1bca766eb71f6f973d362e2290475dbaaf50161f";
33 };
34
35 buildInputs = [
36 startFPC
37 gawk
38 ];
39
40 glibc = stdenv.cc.libc.out;
41
42 # Patch paths for linux systems. Other platforms will need their own patches.
43 patches =
44 [
45 ./mark-paths.patch # mark paths for later substitution in postPatch
46 ]
47 ++ lib.optional stdenv.hostPlatform.isAarch64 (fetchpatch {
48 # backport upstream patch for aarch64 glibc 2.34
49 url = "https://gitlab.com/freepascal.org/fpc/source/-/commit/a20a7e3497bccf3415bf47ccc55f133eb9d6d6a0.patch";
50 hash = "sha256-xKTBwuOxOwX9KCazQbBNLhMXCqkuJgIFvlXewHY63GM=";
51 stripLen = 1;
52 extraPrefix = "fpcsrc/";
53 });
54
55 postPatch = ''
56 # substitute the markers set by the mark-paths patch
57 substituteInPlace fpcsrc/compiler/systems/t_linux.pas --subst-var-by dynlinker-prefix "${glibc}"
58 substituteInPlace fpcsrc/compiler/systems/t_linux.pas --subst-var-by syslibpath "${glibc}/lib"
59
60 substituteInPlace fpcsrc/compiler/systems/t_darwin.pas \
61 --replace-fail "LibrarySearchPath.AddLibraryPath(sysrootpath,'=/usr/lib',true)" "LibrarySearchPath.AddLibraryPath(sysrootpath,'$SDKROOT/usr/lib',true)"
62
63 # Replace the `codesign --remove-signature` command with a custom script, since `codesign` is not available
64 # in nixpkgs
65 # Remove the -no_uuid strip flag which does not work on llvm-strip, only
66 # Apple strip.
67 substituteInPlace fpcsrc/compiler/Makefile \
68 --replace \
69 "\$(CODESIGN) --remove-signature" \
70 "${./remove-signature.sh}" \
71 --replace "ifneq (\$(CODESIGN),)" "ifeq (\$(OS_TARGET), darwin)" \
72 --replace "-no_uuid" ""
73 '';
74
75 preConfigure = lib.optionalString stdenv.hostPlatform.isDarwin ''
76 NIX_LDFLAGS="-syslibroot $SDKROOT -L${lib.getLib libiconv}/lib"
77 '';
78
79 makeFlags = [
80 "NOGDB=1"
81 "FPC=${startFPC}/bin/fpc"
82 ];
83
84 # disabled by default in fpcsrc/compiler/llvm/agllvm.pas
85 hardeningDisable = [ "pie" ];
86
87 installFlags = [ "INSTALL_PREFIX=\${out}" ];
88
89 postInstall = ''
90 for i in $out/lib/fpc/*/ppc*; do
91 ln -fs $i $out/bin/$(basename $i)
92 done
93 mkdir -p $out/lib/fpc/etc/
94 $out/lib/fpc/*/samplecfg $out/lib/fpc/${version} $out/lib/fpc/etc/
95
96 # Generate config files in /etc since on darwin, ppc* does not follow symlinks
97 # to resolve the location of /etc
98 mkdir -p $out/etc
99 $out/lib/fpc/*/samplecfg $out/lib/fpc/${version} $out/etc
100 '';
101
102 passthru = {
103 bootstrap = startFPC;
104 };
105
106 meta = with lib; {
107 description = "Free Pascal Compiler from a source distribution";
108 homepage = "https://www.freepascal.org";
109 maintainers = [ maintainers.raskin ];
110 license = with licenses; [
111 gpl2
112 lgpl2
113 ];
114 platforms = platforms.unix;
115 };
116}