From a50ca4a0a224a2e0c94de629a20cdb53a879e765 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?T=C3=B6r=C3=B6k=20Edwin?= <edwin@etorok.net>
Date: Wed, 29 Jul 2015 00:19:24 +0300
Subject: [PATCH] libstatgrab: unbreak musl

---
 srcpkgs/libstatgrab/patches/configure-musl.patch | 13 +++++++++++++
 srcpkgs/libstatgrab/patches/os_info-musl.patch   | 13 +++++++++++++
 srcpkgs/libstatgrab/template                     |  7 ++++++-
 3 files changed, 32 insertions(+), 1 deletion(-)
 create mode 100644 srcpkgs/libstatgrab/patches/configure-musl.patch
 create mode 100644 srcpkgs/libstatgrab/patches/os_info-musl.patch

diff --git a/srcpkgs/libstatgrab/patches/configure-musl.patch b/srcpkgs/libstatgrab/patches/configure-musl.patch
new file mode 100644
index 00000000000..81975d0cf16
--- /dev/null
+++ b/srcpkgs/libstatgrab/patches/configure-musl.patch
@@ -0,0 +1,13 @@
+fix build failure with musl libc
+
+--- configure.ac	2015-07-28 23:01:23.742669306 -0300
++++ configure.ac	2015-07-28 23:01:42.039440565 -0300
+@@ -609,7 +609,7 @@
+ 	[openbsd*], [
+ 		AC_DEFINE(OPENBSD, , [Building on OpenBSD])
+ 	],
+-	[linux-gnu*], [
++	[linux-gnu*|linux-musl*], [
+ 		AC_DEFINE(LINUX, , [Building on GNU/Linux])
+ 		AM_CONDITIONAL(SETUIDBINS, true)
+ 		BIN_OWNER="root"
diff --git a/srcpkgs/libstatgrab/patches/os_info-musl.patch b/srcpkgs/libstatgrab/patches/os_info-musl.patch
new file mode 100644
index 00000000000..a6fb5a63239
--- /dev/null
+++ b/srcpkgs/libstatgrab/patches/os_info-musl.patch
@@ -0,0 +1,13 @@
+musl doesn't support _SC_LONG_BIT, just use the value from limits.h
+
+--- src/libstatgrab/os_info.c	2015-07-28 23:27:05.860119689 -0300
++++ src/libstatgrab/os_info.c	2015-07-28 23:27:22.931906262 -0300
+@@ -472,7 +472,7 @@
+ 		host_info_buf->bitwidth = 64;
+ 	}
+ 	else {
+-		host_info_buf->bitwidth = sysconf(_SC_LONG_BIT); // well, maybe 64-bit disabled 128-bit system o.O
++		host_info_buf->bitwidth = LONG_BIT;
+ 	}
+ 	host_info_buf->host_state = sg_unknown_configuration;
+ # endif
diff --git a/srcpkgs/libstatgrab/template b/srcpkgs/libstatgrab/template
index f4d305884fb..404d1a7367b 100644
--- a/srcpkgs/libstatgrab/template
+++ b/srcpkgs/libstatgrab/template
@@ -1,9 +1,10 @@
 # Template file for 'libstatgrab'
 pkgname=libstatgrab
 version=0.91
-revision=1
+revision=2
 build_style=gnu-configure
 configure_args="--disable-static"
+hostmakedepends="autoconf"
 makedepends="ncurses-devel"
 short_desc="Library being useful interface to system statistics"
 maintainer="Juan RP <xtraeme@voidlinux.eu>"
@@ -12,6 +13,10 @@ license="LGPL-2.1, GPL-2"
 distfiles="http://www.mirrorservice.org/sites/ftp.i-scream.org/pub/i-scream/${pkgname}/${pkgname}-${version}.tar.gz"
 checksum=03e9328e4857c2c9dcc1b0347724ae4cd741a72ee11acc991784e8ef45b7f1ab
 
+pre_configure() {
+	autoconf
+}
+
 libstatgrab-devel_package() {
 	depends="${sourcepkg}-${version}_${revision}"
 	short_desc+=" -- development files"