From 3f26126aec6a7712634cbc8411ab5bb6bab74579 Mon Sep 17 00:00:00 2001 From: "Tom G. Christensen" Date: Sat, 23 Nov 2013 14:58:45 +0100 Subject: [PATCH] gcc: common settings and functions for gcc package building --- gcc/build.sh.gcc.common | 288 ++++++++++++++++++++++++++++++++++++++++ gcc/build.sh.gcc.cpu | 28 ++++ 2 files changed, 316 insertions(+) create mode 100644 gcc/build.sh.gcc.common create mode 100644 gcc/build.sh.gcc.cpu diff --git a/gcc/build.sh.gcc.common b/gcc/build.sh.gcc.common new file mode 100644 index 0000000..d17973a --- /dev/null +++ b/gcc/build.sh.gcc.common @@ -0,0 +1,288 @@ +# This script defines settings and functions common to all +# gcc packages. It should be included from build.sh. +########################################################### + +# GCC package naming guide +# gcc - c +# gcc-chill - ch +# gcc-c++ - cx +# gcc-g77 - ft +# gcc-gfortran - ft +# gcc-gnat - gn +# gcc-go - go +# gcc-java - jv +# gcc-objc - ob +# gcc-objc++ - ox + +# GCC shared libraries +# 2.95.3: libstdc++.so.2 +# 3.0.4: libstdc++.so.3, libgcc_s.so.1, libobjc.so.1 +# 3.1.1: libstdc++.so.4, libgcc_s.so.1, libobjc.so.1, libg2c.so.0 +# 3.2.3: libstdc++.so.5, libgcc_s.so.1, libobjc.so.1, libg2c.so.0 +# 3.3.6: libstdc++.so.5, libgcc_s.so.1, libobjc.so.1, libg2c.so.0 +# 3.4.6: libstdc++.so.6, libgcc_s.so.1, libobjc.so.1, libg2c.so.0 +# 4.0.4: libstdc++.so.6, libgcc_s.so.1, libobjc.so.1, libgfortran.so.0 +# 4.1.2: libstdc++.so.6, libgcc_s.so.1, libobjc.so.1, libgfortran.so.1, libssp.so.0 +# 4.2.4: libstdc++.so.6, libgcc_s.so.1, libobjc.so.2, libgfortran.so.2, libssp.so.0, libgomp.so.1 +# 4.3.6: libstdc++.so.6, libgcc_s.so.1, libobjc.so.2, libgfortran.so.3, libssp.so.0, libgomp.so.1 + +# Global settings +__configure="$srcdir/$topsrcdir/configure" +make_build_target=bootstrap + +# Define abbreviated version number (for pkgdef) +abbrev_ver=$(echo $version | ${__tr} -d '.') +# Just major.minor, no subminors +majorminor=$(echo $version | cut -d. -f1-2) +abbrev_majorminor=$(echo $majorminor | tr -d '.') +# gcc 2.95 should be 29 +[ $abbrev_majorminor -eq 295 ] && abbrev_majorminor=29 + +# Initialize CPU settings for GCC +. ${BUILDPKG_BASE}/gcc/build.sh.gcc.cpu + +# save main unversioned installdir $prefix as $lprefix +# $prefix will be redefined as the versioned installdir +lprefix=$prefix +prefix=${lprefix}/${topdir}${abbrev_majorminor} + +# In /usr/tgcware/gcc$abbrev_majorminor goes {bin,man,info} +# everything else goes to /usr/tgcware/{lib,libexec,include,share} +# java/gcj has some files in lib that are unversioned and will +# cause conflicts if multiple versions are attempted to be installed + +# Common config args for all GCCs +global_config_args="--prefix=$lprefix --with-local-prefix=$prefix --bindir=${prefix}/bin --mandir=${prefix}/man --infodir=${prefix}/info --disable-nls --enable-shared" + +# Solaris 2.5, 2.5.1 & 2.6 support posix '95 threads +pthreads="--enable-threads=posix95" +# For gcc < 4.0 this is the same as posix +[ $abbrev_majorminor -lt 40 ] && pthreads="--enable-threads=posix" +# For Solaris < 2.5 always use 'solaris' threads +[ ${gnu_os_ver/./} -lt 25 ] && pthreads="--enable-threads=solaris" + +# For gcc < 3.4 we adjust the c++ include path to match gcc > 3.3 +[ $abbrev_majorminor -lt 34 ] && gxxinclude="--with-gxx-include-dir=$lprefix/include/c++/$version" + +# Enable all languages +langs="--enable-languages=c,c++,objc,fortran,ada,obj-c++" +# For gcc < 4.0 fortran is f77 +[ $abbrev_majorminor -lt 40 ] && langs=${langs/fortran/f77} +# For gcc 4.0 fortran is f95 +[ $abbrev_majorminor -eq 40 ] && langs=${langs/fortran/f95} +# No ada for gcc < 3.1 +[ $abbrev_majorminor -lt 31 ] && langs=${langs/,ada/} +# No obj-c++ for gcc < 4.1 +[ $abbrev_majorminor -lt 41 ] && langs=${langs%%,obj-c++} + +# Use Solaris ld by default +linker="--without-gnu-ld --with-ld=/usr/ccs/bin/ld" +# GNU assembler +gnuassembler="--with-gnu-as --with-as=/usr/tgcware/bin/gas" +# Solaris assembler +sunassembler="--without-gnu-as --with-as=/usr/ccs/bin/as" +# For gcc < 3.4 we must use the Solaris assembler or the ada frontend will +# fail to build with symbol scoping issues +# For gcc > 3.3 we use the GNU assembler from binutils +[ $abbrev_majorminor -lt 34 ] && assembler=$sunassembler +[ $abbrev_majorminor -gt 33 ] && assembler=$gnuassembler +# On sparc gcc 4.3.6 fails comparison between stage2 and stage3 when using the +# GNU assembler so for sparc we always use the Solaris assembler +[ "$build_arch" = "sparc" ] && assembler=$sunassembler + +# For gcc 4.0 we need to explicitly disable COMDAT group support +# since configure fails to check if ld also supports it (and it does not) +[ $abbrev_majorminor -eq 40 ] && ac_overrides="gcc_cv_as_comdat_group=no gcc_cv_as_comdat_group_percent=no" + +# For libiconv +hostlibs=(--with-libiconv-prefix=$lprefix) + +# These libraries are needed based on the GCC version being built +withgmp="--with-gmp=$lprefix" +withmpfr="--with-mpfr=$lprefix" +[ $abbrev_majorminor -ge 40 ] && hostlibs+=($withgmp $withmpfr) + +# Assemble a default configure_args +configure_args=($global_config_args $gxxinclude $pthreads "${hostlibs[@]}" $linker $assembler $langs $gcc_cpu) + +# Set a build vendor for gcc > 4.2 +gccbugurl=http://jupiterrise.com/tgcware +gccpkgversion="$pkgdirdesig ${version}-${pkgver}" +[ $abbrev_majorminor -gt 42 ] && configure_args+=(--with-pkgversion="$gccpkgversion" --with-bugurl=$gccbugurl) + +# Solaris 2.6 support was marked obsolete in gcc 4.3.x +[ $abbrev_majorminor -eq 43 -a "$gnu_os_ver" = "2.6" ] && configure_args=(--enable-obsolete "${configure_args[@]}") + +# Default +objdir=all_native + +# For gcc > 3.3 +libsubdir=gcc +# gcc < 3.4 uses gcc-lib +[ $abbrev_majorminor -lt 34 ] && libsubdir=gcc-lib + +# RPATH with just $lprefix since this is where lib goes +# This *may* pose a problem during bootstrap and in that case a two stage bootstrap will be needed. +# This forces all linked objects including libraries (ie. libstdc++.so) to have an RPATH +export LD_OPTIONS="-R$lprefix/lib -R$lprefix/lib/\$ISALIST" + +# As documented ksh or better is needed +export CONFIG_SHELL=/bin/ksh + +# Setup tool path +export PATH=$srcdir/tools:$PATH + +# We set SED explicitly since the fixincludes machinery will +# hardcode the path into an executable and we don't want the +# toolpath from setup_tools() to be there +export SED=${__gsed} + +# Creates tool path +setup_tools() +{ + # Setup tools + # /usr/xpg4/bin/grep mishandles long lines + # use GNU grep instead (/usr/bin/grep would do, but GNU grepisms exists) + # For Java we need GNU diff and GNU find + # For C++/libstdc++ we need c++filt + # GNU sed is not a bad idea either + # Go needs objcopy and does not use the one that configure picks up + # Atleast some configure tests depend on objdump directly + ${__mkdir} -p $srcdir/tools + setdir $srcdir/tools + ${__ln_s} -f /usr/tgcware/bin/grep grep + ${__ln_s} -f /usr/tgcware/bin/diff diff + ${__ln_s} -f /usr/tgcware/bin/find find + ${__ln_s} -f /usr/tgcware/bin/sed sed + ${__ln_s} -f /usr/tgcware/bin/gc++filt c++filt + ${__ln_s} -f /usr/tgcware/bin/gobjcopy objcopy + ${__ln_s} -f /usr/tgcware/bin/gobjdump objdump + ${__ln_s} -f /usr/tgcware/bin/makeinfo makeinfo +} + +# link_helper: redo hardlinks as symlinks +# params: $1 = link target $2... = link names +link_helper() +{ + local target=$1 + local src + shift + cd ${stagedir}${prefix}/${_bindir} + for src in $@ + do + if [ -r $src ]; then + echo "Replacing $src with symlink to $target" + ${__rm} -f $src && ${__ln} -sf ${prefix}/${_bindir}/$target $src + fi + done +} + +# Turn all hardlinks in bin/ into symlinks +redo_bin() +{ + link_helper g++ c++ ${build_arch}-${vendor}-solaris*-c++ ${build_arch}-${vendor}-solaris*-g++ + link_helper gcc ${build_arch}-${vendor}-solaris*-gcc ${build_arch}-${vendor}-solaris*-gcc-$version + link_helper gcj ${build_arch}-${vendor}-solaris${gnu_os_ver}-gcj + link_helper gcjh ${build_arch}-${vendor}-solaris${gnu_os_ver}-gcjh + link_helper gfortran ${build_arch}-${vendor}-solaris*-gfortran + link_helper gccgo ${build_arch}-${vendor}-solaris*-gccgo + link_helper gcc-ar ${build_arch}-${vendor}-solaris*-gcc-ar + link_helper gcc-nm ${build_arch}-${vendor}-solaris*-gcc-nm + link_helper gcc-ranlib ${build_arch}-${vendor}-solaris*-gcc-ranlib +} + +# Rearrange libraries to allow multiple gcc versions +# $1 = archlibdir (subdir under lib where libraries go) +# $2 = gccarchlibdir (subdir in lib/$libsubdir// where libs go) +redo_libs_helper() +{ + local archlibdir=$1 + local gccarchlibdir=$2 + + # For the default case + local backref="../../.." + + if [ -n "$gccarchlibdir" ]; then + gccarchlibdir="/${gccarchlibdir}" + # Need one more backref when using gccarchlibdir + backref="../../../.." + fi + [ -n "$archlibdir" ] && archlibdir="/${archlibdir}" + + mvif() + { + [ -r "$1" ] && mv "$1" "$2" + } + + # Lots of rearranging to do to make multiple gcc versions coexist + # This is based on the rhel6 and Fedora specfiles + # First we need to move all gcc version specific files/libraries to the private versioned + # libdir + FULLPATH=${stagedir}${lprefix}/lib/$libsubdir/${build_arch}-${vendor}-solaris${gnu_os_ver}/${version}${gccarchlibdir} + setdir $FULLPATH + for f in libg2c.a libfrtbegin.a libgfortran.a libgfortran.spec libgomp.a \ + libgomp.spec libffi.a libiberty.a libstdc++.a libsupc++.a \ + libssp.a libssp_nonshared.a libobjc.a libquadmath.a libgo.a \ + libgobegin.a libitm.a libitm.spec libiberty.a libgfortranbegin.a \ + libatomic.a + do + mvif ${backref}${archlibdir}/$f $FULLPATH + done + # Relocate .so files + for f in g2c ffi gcc_s gcc_s_sparcv9 gfortran gomp objc ssp stdc++ \ + quadmath go itm atomic + do + if [ -L ${backref}${archlibdir}/lib$f.so ]; then + # File exists and is a symlink, determine linktarget + # The linktarget is the soname of the library + linktarget=$(elfdump -d ${backref}${archlibdir}/lib$f.so | awk '/SONAME/ { print $4 }') + # Remove the old symlink + ${__rm} -f ${backref}${archlibdir}/lib$f.so + # Create new .so file, note we link not to the full version + # since we want to cheat and allow newer compilers to upgrade + # them as long as the soversion is matching + ${__ln_s} ${backref}${archlibdir}/$linktarget lib$f.so + fi + done + + # For Ada + if [ -d $FULLPATH/adalib ]; then + cd $FULLPATH/adalib + for f in gnarl gnat + do + if [ -L lib$f.so ]; then + # File exists and is a symlink, determine linktarget + # The linktarget is the soname of the library + linktarget=$(elfdump -d lib$f.so | awk '/SONAME/ { print $4 }') + # Relocate linktarget to main libdir + mvif $linktarget ${backref}/..${archlibdir} + # Remove the old symlink + ${__rm} -f lib$f.so + # Create new symlinks to linktarget + ${__ln_s} ${backref}/..${archlibdir}/$linktarget lib$f.so + ${__ln_s} ${backref}/..${archlibdir}/$linktarget $linktarget + fi + done + + # Ada will not work without these symlinks + mkdir -p ${stagedir}${prefix}/lib/$libsubdir/${build_arch}-${vendor}-solaris${gnu_os_ver}/${version}${gccarchlibdir} + cd ${stagedir}${prefix}/lib/$libsubdir/${build_arch}-${vendor}-solaris${gnu_os_ver}/${version}${gccarchlibdir} + ${__ln_s} ${backref}/../../lib/$libsubdir/${build_arch}-${vendor}-solaris${gnu_os_ver}/${version}${gccarchlibdir}/adainclude . + ${__ln_s} ${backref}/../../lib/$libsubdir/${build_arch}-${vendor}-solaris${gnu_os_ver}/${version}${gccarchlibdir}/adalib . + fi +} + +# Wrapper around redo_libs helper +redo_libs() +{ + case $build_arch in + i386|sparc) + redo_libs_helper "" "" + ;; + *) + echo "redo_libs: unknown $build_arch" + ;; + esac +} + +# vim: set sw=4 sts=4 et ft=sh : # diff --git a/gcc/build.sh.gcc.cpu b/gcc/build.sh.gcc.cpu new file mode 100644 index 0000000..70c3306 --- /dev/null +++ b/gcc/build.sh.gcc.cpu @@ -0,0 +1,28 @@ +# This defines the default cpu options to be passed on to +# gcc and gmp configure scripts ($gcc_cpu and $gmp_host) +# +# The gcc bits depends on the definition of $abbrev_majorminor +# usually provided by the gcc build.sh + +# In case this is used directly from build.sh (like with gmp) +abbrev_majorminor=${abbrev_majorminor:-0} + +# Set default arch based on OS minimum cpu required +case "${build_arch}-${gnu_os_ver}" in + i386-2.6) + gcc_arch=i386 + gcc_cpu="--with-arch=$gcc_arch --with-tune=pentium" + gmp_host="i386-${vendor}-solaris${gnu_os_ver}" + ;; + sparc-2.6) + gcc_arch=v7 + gcc_cpu="--with-cpu=$gcc_arch" + gmp_host="sparc-${vendor}-solaris${gnu_os_ver}" + ;; + *) + ;; +esac +# For gcc < 3.4 and x86 there are no arch options +[ $abbrev_majorminor -lt 34 -a "$vendor" = "pc" ] && gcc_cpu= + +# vim: set sw=4 sts=4 et ft=sh : #