{% set version="11.2.0" %}
{% set libgfortran_soname="5" %}
{% set binutils_version="2.38.0" %}
{% set glibc_version="2.17" %}  # [not aarch64]
{% set glibc_version="2.26" %}  # [aarch64]

package:
  name: gcc_activation
  version: {{ version }}

source:
  path: .

build:
  number: 0
  skip: True  # [not linux]

requirements:
  build:
    # this dep is for us to be able to use gcc -dumpmachine to get the CBUILD value
    - gcc_impl_{{ target_platform }}

outputs:
  - name: gcc_{{ target_platform }}
    script: install-gcc.sh
    requirements:
      run:
        - gcc_impl_{{ target_platform }} {{ version }}.*
        # for activation of binutils env vars
        - {{ pin_subpackage("binutils_" ~ target_platform, exact=True) }}
        - sysroot_{{ target_platform }}
    run_exports:
      strong:
        - libgcc-ng >={{ version }}
    test:
      requires:
        - sysroot_{{ target_platform }} {{ glibc_version }}
      files:
        - tests
      commands:
        - echo {{ target_platform_u }}
        - echo {{ linux_machine }}
        - ${CC} ${CFLAGS} -Wall tests/aligned_alloc.c -c -o c_aligned.o -v
        - ${CC} ${LDFLAGS} c_aligned.o -o c_aligned
        - ./c_aligned
        # CONDA_BUILD_SYSROOT is defined for clang++ to find correct C++ headers, see issue 8
        - test -z "${CONDA_BUILD_SYSROOT+x}" && echo "CONDA_BUILD_SYSROOT is not set" && exit 1
        - test -d ${CONDA_BUILD_SYSROOT} || exit 1
    about:
      summary: GNU C Compiler (activation scripts)
      home: https://github.com/AnacondaRecipes/gcc_activation-feedstock
      license: BSD-3-Clause
      license_file: LICENSE

  - name: gxx_{{ target_platform }}
    script: install-g++.sh
    requirements:
      run:
        - gxx_impl_{{ target_platform }} {{ version }}.*
        # for activation of gcc env vars
        - {{ pin_subpackage("gcc_" ~ target_platform, exact=True) }}
        # for activation of binutils env vars
        - {{ pin_subpackage("binutils_" ~ target_platform, exact=True) }}
        - sysroot_{{ target_platform }}
    test:
      requires:
        - sysroot_{{ target_platform }} {{ glibc_version }}
      files:
        - tests
      commands:
        - ${CXX} ${CXXFLAGS} -Wall tests/aligned_alloc.cpp -c -o cpp_aligned.o
        - ${CXX} ${LDFLAGS} cpp_aligned.o -o cpp_aligned
        - ./cpp_aligned
        - test -z "${CONDA_BUILD_SYSROOT+x}" && echo "CONDA_BUILD_SYSROOT is not set" && exit 1
        - test -d ${CONDA_BUILD_SYSROOT} || exit 1
    run_exports:
      strong:
        - libstdcxx-ng >={{ version }}
        # Because transitive run_exports do not work:
        - libgcc-ng >={{ version }}
    about:
      summary: GNU C++ Compiler (activation scripts)
      home: https://github.com/AnacondaRecipes/gcc_activation-feedstock
      license: BSD-3-Clause
      license_file: LICENSE

  - name: gfortran_{{ target_platform }}
    script: install-gfortran.sh
    requirements:
      host:
        # So that pin_compatible has something to work with:
        - libgfortran{{ libgfortran_soname }} {{ version }}.*
        - libgfortran-ng
      run:
        - gfortran_impl_{{ target_platform }} {{ version }}.*
        # for activation of gcc env vars:
        - {{ pin_subpackage("gcc_" ~ target_platform, exact=True) }}
        # for activation of binutils env vars:
        - {{ pin_subpackage("binutils_" ~ target_platform, exact=True) }}
        - sysroot_{{ target_platform }}
    run_exports:
      strong:
        - libgfortran{{ libgfortran_soname }} >={{ version }}
        - libgfortran-ng
        # Because transitive run_exports do not work:
        - libgcc-ng >={{ version }}
    test:
      requires:
        - cmake >=3.11
        - make
        - sysroot_{{ target_platform }} {{ glibc_version }}
      commands:
        - ${FC} --version
        - pushd tests/fortomp
        - sh test_fort.sh
      files:
        - tests/fortomp/*
    about:
      summary: GNU Fortran Compiler (activation scripts)
      home: https://github.com/AnacondaRecipes/gcc_activation-feedstock
      license: BSD-3-Clause
      license_file: LICENSE

  - name: binutils_{{ target_platform }}
    version: "{{ binutils_version }}"
    script: install-binutils.sh
    requirements:
      run:
        - binutils_impl_{{ target_platform }} {{ binutils_version }}.*
        - sysroot_{{ target_platform }}
    test:
      requires:
        - sysroot_{{ target_platform }} {{ glibc_version }}
      commands:
        - test -f $LD
    about:
      summary: The GNU Binutils are a collection of binary tools (activation scripts)
      home: https://github.com/AnacondaRecipes/gcc_activation-feedstock
      license: BSD-3-Clause
      license_file: LICENSE

  - name: gcc_bootstrap_{{ target_platform }}
    version: {{ version }}
    requirements:
      host:
        - {{ pin_subpackage("gcc_" ~ target_platform) }}
        - {{ pin_subpackage("gxx_" ~ target_platform) }}
        - {{ pin_subpackage("gfortran_" ~ target_platform) }}
        - {{ pin_subpackage("binutils_" ~ target_platform) }}
      run:
        - libstdcxx-ng >=4.9
        - libgcc-ng >=4.9
    build:
      always_include_files:
        - bin/
        - etc/
        - lib64/
        - lib/
        - libexec/
        - share/
        - {{ cpu_arch }}-conda-linux-gnu/
      missing_dso_whitelist:
        - "*"
    test:
      commands:
        - test -f $PREFIX/bin/{{ cpu_arch }}-conda-linux-gnu-cc
    about:
      summary: GCC bootstrap compilers for building deps
      home: https://github.com/AnacondaRecipes/gcc_activation-feedstock
      license: GPL
      license_file: GPL_LICENSE

about:
  summary: Activation scripts for gcc, g++, gfortran and binutils
  home: https://github.com/AnacondaRecipes/gcc_activation-feedstock
  license: BSD-3-Clause
  license_file: LICENSE

extra:
  recipe-maintainers:
    - katietz
    - isuruf
    - beckermr
