Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagesmc
Path: blob/master/build/pkgs/gcc/spkg-install
8817 views
#!/usr/bin/env bash

if [ -z "$SAGE_LOCAL" ]; then
    echo >&2 "SAGE_LOCAL undefined ... exiting"
    echo >&2 "Maybe run 'sage --sh'?"
    exit 1
fi


# Exit on error
set -e

# Build in a separate directory, not in src/ (a.k.a. a VPATH build).
# This is the recommended way to build GCC.
mkdir gcc-build
cd gcc-build


# The ld (linker) on old Darwin systems doesn't understand
# -compatibility_version, it needs -dylib_compatibility_version.
# Similarly for a few more options.  We create an ld wrapper to fix
# these command line options.
if { uname -sr | grep 'Darwin [0-9]\.' ;} &>/dev/null; then
    rm -f "$SAGE_LOCAL/bin/ld"
    LD=`which "${LD:-ld}"`

    echo '#!/bin/bash' >>"$SAGE_LOCAL/bin/ld"
    echo '# ld wrapper generated by the GCC spkg' >>"$SAGE_LOCAL/bin/ld"
    echo >>"$SAGE_LOCAL/bin/ld"
    # Hardcode the path to the "real" ld.
    echo "LD=$LD" >>"$SAGE_LOCAL/bin/ld"

cat >>"$SAGE_LOCAL/bin/ld" <<'EOF'

for arg in "$@"; do
    arg=`echo "$arg" | sed \
        -e 's/^-\(compatibility_version\)/-dylib_\1/' \
        -e 's/^-\(current_version\)/-dylib_\1/' \
        -e 's/^-\(install_name\)/-dylib_\1/' \
    `
    argv=("${argv[@]}" "$arg")
done

exec "$LD" "${argv[@]}"
EOF

    chmod +x "$SAGE_LOCAL/bin/ld"

    # Make GCC use this ld wrapper (found in the $PATH)
    export LD=ld
fi

# On OS X 10.9, g++ and the cdefs.h header are currently incompatible
# Temporary workaround posted at http://trac.macports.org/ticket/41033
if { uname -sr | grep 'Darwin 13\.' ;} &>/dev/null; then
    mkdir -p "$SAGE_LOCAL/include/sys"
    sed 's+defined(__GNUC_STDC_INLINE__)+& \&\& !defined(__cplusplus)+' /usr/include/sys/cdefs.h > "$SAGE_LOCAL/include/sys/cdefs.h"
fi

if [ "$SAGE_CHECK" = yes ]; then
    # Enable internal checks in GCC.  These checks do not affect the
    # binaries produced by GCC, but they do increase the compile time
    # of everything compiled with GCC.
    GCC_CONFIGURE="$GCC_CONFIGURE --enable-checking=yes"
fi

# Use conservative CFLAGS for stage 1 and for the "build" executables
# (these are simple programs needed only internally for the build process).
MAKE="$MAKE CFLAGS_FOR_BUILD=-O0 STAGE1_CFLAGS=-O0"

# Disable bootstrap-debug, since it doesn't work on an OS X 10.4 PPC
# machine, nor on some Solaris machine. bootstrap-debug only does
# additional checks during the build, so it is safe not to use it.
MAKE="$MAKE BUILD_CONFIG="

# Use the assembler/linker specified by $AS/$LD if they differ from the
# default.
if [ -n "$AS" -a "$AS" != "as" ]; then
    CONFIGURE_AS="--with-as=$AS"
fi
if [ -n "$LD" -a "$LD" != "ld" ]; then
    CONFIGURE_LD="--with-ld=$LD"
fi


../src/configure \
    --prefix="$SAGE_LOCAL" \
    --with-local-prefix="$SAGE_LOCAL" \
    --with-gmp="$SAGE_LOCAL" --with-mpfr="$SAGE_LOCAL" --with-mpc="$SAGE_LOCAL" \
    --with-system-zlib \
    --disable-multilib \
    --disable-nls \
    $GCC_CONFIGURE "$CONFIGURE_AS" "$CONFIGURE_LD"

$MAKE

$MAKE install


# Force re-installation of mpir, mpfr and mpc with the GCC we just built.
cd "$SAGE_SPKG_INST"
rm -f mpir-* mpfr-* mpc-*