From: Nathan Phillip Brink <binki@gentoo.org>
Subject: Fix perl being automagic and to be safe with
	LDFLAGS=-Wl,--as-needed.

--- a/configure.in
+++ b/configure.in
@@ -1033,37 +1033,38 @@
 dnl
 dnl Perl support?
 dnl
-AC_ARG_WITH(perl,
-[  --with-perl[=PATH_TO_PERL_EXE]       Compile with perl support.],
-[ 
-	perlexe=$withval
-],
-	perlexe=yes
-)
-
-if test "x$perlexe" = "xyes"; then
-	perlexe=perl
-fi
-
-if test "x$perlexe" = "xno"; then
+AC_ARG_WITH([perl], [AS_HELP_STRING([--with-perl=[PATH_TO_PERL_EXE]], [Compile with perl support.])],
+	[], [with_perl=maybe])
+AS_IF([test "x$with_perl" = "xno"],
+	[
 	AC_MSG_CHECKING(whether to support Perl)
 	AC_MSG_RESULT(no)
-else
-	AC_CHECK_PROG(PERLPROG, $perlexe, "yes", "no")
-	AC_MSG_CHECKING(whether to support Perl)
-	if test $PERLPROG != "yes" ; then 
+	],
+	[
+	with_perl_errormsg="You specified --with-perl=$with_perl but I could not find a working perl. Please run ./configure with --without-perl or specify a path to a working perl executable."
+	AS_IF([test "x$with_perl" = "xyes" -o "x$with_perl" = "xmaybe"],
+		[perlexe=perl],
+		[perlexe="$with_perl"])
+	dnl Allow a full path to be specified in --with-perl
+	AS_IF([test -x "$perlexe"],
+		[PERLPROG=yes],
+		[AC_CHECK_PROG(PERLPROG, $perlexe, "yes", "no")])
+	AC_MSG_CHECKING([whether to support Perl])
+	if test $PERLPROG != "yes" ; then
+		AS_IF([test "x$with_perl" != "xmaybe"],
+			[AC_MSG_ERROR([$with_perl_errormsg])])
 		AC_MSG_RESULT(no)
 	else
 		AC_MSG_RESULT(yes)
 		PERLCFLAGS=`$perlexe -MExtUtils::Embed -e ccopts`
-		PERLLDFLAGS=`$perlexe -MExtUtils::Embed -e ldopts`
+		PERLLIBS=`$perlexe -MExtUtils::Embed -e ldopts`
 
 		AC_MSG_CHECKING(whether embedded perl works the way I expect)
 		have_embedded_perl="no"
 		old_CFLAGS="$CFLAGS"
-		old_LDFLAGS="$LDFLAGS"
+		old_LIBS="$LIBS"
 		CFLAGS="$CFLAGS $PERLCFLAGS"
-		LDFLAGS="$LDFLAGS $PERLLDFLAGS"
+		LIBS="$LIBS $PERLLIBS"
 		AC_TRY_RUN([
 #include <EXTERN.h>
 #include <perl.h>
@@ -1101,20 +1102,22 @@
 have_embedded_perl="no",:)
 
 		CFLAGS="$old_CFLAGS"
-		LDFLAGS="$old_LDFLAGS"
+		LIBS="$old_LIBS"
 		if test $have_embedded_perl = "yes" ; then
 			AC_MSG_RESULT(yes)
 			AC_DEFINE(HAVE_PERL)
 			AC_DEFINE(PERLCFLAGS)
-			AC_DEFINE(PERLLDFLAGS)
+			AC_DEFINE(PERLLIBS)
 			PERLDOTOH="perl.o"
 		else
+			AS_IF([test "x$with_perl" != "xmaybe"],
+				[AC_MSG_ERROR([$with_perl_errormsg])])
 			PERLCFLAGS=""
-			PERLLDFLAGS=""
+			PERLLIBS=""
 			AC_MSG_RESULT(no, sorry)
 			PERLCFLAGS=""
-			PERLLDFLAGS=""
+			PERLLIBS=""
 		fi
 	fi
-fi
+	])
 
@@ -1392,7 +1395,7 @@
 AC_SUBST(TCLLIBS)
 AC_SUBST(PERLDOTOH)
 AC_SUBST(PERLCFLAGS)
-AC_SUBST(PERLLDFLAGS)
+AC_SUBST(PERLLIBS)
 AC_SUBST(WSERV_BIN)
 AC_SUBST(WSERV_INSTALL)
 AC_SUBST(bindir)

--- a/source/Makefile.in
+++ b/source/Makefile.in
@@ -38,7 +38,7 @@
 epic5: $(OBJECTS)
 	sh info.c.sh
 	$(CC) $(CFLAGS) $(INCLUDES) -c info.c
-	$(CC) $(CFLAGS) $(LDFLAGS) -o epic5 $(OBJECTS) info.o @PERLLDFLAGS@ @TCLLIBS@ @RUBYLIBS@ $(LIBS)
+	$(CC) $(CFLAGS) $(LDFLAGS) -o epic5 $(OBJECTS) info.o @PERLLIBS@ @TCLLIBS@ @RUBYLIBS@ $(LIBS)
 	$(RM) info.c info.o
 clean::
 	$(RM) epic5 $(OBJECTS)
