From b9b44cd82caceeb638cc6a862b5bb90b93ad6c6a Mon Sep 17 00:00:00 2001
From: Khem Raj <raj.khem@gmail.com>
Date: Sat, 5 Jan 2013 19:53:10 -0800

---
 aclocal.m4   | 2 ++
 configure.in | 8 ++++++--
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/aclocal.m4 b/aclocal.m4
index 2115204..2a9a802 100644
--- a/aclocal.m4
+++ b/aclocal.m4
@@ -7,6 +7,8 @@ dnl --------------------------------------------------------------------------
 AC_DEFUN(AF_PATH_INCLUDE,
 [AC_PATH_PROGS($1,$2,$3,$4)
 if test -n "$$1"; then
+  AH_TEMPLATE([HAVE_$1], [Have $2])
+  AH_TEMPLATE([PATH_$1], [Have $2])
   AC_DEFINE(HAVE_$1,1,[define if you have $1])
   AC_DEFINE_UNQUOTED(PATH_$1, "$$1", [define if you have $1])
   HAVE_$1=1
diff --git a/configure.in b/configure.in
index 25d7c4e..44a1c8b 100644
--- a/configure.in
+++ b/configure.in
@@ -324,13 +324,15 @@ AC_PROG_CC
 cat > pietest.c <<EOF
 int main(void) { return 0; }
 EOF
+AF_tmp_ldflags="$LDFLAGS"
+AF_tmp_cflags="$CFLAGS"
 CFLAGS=-fPIE
 LDFLAGS=-pie
 DAEMON_CFLAGS=
 DAEMON_LDFLAGS=
 AC_MSG_CHECKING([whether gcc -fPIE works])
-AC_RUN_IFELSE([AC_LANG_PROGRAM([[]], [[int main(void) {return 0;}]])],
-	      [gcc_supports_pie=yes], [gcc_supports_pie=no], [gcc_supports_pie=no])
+AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[int main(void) {return 0;}]])],
+	       [gcc_supports_pie=yes], [gcc_supports_pie=no], [gcc_supports_pie=no])
 AC_MSG_RESULT([$gcc_supports_pie])
 if test $gcc_supports_pie = yes ; then
 	DAEMON_CFLAGS="-fPIE"
@@ -339,6 +341,8 @@ fi
 rm -f pietest.c
 AC_SUBST(DAEMON_CFLAGS)
 AC_SUBST(DAEMON_LDFLAGS)
+CFLAGS="${AF_tmp_cflags}"
+LDFLAGS="${AF_tmp_ldflags}"
 
 #
 # Enable ability to access value in external env variable
