perf: fix musl compatibility
authorFelix Fietkau <nbd@openwrt.org>
Sat, 2 Jan 2016 14:47:57 +0000 (14:47 +0000)
committerFelix Fietkau <nbd@openwrt.org>
Sat, 2 Jan 2016 14:47:57 +0000 (14:47 +0000)
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
SVN-Revision: 48067

package/devel/perf/Makefile
package/devel/perf/musl-compat.h [new file with mode: 0644]

index d6db053173bbb4b6f1ba563386a3dac8c3b2731d..c999229324a2742cd58956f10e54bb7253195fed 100644 (file)
@@ -24,7 +24,7 @@ include $(INCLUDE_DIR)/package.mk
 define Package/perf
   SECTION:=devel
   CATEGORY:=Development
-  DEPENDS:= @USE_GLIBC +libelf1 +libdw +libpthread +librt +binutils
+  DEPENDS:= @!USE_UCLIBC +libelf1 +libdw +libpthread +librt +binutils
   TITLE:=Linux performance monitoring tool
   VERSION:=$(LINUX_VERSION)-$(PKG_RELEASE)
   URL:=http://www.kernel.org
@@ -57,6 +57,10 @@ MAKE_FLAGS = \
        WERROR=0 \
        prefix=/usr
 
+ifdef CONFIG_USE_MUSL
+ MAKE_FLAGS += EXTRA_CFLAGS="-include $(CURDIR)/musl-compat.h -D__UCLIBC__"
+endif
+
 define Build/Compile
        +$(MAKE_FLAGS) $(MAKE) $(PKG_JOBS) \
                -C $(PKG_BUILD_DIR) \
diff --git a/package/devel/perf/musl-compat.h b/package/devel/perf/musl-compat.h
new file mode 100644 (file)
index 0000000..ecfbec6
--- /dev/null
@@ -0,0 +1,62 @@
+#ifndef __PERF_MUSL_COMPAT_H
+#define __PERF_MUSL_COMPAT_H
+
+#include <sys/ioctl.h>
+#include <string.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <syscall.h>
+#include <sched.h>
+
+#undef _IOWR
+#undef _IOR
+#undef _IOW
+#undef _IOC
+#undef _IO
+
+/* Change XSI compliant version into GNU extension hackery */
+#define strerror_r(err, buf, buflen) \
+       (strerror_r(err, buf, buflen) ? NULL : buf)
+
+#define _SC_LEVEL1_DCACHE_LINESIZE -1
+
+static inline long sysconf_wrap(int name)
+{
+       FILE *f;
+       int val;
+
+       switch (name) {
+       case _SC_LEVEL1_DCACHE_LINESIZE:
+               f = fopen("/sys/devices/system/cpu/cpu0/cache/index0/coherency_line_size", "r");
+               if (!f)
+                       return 0;
+
+               if (fscanf(f, "%d", &val) != 1)
+                       return 0;
+
+               fclose(f);
+               return val;
+       default:
+               return sysconf(name);
+       }
+}
+
+#define sysconf(_n) sysconf_wrap(_n)
+
+static inline int compat_sched_getcpu(void)
+{
+#ifdef __NR_getcpu
+       unsigned int val;
+
+       if (syscall(__NR_getcpu, &val))
+               return -1;
+
+       return val;
+#else
+       return -1;
+#endif
+}
+
+#define sched_getcpu compat_sched_getcpu
+
+#endif