From 175ab125d4272580957fd804a68a21176ca6d5f3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fran=C3=A7ois=20Revol?= <revol@free.fr>
Date: Sun, 16 Nov 2014 14:50:17 +0100
Subject: configure.ac: Haiku does have a thread-safe getenv

Also force HAVE_PTHREAD.

diff --git a/configure.ac b/configure.ac
index 7f03170..4a25f68 100644
--- a/configure.ac
+++ b/configure.ac
@@ -139,6 +139,7 @@ GPG_DEFAULT=no
 GPGSM_DEFAULT=no
 GPGCONF_DEFAULT=no
 G13_DEFAULT=no
+PTHREAD_LIBS=""
 component_system=None
 have_dosish_system=no
 have_android_system=no
@@ -184,11 +185,16 @@ case "${host}" in
 	    AC_HELP_STRING([--enable-w32-qt], [build GPGME Qt for W32]),
 	    		   build_w32_qt=$enableval)
         ;;
+    *-haiku*)
+	have_thread_safe_getenv=yes
+	# Haiku has it in libroot
+	AC_CHECK_FUNC(pthread_create,have_pthread=yes)
+        ;;
     *)
-	AC_CHECK_LIB(pthread,pthread_create,have_pthread=yes)
-	if test "$have_pthread" = yes; then
-	  AC_DEFINE(HAVE_PTHREAD, ,[Define if we have pthread.])
-	fi
+	save_LIBS="$LIBS"
+	AC_SEARCH_LIBS(pthread_create,pthread,have_pthread=yes)
+	PTHREAD_LIBS="$LIBS"
+	LIBS="$save_LIBS"
 
 	# XXX: Probably use exec-prefix here?
 #	GPG_DEFAULT='/usr/bin/gpg'
@@ -198,6 +204,11 @@ case "${host}" in
 	;;
 esac
 
+if test "$have_pthread" = yes; then
+  AC_DEFINE(HAVE_PTHREAD, ,[Define if we have pthread.])
+fi
+AC_SUBST(PTHREAD_LIBS)
+
 if test "$have_dosish_system" = yes; then
    AC_DEFINE(HAVE_DOSISH_SYSTEM,1,
              [Defined if we run on some of the PCDOS like systems
-- 
1.8.3.4


From 1a7ff2570cc9ed13ac5b94131c44a91b74d7396e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fran=C3=A7ois=20Revol?= <revol@free.fr>
Date: Wed, 19 Nov 2014 21:52:09 +0100
Subject: Makefile.am: replace hardcoded -lpthread by an AC_SUBST


diff --git a/src/Makefile.am b/src/Makefile.am
index 58922f9..c11cbc5 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -188,7 +188,7 @@ libgpgme_pthread_la_LDFLAGS = \
 	@LIBGPGME_LT_CURRENT@:@LIBGPGME_LT_REVISION@:@LIBGPGME_LT_AGE@
 libgpgme_pthread_la_DEPENDENCIES = @LTLIBOBJS@ $(srcdir)/libgpgme.vers
 libgpgme_pthread_la_LIBADD = $(gpgme_res) @LIBASSUAN_LIBS@ @LTLIBOBJS@ \
-	-lpthread @GPG_ERROR_LIBS@
+	@PTHREAD_LIBS@ @GPG_ERROR_LIBS@
 
 if BUILD_W32_GLIB
 libgpgme_glib_la_LDFLAGS = \
diff --git a/tests/gpg/Makefile.am b/tests/gpg/Makefile.am
index 107397b..6575578 100644
--- a/tests/gpg/Makefile.am
+++ b/tests/gpg/Makefile.am
@@ -61,7 +61,7 @@ EXTRA_DIST = initial.test final.test \
 AM_CPPFLAGS = -I$(top_builddir)/src @GPG_ERROR_CFLAGS@
 AM_LDFLAGS = -no-install
 LDADD = ../../src/libgpgme.la
-t_thread1_LDADD = ../../src/libgpgme-pthread.la -lpthread
+t_thread1_LDADD = ../../src/libgpgme-pthread.la @PTHREAD_LIBS@
 
 # We don't run t-genkey in the test suite, because it takes too long
 noinst_PROGRAMS = $(c_tests) t-genkey
-- 
1.8.3.4


From 34d501197541ba7a37d385e064e1f3562546c13a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fran=C3=A7ois=20Revol?= <revol@free.fr>
Date: Wed, 26 Nov 2014 02:24:03 +0100
Subject: gpgme-config.in: replace hardcoded -lpthread by an AC_SUBST


diff --git a/src/gpgme-config.in b/src/gpgme-config.in
index 4be1e08..bf83deb 100644
--- a/src/gpgme-config.in
+++ b/src/gpgme-config.in
@@ -33,7 +33,7 @@ gpg_error_libs="@GPG_ERROR_LIBS@"
 thread_modules=""
 
 @HAVE_PTHREAD_TRUE@thread_modules="$thread_modules pthread"
-libs_pthread="-lpthread"
+libs_pthread="@PTHREAD_LIBS@"
 cflags_pthread=""
 
 # Configure glib.
-- 
1.8.3.4

