{% set version = gcc_version %}
{% set build_num = 7 %}

{% if gcc_maj_ver is not defined %}
{% set gcc_maj_ver = 15 %}
{% endif %}

# libgcc-devel is a noarch: generic package that is built for
# cross-compilers as well. Instead of skipping for cross-compilers,
# let's prioritize the native compilers package
{% if target_platform == cross_target_platform %}
{% set libgcc_devel_build_num = build_num + 100 %}
{% else %}
{% set libgcc_devel_build_num = build_num %}
{% endif %}

{% if cross_target_platform is not defined %}
{% set cross_target_platform = "linux-64" %}
{% endif %}

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

source:
  - url: 
      - https://ftp.gnu.org/gnu/gcc/gcc-{{ version }}/gcc-{{ version }}.tar.gz
      - https://mirrors.ocf.berkeley.edu/gnu/gcc/gcc-{{ version }}/gcc-{{ version }}.tar.gz
    sha256: 7294d65cc1a0558cb815af0ca8c7763d86f7a31199794ede3f630c0d1b0a5723   # [gcc_version == "15.2.0"]
    sha256: ace8b8b0dbfe6abfc22f821cb093e195aa5498b7ccf7cd23e4424b9f14afed22   # [gcc_version == "14.3.0"]
    sha256: bf0baf3e570c9c74c17c8201f0196c6924b4bd98c90e69d6b2ac0cd823f33bbc   # [gcc_version == "13.4.0"]
    patches:
      - patches/0001-allow-commands-in-main-specfile.patch
      - patches/0002-patch-zoneinfo_dir_override-to-point-to-our-tzdata.patch       # [gcc_maj_ver != 13]
      {% if cross_target_platform.startswith("linux-") %}
      - patches/0003-add-ldl-to-libstdc___la_LDFLAGS.patch                          # [gcc_maj_ver != 13]
      - patches/0004-Hardcode-HAVE_ALIGNED_ALLOC-1-in-libstdc-v3-configur.patch
      {% else %}
      # for GCC 15: https://github.com/msys2/MINGW-packages/tree/f59921184b35858d4ceb91679578de0d62475cbf/mingw-w64-gcc
      # for GCC 14: https://github.com/msys2/MINGW-packages/tree/331bf945d21af562d228ed46bda21c8272d1e76e/mingw-w64-gcc
      # for GCC 13: https://github.com/msys2/MINGW-packages/tree/4f1262b4e1072632eccf0958764f90d890b832ac/mingw-w64-gcc
      - patches/mingw/{{ gcc_maj_ver }}/0002-Relocate-libintl.patch                                             # [gcc_maj_ver == 13]
      - patches/mingw/{{ gcc_maj_ver }}/0003-Windows-Follow-Posix-dir-exists-semantics-more-close.patch
      - patches/mingw/{{ gcc_maj_ver }}/0005-Windows-Don-t-ignore-native-system-header-dir.patch
      - patches/mingw/{{ gcc_maj_ver }}/0006-Windows-New-feature-to-allow-overriding.patch                      # [gcc_maj_ver == 13]
      - patches/mingw/{{ gcc_maj_ver }}/0007-Build-EXTRA_GNATTOOLS-for-Ada.patch
      - patches/mingw/{{ gcc_maj_ver }}/0008-Prettify-linking-no-undefined.patch
      - patches/mingw/{{ gcc_maj_ver }}/0011-Enable-shared-gnat-implib.patch
      - patches/mingw/{{ gcc_maj_ver }}/0012-Handle-spaces-in-path-for-default-manifest.patch
      - patches/mingw/{{ gcc_maj_ver }}/0014-gcc-9-branch-clone_function_name_1-Retain-any-stdcall-suffix.patch
      - patches/mingw/{{ gcc_maj_ver }}/0020-libgomp-Don-t-hard-code-MS-printf-attributes.patch
      - patches/mingw/{{ gcc_maj_ver }}/0021-PR14940-Allow-a-PCH-to-be-mapped-to-a-different-addr.patch         # [gcc_maj_ver != 15]
      - patches/mingw/{{ gcc_maj_ver }}/0140-gcc-diagnostic-color.patch
      - patches/mingw/{{ gcc_maj_ver }}/0200-add-m-no-align-vector-insn-option-for-i386.patch
      - patches/mingw/{{ gcc_maj_ver }}/0300-override-builtin-printf-format.patch                               # [gcc_maj_ver == 13]
      - patches/mingw/{{ gcc_maj_ver }}/2000-enable-rust.patch                                                  # [gcc_maj_ver == 13]
      - patches/mingw/{{ gcc_maj_ver }}/2001-fix-building-rust-on-mingw-w64.patch
      - patches/mingw/{{ gcc_maj_ver }}/2f7e7bfa3c6327793cdcdcb5c770b93cecd49bd0.patch                          # [gcc_maj_ver == 13]
      - patches/mingw/{{ gcc_maj_ver }}/3eeb4801d6f45f6250fc77a6d3ab4e0115f8cfdd.patch                          # [gcc_maj_ver == 13]
      - patches/mingw/{{ gcc_maj_ver }}/9002-native-tls.patch                                                   # [gcc_maj_ver == 15]
      {% endif %}

build:
  number: {{ build_num }}
  skip: True  # [win]
  skip: true  # [not (linux or win) or (win and cross_target_platform != "win-64")]
  detect_binary_files_with_prefix: false
  ignore_run_exports_from:
    - {{ cross_target_stdlib }}_{{ cross_target_platform }}

requirements:
  build:
    # Build dependencies are installed in setup_compilers.sh due to
    # conda-build bugs
  host:
    - {{ cross_target_stdlib }}_{{ cross_target_platform }} {{ cross_target_stdlib_version }}

outputs:
  - name: libgcc-devel_{{ cross_target_platform }}
    script: install-libgcc-devel.sh
    build:
      noarch: generic
      number: {{ libgcc_devel_build_num }}
      detect_binary_files_with_prefix: false
      missing_dso_whitelist:
        - "*"
      ignore_run_exports_from:
        - {{ cross_target_stdlib }}_{{ cross_target_platform }}
      overlinking_ignore_patterns:
        - "*/lib/libgcc_s.so.*"
    requirements:
      build:
      host:
        - {{ cross_target_stdlib }}_{{ cross_target_platform }} {{ cross_target_stdlib_version }}
      run:
        - __unix   # [unix]
        - __win    # [win]
    test:
      commands:
        - test -f ${PREFIX}/lib/gcc/{{ triplet }}/{{ gcc_version }}/crtbegin.o
        - test -f ${PREFIX}/lib/gcc/{{ triplet }}/{{ gcc_version }}/libgcc_eh.a
        - test -f ${PREFIX}/lib/gcc/{{ triplet }}/{{ gcc_version }}/libgcc.a
        {% if cross_target_platform.startswith("linux-") %}
        - test -f ${PREFIX}/{{ triplet }}/lib/libgcc_s.so
        {% else %}
        - test -f ${PREFIX}/{{ triplet }}/lib/libgcc_s.a
        {% endif %}
    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:
      noarch: generic
      number: {{ libgcc_devel_build_num }}
      detect_binary_files_with_prefix: false
      missing_dso_whitelist:
        - "*"
      ignore_run_exports_from:
        - {{ cross_target_stdlib }}_{{ cross_target_platform }}
      overlinking_ignore_patterns:
        - "*/lib/libstdc++.so.*"
    requirements:
      build:
      host:
        - {{ cross_target_stdlib }}_{{ cross_target_platform }} {{ cross_target_stdlib_version }}
      run:
        - __unix   # [unix]
        - __win    # [win]
    test:
      commands:
        - test -f ${PREFIX}/lib/gcc/{{ triplet }}/{{ gcc_version }}/libstdc++.a
        - test -f ${PREFIX}/lib/gcc/{{ triplet }}/{{ gcc_version }}/libstdc++fs.a
        - test -f ${PREFIX}/lib/gcc/{{ triplet }}/{{ gcc_version }}/libsupc++.a
        - test -f ${PREFIX}/lib/gcc/{{ triplet }}/{{ gcc_version }}/include/c++/cstdio
        {% if cross_target_platform.startswith("linux-") %}
        - test -f ${PREFIX}/{{ triplet }}/lib/libstdc++.so
        {% else %}
        - test -f ${PREFIX}/lib/gcc/{{ triplet }}/{{ gcc_version }}/libstdc++.dll.a
        {% endif %}
    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:
        - '*'
      ignore_run_exports_from:
        - {{ cross_target_stdlib }}_{{ cross_target_platform }}
    requirements:
      build:
      host:
        - {{ cross_target_stdlib }}_{{ cross_target_platform }} {{ cross_target_stdlib_version }}
        - {{ pin_subpackage("libgomp", exact=True) }}               # [target_platform == cross_target_platform]
        - {{ pin_subpackage("libstdcxx", exact=True) }}             # [target_platform == cross_target_platform]
        - {{ pin_subpackage("libgcc", 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 and not win]
      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 and not win]
        # libstdcxx is a runtime dep of gcc because LTO requires it.
        - {{ pin_subpackage("libstdcxx", max_pin=None) }}       # [target_platform == cross_target_platform]
        - {{ pin_subpackage("libgcc", max_pin=None) }}          # [target_platform == cross_target_platform]
        - {{ pin_subpackage("libgomp", max_pin=None) }}         # [target_platform == cross_target_platform]
        - {{ cross_target_stdlib }}_{{ cross_target_platform }}
    run_exports:
      # impose this requirement across the build/host boundary
      strong:
        - libgcc >={{ gcc_version }}
    test:
      requires:
        - {{ cross_target_stdlib }}_{{ cross_target_platform }} {{ cross_target_stdlib_version }}
      files:
        - tests
      commands:
        - echo {{ c_stdlib }}
        - echo {{ c_stdlib_version }}
        - test -f ${PREFIX}/{{ triplet }}/lib/libgomp.so   # [target_platform == cross_target_platform]
        - test `readlink ${PREFIX}/{{ triplet }}/lib/libgomp.so` == "../../lib/libgomp.so"  # [target_platform == cross_target_platform]
        - test -f ${PREFIX}/bin/{{ triplet }}-gcc
        - test -f ${PREFIX}/bin/{{ triplet }}-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 -Wl,-v -march=native  # [target_platform == cross_target_platform and (x86_64 or s390x)]
        # This test does not work well with QEMU
        - ${CC} -Wall tests/aligned_alloc.c -c -o c_aligned.o -v -Wl,-v -mcpu=native   # [target_platform == cross_target_platform and (not x86_64 and not s390x and not ppc64le)]
        - ${CC} -Wall tests/aligned_alloc.c -c -o c_aligned.o -v -fsanitize=address  # [cross_target_platform != "win-64"]
        - ${CC} -Wall tests/aligned_alloc.c -c -o c_aligned.o -v                     # [cross_target_platform != "win-64"]
        - ${CC} -Wall c_aligned.o -o c_aligned -v && ./c_aligned   # [cross_target_platform == target_platform and cross_target_platform != "win-64"]
        - ${CC} -Wall c_aligned.o -o c_aligned -Wl,-rpath,/foo && {{ triplet }}-readelf -d c_aligned | grep RPATH | grep "/foo:${PREFIX}/lib"  # [cross_target_platform == target_platform and cross_target_platform != "win-64"]
        - ${CC} -Wall tests/hello_world.c -c -o hello_world.o -v
        - ${CC} -Wall hello_world.o -o hello_world -v
        {% if cross_target_platform.startswith("linux-") %}
        - test -f ${PREFIX}/{{ triplet }}/lib/libgcc_s.so
        - test -f ${PREFIX}/{{ triplet }}/lib/libsanitizer.spec
        - test -f ${PREFIX}/{{ triplet }}/lib/libasan_preinit.o
        {% else %}
        - test -f ${PREFIX}/{{ triplet }}/lib/libgcc_s.a
        - test -f ${PREFIX}/lib/gcc/{{ triplet }}/{{ gcc_version }}/libquadmath.a
        - test -f ${PREFIX}/lib/gcc/{{ triplet }}/{{ gcc_version }}/libgomp.a
        {% endif %}
        - test -f ${PREFIX}/{{ triplet }}/lib/libgomp.spec
    about:
      summary: GNU C Compiler
      home: https://gcc.gnu.org/
      license: GPL-3.0-only WITH GCC-exception-3.1

  - name: gcc
    script: install-symlinks.sh
    build:
      skip: true  # [target_platform != cross_target_platform]
      track_features:            # [not with_conda_specs]
        - gcc_no_conda_specs     # [not with_conda_specs]
    requirements:
      host:
        - gcc_impl_{{ target_platform }} {{ gcc_version }}.*
      run:
        - gcc_impl_{{ target_platform }} {{ gcc_version }}.*
        - conda-gcc-specs        # [with_conda_specs]
    test:
      commands:
        - ${PREFIX}/bin/gcc -v
        - ${PREFIX}/bin/gcov -v
    about:
      summary: GNU C native compiler (symlinks)
      home: https://github.com/conda-forge/ctng-compilers-feedstock
      license: BSD-3-Clause
      license_file: LICENSE

  - name: gcc-no-conda-specs
    build:
      skip: true   # [with_conda_specs]
    requirements:
      run:
        - gcc
      run_constrained:
        - conda-gcc-specs <0.0a0
    test:
      commands:
        - gcc --version

  - name: conda-gcc-specs
    script: install-conda-specs.sh
    build:
      number: {{ build_num }}
      skip: true                # [cross_target_platform != target_platform]
      detect_binary_files_with_prefix: false
    requirements:
      build:
      run:
        - {{ pin_subpackage("gcc_impl_" ~ cross_target_platform, max_pin='x.x.x.x') }}
    test:
      files:
        - tests
      commands:
        - specdir=$PREFIX/lib/gcc/{{ triplet }}/{{ 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   <({{ triplet }}-readelf -d howdy-dso)
        - "! grep RUNPATH <({{ triplet }}-readelf -d howdy-dso)"
        - ${CC} -Wl,-enable-new-dtags -o howdy-dso-runpath tests/howdy-dso.c -lhowdy
        - ./howdy-dso-runpath
        - "! grep RPATH   <({{ triplet }}-readelf -d howdy-dso-runpath)"
        -    grep RUNPATH <({{ triplet }}-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_from:
        - {{ cross_target_stdlib }}_{{ cross_target_platform }}
    requirements:
      build:
      host:
        - {{ cross_target_stdlib }}_{{ cross_target_platform }} {{ cross_target_stdlib_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
        - {{ cross_target_stdlib }}_{{ cross_target_platform }}
        - {{ pin_subpackage("libstdcxx-devel_" ~ cross_target_platform, exact=True) }}
        # for C++20 chrono support
        - tzdata
    run_exports:
      # impose this requirement across the build/host boundary
      strong:
        - libstdcxx >={{ gcc_version }}
    test:
      requires:
        - {{ cross_target_stdlib }}_{{ cross_target_platform }} {{ cross_target_stdlib_version }}
        - strace_{{ cross_target_platform }}
      files:
        - tests
      commands:
        - test -f ${PREFIX}/bin/{{ triplet }}-g++
        - CXX=$(${PREFIX}/bin/*-gcc -dumpmachine)-g++
        - ${CXX} -Wall tests/aligned_alloc.cpp -c -o cpp_aligned.o --std=c++17    # [cross_target_platform != "win-64"]
        - ${CXX} -Wall cpp_aligned.o -o cpp_aligned --std=c++17 && ./cpp_aligned  # [cross_target_platform == target_platform and cross_target_platform != "win-64"]
        - ${CXX} -Wall tests/hello_world.cpp -c -o hello_world.o --std=c++17
        - ${CXX} -Wall hello_world.o -o hello_world --std=c++17

        # test tzdb integration
      {% if gcc_maj_ver|int >= 14 %}
        - ${CXX} -isystem ${PREFIX}/include --std=c++20 -Wall tests/tzdb-override.cpp -c -o tzdb-override.o
        - ${CXX} -isystem ${PREFIX}/include --std=c++20 -Wall tests/tzdb.cpp -c -o tzdb.o
        {% if target_platform == cross_target_platform %}
        - ${CXX} tzdb-override.o -o tzdb-override && ./tzdb-override
        - ${CXX} tzdb.o -o tzdb && ./tzdb
        - $PREFIX/usr/bin/strace ./tzdb 2>&1 | grep ${CONDA_PREFIX}/lib/../share/zoneinfo/tzdata.zi
        # also test without any environment activation
        - unset PREFIX
        - unset CONDA_PREFIX
        - ./tzdb
        {% endif %}
      {% endif %}
    about:
      summary: GNU C++ Compiler
      home: https://gcc.gnu.org/
      license: GPL-3.0-only WITH GCC-exception-3.1

  - name: gxx
    script: install-symlinks.sh
    build:
      skip: true  # [target_platform != cross_target_platform]
    requirements:
      host:
        - gxx_impl_{{ target_platform }} {{ gcc_version }}.*
        - gcc {{ gcc_version }}.*
      run:
        - gxx_impl_{{ target_platform }} {{ gcc_version }}.*
        - gcc {{ gcc_version }}.*
    test:
      commands:
        - ${PREFIX}/bin/g++ -v
        - ${PREFIX}/bin/gcc -v
    about:
      summary: GNU C++ native compiler (symlinks)
      home: https://github.com/conda-forge/ctng-compilers-feedstock
      license: BSD-3-Clause
      license_file: LICENSE

  - 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_from:
        - {{ cross_target_stdlib }}_{{ cross_target_platform }}
    requirements:
      build:
      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
        - {{ cross_target_stdlib }}_{{ cross_target_platform }} {{ cross_target_stdlib_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", max_pin=None) }}                            # [target_platform == cross_target_platform]
        - {{ pin_subpackage("libstdcxx", max_pin=None) }}                         # [target_platform == cross_target_platform]
        - {{ cross_target_stdlib }}_{{ cross_target_platform }}
    run_exports:
      # impose this requirement across the build/host boundary
      strong:
        - libgfortran{{ libgfortran_soname }} {{ gcc_version }}.*
        - libgcc >={{ gcc_version }}
    test:
      requires:
        - cmake >=3.11,<4  # [x86_64 or aarch64 or ppc64le]
        - make
        - {{ cross_target_stdlib }}_{{ cross_target_platform }} {{ cross_target_stdlib_version }}
      commands:
        {% if cross_target_platform.startswith("linux-") %}
        - test -f ${PREFIX}/{{ triplet }}/lib/libgfortran.so
        {% else %}
        - test -f ${PREFIX}/{{ triplet }}/lib/libgfortran.dll.a
        {% endif %}
        - test -f ${PREFIX}/{{ triplet }}/lib/libgfortran.a
        - test -f ${PREFIX}/bin/{{ triplet }}-gfortran
        - find $PREFIX/lib -iname omp_lib.mod | grep '.'
        - find $PREFIX/lib -iname omp_lib.h | grep '.'
        - find $PREFIX/lib -iname ISO_Fortran_binding.h | grep '.'
        - echo {{ gcc_maj_ver }}
        - 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: gfortran
    script: install-symlinks.sh
    build:
      skip: true  # [target_platform != cross_target_platform]
    requirements:
      host:
        - gfortran_impl_{{ target_platform }} {{ gcc_version }}.*
        - gcc_impl_{{ target_platform }} {{ gcc_version }}.*
        - gcc {{ gcc_version }}.*
      run:
        - gfortran_impl_{{ target_platform }} {{ gcc_version }}.*
        - gcc_impl_{{ target_platform }} {{ gcc_version }}.*
        - gcc {{ gcc_version }}.*
    test:
      commands:
        - ${PREFIX}/bin/gfortran -v
        - ${PREFIX}/bin/gcc -v
    about:
      summary: GNU Fortran native compiler (symlinks)
      home: https://github.com/conda-forge/ctng-compilers-feedstock
      license: BSD-3-Clause
      license_file: LICENSE

  - name: libstdcxx
    target: {{ cross_target_platform }}
    script: install-libstdc++.sh
    build:
      number: {{ build_num }}
      skip: true                # [target_platform != cross_target_platform]
      detect_binary_files_with_prefix: false
      missing_dso_whitelist:
        - "*"
      overlinking_ignore_patterns:
        - "lib/libstdc++.so.*"
    requirements:
      build:
      host:
        - {{ cross_target_stdlib }}_{{ cross_target_platform }} {{ cross_target_stdlib_version }}
        - {{ pin_subpackage("libgcc", exact=True) }}
      run:
        - {{ pin_subpackage("libgcc", exact=True) }}
      run_constrained:
        # avoid installing incompatible version of old name for this output
        - libstdcxx-ng =={{ version }}=*_{{ build_num }}
    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
    build:
      number: {{ build_num }}
      skip: true                # [target_platform != cross_target_platform or win]
      detect_binary_files_with_prefix: false
      missing_dso_whitelist:
        - "*"
      run_exports:
        - libsanitizer {{ gcc_version }}
      overlinking_ignore_patterns:
        - "lib/libtsan.so.*"
        - "lib/libasan.so.*"
        - "lib/liblsan.so.*"
        - "lib/libhwasan.so.*"
    requirements:
      build:
      host:
        - {{ cross_target_stdlib }}_{{ cross_target_platform }}  {{ cross_target_stdlib_version }}
      run:
        - libgcc >={{ gcc_version }}
        - libstdcxx >={{ gcc_version }}
    test:
      requires:
        - {{ cross_target_stdlib }}_{{ cross_target_platform }}  {{ cross_target_stdlib_version }}
        - gcc_impl_{{ cross_target_platform }}
      commands:
        - test -f ${PREFIX}/lib/libasan.so
        - test -f ${PREFIX}/lib/libhwasan.so   # [x86_64 or aarch64]
        - file ${PREFIX}/bin/{{ triplet }}-gcc
        - echo 'void main(){}' | {{ triplet }}-gcc -fsanitize=address -Wl,--fatal-warnings -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
    build:
      number: {{ build_num }}
      skip: true                # [target_platform != cross_target_platform]
      detect_binary_files_with_prefix: false
      missing_dso_whitelist:
        - "*"
      run_exports:
        strong:
          - {{ pin_subpackage("_openmp_mutex", max_pin=None) }}
          {% if cross_target_platform.startswith("win-") %}
          - {{ pin_subpackage("libgomp", max_pin=None) }}
          {% endif %}
    requirements:
      build:
      host:
        - {{ cross_target_stdlib }}_{{ cross_target_platform }}  {{ cross_target_stdlib_version }}
      run_constrained:
        - msys2-conda-epoch <0.0a0    # [win]
    test:
      requires:
        - {{ cross_target_stdlib }}_{{ 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
    target: {{ cross_target_platform }}
    script: install-libgcc-no-gomp.sh
    build:
      number: {{ build_num }}
      skip: true                # [target_platform != cross_target_platform]
      detect_binary_files_with_prefix: false
      missing_dso_whitelist:
        - "*"
      rpaths_patcher: patchelf
      overlinking_ignore_patterns:
        - "lib/libgcc_s.so.*"
    requirements:
      build:
      host:
        - {{ pin_subpackage("libgomp", exact=True) }}
        - {{ pin_subpackage('_openmp_mutex', exact=True) }}
        - {{ cross_target_stdlib }}_{{ cross_target_platform }}  {{ cross_target_stdlib_version }}
      run:
        - {{ pin_subpackage("_openmp_mutex", max_pin=None) }}
      run_constrained:
        - {{ pin_subpackage("libgomp", exact=True) }}
        - msys2-conda-epoch <0.0a0    # [win]
        # avoid installing incompatible version of old name for this output
        - libgcc-ng =={{ version }}=*_{{ build_num }}
    test:
      requires:
        - {{ cross_target_stdlib }}_{{ 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 }}
    build:
      string: 3_gnu
      skip: true    # [target_platform != cross_target_platform]
      run_exports:
        strong:
          - {{ pin_subpackage("_openmp_mutex", max_pin=None) }}
    requirements:
      build:
      host:
        - {{ pin_subpackage('libgomp', exact=True) }}
        - {{ cross_target_stdlib }}_{{ cross_target_platform }}  {{ cross_target_stdlib_version }}
      run:
        - libgomp >=7.5.0
      run_constrained:
        # conflict with previous name
        - openmp_impl <0.0a0
        - msys2-conda-epoch <0.0a0    # [win]
    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 }}
      skip: true                # [target_platform != cross_target_platform]
      detect_binary_files_with_prefix: false
      missing_dso_whitelist:
        - "*"
      overlinking_ignore_patterns:
        - "lib/libgfortran.so.*"
    requirements:
      build:
      host:
        - {{ cross_target_stdlib }}_{{ cross_target_platform }} {{ cross_target_stdlib_version }}
      run:
        - libgcc >={{ gcc_version }}
      run_constrained:
        - libgfortran {{ 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
    target: {{ cross_target_platform }}
    build:
      skip: true   # [target_platform != cross_target_platform]
      number: {{ build_num }}
    requirements:
      run:
        - {{ pin_subpackage('libgfortran' ~ libgfortran_soname, exact=True) }}
      run_constrained:
        # avoid installing incompatible version of old name for this output
        - libgfortran-ng =={{ version }}=*_{{ build_num }}
    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: gdb-pretty-printer
    version: {{ gcc_version }}
    script: install-gdb-pretty-printer.sh
    build:
      # skip until gdb 16.3 is on defaults (which is built against GCC 14.3.0)
      skip: true
      number: {{ build_num }}
      ignore_run_exports:   # [linux]
        - libstdcxx         # [linux]
    requirements:
      host:
        - python
      run:
        - python
        - gdb >= 16.3
        - libstdcxx >={{ gcc_version }}
    about:
      summary: GNU Compiler Collection Python Pretty Printers
      home: https://gcc.gnu.org/
      license: GPL-3.0-only WITH GCC-exception-3.1

  # compatibility outputs for previous naming of the runtime libraries
  # with "-ng" suffix; for windows the suffix had never been introduced
  {% if not cross_target_platform.startswith("win-") %}
  - name: libgcc-ng
    target: {{ cross_target_platform }}
    build:
      number: {{ build_num }}
      skip: true    # [target_platform != cross_target_platform]
      run_exports:
        strong:
          - libgcc
    requirements:
      host:
        - {{ pin_subpackage("libgcc", exact=True) }}
      run:
        - {{ pin_subpackage("libgcc", exact=True) }}
    test:
      commands:
        - echo "empty wrapper for compatibility with previous naming"
    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: libstdcxx-ng
    target: {{ cross_target_platform }}
    script: install-libstdc++.sh
    build:
      number: {{ build_num }}
      skip: true   # [target_platform != cross_target_platform]
      run_exports:
        strong:
          - libstdcxx
    requirements:
      host:
        - {{ pin_subpackage("libstdcxx", exact=True) }}
      run:
        - {{ pin_subpackage("libstdcxx", exact=True) }}
    test:
      commands:
        - echo "empty wrapper for compatibility with previous naming"
    about:
      summary: The GNU C++ 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:
      number: {{ build_num }}
      skip: true   # [target_platform != cross_target_platform]
      run_exports:
        strong:
          - libgfortran
    requirements:
      host:
        - {{ pin_subpackage('libgfortran', exact=True) }}
      run:
        - {{ pin_subpackage('libgfortran', exact=True) }}
    test:
      commands:
        - echo "empty wrapper for compatibility with previous naming"
    about:
      summary: The GNU Fortran Runtime Library
      home: https://gcc.gnu.org/
      license: GPL-3.0-only WITH GCC-exception-3.1
  {% endif %}

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:
  feedstock-name: ctng-compilers-feedstock
  recipe-maintainers:
    - timsnyder
    - xhochy
    - isuruf
    - beckermr
