# GNU C Compiler
# Required to use a "known good version" of the compiler or to support languages different than C or C++
[buildout]
extends =
  ../gettext/buildout.cfg
  ../gmp/buildout.cfg
  ../patch/buildout.cfg
  ../perl/buildout.cfg
  ../tar/buildout.cfg
  ../binutils/buildout.cfg

parts =
  gcc-8.2

[gcc-common]
recipe = slapos.recipe.cmmi
shared = true
url = http://ftp.gnu.org/gnu/gcc/gcc-${:version}/gcc-${:version}.tar.xz
pre-configure =
  set %(location)s/bin
  mkdir -p $1
  ln -s ${binutils:location}/bin/ld $1/ld
# remove "dependency_libs=' -lz'" line  (-lz not needed anymore because the internal zlib was used)
  sed -i '/^libbacktrace\.la:/{ N; s,$,\n\tsed -i /^dependency_libs=/d $@,; }' libbacktrace/Makefile.in
configure-options =
  --disable-bootstrap
  --disable-multilib
  --with-gmp=${gmp:location}
  --with-mpfr=${mpfr:location}
  --with-mpc=${mpc:location}
  --enable-languages="c,c++,fortran"
  --with-isl=${isl:location}
  --with-ld=@@LOCATION@@/bin/ld
  --with-as=${binutils:location}/bin/as
  --with-internal-zlib
post-install =
  cd '%(location)s/bin'
  ln -s gcc cc
  rm ld
  for x in `for x in %(location)s/lib*/*.so; do echo $${x%%/*}; done |sort -u`
  do set $1:$x "$2 -rpath=$x"
  done
  cat <<EOF >ld
  #!/bin/sh -e
  for x; do case \$x in -rpath|-rpath=*)
    set -- "\$@" $2
    ! break
    ;;
  esac; done && export LD_RUN_PATH=\$${LD_RUN_PATH:+\$LD_RUN_PATH:}$${1#:}
  exec ${binutils:location}/bin/ld "\$@"
  EOF
  chmod +x ld
environment =
  LDFLAGS=-Wl,-rpath=${gmp:location}/lib -Wl,-rpath=${isl:location}/lib -Wl,-rpath=${mpc:location}/lib -Wl,-rpath=${mpfr:location}/lib
  PATH=${binutils:location}/bin:${gettext:location}/bin:${perl:location}/bin:${tar:location}/bin:%(PATH)s

[gcc-5.5]
<= gcc-common
version = 5.5.0
md5sum = 0f70424213b4a1113c04ba66ddda0c1f
# make install does not work when several core are used
make-targets = install -j1
patch-binary = ${patch:location}/bin/patch
patch-options = -p1
patches =
  ${:_profile_base_location_}/libsanitizer_Use_pre-computed_size_of_struct_ustat_for_Linux.patch#1e5f33e89f9fe1ca3e406eabcc621762

[gcc-8.2]
<= gcc-common
version = 8.2.0
md5sum = 4ab282f414676496483b3e1793d07862
patch-binary = ${patch:location}/bin/patch
patch-options = -p1
# glibc-2.31-libsanitizer comes from https://github.com/spack/spack/pull/15403
patches =
  ${:_profile_base_location_}/glibc-2.31-libsanitizer-1.patch
  ${:_profile_base_location_}/glibc-2.31-libsanitizer-2.patch

[gcc-minimal]
<= gcc-5.5
configure-options =
  --disable-bootstrap
  --disable-multilib
  --with-gmp=${gmp:location}
  --with-mpfr=${mpfr:location}
  --with-mpc=${mpc:location}
  --enable-languages=c
  --without-isl
  --without-cloog
environment =
  LDFLAGS=-Wl,-rpath=${gmp:location}/lib -Wl,-rpath=${mpc:location}/lib -Wl,-rpath=${mpfr:location}/lib
  PATH=${perl:location}/bin:${tar:location}/bin:%(PATH)s
