From d3f8d98df7e2afb5f264a46f526cf21db0b22b58 Mon Sep 17 00:00:00 2001 From: Etienne Laurin Date: Tue, 21 Feb 2023 01:35:54 -0700 Subject: [PATCH] 7zz: cross-compile for mingw --- pkgs/tools/archivers/7zz/default.nix | 44 ++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/pkgs/tools/archivers/7zz/default.nix b/pkgs/tools/archivers/7zz/default.nix index 150230f775a4..841d2acc2017 100644 --- a/pkgs/tools/archivers/7zz/default.nix +++ b/pkgs/tools/archivers/7zz/default.nix @@ -56,8 +56,45 @@ stdenv.mkDerivation rec { patches = [ ./fix-build-on-darwin.patch ]; patchFlags = [ "-p0" ]; + postPatch = lib.optionalString stdenv.hostPlatform.isMinGW '' + find . \( -iname '*.cpp' -o -iname '*.h' -o -iname '*.c' -o -iname '*.rc' \) -print0 \ + | xargs -0 sed -i ' + s/// + s/// + s/// + s/// + s/// + s/// + s/// + s/// + s/// + s/// + s/// + s/// + s/// + s/// + s/// + s/// + s/// + /#include/ s|\\|/|g + ' + find . -iname '*mak*' -print0 \ + | xargs -0 sed -i ' + s/-lUser32/-luser32/g + s/-lOle32/-lole32/g + s/-lGdi32/-lgdi32/g + s/-lComctl32/-lcomctl32/g + s/-lComdlg32/-lcomdlg32/g + ' + substituteInPlace CPP/7zip/7zip_gcc.mak C/7zip_gcc_c.mak \ + --replace windres.exe ${stdenv.cc.targetPrefix}windres + ''; + NIX_CFLAGS_COMPILE = lib.optionals stdenv.isDarwin [ "-Wno-deprecated-copy-dtor" + ] ++ lib.optionals stdenv.hostPlatform.isMinGW [ + "-Wno-conversion" + "-Wno-unused-macros" ]; inherit makefile; @@ -73,7 +110,8 @@ stdenv.mkDerivation rec { # aarch64-darwin so we don't need additional changes for it ++ lib.optionals stdenv.isDarwin [ "MACOSX_DEPLOYMENT_TARGET=10.16" ] # it's the compression code with the restriction, see DOC/License.txt - ++ lib.optionals (!enableUnfree) [ "DISABLE_RAR_COMPRESS=true" ]; + ++ lib.optionals (!enableUnfree) [ "DISABLE_RAR_COMPRESS=true" ] + ++ lib.optionals (stdenv.hostPlatform.isMinGW) [ "IS_MINGW=1" "MSYSTEM=1" ]; nativeBuildInputs = lib.optionals useUasm [ uasm ]; @@ -84,7 +122,7 @@ stdenv.mkDerivation rec { installPhase = '' runHook preInstall - install -Dm555 -t $out/bin b/*/7zz + install -Dm555 -t $out/bin b/*/7zz${stdenv.hostPlatform.extensions.executable} install -Dm444 -t $out/share/doc/${pname} ../../../../DOC/*.txt runHook postInstall @@ -109,7 +147,7 @@ stdenv.mkDerivation rec { # the unRAR compression code is disabled by default lib.optionals enableUnfree [ unfree ]; maintainers = with maintainers; [ anna328p peterhoeg jk ]; - platforms = platforms.unix; + platforms = platforms.unix ++ platforms.windows; mainProgram = "7zz"; }; }