scripts/patch-renumber.sh
author "Benoît Thébaudeau" <benoit.thebaudeau@advansee.com>
Fri Jan 27 13:31:16 2012 +0100 (2012-01-27)
changeset 2854 a70abdbfa342
parent 1623 f935634ef900
permissions -rwxr-xr-x
complibs/cloog: fix linking with libm

In Ubuntu 11.04 and 11.10, the default options for ld have changed.
--no-copy-dt-needed-entries and --as-needed are now enabled by default, which
causes errors like:

[EXTRA] Checking CLooG/ppl
[DEBUG] ==> Executing: 'make' '-j3' '-s' 'check'
[ALL ] Making check in .
[ALL ] config.status: creating include/cloog/cloog-config.h
[ALL ] config.status: include/cloog/cloog-config.h is unchanged
[ALL ] libtool: link: i686-build_pc-linux-gnu-gcc -Wall -fomit-frame-pointer
-pipe -o cloog cloog.o -L/<snip>/build/static/lib ./.libs/libcloog.a -lm
/<snip>/build/static/lib/libppl_c.a /<snip>/build/static/lib/libpwl.a
/<snip>/build/static/lib/libppl.a /<snip>/build/static/lib/libgmpxx.a
/<snip>/build/static/lib/libgmp.a -lstdc++
[ALL ] /usr/bin/ld: /<snip>/build/static/lib/libppl.a(MIP_Problem.o):
undefined reference to symbol 'sqrt@@GLIBC_2.0'
[ALL ] /usr/bin/ld: note: 'sqrt@@GLIBC_2.0' is defined in DSO
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../i386-linux-gnu/libm.so so try adding
it to the linker command line
[ALL ] /usr/lib/gcc/i686-linux-gnu/4.6.1/../../../i386-linux-gnu/libm.so:
could not read symbols: Invalid operation
[ALL ] collect2: ld returned 1 exit status
[ERROR] make[2]: *** [cloog] Error 1
[ERROR] make[1]: *** [check-recursive] Error 1

See:
https://wiki.ubuntu.com/NattyNarwhal/ToolchainTransition

This patch fixes these errors by placing '-lm' at the right place on the command
line as libppl requires libm when linking cloog.

Signed-off-by: "Benoît Thébaudeau" <benoit.thebaudeau@advansee.com>
     1 #!/bin/sh
     2 # Yes, this intends to be a true POSIX script file.
     3 set -e
     4 
     5 myname="$0"
     6 
     7 # Parse the tools' paths configuration
     8 # It is expected that this script is only to be run from the
     9 # source directory of crosstool-NG, so it is trivial to find
    10 # paths.sh (we can't use  ". paths.sh", as POSIX states that
    11 # $PATH should be searched for, and $PATH most probably doe
    12 # not include "."), hence the "./".
    13 . "./paths.sh"
    14 
    15 doUsage() {
    16   cat <<_EOF_
    17 Usage: ${myname} <src_dir> <dst_dir> <base> <inc> [sed_re]
    18     Renumbers all patches found in 'src_dir', starting at 'base', with an
    19     increment of 'inc', and puts the renumbered patches in 'dst_dir'.
    20     Leading digits are replaced with the new indexes, and a subsequent '_'
    21     is replaced with a '-'.
    22     If 'sed_re' is given, it is interpreted as a valid sed expression, and
    23     is be applied to the patch name.
    24     If the environment variable FAKE is set to 'y', then nothing gets done,
    25     the command to run is only be printed, and not executed (so you can
    26     check beforehand).
    27     'dst_dir' must not yet exist.
    28     Eg.:
    29       patch-renumber.sh patches/gcc/4.2.3 patches/gcc/4.2.4 100 10
    30       patch-renumber.sh /some/dir/my-patches patches/gcc/4.3.1 100 10 's/(all[_-])*(gcc[-_])*//;'
    31 _EOF_
    32 }
    33 
    34 [ $# -lt 4 -o $# -gt 5 ] && { doUsage; exit 1; }
    35 
    36 src="${1}"
    37 dst="${2}"
    38 cpt="${3}"
    39 inc="${4}"
    40 sed_re="${5}"
    41 if [ ! -d "${src}" ]; then
    42     printf "%s: '%s': not a directory\n" "${myname}" "${src}"
    43     exit 1
    44 fi
    45 if [ -d "${dst}" ]; then
    46     printf "%s: '%s': directory already exists\n" "${myname}" "${dst}"
    47     exit 1
    48 fi
    49 
    50 Q=
    51 if [ -n "${FAKE}" ]; then
    52     printf "%s: won't do anything: FAKE='%s'\n" "${myname}" "${FAKE}"
    53     Q="echo"
    54 fi
    55 
    56 ${Q} mkdir -pv "${dst}"
    57 for p in "${src}/"*.patch*; do
    58     [ -e "${p}" ] || { echo "No such file '${p}'"; exit 1; }
    59     newname="$(printf "%03d-%s"                                     \
    60                       "${cpt}"                                      \
    61                       "$( basename "${p}"                           \
    62                           |"${sed}" -r -e 's/^[[:digit:]]+[-_]//'   \
    63                                        -e "${sed_re}"               \
    64                         )"                                          \
    65               )"
    66     ${Q} cp -v "${p}" "${dst}/${newname}"
    67     cpt=$((cpt+inc))
    68 done