# 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-10.5

[gcc-common]
recipe = slapos.recipe.cmmi
shared = true
url = https://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
  ${:extra-configure-options}
extra-configure-options =

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-common:os.path.isdir('/usr/lib/arm-linux-gnueabihf') and os.access('/proc/device-tree/model', os.R_OK) and 'OLinuXino' in open('/proc/device-tree/model').read()]
extra-configure-options =
  --with-arch=armv7-a
  --with-fpu=vfp
  --with-float=hard

[gcc-8.5]
<= gcc-common
version = 8.5.0
md5sum = 0c1f625768840187ef3b10adebe8e3b0
patch-binary = ${patch:location}/bin/patch
patch-options = -p1
patches =
  ${:_profile_base_location_}/gcc-libsanitizer-multiple-definition-fsconfig_command.patch#2135c53c901d67ce230f5c94352b7780

[gcc-10.5]
<= gcc-common
version = 10.5.0
md5sum = c7d1958570fbd1cd859b015774b9987a

[gcc-12.3]
<= gcc-common
version = 12.3.0
md5sum = 58a863b2a50e4d42eacc20fec419bc3b