Ihar Hrachyshka 5ca364e30a fpc: add apple-sdk SDKROOT to default library paths
This fixes darwin build for xidel, among other things.

Note: there are some impurities in the package where xcode and other
paths may be injected into build environment. These are left out of
scope for this patch, to be dealt by other interested parties.

Signed-off-by: Ihar Hrachyshka <ihar.hrachyshka@gmail.com>
2025-04-19 23:51:45 -04:00

117 lines
3.1 KiB
Nix

{
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"
];
# disabled by default in fpcsrc/compiler/llvm/agllvm.pas
hardeningDisable = [ "pie" ];
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 = with lib; {
description = "Free Pascal Compiler from a source distribution";
homepage = "https://www.freepascal.org";
maintainers = [ maintainers.raskin ];
license = with licenses; [
gpl2
lgpl2
];
platforms = platforms.unix;
};
}