From 23d2b366e4aea63d874784f3b86a27f1fc8b5509 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Fri, 3 Apr 2020 15:09:41 -0400 Subject: [PATCH] Trac #29454: hack m4/ppl.m4 to define PPL_LIBS. The upstream AM_PATH_PPL macro gets its LDFLAGS from the ppl-config program, but fails to differentiate between LDFLAGS and LIBS. This ultimately causes "-lppl" to be appended to the command-line in the wrong spot. This commit hacks the macro to additionally define a PPL_LIBS variable in the event that PPL is detected. This allows us to append the flag in the right place, and avoid appending it in the wrong place. --- build/pkgs/ppl/spkg-configure.m4 | 19 ++++++++++++------- m4/ppl.m4 | 23 ++++++++++++++++++++++- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/build/pkgs/ppl/spkg-configure.m4 b/build/pkgs/ppl/spkg-configure.m4 index cc094d67cb9..9b75a46959f 100644 --- a/build/pkgs/ppl/spkg-configure.m4 +++ b/build/pkgs/ppl/spkg-configure.m4 @@ -1,13 +1,18 @@ SAGE_SPKG_CONFIGURE([ppl], [ SAGE_SPKG_DEPCHECK([glpk gmp mpir], [ - # If our dependencies come from the system, then we can use - # the system ppl, too. This macro works sort-of like the + # If our dependencies come from the system, then we can use the + # system ppl, too. This macro works sort-of like the # PKG_CHECK_MODULES macro, defining e.g. PPL_CFLAGS when a - # suitable version of PPL is detected. But notably, it doesn't - # define PPL_LIBS. - AM_PATH_PPL([1.2], - [sage_spkg_install_ppl=no], - [sage_spkg_install_ppl=yes]) + # suitable version of PPL is detected. The upstream version fails + # to differentiate between LDFLAGS and LIBS (which is in turn the + # fault of the ppl-config program), leading to argument-order + # problems on the command line. Our version of the macro + # defines PPL_LIBS separately so that we can distinguish the two. + AM_PATH_PPL([1.2], [ + LIBS="$LIBS $PPL_LIBS" + sage_spkg_install_ppl=no + ], + [sage_spkg_install_ppl=yes]) ], [ # Some of its dependencies are installed as SPKGs, so install the # ppl SPKG as well. diff --git a/m4/ppl.m4 b/m4/ppl.m4 index caeabbdea48..060c93f394e 100644 --- a/m4/ppl.m4 +++ b/m4/ppl.m4 @@ -76,15 +76,31 @@ then no_ppl=yes else PPL_CPPFLAGS=`$PPL_CONFIG $ppl_config_args --cppflags` - PPL_LDFLAGS=`$PPL_CONFIG $ppl_config_args --ldflags` + PPL_LDFLAGS="" + PPL_LIBS="" + for flag in $($PPL_CONFIG $ppl_config_args --ldflags); do + dnl Check if each "ldflag" starts with -l or not. The ones that do + dnl start with -l are libs and belong in PPL_LIBS, the others belong + dnl in PPL_LDFLAGS. The LDFLAGS and LIBS variables get appended at + dnl different locations in the link command, so the distinction is + dnl not academic. + if test "x${flag#-l}" = "x$flag"; then + dnl this flag doesn't start with -l + PPL_LDFLAGS="$PPL_LDFLAGS $flag" + else + PPL_LIBS="$PPL_LIBS $flag" + fi + done ppl_config_version="`$PPL_CONFIG $ppl_config_args --version`" if test "x$enable_ppltest" = xyes then ac_save_CPPFLAGS="$CPPFLAGS" ac_save_LDFLAGS="$LDFLAGS" + ac_save_LIBS="$LIBS" CPPFLAGS="$CPPFLAGS $PPL_CPPFLAGS" LDFLAGS="$PPL_LDFLAGS $LDFLAGS" + LIBS="$LIBS $PPL_LIBS" dnl Now check if the installed PPL is sufficiently new. dnl (Also sanity checks the results of ppl-config to some extent.) @@ -224,6 +240,7 @@ main() { CPPFLAGS="$ac_save_CPPFLAGS" LDFLAGS="$ac_save_LDFLAGS" + LIBS="$ac_save_LIBS" fi fi @@ -247,6 +264,7 @@ else echo "*** Could not run PPL test program, checking why..." CPPFLAGS="$CPPFLAGS $PPL_CPPFLAGS" LDFLAGS="$LDFLAGS $PPL_LDFLAGS" + LIBS="$LIBS $PPL_LIBS" AC_TRY_LINK([ #include using namespace Parma_Polyhedra_Library; @@ -276,13 +294,16 @@ using namespace Parma_Polyhedra_Library; ]) CPPFLAGS="$ac_save_CPPFLAGS" LDFLAGS="$ac_save_LDFLAGS" + LIBS="$ac_save_LIBS" fi fi PPL_CPPFLAGS="" PPL_LDFLAGS="" + PPL_LIBS="" ifelse([$3], , :, [$3]) fi AC_SUBST(PPL_CPPFLAGS) AC_SUBST(PPL_LDFLAGS) +AC_SUBST(PPL_LIBS) rm -f conf.ppltest ])