tzdata: enable cross-compilation for Windows

* Additional make flags are needed since some functions do not exist
    or have different names or parameters on Windows.

  * When compiling for Windows, GCC implicitly adds a `.exe` suffix to
    the output file name. A patch is needed for the `install` target
    to locate and install the correct files.

  * The tzdata Makefile contains `zic` and `ZIC` variables. The former
    refers to the path of the program to execute, while the latter
    invokes the former with additional arguments (it is defined as
    `ZIC=$(zic) $(ZFLAGS)`, `ZFLAGS` is normally empty).

    Previously, `ZIC` was overridden, potentially loosing `ZFLAGS`
    arguments. This commit changes it to override `zic` instead.

  * The `zic` program is built and installed as part of the package and
    also executed during the build to translate time-related files. When
    cross-compiling it means that two executables need to be compiled:
    one to get installed and run on the host platform, and another to
    run on the build platform. Instead of renaming files and building a
    temporary executable for the build platform, this commit references
    the build platform's `tzdata.bin` package and runs its `zic`
    program.
This commit is contained in:
Nicolas Benes 2022-10-01 21:00:15 +02:00
parent 2f107ad427
commit 1654dc831c
2 changed files with 26 additions and 12 deletions

View file

@ -0,0 +1,15 @@
diff --git a/Makefile b/Makefile
index a9a989e..4da737b 100644
--- a/Makefile
+++ b/Makefile
@@ -579,8 +579,8 @@ install: all $(DATA) $(REDO) $(MANS)
-t '$(DESTDIR)$(TZDEFAULT)'
cp -f $(TABDATA) '$(DESTDIR)$(TZDIR)/.'
cp tzselect '$(DESTDIR)$(BINDIR)/.'
- cp zdump '$(DESTDIR)$(ZDUMPDIR)/.'
- cp zic '$(DESTDIR)$(ZICDIR)/.'
+ cp zdump.exe '$(DESTDIR)$(ZDUMPDIR)/.'
+ cp zic.exe '$(DESTDIR)$(ZICDIR)/.'
cp libtz.a '$(DESTDIR)$(LIBDIR)/.'
$(RANLIB) '$(DESTDIR)$(LIBDIR)/libtz.a'
cp -f newctime.3 newtzset.3 '$(DESTDIR)$(MANDIR)/man3/.'

View file

@ -17,6 +17,10 @@ stdenv.mkDerivation rec {
sourceRoot = ".";
patches = lib.optionals stdenv.hostPlatform.isWindows [
./0001-Add-exe-extension-for-MS-Windows-binaries.patch
];
outputs = [ "out" "bin" "man" "dev" ];
propagatedBuildOutputs = [];
@ -34,22 +38,17 @@ stdenv.mkDerivation rec {
"CFLAGS+=-DZIC_BLOAT_DEFAULT=\\\"fat\\\""
"cc=${stdenv.cc.targetPrefix}cc"
"AR=${stdenv.cc.targetPrefix}ar"
] ++ lib.optionals stdenv.hostPlatform.isWindows [
"CFLAGS+=-DHAVE_DIRECT_H"
"CFLAGS+=-DHAVE_SYMLINK=0"
"CFLAGS+=-DRESERVE_STD_EXT_IDS"
];
depsBuildBuild = [ buildPackages.stdenv.cc ];
doCheck = false; # needs more tools
installFlags = [ "ZIC=./zic-native" ];
preInstall = ''
mv zic.o zic.o.orig
mv zic zic.orig
make $makeFlags cc=${stdenv.cc.nativePrefix}cc AR=${stdenv.cc.nativePrefix}ar zic
mv zic zic-native
mv zic.o.orig zic.o
mv zic.orig zic
'';
installFlags = lib.optionals (stdenv.buildPlatform != stdenv.hostPlatform) [
"zic=${buildPackages.tzdata.bin}/bin/zic"
];
postInstall =
''