libpfm: Fix windows build

This commit is contained in:
t4ccer 2023-09-02 11:27:56 -06:00
parent ea472482d4
commit a08a688b37
No known key found for this signature in database
GPG key ID: 19E5A2D8B1E43F19
2 changed files with 41 additions and 10 deletions

View file

@ -1,16 +1,30 @@
{ lib, stdenv, fetchurl
{ lib
, stdenv
, fetchurl
, enableShared ? !stdenv.hostPlatform.isStatic
, windows
}:
stdenv.mkDerivation (rec {
stdenv.mkDerivation (finalAttrs: {
version = "4.13.0";
pname = "libpfm";
src = fetchurl {
url = "mirror://sourceforge/perfmon2/libpfm4/${pname}-${version}.tar.gz";
url = "mirror://sourceforge/perfmon2/libpfm4/libpfm-${finalAttrs.version}.tar.gz";
sha256 = "sha256-0YuXdkx1VSjBBR03bjNUXQ62DG6/hWgENoE/pbBMw9E=";
};
# Don't install libpfm.so on windows as it doesn't exist
# This target is created only if `ifeq ($(SYS),Linux)` passes
patches = [ ./fix-windows.patch ];
# Upstream uses "WINDOWS" instead of "Windows" which is incorrect
# See: https://github.com/NixOS/nixpkgs/pull/252982#discussion_r1314346216
postPatch = ''
substituteInPlace config.mk examples/Makefile \
--replace '($(SYS),WINDOWS)' '($(SYS),Windows)'
'';
makeFlags = [
"PREFIX=${placeholder "out"}"
"LDCONFIG=true"
@ -19,6 +33,9 @@ stdenv.mkDerivation (rec {
];
env.NIX_CFLAGS_COMPILE = "-Wno-error";
env.CONFIG_PFMLIB_SHARED = if enableShared then "y" else "n";
buildInputs = lib.optional stdenv.hostPlatform.isWindows windows.libgnurx;
meta = with lib; {
description = "Helper library to program the performance monitoring events";
@ -29,11 +46,7 @@ stdenv.mkDerivation (rec {
(PMU) of modern processors.
'';
license = licenses.gpl2;
maintainers = [ maintainers.pierron ];
platforms = platforms.linux;
maintainers = with maintainers; [ pierron t4ccer ];
platforms = platforms.linux ++ platforms.windows;
};
} // lib.optionalAttrs ( ! enableShared )
{
CONFIG_PFMLIB_SHARED = "n";
}
)
})

View file

@ -0,0 +1,18 @@
diff --git a/lib/Makefile b/lib/Makefile
index 5ca71e3..cd0717f 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -428,11 +428,13 @@ install:
-mkdir -p $(DESTDIR)$(LIBDIR)
$(INSTALL) -m 644 $(ALIBPFM) $(DESTDIR)$(LIBDIR)
ifeq ($(CONFIG_PFMLIB_SHARED),y)
+ifeq ($(SYS),Linux)
$(INSTALL) $(SLIBPFM) $(DESTDIR)$(LIBDIR)
cd $(DESTDIR)$(LIBDIR); $(LN) $(SLIBPFM) $(VLIBPFM)
cd $(DESTDIR)$(LIBDIR); $(LN) $(SLIBPFM) libpfm.$(SOLIBEXT)
-$(LDCONFIG)
endif
+endif
tags:
$(CTAGS) -o $(TOPDIR)/tags --tag-relative=yes $(SRCS) $(INCDEP)