7zz: cross-compile for mingw

This commit is contained in:
Etienne Laurin 2023-02-21 01:35:54 -07:00
parent 6c5bf4e060
commit d3f8d98df7

View file

@ -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/<Windows.h>/<windows.h>/
s/<WinIoCtl.h>/<winioctl.h>/
s/<ShlObj.h>/<shlobj.h>/
s/<CommCtrl.h>/<commctrl.h>/
s/<Shlwapi.h>/<shlwapi.h>/
s/<ShObjIdl.h>/<shobjidl.h>/
s/<Psapi.h>/<psapi.h>/
s/<WindowsX.h>/<windowsx.h>/
s/<WinBase.h>/<winbase.h>/
s/<TlHelp32.h>/<tlhelp32.h>/
s/<PrSht.h>/<prsht.h>/
s/<OleCtl.h>/<olectl.h>/
s/<NTSecAPI.h>/<ntsecapi.h>/
s/<MAPI.h>/<mapi.h>/
s/<InitGuid.h>/<initguid.h>/
s/<HtmlHelp.h>/<htmlhelp.h>/
s/<WinVer.h>/<winver.h>/
/#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";
};
}