aboutsummaryrefslogtreecommitdiff
# Contributor: Wojtek Kosior <kwojtus@protonmail.com>

# TODO Maybe enable more languages? And pack them separately?

_target=arm-linux-gnueabi
pkgname=${_target}-gcc
pkgver=6.3.0
pkgrel=1
pkgdesc="The GNU Compiler Collection - cross compiler for ARM GNU/Linux EABI target"
arch=('i686' 'x86_64')
license=('GPL-3' 'LGPL-3' 'custom:GCC-Exception-3.1' 'FDL-1.3')
url="https://gcc.gnu.org"
groups=('cross-devel')
depends=("${_target}-binutils>=2.28" "${_target}-glibc" 'libmpc')
makedepends=('gcc-ada' 'doxygen' "gcc-source=${pkgver}")
# Check()ing a cross-compiler would require using an emulator (qemu), I believe.
# For now - leave checkdepends commented-out
# checkdepends=('dejagnu' 'inetutils')
options=('!emptydirs' 'staticlibs' '!strip')
source=(COPYING.DOC)
sha512sums=('bea1788b2bdc84f470e459114b871cf4ee991718964a63e18adde65116806d7676484cb30857cf74dece5eef5f96a015ee4a21900e019623e5d3484868b28b7f')

prepare() {
    cd "${srcdir}"
    
    prepare-gcc-source .
    
    # Do not run fixincludes
    sed -i 's@\./fixinc\.sh@-c true@' gcc-${pkgver}/gcc/Makefile.in
    
    # hack! - some configure tests for header files using "$CPP $CPPFLAGS"
    sed -i "/ac_cpp=/s/\$CPPFLAGS/\$CPPFLAGS -O2/" gcc-${pkgver}/{libiberty,gcc}/configure
    
    mkdir gcc_build
}

build() {
  cd "${srcdir}/gcc_build"

  # using -pipe causes spurious test-suite failures
  # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48565
  CFLAGS=${CFLAGS/-pipe/}
  CXXFLAGS=${CXXFLAGS/-pipe/}

  # libmpx seems to be some intel stuff - x86 only
  "${srcdir}/gcc-${pkgver}/configure"                   \
	   --prefix=/usr                                \
	   --libdir=/usr/lib                            \
	   --libexecdir=/usr/libexec                    \
	   --with-local-prefix=/usr/${_target}          \
	   --with-sysroot=/usr/${_target}               \
	   --with-build-sysroot=/usr/${_target}         \
	   --with-as=/usr/bin/${_target}-as             \
	   --with-ld=/usr/bin/${_target}-ld             \
	   --with-native-system-header-dir=/include     \
	   --with-bugurl=https://issues.hyperbola.info/ \
	   --enable-languages=c,c++,lto                 \
	   --enable-shared                              \
	   --enable-threads=posix                       \
	   `[[ $_target =~ (i686)|(x86_64) ]] && 
	       echo --enable-libmpx`                    \
	   --with-system-zlib                           \
	   --with-isl                                   \
	   --enable-__cxa_atexit                        \
	   --disable-libunwind-exceptions               \
	   --enable-clocale=gnu                         \
	   --disable-libstdcxx-pch                      \
	   --disable-libssp                             \
	   --enable-gnu-unique-object                   \
	   --enable-linker-build-id                     \
	   --enable-lto                                 \
	   --enable-plugin                              \
	   --enable-install-libiberty                   \
	   --with-linker-hash-style=gnu                 \
	   --enable-gnu-indirect-function               \
	   --disable-multilib                           \
	   --disable-werror                             \
	   --enable-checking=release                    \
	   --disable-nls                                \
	   --target=${_target}
  
  make
}

# maybe check() using qemu?

package() {
  cd "${srcdir}/gcc_build"

  make DESTDIR="${pkgdir}" install-gcc                          \
       install-target-{libgcc,libstdc++-v3,libgomp,libquadmath}
  
  # TODO I'm not sure about this stripping. Everybody seems to be doing it a different way...
  # I commented out all 2>/dev/null to be able to see what's going on. Uncomment them once
  # everything works as it should :)
  
  # strip target binaries
  find "${pkgdir}/usr/lib/gcc/${_target}/" "${pkgdir}/usr/${_target}/lib" \
       -type f -and \( -name \*.a -or -name \*.o \)                       \
       -exec ${_target}-strip $STRIP_STATIC '{}' + 2>/dev/null

  find "${pkgdir}/usr/lib/gcc/${_target}/" "${pkgdir}/usr/${_target}/lib" \
       -not -name 'libgcc_s.so' -name \*.so -type f                       \
       -exec ${_target}-strip $STRIP_SHARED '{}' + 2>/dev/null

  # strip host binaries
  find "${pkgdir}/usr/bin/" "${pkgdir}/usr/lib/gcc/${_target}/"           \
       -type f -executable -exec strip $STRIP_BINARIES '{}' + 2>/dev/null
       
  # many packages expect this symlink
  ln -s "${_target}-gcc" "${pkgdir}/usr/bin/${_target}-cc"

  # POSIX conformance launcher scripts for c89 and c99
  cat > "${pkgdir}/usr/bin/${_target}-c89" <<"EOF"
#!/bin/sh
fl="-std=c89"
for opt; do
  case "$opt" in
    -ansi|-std=c89|-std=iso9899:1990) fl="";;
    -std=*) echo "`basename $0` called with non ANSI/ISO C option $opt" >&2
	    exit 1;;
  esac
done
exec gcc $fl ${1+"$@"}
EOF
sed -i "s|exec gcc|exec ${_target}-gcc|" "${pkgdir}/usr/bin/${_target}-c89"

  cat > "${pkgdir}/usr/bin/${_target}-c99" <<"EOF"
#!/bin/sh
fl="-std=c99"
for opt; do
  case "$opt" in
    -std=c99|-std=iso9899:1999) fl="";;
    -std=*) echo "`basename $0` called with non ISO C99 option $opt" >&2
	    exit 1;;
  esac
done
exec gcc $fl ${1+"$@"}
EOF
sed -i "s|exec gcc|exec ${_target}-gcc|" "${pkgdir}/usr/bin/${_target}-c99"

  chmod 755 "${pkgdir}/usr/bin/${_target}"-c{8,9}9
 
  # Remove man documents that conflict with host version
  rm -rf ${pkgdir}/usr/share/man/man7

  # Remove unused dirs
  rm -rf ${pkgdir}/usr/share/{info,gcc-${pkgver}}

  # Add licenses
  install -m755 -d "${pkgdir}/usr/share/licenses/${_target}-gcc"
  install -m644 "${srcdir}/gcc-${pkgver}"/COPYING{3{,.LIB},.RUNTIME} "${srcdir}/COPYING.DOC" \
	  "${pkgdir}/usr/share/licenses/${_target}-gcc"
}