Skip to content

Commit

Permalink
Trac #29345: replace bashisms in m4/sage_spkg_collect.m4, m4/sage_spk…
Browse files Browse the repository at this point in the history
…g_enable.m4, build/pkgs/*/spkg-configure.m4, src/bin/sage-env, build/make/Makefile.in

Autoconf scripts should be POSIX sh rather than bash, but there are a
few bashisms in m4/sage_spkg_collect.m4 and m4/sage_spkg_enable.m4:

  * The quoted newlines `$'\n'`
  * The use of `VAR+=VALUE`

Some of these should be straightforward to fix. The format

{{{
SAGE_BUILT_PACKAGES+="    $SPKG_NAME \\"$'\n'
}}}

can be changed to

{{{
SAGE_BUILT_PACKAGES="$SAGE_BUILT_PACKAGES $SPKG_NAME"
}}}

since the newline is only used to make the `BUILT_PACKAGES` rule in the
resulting Makefile look nice. Changing them to spaces doesn't change
what the rule does. I'm not sure about

{{{
SAGE_PACKAGE_VERSIONS+="vers_$SPKG_NAME = $SPKG_VERSION"$'\n
}}}

and

{{{
SAGE_PACKAGE_DEPENDENCIES+="deps_$SPKG_NAME = $DEPS"$'\n'
}}}

though, because those are inserted verbatim into the Makefile as rules,
and the newlines probably matter.

URL: https://trac.sagemath.org/29345
Reported by: mjo
Ticket author(s): Michael Orlitzky
Reviewer(s): Dima Pasechnik
  • Loading branch information
Release Manager committed Jun 21, 2020
2 parents e8c2f50 + 0e66a0a commit 0527ee7
Show file tree
Hide file tree
Showing 15 changed files with 192 additions and 89 deletions.
16 changes: 7 additions & 9 deletions build/make/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,12 @@ STANDARD_PACKAGE_INSTS = \
$(foreach pkgname,$(STANDARD_PACKAGES),$(inst_$(pkgname)))

# All optional installed packages (triggers the auto-update)
OPTIONAL_INSTALLED_PACKAGES = \
@SAGE_OPTIONAL_INSTALLED_PACKAGES@
OPTIONAL_INSTALLED_PACKAGES = @SAGE_OPTIONAL_INSTALLED_PACKAGES@
OPTIONAL_INSTALLED_PACKAGE_INSTS = \
$(foreach pkgname,$(OPTIONAL_INSTALLED_PACKAGES),$(inst_$(pkgname)))

# All previously installed optional packages that are to be uninstalled
OPTIONAL_CLEANED_PACKAGES = \
@SAGE_OPTIONAL_CLEANED_PACKAGES@
OPTIONAL_CLEANED_PACKAGES = @SAGE_OPTIONAL_CLEANED_PACKAGES@
OPTIONAL_CLEANED_PACKAGES_CLEANS = $(OPTIONAL_CLEANED_PACKAGES:%=%-clean)

# All packages which should be downloaded
Expand Down Expand Up @@ -337,7 +335,7 @@ sagelib-build-deps: \

sagelib: sagelib-build-deps
$(AM_V_at)if [ -z "$$SAGE_INSTALL_FETCH_ONLY" ]; then \
cd $(SAGE_SRC) && source bin/sage-env && source $(SAGE_ROOT)/build/bin/sage-build-env-config && \
cd $(SAGE_SRC) && . bin/sage-env && . $(SAGE_ROOT)/build/bin/sage-build-env-config && \
sage-logger -p 'time $(MAKE) sage' '$(SAGE_LOGS)/sagelib-$(SAGE_VERSION).log'; \
fi

Expand Down Expand Up @@ -560,14 +558,14 @@ endif
#
# $(INST)/<pkgname>-<pkgvers>: <dependencies>
# $(AM_V_at)cd '$SAGE_ROOT' && \\
# source '$SAGE_ROOT/src/bin/sage-env' && \\
# . '$SAGE_ROOT/src/bin/sage-env' && \\
# sage-logger -p '$SAGE_ROOT/build/pkgs/<pkgname>/spkg-install' '$(SAGE_LOGS)/<pkgname>.log'
#
# <pkgname>: $(INST)/<pkgname>-<pkgvers>
#
# <pkgname>-clean:
# -$(AM_V_at)cd '$SAGE_ROOT' && \\
# source '$SAGE_ROOT/src/bin/sage-env' && \\
# . '$SAGE_ROOT/src/bin/sage-env' && \\
# '$SAGE_ROOT/build/pkgs/$PKG_NAME/spkg-uninstall'

# Positional arguments:
Expand All @@ -577,15 +575,15 @@ endif
define SCRIPT_PACKAGE_templ
$$(INST)/$(1)-$(2): $(3)
$(AM_V_at)cd '$$(SAGE_ROOT)' && \
source '$$(SAGE_ROOT)/src/bin/sage-env' && source '$$(SAGE_ROOT)/build/bin/sage-build-env-config' && \
. '$$(SAGE_ROOT)/src/bin/sage-env' && . '$$(SAGE_ROOT)/build/bin/sage-build-env-config' && \
sage-logger -p '$$(SAGE_ROOT)/build/pkgs/$(1)/spkg-install' '$$(SAGE_LOGS)/$(1).log'
touch "$$@"

$(1): $$(INST)/$(1)-$(2)

$(1)-clean:
-$(AM_V_at)cd '$$(SAGE_ROOT)' && \
source '$$(SAGE_ROOT)/src/bin/sage-env' && source '$$(SAGE_ROOT)/build/bin/sage-build-env-config' && \
. '$$(SAGE_ROOT)/src/bin/sage-env' && . '$$(SAGE_ROOT)/build/bin/sage-build-env-config' && \
'$$(SAGE_ROOT)/build/pkgs/$(1)/spkg-uninstall'
-rm -f "$$(INST)/$(1)-$(2)"

Expand Down
67 changes: 58 additions & 9 deletions build/pkgs/cvxopt/spkg-install.in
Original file line number Diff line number Diff line change
@@ -1,20 +1,69 @@
cd src

# Stolen from Gentoo
pkg_libs() {
pkg-config --libs-only-l $* | \
sed -e 's:[ ]-l*\(pthread\|m\)\([ ]\|$\)::g' -e 's:[ ]*$::' | \
tr ' ' '\n' | sort -u | sed -e "s:^-l\(.*\):\1:g" | \
tr '\n' ';' | sed -e 's:;$::'
}
# This is a POSIX (non-bash) compatible version of the same function
# in the Gentoo cvxopt package. It's more general than it needs to
# be right now because we may need to use the "L" and "I" modes in
# the future to support system installations of e.g. suitesparse.
#
# The BLAS_LIB and LAPACK_LIB variables (among others) in cvxopt's
# setup.py are passed in as colon-delimited strings. So, for example,
# if your blas "l" flags are "-lblas -lcblas", then cvxopt wants
# "blas;cblas" for BLAS_LIB.
#
# The following function takes a flag type ("l", "L", or "I") as its
# first argument and a list of packages as its remaining arguments. It
# outputs a list of libraries, library paths, or include paths,
# respectively, for the given packages, retrieved using pkg-config and
# deduplicated, in the appropriate format.
#
cvxopt_output() {
FLAGNAME="${1}"
shift
PACKAGES="${@}"

case "${FLAGNAME}" in
l) PKGCONFIG_MODE="--libs-only-l";;
L) PKGCONFIG_MODE="--libs-only-L";;
I) PKGCONFIG_MODE="--cflags-only-I";;
*) echo "invalid flag name: ${FLAGNAME}"; exit 1;;
esac

CVXOPT_OUTPUT=""
for PKGCONFIG_ITEM in $(pkg-config ${PKGCONFIG_MODE} ${PACKAGES}); do
# First strip off the leading "-l", "-L", or "-I", and replace
# it with a semicolon...
PKGCONFIG_ITEM=";${PKGCONFIG_ITEM#-${FLAGNAME}}"

# Now check to see if this element is already present in the
# list, and skip it if it is. This eliminates multiple entries
# from winding up in the list when multiple package arguments are
# passed to this function.
if [ "${CVXOPT_OUTPUT}" != "${CVXOPT_OUTPUT%${PKGCONFIG_ITEM}}" ]
then
# It was already the last entry in the list, so skip it.
continue
elif [ "${CVXOPT_OUTPUT}" != "${CVXOPT_OUTPUT%${PKGCONFIG_ITEM};*}" ]
then
# It was an earlier entry in the list. These two cases are
# separate to ensure that we can e.g. find ";m" at the end
# of the list, but that we don't find ";metis" in the process.
continue
fi

# It isn't in the list yet, so append it.
CVXOPT_OUTPUT="${CVXOPT_OUTPUT}${PKGCONFIG_ITEM}"
done

# Strip the leading ";" from ";foo;bar" before output.
echo "${CVXOPT_OUTPUT#;}"
}

# configure cvxopt by variables
# Note that *_INC_DIR variables have to be non-empty.
# Compilers don't like "-I ".
export CVXOPT_BLAS_LIB="$(pkg_libs blas)"
export CVXOPT_BLAS_LIB="$(cvxopt_output l blas)"
export CVXOPT_BLAS_LIB_DIR="$(pkg-config --variable=libdir blas)"
export CVXOPT_LAPACK_LIB="$(pkg_libs lapack)"
export CVXOPT_LAPACK_LIB="$(cvxopt_output l lapack)"

if test "x$SAGE_SUITESPARSE_LOCALINSTALL" != "x"; then
export CVXOPT_SUITESPARSE_LIB_DIR="${SAGE_LOCAL}"
Expand Down
28 changes: 28 additions & 0 deletions build/pkgs/fflas_ffpack/patches/fix-ksh-pkgconfig.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
From 33a5ec4977f36ce3a24c9ee824d9dd053b8cea04 Mon Sep 17 00:00:00 2001
From: Dima Pasechnik <dimpase@gmail.com>
Date: Fri, 8 May 2020 15:55:27 +0100
Subject: [PATCH 1/1] remove 1st and last file in .pc file

this causes problem if building with ksh, as they remain, causing a broken .pc file.
---
fflas-ffpack.pc.in | 2 --
1 file changed, 2 deletions(-)

diff --git a/fflas-ffpack.pc.in b/fflas-ffpack.pc.in
index a2618d6..e34a744 100644
--- a/fflas-ffpack.pc.in
+++ b/fflas-ffpack.pc.in
@@ -1,4 +1,3 @@
-/------------------ fflas-ffpack.pc ------------------------
prefix=@prefix@
exec_prefix=@prefix@
libdir=@prefix@/lib
@@ -11,4 +10,3 @@ Version: @VERSION@
Requires: givaro >= 4.0.3
Libs: @PARLIBS@ @PRECOMPILE_LIBS@ @BLAS_LIBS@
Cflags: -I@includedir@ @BLAS_CFLAGS@ @PARFLAGS@ @PRECOMPILE_FLAGS@ @REQUIRED_FLAGS@
-\-------------------------------------------------------
\ No newline at end of file
--
2.26.2

27 changes: 27 additions & 0 deletions build/pkgs/givaro/patches/fix-ksh-pkgconfig.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
From 91dcba743e15288abe69966a5f71704d9adcc57c Mon Sep 17 00:00:00 2001
From: Dima Pasechnik <dimpase@gmail.com>
Date: Fri, 8 May 2020 10:22:57 +0100
Subject: [PATCH 1/1] remove 1st and last lines in givaro.pc.in

---
givaro.pc.in | 2 --
1 file changed, 2 deletions(-)

diff --git a/givaro.pc.in b/givaro.pc.in
index 285b854..af38bf3 100644
--- a/givaro.pc.in
+++ b/givaro.pc.in
@@ -1,4 +1,3 @@
-/------------------ givaro.pc ------------------------
prefix=@prefix@
exec_prefix=@prefix@
libdir=@prefix@/lib
@@ -11,4 +10,3 @@ Version: @VERSION@
Requires:
Libs: -L@libdir@ -lgivaro @LIBS@
Cflags: -I@includedir@ @REQUIRED_FLAGS@
-\-------------------------------------------------------
\ No newline at end of file
--
2.26.2

28 changes: 28 additions & 0 deletions build/pkgs/linbox/patches/fix-ksh-pkgconfig.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
From 52c78df67a08de074991a93b57946b7bd5ea7196 Mon Sep 17 00:00:00 2001
From: Dima Pasechnik <dimpase@gmail.com>
Date: Fri, 8 May 2020 15:53:25 +0100
Subject: [PATCH 1/1] remove redundant 1st and last lines

they remain if the script is run under ksh, leading to broken .pc file
---
linbox.pc.in | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/linbox.pc.in b/linbox.pc.in
index f54285e..eb6835b 100644
--- a/linbox.pc.in
+++ b/linbox.pc.in
@@ -1,4 +1,3 @@
-/------------------ linbox.pc ------------------------
prefix=@prefix@
exec_prefix=@prefix@
libdir=@libdir@
@@ -11,4 +10,4 @@ Version: @VERSION@
Requires: fflas-ffpack >= 2.4.0, givaro >= 4.1.0
Libs: -L${libdir} -llinbox @LINBOXSAGE_LIBS@ @NTL_LIBS@ @MPFR_LIBS@ @FPLLL_LIBS@ @IML_LIBS@ @FLINT_LIBS@ @OCL_LIBS@
Cflags: @DEFAULT_CFLAGS@ -DDISABLE_COMMENTATOR -I${includedir} @NTL_CFLAGS@ @MPFR_CFLAGS@ @FPLLL_CFLAGS@ @IML_CFLAGS@ @FLINT_CFLAGS@
-\-------------------------------------------------------
+
--
2.26.2

3 changes: 2 additions & 1 deletion build/pkgs/lrcalc/spkg-install.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
cd src

# Use newer version of config.guess and config.sub (see Trac #19725)
cp "$SAGE_ROOT"/config/config.* .
cp "$SAGE_ROOT"/config/config.guess .
cp "$SAGE_ROOT"/config/config.sub .

sdh_configure
sdh_make
Expand Down
2 changes: 1 addition & 1 deletion build/pkgs/mpc/spkg-configure.m4
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ SAGE_SPKG_CONFIGURE([mpc], [
AC_MSG_RESULT([no])
AC_CHECK_HEADER(mpc.h, [], [sage_spkg_install_mpc=yes])
dnl mpc_cmp_abs appeared in MPC 1.1.0
AC_SEARCH_LIBS([mpc_cmp_abs], [mpc], [break], [sage_spkg_install_mpc=yes])
AC_SEARCH_LIBS([mpc_cmp_abs], [mpc], [], [sage_spkg_install_mpc=yes])
fi
], [], [], [
if test x$sage_spkg_install_mpc = xyes; then
Expand Down
2 changes: 1 addition & 1 deletion build/pkgs/mpfr/spkg-configure.m4
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ SAGE_SPKG_CONFIGURE([mpfr], [
AC_MSG_RESULT([no])
AC_CHECK_HEADER(mpfr.h, [], [sage_spkg_install_mpfr=yes])
dnl mpfr_free_pool appeared in r11922 (Dec 2017) on MPFR svn
AC_SEARCH_LIBS([mpfr_free_pool], [mpfr], [break], [sage_spkg_install_mpfr=yes])
AC_SEARCH_LIBS([mpfr_free_pool], [mpfr], [], [sage_spkg_install_mpfr=yes])
fi
], [], [], [
if test x$sage_spkg_install_mpfr = xyes; then
Expand Down
2 changes: 1 addition & 1 deletion build/pkgs/mpir/spkg-configure.m4
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ dnl Implement cases for what to do on different options here
AC_CHECK_HEADER(gmp.h, [], [sage_spkg_install_mpir=yes])
AC_CHECK_HEADER(gmpxx.h, [], [sage_spkg_install_mpir=yes])
dnl mpq_cmp_z appeared in GMP 6.1.0 and is used by pynac
AC_SEARCH_LIBS([__gmpq_cmp_z], [gmp], [break],
AC_SEARCH_LIBS([__gmpq_cmp_z], [gmp], [],
[sage_spkg_install_mpir=yes])
SAGE_MP_LIBRARY=mpir
;;
Expand Down
4 changes: 2 additions & 2 deletions build/pkgs/ncurses/spkg-configure.m4
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ SAGE_SPKG_CONFIGURE([ncurses], [
dnl First try checking for ncurses with pkg-config
PKG_CHECK_MODULES([NCURSES], [ncurses >= 6.0], [],
[AC_CHECK_HEADERS([ncurses.h],
[AC_SEARCH_LIBS([wresize], [ncurses tinfo], [break],
[sage_spkg_install_ncurses=yes])],
[AC_SEARCH_LIBS([wresize], [ncurses tinfo], [],
[sage_spkg_install_ncurses=yes])],
[sage_spkg_install_ncurses=yes])],
[sage_spkg_install_ncurses=yes])
])
2 changes: 1 addition & 1 deletion build/pkgs/readline/spkg-configure.m4
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ SAGE_SPKG_CONFIGURE([readline], [
[AC_CHECK_HEADERS([readline/readline.h],
dnl rl_bind_keyseq is not present in macos's readline
dnl and is not present in readline version 4 (the one in OpenBSD)
[AC_SEARCH_LIBS([rl_bind_keyseq], [readline], [break],
[AC_SEARCH_LIBS([rl_bind_keyseq], [readline], [],
[sage_spkg_install_readline=yes])],
[sage_spkg_install_readline=yes])],
[sage_spkg_install_readline=yes])
Expand Down
30 changes: 2 additions & 28 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,6 @@ AC_PREREQ([2.69])
AC_DEFUN([SAGE_VERSION], m4_esyscmd_s([. src/bin/sage-version.sh && echo $SAGE_VERSION]))
AC_INIT([Sage], SAGE_VERSION, [sage-devel@googlegroups.com])

# The following needs to be immediately after calling AC_INIT
#------------------------------------------------------------
# We need to run this configure script with bash
if test -z "$BASH_VERSION"
then
CONFIG_SHELL=`command -v bash`
export CONFIG_SHELL
if $CONFIG_SHELL -c "exit 0"
then
exec $CONFIG_SHELL $0 "$@"
else
AC_MSG_NOTICE([The 'bash' shell is needed to build AC_PACKAGE_NAME])
AC_MSG_NOTICE([All modern systems will have the 'bash' shell installed somewhere])
if test -d /opt/OpenSource/bin
then
AC_MSG_NOTICE([On HP-UX you may try adding /opt/OpenSource/bin to your path])
fi
if test -d /opt/pware/bin
then
AC_MSG_NOTICE([On AIX you may try adding /opt/pware/bin to your path])
fi
AC_MSG_ERROR(['bash' not found])
fi
fi


AC_COPYRIGHT([GPL version 3])
AC_CONFIG_SRCDIR([configure.ac])
Expand Down Expand Up @@ -443,13 +418,12 @@ SAGE_SPKG_COLLECT()
# TODO: fix this in Trac #21524
touch "$SAGE_SRC/bin/sage-env-config"

SAGE_SCRIPTS='\
'
SAGE_SCRIPTS=''
for file in "$SAGE_SRC/bin/"*; do
# Skip files with ".in" extension
ext=${file##*.}
if test "$ext" != in; then
SAGE_SCRIPTS+=" \$(SAGE_LOCAL)${file#$SAGE_SRC} \\"$'\n'
SAGE_SCRIPTS="${SAGE_SCRIPTS} \\$(printf '\n ')\$(SAGE_LOCAL)${file#$SAGE_SRC}"
fi
done

Expand Down
Loading

0 comments on commit 0527ee7

Please sign in to comment.