From 0aaca0a6204d5fdd823fda311a91367d2d9d8097 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Bartelme=C3=9F?= Date: Mon, 29 Aug 2022 23:25:50 +0200 Subject: [PATCH] fpc: support darwin --- .../compilers/fpc/binary-builder-darwin.sh | 17 +++++++++++ pkgs/development/compilers/fpc/binary.nix | 21 ++++++++++++-- pkgs/development/compilers/fpc/default.nix | 28 ++++++++++++++++--- .../compilers/fpc/remove-signature.sh | 3 ++ 4 files changed, 63 insertions(+), 6 deletions(-) create mode 100755 pkgs/development/compilers/fpc/binary-builder-darwin.sh create mode 100755 pkgs/development/compilers/fpc/remove-signature.sh diff --git a/pkgs/development/compilers/fpc/binary-builder-darwin.sh b/pkgs/development/compilers/fpc/binary-builder-darwin.sh new file mode 100755 index 00000000000..f9bdf18e7d6 --- /dev/null +++ b/pkgs/development/compilers/fpc/binary-builder-darwin.sh @@ -0,0 +1,17 @@ +source $stdenv/setup + +pkgdir=$(pwd)/pkg +deploydir=$(pwd)/deploy + +undmg $src +mkdir $out +mkdir $pkgdir +mkdir $deploydir + +pkg=*.mpkg/Contents/Packages/*.pkg +xar -xf $pkg -C $pkgdir +pushd $deploydir +cat $pkgdir/Payload | gunzip -dc | cpio -i +popd +echo $deploydir +cp -r $deploydir/usr/local/* $out diff --git a/pkgs/development/compilers/fpc/binary.nix b/pkgs/development/compilers/fpc/binary.nix index e7afa7c7698..e4c8a2358fc 100644 --- a/pkgs/development/compilers/fpc/binary.nix +++ b/pkgs/development/compilers/fpc/binary.nix @@ -1,4 +1,4 @@ -{ stdenv, fetchurl }: +{ stdenv, fetchurl, undmg, cpio, xar, lib }: stdenv.mkDerivation rec { pname = "fpc-binary"; @@ -20,9 +20,26 @@ stdenv.mkDerivation rec { url = "mirror://sourceforge/project/freepascal/Linux/${version}/fpc-${version}.aarch64-linux.tar"; sha256 = "b39470f9b6b5b82f50fc8680a5da37d2834f2129c65c24c5628a80894d565451"; } + else if stdenv.isDarwin then + fetchurl { + url = "mirror://sourceforge/project/freepascal/Mac%20OS%20X/${version}/fpc-${version}.intelarm64-macosx.dmg"; + sha256 = "05d4510c8c887e3c68de20272abf62171aa5b2ef1eba6bce25e4c0bc41ba8b7d"; + } else throw "Not supported on ${stdenv.hostPlatform.system}."; - builder = ./binary-builder.sh; + + nativeBuildInputs = lib.optionals stdenv.hostPlatform.isDarwin [ + undmg + xar + cpio + ]; + + builder = + if stdenv.hostPlatform.isLinux then + ./binary-builder.sh + else if stdenv.hostPlatform.isDarwin then + ./binary-builder-darwin.sh + else throw "Not supported on ${stdenv.hostPlatform}."; meta = { description = "Free Pascal Compiler from a binary distribution"; diff --git a/pkgs/development/compilers/fpc/default.nix b/pkgs/development/compilers/fpc/default.nix index 2b14e48ba4b..ca16c08b572 100644 --- a/pkgs/development/compilers/fpc/default.nix +++ b/pkgs/development/compilers/fpc/default.nix @@ -1,6 +1,6 @@ -{ lib, stdenv, fetchurl, gawk, fetchpatch }: +{ lib, stdenv, fetchurl, gawk, fetchpatch, undmg, cpio, xar, darwin, libiconv }: -let startFPC = import ./binary.nix { inherit stdenv fetchurl; }; in +let startFPC = import ./binary.nix { inherit stdenv fetchurl undmg cpio xar lib; }; in stdenv.mkDerivation rec { version = "3.2.2"; @@ -11,7 +11,12 @@ stdenv.mkDerivation rec { sha256 = "85ef993043bb83f999e2212f1bca766eb71f6f973d362e2290475dbaaf50161f"; }; - buildInputs = [ startFPC gawk ]; + buildInputs = [ startFPC gawk ] + ++ lib.optionals stdenv.isDarwin [ + libiconv + darwin.apple_sdk.frameworks.CoreFoundation + ]; + glibc = stdenv.cc.libc.out; # Patch paths for linux systems. Other platforms will need their own patches. @@ -29,8 +34,18 @@ stdenv.mkDerivation rec { # 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" + # Replace the `codesign --remove-signature` command with a custom script, since `codesign` is not available + # in nixpkgs + substituteInPlace fpcsrc/compiler/Makefile \ + --replace \ + "\$(CODESIGN) --remove-signature" \ + "${./remove-signature.sh}" \ + --replace "ifneq (\$(CODESIGN),)" "ifeq (\$(OS_TARGET), darwin)" ''; + NIX_LDFLAGS = lib.optionalString + stdenv.isDarwin (with darwin.apple_sdk.frameworks; "-F${CoreFoundation}/Library/Frameworks"); + makeFlags = [ "NOGDB=1" "FPC=${startFPC}/bin/fpc" ]; installFlags = [ "INSTALL_PREFIX=\${out}" ]; @@ -41,6 +56,11 @@ stdenv.mkDerivation rec { 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 = { @@ -52,6 +72,6 @@ stdenv.mkDerivation rec { homepage = "https://www.freepascal.org"; maintainers = [ maintainers.raskin ]; license = with licenses; [ gpl2 lgpl2 ]; - platforms = platforms.linux; + platforms = platforms.unix; }; } diff --git a/pkgs/development/compilers/fpc/remove-signature.sh b/pkgs/development/compilers/fpc/remove-signature.sh new file mode 100755 index 00000000000..9fed8ab057c --- /dev/null +++ b/pkgs/development/compilers/fpc/remove-signature.sh @@ -0,0 +1,3 @@ +source $stdenv/setup + +codesign_allocate -r -i "$1" -o "$1"