{% set version = gcc_version %}
{% set chost = gcc_machine ~ "-" ~ gcc_vendor ~ "-linux-gnu-" %}
{% set build_num = 19 %}

package:
  name: gcc_compilers
  version: {{ version }}

source:
  - url: https://ftp.gnu.org/gnu/gcc/gcc-{{ version }}/gcc-{{ version }}.tar.gz
    sha256: ac6b317eb4d25444d87cf29c0d141dedc1323a1833ec9995211b13e1a851261c   # [gcc_version == "12.2.0"]
    sha256: 98438e6cc7294298b474cf0da7655d9a8c8b796421bb0210531c294a950374ed   # [gcc_version == "11.3.0"]
    sha256: ab1974017834430de27fd803ade4389602a7d6ca1362496c57bef384b2a4cb07   # [gcc_version == "10.4.0"]
    sha256: 15b34072105272a3eb37f6927409f7ce9aa0dd1498efebc35f851d6e6f029a4d   # [gcc_version == "9.5.0"]
    sha256: 6e6e0628573d2185727a2dd83211d04a2b2748e4a262099099b9c8064634c9ee   # [gcc_version == "8.5.0"]
    sha256: 4f518f18cfb694ad7975064e99e200fe98af13603b47e67e801ba9580e50a07f   # [gcc_version == "7.5.0"]
    patches:
      - patches/0021-Hardcode-HAVE_ALIGNED_ALLOC-1-in-libstdc-v3-configur.patch
      - patches/0022-cross-compile-older-glibc.patch   # [glibc_version == "2.12" and target_platform != "linux-64"]
      - patches/old-allow-commands-in-main-specfile.patch                      # [gcc_maj_ver < 12]
      - patches/new-allow-commands-in-main-specfile.patch                      # [gcc_maj_ver >= 12]
      - patches/fix-inconsistent-noexcept-spec.patch                           # [gcc_version == "10.4.0"]

build:
  number: {{ build_num }}
  skip: True  # [not linux]
  detect_binary_files_with_prefix: False

requirements:
  build:
    - binutils_impl_{{ target_platform }}  {{ binutils_version }}
    - binutils_impl_{{ cross_target_platform }}  {{ binutils_version }}
    - gcc_impl_{{ target_platform }}  {{ gcc_version }}               # [build_platform != target_platform]
    - gxx_impl_{{ target_platform }}  {{ gcc_version }}               # [build_platform != target_platform]
    - gcc_impl_{{ cross_target_platform }}  {{ gcc_version }}         # [build_platform != target_platform]
    - gxx_impl_{{ cross_target_platform }}  {{ gcc_version }}         # [build_platform != target_platform]
    - gfortran_impl_{{ cross_target_platform }}  {{ gcc_version }}    # [build_platform != target_platform]
    - sysroot_{{ cross_target_platform }} {{ glibc_version }}
    - gcc_bootstrap_{{ build_platform }} <={{ gcc_version }}          # [(not use_system_gcc and build_platform == target_platform) or (build_platform != target_platform and build_platform != cross_target_platform)]
  host:
    - sysroot_{{ cross_target_platform }} {{ glibc_version }}

outputs:
  - name: libgcc-devel_{{ cross_target_platform }}
    script: install-libgcc-devel.sh
    build:
      number: {{ build_num }}
      detect_binary_files_with_prefix: False
      missing_dso_whitelist:
        - "*"
      ignore_run_exports:
        - __glibc
      ignore_run_exports_from:
        - gcc_impl_{{ build_platform }}  {{ gcc_version }}                # [build_platform != target_platform]
        - gxx_impl_{{ build_platform }}  {{ gcc_version }}                # [build_platform != target_platform]
    requirements:
      build:
        - binutils_impl_{{ target_platform }}  {{ binutils_version }}
        - binutils_impl_{{ cross_target_platform }}  {{ binutils_version }}
        - gcc_impl_{{ target_platform }}  {{ gcc_version }}               # [build_platform != target_platform]
        - gxx_impl_{{ target_platform }}  {{ gcc_version }}               # [build_platform != target_platform]
        - gcc_impl_{{ cross_target_platform }}  {{ gcc_version }}         # [build_platform != target_platform]
        - gxx_impl_{{ cross_target_platform }}  {{ gcc_version }}         # [build_platform != target_platform]
        - gfortran_impl_{{ cross_target_platform }}  {{ gcc_version }}    # [build_platform != target_platform]
        - sysroot_{{ cross_target_platform }} {{ glibc_version }}
        - gcc_bootstrap_{{ build_platform }} <={{ gcc_version }}          # [(not use_system_gcc and build_platform == target_platform) or (build_platform != target_platform and build_platform != cross_target_platform)]
      host:
        - sysroot_{{ cross_target_platform }} {{ glibc_version }}
    test:
      commands:
        - test -f ${PREFIX}/lib/gcc/{{ gcc_machine }}-{{ gcc_vendor }}-linux-gnu/{{ gcc_version }}/crtbegin.o
        - test -f ${PREFIX}/lib/gcc/{{ gcc_machine }}-{{ gcc_vendor }}-linux-gnu/{{ gcc_version }}/libgcc_eh.a
        - test -f ${PREFIX}/lib/gcc/{{ gcc_machine }}-{{ gcc_vendor }}-linux-gnu/{{ gcc_version }}/libgcc.a
    about:
      summary: The GNU C development libraries and object files
      home: https://gcc.gnu.org/
      license: GPL-3.0-only WITH GCC-exception-3.1

  - name: libstdcxx-devel_{{ cross_target_platform }}
    script: install-libstdc++-devel.sh
    build:
      number: {{ build_num }}
      detect_binary_files_with_prefix: False
      missing_dso_whitelist:
        - "*"
      ignore_run_exports:
        - __glibc
    requirements:
      build:
        - binutils_impl_{{ target_platform }}  {{ binutils_version }}
        - binutils_impl_{{ cross_target_platform }}  {{ binutils_version }}
        - gcc_impl_{{ target_platform }}  {{ gcc_version }}               # [build_platform != target_platform]
        - gxx_impl_{{ target_platform }}  {{ gcc_version }}               # [build_platform != target_platform]
        - gcc_impl_{{ cross_target_platform }}  {{ gcc_version }}         # [build_platform != target_platform]
        - gxx_impl_{{ cross_target_platform }}  {{ gcc_version }}         # [build_platform != target_platform]
        - gfortran_impl_{{ cross_target_platform }}  {{ gcc_version }}    # [build_platform != target_platform]
        - gcc_bootstrap_{{ build_platform }} <={{ gcc_version }}          # [(not use_system_gcc and build_platform == target_platform) or (build_platform != target_platform and build_platform != cross_target_platform)]
        - sysroot_{{ cross_target_platform }} {{ glibc_version }}
      host:
        - sysroot_{{ cross_target_platform }} {{ glibc_version }}
    test:
      requires:
        - gxx_impl_{{ cross_target_platform }} {{ gcc_version }}
      commands:
        - test -f ${PREFIX}/lib/gcc/{{ gcc_machine }}-{{ gcc_vendor }}-linux-gnu/{{ gcc_version }}/libstdc++.a
        - test -f ${PREFIX}/lib/gcc/{{ gcc_machine }}-{{ gcc_vendor }}-linux-gnu/{{ gcc_version }}/libstdc++.so
        - test -f ${PREFIX}/lib/gcc/{{ gcc_machine }}-{{ gcc_vendor }}-linux-gnu/{{ gcc_version }}/libstdc++fs.a
        - test -f ${PREFIX}/lib/gcc/{{ gcc_machine }}-{{ gcc_vendor }}-linux-gnu/{{ gcc_version }}/libsupc++.a
        - test -f ${PREFIX}/{{ gcc_machine }}-{{ gcc_vendor }}-linux-gnu/include/c++/{{ gcc_version }}/cstdio
    about:
      summary: The GNU C++ headers and development libraries
      home: https://gcc.gnu.org/
      license: GPL-3.0-only WITH GCC-exception-3.1

  - name: gcc_impl_{{ cross_target_platform }}
    script: install-gcc.sh
    build:
      number: {{ build_num }}
      detect_binary_files_with_prefix: False
      missing_dso_whitelist:
        - '*'
      runpath_whitelist:
        - "x86_64-{{ gcc_vendor }}-linux-gnu/sysroot/lib/libpthread-2.12.2.so"
      ignore_run_exports:
        - __glibc
    requirements:
      build:
        - binutils_impl_{{ target_platform }}  {{ binutils_version }}
        - binutils_impl_{{ cross_target_platform }}  {{ binutils_version }}
        - gcc_impl_{{ target_platform }}  {{ gcc_version }}               # [build_platform != target_platform]
        - gxx_impl_{{ target_platform }}  {{ gcc_version }}               # [build_platform != target_platform]
        - gcc_impl_{{ cross_target_platform }}  {{ gcc_version }}         # [build_platform != target_platform]
        - gxx_impl_{{ cross_target_platform }}  {{ gcc_version }}         # [build_platform != target_platform]
        - gfortran_impl_{{ cross_target_platform }}  {{ gcc_version }}    # [build_platform != target_platform]
        - gcc_bootstrap_{{ build_platform }} <={{ gcc_version }}          # [(not use_system_gcc and build_platform == target_platform) or (build_platform != target_platform and build_platform != cross_target_platform)]
        - sysroot_{{ cross_target_platform }} {{ glibc_version }}
      host:
        - sysroot_{{ cross_target_platform }} {{ glibc_version }}
        - {{ pin_subpackage("libgomp", exact=True) }}               # [target_platform == cross_target_platform]
        - {{ pin_subpackage("libstdcxx-ng", exact=True) }}          # [target_platform == cross_target_platform]
        - {{ pin_subpackage("libgcc-ng", exact=True) }}             # [target_platform == cross_target_platform]
        - {{ pin_subpackage("libgfortran" ~ libgfortran_soname) }}  # [target_platform == cross_target_platform]
        - {{ pin_subpackage("libsanitizer", exact=True) }}          # [target_platform == cross_target_platform]
      run:
        - binutils_impl_{{ cross_target_platform }} >={{ binutils_version }}
        - {{ pin_subpackage("libgcc-devel_" ~ cross_target_platform, exact=True) }}
        - {{ pin_subpackage("libsanitizer", exact=True) }}      # [target_platform == cross_target_platform]
        # libstdcxx-ng is a runtime dep of gcc because LTO requires it.
        - {{ pin_subpackage("libstdcxx-ng", max_pin=None) }}    # [target_platform == cross_target_platform]
        - {{ pin_subpackage("libgcc-ng", max_pin=None) }}       # [target_platform == cross_target_platform]
        - {{ pin_subpackage("libgomp", max_pin=None) }}         # [target_platform == cross_target_platform]
        - sysroot_{{ cross_target_platform }}
        # Any version newer than the devtoolset works.
        - libstdcxx-ng >=4.9   # [use_system_gcc]
        - libgcc-ng >=4.9      # [use_system_gcc]
    run_exports:
      # impose this requirement across the build/host boundary
      strong:
        - libgcc-ng >={{ gcc_version }}
    test:
      requires:
        - sysroot_{{ cross_target_platform }} {{ glibc_version }}
      files:
        - tests
      commands:
        - echo {{ old_gcc_vendor }}
        - test -f ${PREFIX}/{{ gcc_machine }}-{{ gcc_vendor }}-linux-gnu/lib/libgomp.so   # [target_platform == cross_target_platform]
        - test `readlink ${PREFIX}/{{ gcc_machine }}-{{ gcc_vendor }}-linux-gnu/lib/libgomp.so` == "../../lib/libgomp.so"  # [target_platform == cross_target_platform]
        - test -f ${PREFIX}/bin/{{ gcc_machine }}-{{ old_gcc_vendor }}-linux-gnu-gcc
        - test -f ${PREFIX}/bin/{{ gcc_machine }}-{{ old_gcc_vendor }}-linux-gnu-cpp
        - test -f ${PREFIX}/bin/{{ gcc_machine }}-{{ gcc_vendor }}-linux-gnu-gcc
        - test -f ${PREFIX}/bin/{{ gcc_machine }}-{{ gcc_vendor }}-linux-gnu-cpp
        - test ! -f ${PREFIX}/bin/gcc
        - test ! -f ${PREFIX}/bin/cpp
        - CC=$(${PREFIX}/bin/*-gcc -dumpmachine)-gcc
        - ${CC} -Wall tests/aligned_alloc.c -c -o c_aligned.o -v -fsanitize=address
        - ${CC} -Wall tests/aligned_alloc.c -c -o c_aligned.o -v
        - ${CC} -Wall c_aligned.o -o c_aligned -v && ./c_aligned   # [cross_target_platform == target_platform]
        - ${CC} -Wall c_aligned.o -o c_aligned -Wl,-rpath,/foo && {{ gcc_machine }}-{{ gcc_vendor }}-linux-gnu-readelf -d c_aligned | grep RPATH | grep "/foo:${PREFIX}/lib"  # [cross_target_platform == target_platform]
        - test -f ${PREFIX}/{{ gcc_machine }}-{{ gcc_vendor }}-linux-gnu/lib/libgcc_s.so
        - test -f ${PREFIX}/{{ gcc_machine }}-{{ gcc_vendor }}-linux-gnu/lib/libgomp.spec
        - test -f ${PREFIX}/{{ gcc_machine }}-{{ gcc_vendor }}-linux-gnu/lib/libsanitizer.spec
        - test -f ${PREFIX}/{{ gcc_machine }}-{{ gcc_vendor }}-linux-gnu/lib/libasan_preinit.o
    about:
      summary: GNU C Compiler
      home: https://gcc.gnu.org/
      license: GPL-3.0-only WITH GCC-exception-3.1

  - name: conda-gcc-specs
    script: install-conda-specs.sh
    build:
      number: {{ build_num }}
      detect_binary_files_with_prefix: False
      skip: True  # [cross_target_platform != target_platform]
    requirements:
      build:
      run:
        - {{ pin_subpackage("gcc_impl_" ~ cross_target_platform, max_pin='x.x.x.x') }}
    test:
      files:
        - tests
      commands:
        - specdir=$PREFIX/lib/gcc/{{ gcc_machine }}-{{ gcc_vendor }}-linux-gnu/{{ gcc_version }}
        - test -f $specdir/conda.specs
        - CC=$(${PREFIX}/bin/*-gcc -dumpmachine)-gcc
        - echo | ${CC} -E -v -x c - |& grep '^Reading specs from' | awk '{print $NF}' | xargs readlink -e | awk -v ORS= '{print $1":"}' | grep "${specdir}/specs:${specdir}/conda.specs:"
        - cp tests/libhowdy.h $PREFIX/include/
        - ${CC} -shared -fpic -o $PREFIX/lib/libhowdy.so tests/libhowdy.c
        - ${CC} -o howdy-dso tests/howdy-dso.c -lhowdy
        - ./howdy-dso
        -    grep RPATH   <({{ gcc_machine }}-{{ gcc_vendor }}-linux-gnu-readelf -d howdy-dso)
        - "! grep RUNPATH <({{ gcc_machine }}-{{ gcc_vendor }}-linux-gnu-readelf -d howdy-dso)"
        - ${CC} -Wl,-enable-new-dtags -o howdy-dso-runpath tests/howdy-dso.c -lhowdy
        - ./howdy-dso-runpath
        - "! grep RPATH   <({{ gcc_machine }}-{{ gcc_vendor }}-linux-gnu-readelf -d howdy-dso-runpath)"
        -    grep RUNPATH <({{ gcc_machine }}-{{ gcc_vendor }}-linux-gnu-readelf -d howdy-dso-runpath)
        - echo | ${CC} -E -Wp,-v -x c - |& awk '/include <\.\.\.> search starts/,/^End of search/ {print}' | tail -n2 | head -n1 | grep "$PREFIX/include"
        - echo | ${CC} -isystem "$PREFIX/include" -E -Wp,-v -x c - |& awk '/include <\.\.\.> search starts/, /^End of search/ {print}' | head -n2 | tail -n1 | grep "$PREFIX/include"

    about:
      summary: conda-specific specfile for GNU C/C++ Compiler
      description: |
          When installed, this optional package provides a specfile that
          directs gcc (and g++ or gfortran) to automatically:
            * search for includes in $PREFIX/include
            * link libraries in $PREFIX/lib
            * set RPATH to $PREFIX/lib
            * use RPATH instead of the newer RUNPATH
          This package is intended to aid usability of the compiler
          toolchain as a replacement for system-installed compilers.
          It should not be used in recipes.  Use the 'compiler(<lang>)'
          jinja function as described on
          https://conda-forge.org/docs/maintainer/knowledge_base.html#dep-compilers
      home: https://gcc.gnu.org/
      license: GPL-3.0-only WITH GCC-exception-3.1
      doc_url: https://gcc.gnu.org/onlinedocs/gcc/Spec-Files.html

  - name: gxx_impl_{{ cross_target_platform }}
    script: install-g++.sh
    build:
      number: {{ build_num }}
      detect_binary_files_with_prefix: False
      missing_dso_whitelist:
        - "*"
      ignore_run_exports:
        - __glibc
    requirements:
      build:
        - binutils_impl_{{ target_platform }}  {{ binutils_version }}
        - binutils_impl_{{ cross_target_platform }}  {{ binutils_version }}
        - gcc_impl_{{ target_platform }}  {{ gcc_version }}               # [build_platform != target_platform]
        - gxx_impl_{{ target_platform }}  {{ gcc_version }}               # [build_platform != target_platform]
        - gcc_impl_{{ cross_target_platform }}  {{ gcc_version }}         # [build_platform != target_platform]
        - gxx_impl_{{ cross_target_platform }}  {{ gcc_version }}         # [build_platform != target_platform]
        - gfortran_impl_{{ cross_target_platform }}  {{ gcc_version }}    # [build_platform != target_platform]
        - gcc_bootstrap_{{ build_platform }} <={{ gcc_version }}          # [(not use_system_gcc and build_platform == target_platform) or (build_platform != target_platform and build_platform != cross_target_platform)]
        - sysroot_{{ cross_target_platform }} {{ glibc_version }}
      host:
        - sysroot_{{ cross_target_platform }} {{ glibc_version }}
        # For cpp and crt{i,n}.o
        - {{ pin_subpackage("gcc_impl_" ~ cross_target_platform, exact=True) }}
      run:
        # For cpp and crt{i,n}.o
        - {{ pin_subpackage("gcc_impl_" ~ cross_target_platform, exact=True) }}
        # not needed due to pinning above but marks this build as using the new sysroots
        - sysroot_{{ cross_target_platform }}
        - {{ pin_subpackage("libstdcxx-devel_" ~ cross_target_platform, exact=True) }}
    run_exports:
      # impose this requirement across the build/host boundary
      strong:
        - libstdcxx-ng >={{ gcc_version }}
    test:
      requires:
        - sysroot_{{ cross_target_platform }} {{ glibc_version }}
      files:
        - tests
      commands:
        - test -f ${PREFIX}/bin/{{ gcc_machine }}-{{ old_gcc_vendor }}-linux-gnu-g++
        - test -f ${PREFIX}/bin/{{ gcc_machine }}-{{ gcc_vendor }}-linux-gnu-g++
        - CXX=$(${PREFIX}/bin/*-gcc -dumpmachine)-g++
        - ${CXX} -Wall tests/aligned_alloc.cpp -c -o cpp_aligned.o --std=c++17
        - ${CXX} -Wall cpp_aligned.o -o cpp_aligned --std=c++17 && ./cpp_aligned  # [cross_target_platform == target_platform]
    about:
      summary: GNU C++ Compiler
      home: https://gcc.gnu.org/
      license: GPL-3.0-only WITH GCC-exception-3.1

  - name: gfortran_impl_{{ cross_target_platform }}
    script: install-gfortran.sh
    build:
      number: {{ build_num }}
      detect_binary_files_with_prefix: False
      missing_dso_whitelist:
        - "*"
      ignore_run_exports:
        - __glibc
    requirements:
      build:
        - binutils_impl_{{ target_platform }}  {{ binutils_version }}
        - binutils_impl_{{ cross_target_platform }}  {{ binutils_version }}
        - gcc_impl_{{ target_platform }}  {{ gcc_version }}               # [build_platform != target_platform]
        - gxx_impl_{{ target_platform }}  {{ gcc_version }}               # [build_platform != target_platform]
        - gcc_impl_{{ cross_target_platform }}  {{ gcc_version }}         # [build_platform != target_platform]
        - gxx_impl_{{ cross_target_platform }}  {{ gcc_version }}         # [build_platform != target_platform]
        - gfortran_impl_{{ cross_target_platform }}  {{ gcc_version }}    # [build_platform != target_platform]
        - gcc_bootstrap_{{ build_platform }} <={{ gcc_version }}          # [(not use_system_gcc and build_platform == target_platform) or (build_platform != target_platform and build_platform != cross_target_platform)]
        - sysroot_{{ cross_target_platform }} {{ glibc_version }}
      host:
        # For cpp and crt{i,n}.o
        - {{ pin_subpackage("gcc_impl_" ~ cross_target_platform, exact=True) }}
        # not needed due to pinning above but marks this build as using the new sysroots
        - sysroot_{{ cross_target_platform }} {{ glibc_version }}
      run:
        # For cpp and crt{i,n}.o
        - gcc_impl_{{ cross_target_platform }} >={{ gcc_version }}
        - {{ pin_subpackage("libgfortran" ~ libgfortran_soname, max_pin=None) }}  # [target_platform == cross_target_platform]
        - {{ pin_subpackage("libgcc-ng", max_pin=None) }}           # [target_platform == cross_target_platform]
        - sysroot_{{ cross_target_platform }}
        # Any version newer than the devtoolset works. This can be removed when bootstrapping.
        - libgcc-ng >=4.9
        - libstdcxx-ng >=4.9
    run_exports:
      # impose this requirement across the build/host boundary
      strong:
        - libgfortran{{ libgfortran_soname }} {{ gcc_version }}.*
        - libgcc-ng >={{ gcc_version }}
    test:
      requires:
        - cmake >=3.11  # [x86_64 or aarch64 or ppc64le]
        - sysroot_{{ cross_target_platform }} {{ glibc_version }}
      commands:
        - test -f ${PREFIX}/{{ gcc_machine }}-{{ gcc_vendor }}-linux-gnu/lib/libgfortran.so
        - test -f ${PREFIX}/{{ gcc_machine }}-{{ gcc_vendor }}-linux-gnu/lib/libgfortran.a
        - test -f ${PREFIX}/bin/{{ gcc_machine }}-{{ old_gcc_vendor }}-linux-gnu-gfortran
        - test -f ${PREFIX}/bin/{{ gcc_machine }}-{{ gcc_vendor }}-linux-gnu-gfortran
        - find $PREFIX/lib -iname omp_lib.mod | grep '.'
        - find $PREFIX/lib -iname omp_lib.h | grep '.'
        - pushd tests/fortomp
        - sh test_fort.sh   # [target_platform == cross_target_platform and (x86_64 or aarch64 or ppc64le)]
      files:
        - tests/fortomp/*
    about:
      summary: GNU Fortran Compiler
      home: https://gcc.gnu.org/
      license: GPL-3.0-only WITH GCC-exception-3.1

  - name: libstdcxx-ng
    target: {{ cross_target_platform }}
    script: install-libstdc++.sh
    build:
      number: {{ build_num }}
      detect_binary_files_with_prefix: False
      skip: True   # [target_platform != cross_target_platform]
      missing_dso_whitelist:
        - "*"
      ignore_run_exports:
        - __glibc
    requirements:
      build:
        - binutils_impl_{{ target_platform }}  {{ binutils_version }}
        - binutils_impl_{{ cross_target_platform }}  {{ binutils_version }}
        - gcc_impl_{{ target_platform }}  {{ gcc_version }}               # [build_platform != target_platform]
        - gxx_impl_{{ target_platform }}  {{ gcc_version }}               # [build_platform != target_platform]
        - gcc_impl_{{ cross_target_platform }}  {{ gcc_version }}         # [build_platform != target_platform]
        - gxx_impl_{{ cross_target_platform }}  {{ gcc_version }}         # [build_platform != target_platform]
        - gfortran_impl_{{ cross_target_platform }}  {{ gcc_version }}    # [build_platform != target_platform]
        - gcc_bootstrap_{{ build_platform }} <={{ gcc_version }}          # [(not use_system_gcc and build_platform == target_platform) or (build_platform != target_platform and build_platform != cross_target_platform)]
        - sysroot_{{ cross_target_platform }} {{ glibc_version }}
      host:
        - sysroot_{{ cross_target_platform }} {{ glibc_version }}
        - {{ pin_subpackage("libgcc-ng", exact=True) }}
    test:
      commands:
        - test -f ${PREFIX}/lib/libstdc++.so
    about:
      summary: The GNU C++ Runtime Library
      home: https://gcc.gnu.org/
      license: GPL-3.0-only WITH GCC-exception-3.1

  - name: libsanitizer
    target: {{ cross_target_platform }}
    script: install-libsanitizer.sh
    requirements:
      build:
        - binutils_impl_{{ target_platform }}  {{ binutils_version }}
        - binutils_impl_{{ cross_target_platform }}  {{ binutils_version }}
        - gcc_impl_{{ target_platform }}  {{ gcc_version }}               # [build_platform != target_platform]
        - gxx_impl_{{ target_platform }}  {{ gcc_version }}               # [build_platform != target_platform]
        - gcc_impl_{{ cross_target_platform }}  {{ gcc_version }}         # [build_platform != target_platform]
        - gxx_impl_{{ cross_target_platform }}  {{ gcc_version }}         # [build_platform != target_platform]
        - gfortran_impl_{{ cross_target_platform }}  {{ gcc_version }}    # [build_platform != target_platform]
        - gcc_bootstrap_{{ build_platform }} <={{ gcc_version }}          # [(not use_system_gcc and build_platform == target_platform) or (build_platform != target_platform and build_platform != cross_target_platform)]
        - sysroot_{{ cross_target_platform }} {{ glibc_version }}
      host:
        - sysroot_{{ cross_target_platform }}  {{ glibc_version }}
      run:
        - libgcc-ng >={{ gcc_version }}
    build:
      number: {{ build_num }}
      detect_binary_files_with_prefix: False
      skip: True   # [target_platform != cross_target_platform]
      missing_dso_whitelist:
        - "*"
      ignore_run_exports:
        - __glibc
      run_exports:
        - libsanitizer {{ gcc_version }}
    test:
      requires:
        - sysroot_{{ cross_target_platform }}
        - gcc_impl_{{ cross_target_platform }}
      commands:
        - test -f ${PREFIX}/lib/libasan.so
        - echo 'void main(){}' | {{ chost }}gcc -fsanitize=address -x c -
    about:
      summary: The GCC runtime libraries for sanitizers
      home: https://gcc.gnu.org/onlinedocs/gccint/Libgcc.html
      license: GPL-3.0-only WITH GCC-exception-3.1

  - name: libgomp
    target: {{ cross_target_platform }}
    script: install-libgomp.sh
    requirements:
      build:
        - binutils_impl_{{ target_platform }}  {{ binutils_version }}
        - binutils_impl_{{ cross_target_platform }}  {{ binutils_version }}
        - gcc_impl_{{ target_platform }}  {{ gcc_version }}               # [build_platform != target_platform]
        - gxx_impl_{{ target_platform }}  {{ gcc_version }}               # [build_platform != target_platform]
        - gcc_impl_{{ cross_target_platform }}  {{ gcc_version }}         # [build_platform != target_platform]
        - gxx_impl_{{ cross_target_platform }}  {{ gcc_version }}         # [build_platform != target_platform]
        - gfortran_impl_{{ cross_target_platform }}  {{ gcc_version }}    # [build_platform != target_platform]
        - gcc_bootstrap_{{ build_platform }} <={{ gcc_version }}          # [(not use_system_gcc and build_platform == target_platform) or (build_platform != target_platform and build_platform != cross_target_platform)]
        - sysroot_{{ cross_target_platform }} {{ glibc_version }}
      host:
        - sysroot_{{ cross_target_platform }}  {{ glibc_version }}
      run:
        - _libgcc_mutex {{ _libgcc_mutex }}  # [linux64 or ppc64le]
    build:
      number: {{ build_num }}
      detect_binary_files_with_prefix: False
      skip: True   # [target_platform != cross_target_platform]
      missing_dso_whitelist:
        - "*"
      run_exports:
        strong:
          - {{ pin_subpackage("_openmp_mutex", max_pin=None) }}
      ignore_run_exports:
        - __glibc
    test:
      requires:
        - sysroot_{{ cross_target_platform }}
      commands:
        - test -f ${PREFIX}/lib/libgomp.so.{{ libgomp_ver }}
        - test ! -f ${PREFIX}/lib/libgomp.so.{{ libgomp_ver[0:1] }}
    about:
      summary: The GCC OpenMP implementation.
      home: https://gcc.gnu.org/onlinedocs/gccint/Libgcc.html
      license: GPL-3.0-only WITH GCC-exception-3.1

  - name: libgcc-ng
    target: {{ cross_target_platform }}
    script: install-libgcc-no-gomp.sh
    requirements:
      build:
        - binutils_impl_{{ target_platform }}  {{ binutils_version }}
        - binutils_impl_{{ cross_target_platform }}  {{ binutils_version }}
        - gcc_impl_{{ target_platform }}  {{ gcc_version }}               # [build_platform != target_platform]
        - gxx_impl_{{ target_platform }}  {{ gcc_version }}               # [build_platform != target_platform]
        - gcc_impl_{{ cross_target_platform }}  {{ gcc_version }}         # [build_platform != target_platform]
        - gxx_impl_{{ cross_target_platform }}  {{ gcc_version }}         # [build_platform != target_platform]
        - gfortran_impl_{{ cross_target_platform }}  {{ gcc_version }}    # [build_platform != target_platform]
        - gcc_bootstrap_{{ build_platform }} <={{ gcc_version }}          # [(not use_system_gcc and build_platform == target_platform) or (build_platform != target_platform and build_platform != cross_target_platform)]
        - sysroot_{{ cross_target_platform }} {{ glibc_version }}
      host:
        - {{ pin_subpackage("libgomp", exact=True) }}
        - {{ pin_subpackage('_openmp_mutex', exact=True) }}
        - sysroot_{{ cross_target_platform }}  {{ glibc_version }}
      run:
        - _libgcc_mutex {{ _libgcc_mutex }}  # [linux64 or ppc64le]
        - {{ pin_subpackage("_openmp_mutex", max_pin=None) }}
      run_constrained:
        - {{ pin_subpackage("libgomp", exact=True) }}
    build:
      number: {{ build_num }}
      detect_binary_files_with_prefix: False
      skip: True   # [target_platform != cross_target_platform]
      missing_dso_whitelist:
        - "*"
      ignore_run_exports:
        - __glibc
      rpaths_patcher: patchelf
    test:
      requires:
        - sysroot_{{ cross_target_platform }}
      commands:
        - test -f ${PREFIX}/lib/libgcc_s.so
        - test -f ${PREFIX}/lib/libgomp.so.{{ libgomp_ver[0:1] }}
        - test `readlink ${PREFIX}/lib/libgomp.so.{{ libgomp_ver[0:1] }}` == "libgomp.so.{{ libgomp_ver }}"
    about:
      summary: The GCC low-level runtime library
      home: https://gcc.gnu.org/onlinedocs/gccint/Libgcc.html
      license: GPL-3.0-only WITH GCC-exception-3.1

  - name: _openmp_mutex
    script: install-openmp_impl.sh
    version: {{ openmp_ver }}
    requirements:
      build:
        - binutils_impl_{{ target_platform }}  {{ binutils_version }}
        - binutils_impl_{{ cross_target_platform }}  {{ binutils_version }}
        - gcc_impl_{{ target_platform }}  {{ gcc_version }}               # [build_platform != target_platform]
        - gxx_impl_{{ target_platform }}  {{ gcc_version }}               # [build_platform != target_platform]
        - gcc_impl_{{ cross_target_platform }}  {{ gcc_version }}         # [build_platform != target_platform]
        - gxx_impl_{{ cross_target_platform }}  {{ gcc_version }}         # [build_platform != target_platform]
        - gfortran_impl_{{ cross_target_platform }}  {{ gcc_version }}    # [build_platform != target_platform]
        - sysroot_{{ cross_target_platform }} {{ glibc_version }}
        - gcc_bootstrap_{{ build_platform }} <={{ gcc_version }}          # [(not use_system_gcc and build_platform == target_platform) or (build_platform != target_platform and build_platform != cross_target_platform)]
      host:
        - {{ pin_subpackage('libgomp', exact=True) }}
        - sysroot_{{ cross_target_platform }}  {{ glibc_version }}
      run:
        - _libgcc_mutex {{ _libgcc_mutex }}  # [linux64 or ppc64le]
        - libgomp >=7.5.0
      run_constrained:
        # conflict with previous name
        - openmp_impl 9999
    build:
      string: 2_gnu
      skip: True   # [target_platform != cross_target_platform]
      run_exports:
        strong:
          - {{ pin_subpackage("_openmp_mutex", max_pin=None) }}
    test:
      commands:
        - test -f ${PREFIX}/lib/libgomp.so.{{ libgomp_ver[0:1] }}
        - test `readlink ${PREFIX}/lib/libgomp.so.{{ libgomp_ver[0:1] }}` == "libgomp.so.{{ libgomp_ver }}"
    about:
      summary: OpenMP Implementation Mutex
      license: BSD-3-Clause
      license_file: LICENSE
      home: https://github.com/conda-forge/ctng-compilers-feedstock

  - name: libgfortran{{ libgfortran_soname }}
    target: {{ cross_target_platform }}
    script: install-libgfortran.sh
    build:
      number: {{ build_num }}
      detect_binary_files_with_prefix: False
      skip: True   # [target_platform != cross_target_platform]
      missing_dso_whitelist:
        - "*"
      ignore_run_exports:
        - __glibc
    requirements:
      build:
        - binutils_impl_{{ target_platform }}  {{ binutils_version }}
        - binutils_impl_{{ cross_target_platform }}  {{ binutils_version }}
        - gcc_impl_{{ target_platform }}  {{ gcc_version }}               # [build_platform != target_platform]
        - gxx_impl_{{ target_platform }}  {{ gcc_version }}               # [build_platform != target_platform]
        - gcc_impl_{{ cross_target_platform }}  {{ gcc_version }}         # [build_platform != target_platform]
        - gxx_impl_{{ cross_target_platform }}  {{ gcc_version }}         # [build_platform != target_platform]
        - gfortran_impl_{{ cross_target_platform }}  {{ gcc_version }}    # [build_platform != target_platform]
        - gcc_bootstrap_{{ build_platform }} <={{ gcc_version }}          # [(not use_system_gcc and build_platform == target_platform) or (build_platform != target_platform and build_platform != cross_target_platform)]
        - sysroot_{{ cross_target_platform }} {{ glibc_version }}
      host:
        - sysroot_{{ cross_target_platform }} {{ glibc_version }}
      run_constrained:
        - libgfortran-ng {{ gcc_version }}
    test:
      commands:
        - test -f ${PREFIX}/lib/libgfortran.so
    about:
      summary: The GNU Fortran Runtime Library
      home: https://gcc.gnu.org/
      license: GPL-3.0-only WITH GCC-exception-3.1

  - name: libgfortran-ng
    target: {{ cross_target_platform }}
    build:
      skip: True   # [target_platform != cross_target_platform]
      number: {{ build_num }}
    requirements:
      run:
        - {{ pin_subpackage('libgfortran' ~ libgfortran_soname, exact=True) }}
    test:
      commands:
        - test -f ${PREFIX}/lib/libgfortran.so
    about:
      summary: The GNU Fortran Runtime Library
      home: https://gcc.gnu.org/
      license: GPL-3.0-only WITH GCC-exception-3.1


about:
  summary: GNU Compiler Collection
  home: https://gcc.gnu.org/
  license: GPL-3.0-only WITH GCC-exception-3.1
  license_file:
    - COPYING
    - COPYING.LIB
    - COPYING3
    - COPYING3.LIB

extra:
  recipe-maintainers:
    - timsnyder
    - xhochy
    - isuruf
    - beckermr
