Ticket #11970: trac_11970-readline.patch

File trac_11970-readline.patch, 17.7 KB (added by jhpalmieri, 7 years ago)

patch for readline spkg. For review only.

  • SPKG.txt

    # HG changeset patch
    # User Leif Leonhardy <not.really@online.de>
    # Date 1325629504 28800
    # Node ID e92e10c8d59f3c7b25fdffbb444ded3cc10a27f1
    # Parent  9e9cac87cb1f304a033fae9a87fbb8ee94203e65
    #11970: Support Ubuntu 11.10 by adding the library libreadline depends
    on (libtermcap or a replacement) to the shared library, i.e. link
    against it, such that it appears in libreadline's DT_NEEDED tags.
    This is currently done by patching `src/shlib/Makefile.in`; we could
    also do this [conditionally] in `spkg-install`, probably by also
    performing some tests to check whether that (and which library) is
    needed.  It's likely to also fix the previous "undefined symbol" error
    on Arch Linux (although currently our readline 6.2 works well without
    this; we previously instead used the system's libreadline on that
    platform).
    
    Do not make the static libraries executable.
    
    Further clean-up to `spkg-install`, add comments and some more
    messages.  All error messages now start with "Error", and go to
    stderr. Also consistently use the shell's built-in `test` (`[[
    ... ]]`), which is faster and more reliable.
    
    diff --git a/SPKG.txt b/SPKG.txt
    a b Website: http://tiswww.case.edu/php/chet 
    2727
    2828 * GNU patch
    2929
     30 * libtermcap (or libncurses or libtinfo), but not Sage's one,
     31   since we only build a static version. I.e., the system has
     32   to provide one of these.
     33
    3034== Special Update/Build Instructions ==
    3135
    3236 * Deleted some files from the doc directory from the standard distro,
    3337   since it took tons of space; didn't delete anything else.
    34  * Work around some MacOSX dynamic lib flags
     38 * Work around some MacOSX dynamic lib flags.
    3539 * When self-tests are added upstream, we may have to set up
    3640   variables like CFLAGS in the script spkg-check: imitate the
    37    settings in spkg-install.
     41   settings in spkg-install.  For self-tests, when we use the system's
     42   version of libreadline (e.g. [Open]SuSE or Arch Linux), we have to
     43   make sure we don't try to run the test suite in `spkg-check`, since
     44   this wouldn't work (and wouldn't make any sense either).
    3845 * In #11882, we turned off the fixes for Arch Linux and OpenSuSE by
    3946   changing various tests in spkg-install from "if ..." to "if false
    4047   && ...".  When Arch Linux or OpenSuSE are updated, modified
    Website: http://tiswww.case.edu/php/chet 
    4249
    4350== Changelog ==
    4451
     52=== readline-6.2.p3 (Leif Leonhardy, 3 January 2012) ===
     53 * #11970: Support Ubuntu 11.10 by adding the library libreadline depends on
     54   (libtermcap or a replacement) to the shared library, i.e. link against it,
     55   such that it appears in libreadline's DT_NEEDED tags.
     56   This is currently done by patching `src/shlib/Makefile.in`; we could also
     57   do this [conditionally] in `spkg-install`, probably by also performing
     58   some tests to check whether that (and which library) is needed.
     59   It's likely to also fix the previous "undefined symbol" error on Arch Linux
     60   (although currently our readline 6.2 works well without this; we previously
     61   instead used the system's libreadline on that platform).
     62 * Do not make the static libraries executable.
     63 * Further clean-up to `spkg-install`, add comments and some more
     64   messages.  All error messages now start with "Error", and go to
     65   stderr. Also consistently use the shell's built-in `test` (`[[
     66   ... ]]`), which is faster and more reliable.
     67
    4568=== readline-6.2.p2 (Volker Braun, 10 Dec 2011) ===
    4669 * Add configure --libdir (trac #12131).
    4770
  • new file patches/shlib__Makefile.in.patch

    diff --git a/patches/shlib__Makefile.in.patch b/patches/shlib__Makefile.in.patch
    new file mode 100644
    - +  
     1--- src/shlib/Makefile.in       2010-12-28 21:56:21.000000000 +0100
     2+++ src/shlib/Makefile.in       2011-10-28 06:39:23.000000000 +0200
     3@@ -166,7 +166,8 @@
     4 
     5 $(SHARED_READLINE):    $(SHARED_OBJ)
     6        $(RM) $@
     7-       $(SHOBJ_LD) ${SHOBJ_LDFLAGS} ${SHLIB_XLDFLAGS} -o $@ $(SHARED_OBJ) $(SHLIB_LIBS)
     8+       # $(SHOBJ_LD) ${SHOBJ_LDFLAGS} ${SHLIB_XLDFLAGS} -o $@ $(SHARED_OBJ) $(SHLIB_LIBS)
     9+       $(SHOBJ_LD) ${SHOBJ_LDFLAGS} ${SHLIB_XLDFLAGS} -o $@ $(SHARED_OBJ) $(SHLIB_LIBS) $(TERMCAP_LIB)
     10 
     11 $(SHARED_HISTORY):     $(SHARED_HISTOBJ) xmalloc.so xfree.so
     12        $(RM) $@
  • spkg-install

    diff --git a/spkg-install b/spkg-install
    a b  
    11#!/usr/bin/env bash
    22
    33if [[ -z $SAGE_LOCAL ]]; then
    4     echo "SAGE_LOCAL undefined ... exiting"
    5     echo "Maybe run 'sage -sh'?"
     4    echo >&2 "Error: SAGE_LOCAL undefined - exiting..."
     5    echo >&2 "Maybe run 'sage -sh'?"
    66    exit 1
    77fi
    88
    9 if [[ -z $CFLAG64 ]] ; then
    10    CFLAG64=-m64
     9if [[ -z $CFLAG64 ]]; then
     10    CFLAG64=-m64
    1111fi
    1212
    13 # Compile for 64-bit if SAGE64 is set to 'yes'
    14 if [[ $SAGE64 = yes ]] ; then
    15    echo "Building a 64-bit version of Readline"
    16    CFLAGS="$CFLAGS $CFLAG64"
    17    CPPFLAGS="$CPPFLAGS $CFLAG64"
    18    # Some packages may need LDFLAGS and/or ABI set here.
    19    LDFLAGS="$LDFLAGS $CFLAG64"
     13# Compile for 64-bit if SAGE64 is set to 'yes':
     14if [[ $SAGE64 = yes ]]; then
     15    echo "Building a 64-bit version of Readline."
     16    CFLAGS="$CFLAGS $CFLAG64"
     17    CPPFLAGS="$CPPFLAGS $CFLAG64"
     18    # Some packages may need LDFLAGS and/or ABI set here.
     19    LDFLAGS="$LDFLAGS $CFLAG64"
    2020fi
    2121
    22 if [[ $SAGE_DEBUG = yes ]] ; then
    23    CFLAGS="$CFLAGS -g -O0"
     22if [[ $SAGE_DEBUG = yes ]]; then
     23    CFLAGS="$CFLAGS -g -O0"
    2424else
    25    CFLAGS="-g -O2 $CFLAGS"
     25    CFLAGS="-g -O2 $CFLAGS"
    2626fi
    2727
    28 # These are all used by GNU to specify compilers.
     28# NOTE: Do *not* add -L$SAGE_LOCAL/lib to LDFLAGS,
     29#       nor -I$SAGE_LOCAL/include to CPPFLAGS or CFLAGS.
     30#       Sage ships and builds a libtermcap, but only a static one,
     31#       and we actually *want* readline to use the system's
     32#       libtermcap (or libncurses, or libtinfo).
     33#       Readline does not need any [other] headers or libraries
     34#       shipped / installed by Sage, so this is pretty ok.
     35
     36
     37echo "The following environment variables will be exported:"
    2938echo "Using CC=$CC"
    30 
    31 
    32 # Flags which may be set.
    33 echo "The following environment variables will be exported."
    3439echo "Using CFLAGS=$CFLAGS"
    3540echo "Using CPPFLAGS=$CPPFLAGS"
    3641echo "Using LDFLAGS=$LDFLAGS"
    37 echo "configure scripts and/or makefiles might override these later"
    38 echo " "
     42echo "Configure scripts and/or makefiles might override these later."
     43echo
    3944
    4045export CFLAGS
    4146export CPPFLAGS
    4247export LDFLAGS
    4348
    44 # End of pretty general spkg-install file.
    45 # Now do the specific things needed for this package (Readline)
     49# End of pretty generic spkg-install file.
     50# Now do the specific things needed for this package (Readline).
    4651
    4752# OVERWRITE_READLINE=false; export OVERWRITE_READLINE
    4853
    49 # First we check for OpenSUSE 11.x, since there bash is linked dynamically with a
    50 # more recent readline such that bash crashes when we build Sage's readline, so
     54# First we check for OpenSUSE 11.x, since there bash is linked dynamically with
     55# a potentially more recent readline such that bash crashes when we build Sage's
     56# readline (or more precisely Sage's version is found along LD_LIBRARY_PATH), so
    5157# we work around this for now by not building Sage's version and instead using
    5258# the system's one.
     59#
     60# Since Sage's readline version (6.2) is meanwhile (or at the moment) current,
     61# there are no problems building it on OpenSuSE (and Arch Linux) as well, so
     62# we can bypass the work-arounds.  This might change once these operating
     63# systems are again ahead of Sage w.r.t. their readline version.
    5364
    54 if [ -f /etc/SuSE-release ]; then
    55     echo "OpenSuSE detected"
    56     # #11882: bypass this test for OpenSuSE.
     65if [[ -f /etc/SuSE-release ]]; then
     66    echo "OpenSuSE or SuSE Linux detected."
     67    # #11882: Bypass this work-around for OpenSuSE.
    5768    #
    5869    # Note that "-q" doesn't work with Solaris' non-POSIX grep
    5970    # in the default path, but we're certainly on Linux here:
    6071    if false && grep -q 11\\. /etc/SuSE-release 2>/dev/null; then
    61         echo "OpenSuSE 11 detected"
    62         if [ -d /usr/include/readline/ ]; then
    63             echo "The development version of libreadline is installed -> copying"
    64             # Note that "cp -a" isn't POSIX, but again: We're on Linux.
    65             # ("uname -p" gives "unknown" on at least some Linuces, so we
    66             # better use the more portable "-m".)
    67             if [ "`uname -m`" = "x86_64" ]; then
    68                 cp -af /lib64/libreadline.so.6* "$SAGE_LOCAL"/lib
    69             else
    70                 cp -af /lib/libreadline.so.6* "$SAGE_LOCAL"/lib
    71             fi
    72             if [ $? -ne 0 ]; then
    73                 echo "Error copying the system's libreadline"
    74                 exit 1
    75             fi
    76             ln -snf libreadline.so.6 "$SAGE_LOCAL"/lib/libreadline.so
    77             if [ $? -ne 0 ]; then
    78                 echo "Error creating symbolic link to libreadline.so.6"
    79                 exit 1
    80             fi
    81             cp -rf /usr/include/readline "$SAGE_LOCAL"/include
    82             if [ $? -ne 0 ]; then
    83                 echo "Error copying the system's readline header files"
    84                 exit 1
    85             fi
    86             exit 0
     72        echo "OpenSuSE 11 detected."
     73        if [[ -d /usr/include/readline/ ]]; then
     74            echo "The development version of libreadline is installed => copying..."
     75            # Note that "cp -a" isn't POSIX, but again: We're on Linux.
     76            # ("uname -p" gives "unknown" on at least some Linuces, so we
     77            # better use the more portable "-m".)
     78            if [[ "`uname -m`" = x86_64 ]]; then
     79                cp -af /lib64/libreadline.so.6* "$SAGE_LOCAL"/lib
     80            else
     81                cp -af /lib/libreadline.so.6* "$SAGE_LOCAL"/lib
     82            fi
     83            if [[ $? -ne 0 ]]; then
     84                echo >&2 "Error copying the system's libreadline."
     85                exit 1
     86            fi
     87            ln -snf libreadline.so.6 "$SAGE_LOCAL"/lib/libreadline.so
     88            if [[ $? -ne 0 ]]; then
     89                echo >&2 "Error creating symbolic link to libreadline.so.6."
     90                exit 1
     91            fi
     92            cp -rf /usr/include/readline "$SAGE_LOCAL"/include
     93            if [[ $? -ne 0 ]]; then
     94                echo >&2 "Error copying the system's readline header files."
     95                exit 1
     96            fi
     97            # Copying succeeded, nothing else to be done.
     98            exit 0
    8799        else
    88             echo "No readline headers found. Please install OpenSuSE's development"
    89             echo "version of libreadline 6.x since building the version currently"
    90             echo "shipped with Sage would break your shell (bash). Sorry."
    91             exit 1
     100            echo >&2 "Error: No readline headers found. Please install OpenSuSE's development"
     101            echo >&2 "version of libreadline 6.x since building the version currently shipped"
     102            echo >&2 "with Sage would break your shell (bash). Sorry."
     103            exit 1
    92104            # # This variable is only set to "true" on openSUSE 11.1.
    93105            # OVERWRITE_READLINE="true"; export OVERWRITE_READLINE
    94106        fi
    95107    else
    96         # echo "... but not OpenSuSE 11 -> building Sage's version of libreadline."
    97         echo "Building Sage's version of readline 6.2 anyway..."
     108        if false; then
     109            echo "... but not OpenSuSE 11 => building Sage's version of libreadline."
     110        else
     111            echo "Building Sage's version of readline 6.2 anyway, since it is assumed"
     112            echo "to be current and to not break your dynamically linked bash..."
     113            echo "(Please report if this is no longer the case.)"
     114        fi
    98115    fi
    99116fi
    100117
    101 # #11882: bypass this test for Arch Linux.
     118# #11882: Bypass this test / work-around for Arch Linux since it apparently
     119#         is no longer needed, at least at the moment (October 2011).
    102120#
    103121# We also check for Arch Linux, since it crashes with "undefined symbol: PC".
    104122# If anyone knows a better way to fix this, please do.
    105 if [ -f /etc/arch-release ]; then
    106     echo "Arch Linux detected"
     123# [This is likely to be fixed by putting libtermcap or libncurses into
     124#  the NEEDED tags of our shared libreadline. -leif (October 2011)]
     125if [[ -f /etc/arch-release ]]; then
     126    echo "Arch Linux detected."
    107127fi
    108 if false && [ -f /etc/arch-release ]; then
    109     if [ -f "/lib/libreadline.so.6" ]; then
    110         echo "Copying over system's libreadline (version 6.x)."
    111         cp -af /lib/libreadline.so.6* "$SAGE_LOCAL"/lib
    112         if [ $? -ne 0 ]; then
    113             echo "Error copying the system's libreadline"
    114             exit 1
    115         fi
    116         ln -snf libreadline.so.6 "$SAGE_LOCAL"/lib/libreadline.so
    117         if [ $? -ne 0 ]; then
    118             echo "Error creating symbolic link to libreadline.so.6"
    119             exit 1
    120         fi
    121         # We shouldn't have to copy the headers...
    122         # (On Arch Linux, these are installed by default.)
    123         exit 0
    124     elif [ -f "/lib/libreadline.so.5" ]; then
    125         # We might have only an older version of libreadline
    126         echo "Couldn't find a system copy of libreadline 6.x, only 5.x."
    127         echo "Building Sage's more recent version of libreadline."
     128if false && [[ -f /etc/arch-release ]]; then
     129    if [[ -f "/lib/libreadline.so.6" ]]; then
     130        echo "Copying over system's libreadline (version 6.x)..."
     131        cp -af /lib/libreadline.so.6* "$SAGE_LOCAL"/lib
     132        if [[ $? -ne 0 ]]; then
     133            echo >&2 "Error copying the system's libreadline."
     134            exit 1
     135        fi
     136        ln -snf libreadline.so.6 "$SAGE_LOCAL"/lib/libreadline.so
     137        if [[ $? -ne 0 ]]; then
     138            echo >&2 "Error creating symbolic link to libreadline.so.6."
     139            exit 1
     140        fi
     141        # We shouldn't have to copy the headers...
     142        # (On Arch Linux, these are installed by default.)
     143        exit 0
     144    elif [[ -f "/lib/libreadline.so.5" ]]; then
     145        # We might have only an older version of libreadline.
     146        echo "Couldn't find a system copy of libreadline 6.x, only 5.x."
     147        echo "Building Sage's more recent version of libreadline..."
    128148    else
    129         echo "Could not find a system copy of libreadline 5.x or 6.x."
    130         echo "This is abnormal, so we better stop here..."
    131         exit 1
     149        echo >&2 "Error: Could not find a system copy of libreadline 5.x or 6.x."
     150        echo >&2 "This is abnormal, so we better stop here..."
     151        exit 1
    132152    fi
    133153fi
    134154
     155
    135156cd src/
    136157
     158echo "Applying patches to upstream source..."
    137159for patch in ../patches/*.patch; do
    138160    patch -p1 <"$patch"
    139     if [ $? -ne 0 ]; then
    140         echo >&2 "Error applying '$patch'"
     161    if [[ $? -ne 0 ]]; then
     162        echo >&2 "Error applying '$patch'."
    141163        exit 1
    142164    fi
    143165done
    144166
     167echo "Configuring readline..."
    145168./configure --prefix="$SAGE_LOCAL" --libdir="$SAGE_LOCAL/lib"
    146 if [ $? -ne 0 ]; then
    147   echo "Error configuring readline."
    148   exit 1
    149 fi
    150 
    151 $MAKE
    152 if [ $? -ne 0 ]; then
    153     echo "Error building readline."
     169if [[ $? -ne 0 ]]; then
     170    echo >&2 "Error configuring readline."
    154171    exit 1
    155172fi
    156173
    157 echo "'make' was successful.  Deleting old readline headers and libs"
    158 echo "before running 'make install'..."
    159 rm -rf "$SAGE_LOCAL"/include/readline/ "$SAGE_LOCAL"/lib/libreadline.*
    160 if [ $? -ne 0 ]; then
    161     echo "Error removing old version of readline."
     174echo "Now building static and shared readline libraries..."
     175$MAKE
     176if [[ $? -ne 0 ]]; then
     177    echo >&2 "Error building readline."
    162178    exit 1
    163179fi
    164180
    165 $MAKE install
    166 if [ $? -ne 0 ]; then
    167     echo "Error installing readline."
     181echo "Build succeedeed.  Deleting old readline headers and libs"
     182echo "before installing the new ones..."
     183# (Note; Actually also readline does this by itself, but doing it
     184# here, too, doesn't hurt either.)
     185rm -rf "$SAGE_LOCAL"/include/readline/ "$SAGE_LOCAL"/lib/libreadline.*
     186if [[ $? -ne 0 ]]; then
     187    echo >&2 "Error removing old version of readline."
    168188    exit 1
    169189fi
    170190
    171 if [ "$UNAME" = "Darwin" ]; then
    172   DYLIB_NAME="$SAGE_LOCAL"/lib/libreadline.dylib
    173 elif [ "$UNAME" = "CYGWIN" ]; then
    174   # It is of course very lame that readline names the file .dll.a, but that's what it does.
    175   DYLIB_NAME="$SAGE_LOCAL"/lib/libreadline.dll.a
    176 elif [ "$UNAME" = "OpenBSD" ]; then
    177   DYLIB_NAME="$SAGE_LOCAL"/lib/libreadline.so.6.2  # Untested. David Kirkby, 11th November 2010
    178 elif [ "$UNAME" = "FreeBSD" ]; then
    179   DYLIB_NAME="$SAGE_LOCAL"/lib/libreadline.so.6
    180 elif [ "$UNAME" = "HP-UX" ]; then
    181   DYLIB_NAME="$SAGE_LOCAL"/lib/libreadline.sl.6
    182 else
    183   DYLIB_NAME="$SAGE_LOCAL"/lib/libreadline.so
     191echo "Now installing the new readline headers and libraries..."
     192$MAKE install
     193if [[ $? -ne 0 ]]; then
     194    echo >&2 "Error installing readline."
     195    exit 1
    184196fi
    185197
    186 # Make sure that the install worked, despite whatever the error
    187 # code of build was.
    188 if [ -f "$DYLIB_NAME" -a -f "$SAGE_LOCAL"/lib/libreadline.a ]; then
    189   # Fix permissions.
    190   echo "Fixing permissions..."
    191   chmod 755 "$SAGE_LOCAL"/lib/libreadline.*
    192   chmod 755 "$SAGE_LOCAL"/lib/libhistory.*
    193   exit 0
     198case "$UNAME" in
     199    Darwin)
     200        DYLIB_NAME=libreadline.dylib;;
     201    CYGWIN)
     202        # It is of course very lame that readline names the file .dll.a, but that's what it does.
     203        DYLIB_NAME=libreadline.dll.a;;
     204    OpenBSD)
     205        # Untested. (David Kirkby, 11th November 2010)
     206        # Extension changed from 6.1 to 6.2; still untested. (October 2011)
     207        DYLIB_NAME=libreadline.so.6.2;;
     208    FreeBSD)
     209        DYLIB_NAME=libreadline.so.6;;
     210    HP-UX)
     211        DYLIB_NAME=libreadline.sl.6;;
     212    *)  # e.g. "Linux" or "SunOS"
     213        DYLIB_NAME=libreadline.so
     214esac
     215
     216# Make sure that the install worked, despite whatever the
     217# exit code of 'make' or 'make install' was:
     218if [[ -f "$SAGE_LOCAL/lib/$DYLIB_NAME" && -f "$SAGE_LOCAL"/lib/libreadline.a ]]; then
     219    # Both the shared and the static library are present, i.e.
     220    # have successfully been (re)installed.
     221    # Fix permissions:
     222    echo "Fixing permissions of libraries..."
     223    chmod 755 "$SAGE_LOCAL"/lib/libreadline.*
     224    chmod 755 "$SAGE_LOCAL"/lib/libhistory.*
     225    # It's pretty wrong to also make the static library executable:
     226    chmod 644 "$SAGE_LOCAL"/lib/lib{readline,history}.a
     227    exit 0
    194228else
    195   echo "Error: Readline's build claims to have finished, but files that should have been built weren't."
    196   exit 1
     229    # One or both of the readline libraries are missing, i.e.
     230    # haven't been installed.
     231    echo >&2 "Error: Readline's build claims to have finished, but files"
     232    echo >&2 "that should have been built and installed weren't."
     233    echo >&2 "(In particular, libreadline.a or $DYLIB_NAME, or both.)"
     234    exit 1
    197235fi