configure: add workaround for systems without zlib.pc
authorFelipe Contreras <felipe.contreras@gmail.com>
Mon, 12 May 2014 03:09:32 +0000 (22:09 -0500)
committerDavid Bremner <david@tethera.net>
Sat, 21 Jun 2014 19:40:39 +0000 (16:40 -0300)
Some systems (e.g. FreeBSD) might not have installed the appropriate
pkg-config file as they should. We can workaround the issue by creating
the .pc file they should have distributed.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
compat/.gitignore [new file with mode: 0644]
compat/gen_zlib_pc.c [new file with mode: 0644]
configure

diff --git a/compat/.gitignore b/compat/.gitignore
new file mode 100644 (file)
index 0000000..107ba17
--- /dev/null
@@ -0,0 +1 @@
+zlib.pc
diff --git a/compat/gen_zlib_pc.c b/compat/gen_zlib_pc.c
new file mode 100644 (file)
index 0000000..198a727
--- /dev/null
@@ -0,0 +1,18 @@
+#include <stdio.h>
+#include <zlib.h>
+
+static const char *template =
+       "prefix=/usr\n"
+       "exec_prefix=${prefix}\n"
+       "libdir=${exec_prefix}/lib\n"
+       "\n"
+       "Name: zlib\n"
+       "Description: zlib compression library\n"
+       "Version: %s\n"
+       "Libs: -lz\n";
+
+int main(void)
+{
+       printf(template, ZLIB_VERSION);
+       return 0;
+}
index 9bde2eb72b0e6811505391b0c759a9345f38313a..99ab74dcfb97c515a8c2b96ffd7d75f551652e0c 100755 (executable)
--- a/configure
+++ b/configure
@@ -340,6 +340,15 @@ else
     errors=$((errors + 1))
 fi
 
+if ! pkg-config --exists zlib; then
+  ${CC} ${zlib_cflags} -o compat/gen_zlib_pc \
+         "$srcdir"/compat/gen_zlib_pc.c ${zlib_ldflags} > /dev/null 2>&1 &&
+  compat/gen_zlib_pc > compat/zlib.pc &&
+  PKG_CONFIG_PATH="$PKG_CONFIG_PATH":compat &&
+  export PKG_CONFIG_PATH
+  rm -f compat/gen_zlib_pc
+fi
+
 printf "Checking for zlib (>= 1.2.5.2)... "
 have_zlib=0
 if pkg-config --atleast-version=1.2.5.2 zlib; then