{% set build_num = ctng_gcc_build_number %}

package:
  name: ctng-compilers
  version: {{ ctng_gcc }}

source:
  path: .

build:
  merge_build_host: False
  # defined in conda_build_config.yaml so that we can keep it associated with a particular GCC version number
  number: {{ build_num | default(0) }}
  skip: True  # [not linux or ((aarch64 or ppc64le or s390x) and target_platform != ctng_target_platform)]
  # The CentOS7 system libraries should be used for everything here.
  # We do not have CDT packages yet, nor compilers that would use them!
  missing_dso_whitelist:
    - "*"

requirements:
  build:
    - crosstool-ng
    - make
    - bash  # [osx]
    - autoconf  # [linux64]
    - automake  # [linux64]
    - libtool
  # Need something here so that build does not get installed to a long prefix
  # as that breaks on some systems.
  host:
    - crosstool-ng

outputs:
  - name: libgcc-devel_{{ ctng_target_platform }}
    script: install-libgcc-devel.sh
    build:
      number: {{ build_num }}
      detect_binary_files_with_prefix: False
      binary_relocation: False
      missing_dso_whitelist:
        - "*"
    test:
      commands:
        - test -f ${PREFIX}/lib/gcc/{{ ctng_cpu_arch }}-{{ ctng_vendor }}-linux-gnu/{{ ctng_gcc }}/crtbegin.o
    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_{{ ctng_target_platform }}
    script: install-libstdc++-devel.sh
    build:
      number: {{ build_num }}
      detect_binary_files_with_prefix: False
      binary_relocation: False
      missing_dso_whitelist:
        - "*"
    test:
      commands:
        - test -f ${PREFIX}/{{ ctng_cpu_arch }}-{{ ctng_vendor }}-linux-gnu/lib/libstdc++.a
    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_{{ ctng_target_platform }}
    script: install-gcc.sh
    build:
      number: {{ build_num }}
      detect_binary_files_with_prefix: False
      binary_relocation:
        - 'bin/*'
        - 'lib/*.so*'
        - 'libexec/**/*.so*'
        - 'libexec/**/cc1*'
        - 'libexec/**/collect2'
        - 'libexec/**/gcc'
        - 'libexec/**/lto*'
        - 'libexec/**/plugin/gengtype'
      missing_dso_whitelist:
        - '*'
      runpath_whitelist:
        - "x86_64-{{ ctng_vendor }}-linux-gnu/sysroot/lib/libpthread-2.12.2.so"
      ignore_run_exports:
        - __glibc
    requirements:
      host:
        - sysroot_{{ ctng_target_platform }} {{ conda_glibc_ver }}
        - {{ pin_subpackage("libgomp", exact=True) }}               # [target_platform == ctng_target_platform]
        - {{ pin_subpackage("libstdcxx-ng", exact=True) }}          # [target_platform == ctng_target_platform]
        - {{ pin_subpackage("libgcc-ng", exact=True) }}             # [target_platform == ctng_target_platform]
        - {{ pin_subpackage("libgfortran" ~ libgfortran_soname) }}  # [target_platform == ctng_target_platform]
      run:
        - {{ pin_subpackage("binutils_impl_" ~ ctng_target_platform, max_pin=None) }}
        - {{ pin_subpackage("libgcc-devel_" ~ ctng_target_platform, exact=True) }}
        # libstdcxx-ng is a runtime dep of gcc because LTO requires it.
        - {{ pin_subpackage("libstdcxx-ng", max_pin=None) }}    # [target_platform == ctng_target_platform]
        - {{ pin_subpackage("libgcc-ng", max_pin=None) }}       # [target_platform == ctng_target_platform]
        - {{ pin_subpackage("libgomp", max_pin=None) }}         # [target_platform == ctng_target_platform]
        - sysroot_{{ ctng_target_platform }}
        # Any version newer than the devtoolset works. This can be removed when bootstrapping.
        - libstdcxx-ng >=4.9
        - libgcc-ng >=4.9
    run_exports:
      # impose this requirement across the build/host boundary
      strong:
        - libgcc-ng >={{ ctng_gcc }}
    test:
      requires:
        - sysroot_{{ ctng_target_platform }} {{ conda_glibc_ver }}
      files:
        - tests
      commands:
        - echo {{ ctng_sample }}
        - echo {{ gnu }}
        - echo {{ old_ctng_vendor }}
        - echo {{ ctng_kernel }}
        - test -f ${PREFIX}/{{ ctng_cpu_arch }}-{{ ctng_vendor }}-linux-gnu/sysroot/lib/libgomp.so   # [target_platform == ctng_target_platform]
        - test `readlink ${PREFIX}/{{ ctng_cpu_arch }}-{{ ctng_vendor }}-linux-gnu/sysroot/lib/libgomp.so` == "../../../lib/libgomp.so"  # [target_platform == ctng_target_platform]
        - test -f ${PREFIX}/bin/{{ ctng_cpu_arch }}-{{ old_ctng_vendor }}-linux-gnu-gcc
        - CC=$(${PREFIX}/bin/*-gcc -dumpmachine)-gcc
        - ${CC} -Wall tests/aligned_alloc.c -c -o c_aligned.o -v
        - ${CC} -Wall c_aligned.o -o c_aligned -v && ./c_aligned   # [ctng_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: gxx_impl_{{ ctng_target_platform }}
    script: install-g++.sh
    build:
      number: {{ build_num }}
      detect_binary_files_with_prefix: False
      binary_relocation:
        - 'bin/*'
        - 'lib/*.so'
        - 'libexec/**/*.so*'
        - 'libexec/**/cc1*'
      missing_dso_whitelist:
        - "*"
      ignore_run_exports:
        - __glibc
    requirements:
      host:
        # For cpp and crt{i,n}.o
        - {{ pin_subpackage("gcc_impl_" ~ ctng_target_platform, exact=True) }}
      run:
        # For cpp and crt{i,n}.o
        - {{ pin_subpackage("gcc_impl_" ~ ctng_target_platform, exact=True) }}
        # not needed due to pinning above but marks this build as using the new sysroots
        - sysroot_{{ ctng_target_platform }}
        - {{ pin_subpackage("libstdcxx-devel_" ~ ctng_target_platform, exact=True) }}
    run_exports:
      # impose this requirement across the build/host boundary
      strong:
        - libstdcxx-ng >={{ ctng_gcc }}
    test:
      requires:
        - sysroot_{{ ctng_target_platform }} {{ conda_glibc_ver }}
      files:
        - tests
      commands:
        - test -f ${PREFIX}/bin/{{ ctng_cpu_arch }}-{{ old_ctng_vendor }}-linux-gnu-g++
        - test -f ${PREFIX}/bin/{{ ctng_cpu_arch }}-{{ ctng_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  # [ctng_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_{{ ctng_target_platform }}
    script: install-gfortran.sh
    build:
      number: {{ build_num }}
      detect_binary_files_with_prefix: False
      binary_relocation:
        - 'bin/*'
        - 'lib/*.so'
        - 'libexec/**/*.so*'
        - 'libexec/**/f951'
      missing_dso_whitelist:
        - "*"
      ignore_run_exports:
        - __glibc
    requirements:
      build:
        # For cpp and crt{i,n}.o
        - {{ pin_subpackage("gcc_impl_" ~ ctng_target_platform, exact=True) }}
      host:
        - {{ pin_subpackage("gcc_impl_" ~ ctng_target_platform, exact=True) }}
        # not needed due to pinning above but marks this build as using the new sysroots
        - sysroot_{{ ctng_target_platform }}
      run:
        # For cpp and crt{i,n}.o
        - gcc_impl_{{ ctng_target_platform }} >={{ ctng_gcc }}
        - {{ pin_subpackage("libgfortran" ~ libgfortran_soname) }}  # [target_platform == ctng_target_platform]
        - {{ pin_subpackage("libgcc-ng", max_pin=None) }}           # [target_platform == ctng_target_platform]
        - sysroot_{{ ctng_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 }} {{ ctng_gcc }}.*
        - libgcc-ng >={{ ctng_gcc }}
    test:
      requires:
        - cmake >=3.11
        - sysroot_{{ ctng_target_platform }} {{ conda_glibc_ver }}
      commands:
        - test -f ${PREFIX}/bin/{{ ctng_cpu_arch }}-{{ old_ctng_vendor }}-linux-gnu-gfortran
        - test -f ${PREFIX}/bin/{{ ctng_cpu_arch }}-{{ ctng_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 == ctng_target_platform]
      files:
        - tests/fortomp/*
    about:
      summary: GNU Fortran Compiler
      home: https://gcc.gnu.org/
      license: GPL-3.0-only WITH GCC-exception-3.1

  - name: binutils_impl_{{ ctng_target_platform }}
    version: "{{ ctng_binutils }}"
    script: install-binutils.sh
    build:
      number: {{ build_num }}
      detect_binary_files_with_prefix: False
      binary_relocation:
        - 'bin/*'
        - 'lib/*.so'
        - 'libexec/**/*.so*'
      missing_dso_whitelist:
        - "*"
    requirements:
      run:
        - sysroot_{{ ctng_target_platform }}
      run_constrained:
        - gcc_impl_{{ ctng_target_platform }} {{ ctng_gcc }}.*
        - gfortran_impl_{{ ctng_target_platform }} {{ ctng_gcc }}.*
    test:
      commands:
        - test -f ${PREFIX}/{{ ctng_cpu_arch }}-{{ ctng_vendor }}-linux-gnu/bin/ar
        - test -f ${PREFIX}/{{ ctng_cpu_arch }}-{{ ctng_vendor }}-linux-gnu/bin/ld
        - test -f ${PREFIX}/bin/{{ ctng_cpu_arch }}-{{ old_ctng_vendor }}-linux-gnu-ar
        - test -f ${PREFIX}/bin/{{ ctng_cpu_arch }}-{{ ctng_vendor }}-linux-gnu-ar
        - test -f ${PREFIX}/bin/{{ ctng_cpu_arch }}-{{ old_ctng_vendor }}-linux-gnu-ld
        - test -f ${PREFIX}/bin/{{ ctng_cpu_arch }}-{{ ctng_vendor }}-linux-gnu-ld
    about:
      summary: The GNU Binutils are a collection of binary tools.
      home: https://www.gnu.org/software/binutils/
      license: GPL-3.0-only

  - name: libstdcxx-ng
    target: {{ ctng_target_platform }}
    script: install-libstdc++.sh
    build:
      number: {{ build_num }}
      detect_binary_files_with_prefix: False
      binary_relocation: False
      skip: True   # [target_platform != ctng_target_platform]
      missing_dso_whitelist:
        - "*"
      ignore_run_exports:
        - __glibc
    requirements:
      host:
        - sysroot_{{ ctng_target_platform }}
    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: libgcc-ng
    target: {{ ctng_target_platform }}
    script: install-libgcc-no-gomp.sh
    requirements:
      host:
        - {{ pin_subpackage("libgomp", exact=True) }}
        - {{ pin_subpackage('_openmp_mutex', exact=True) }}
        - sysroot_{{ ctng_target_platform }}
      run:
        - _libgcc_mutex {{ _libgcc_mutex }}  # [linux64 or ppc64le or s390x]
        - {{ pin_subpackage("_openmp_mutex", max_pin=None) }}
      run_constrained:
        - {{ pin_subpackage("libgomp", exact=True) }}
    build:
      number: {{ build_num }}
      detect_binary_files_with_prefix: False
      binary_relocation: False
      skip: True   # [target_platform != ctng_target_platform]
      missing_dso_whitelist:
        - "*"
      ignore_run_exports:
        - __glibc
    test:
      requires:
        - sysroot_{{ ctng_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: libgomp
    target: {{ ctng_target_platform }}
    script: install-libgomp.sh
    requirements:
      host:
        - sysroot_{{ ctng_target_platform }}
      run:
        - _libgcc_mutex {{ _libgcc_mutex }}  # [linux64 or ppc64le or s390x]
    build:
      number: {{ build_num }}
      detect_binary_files_with_prefix: False
      binary_relocation: False
      skip: True   # [target_platform != ctng_target_platform]
      missing_dso_whitelist:
        - "*"
      run_exports:
        strong:
          - {{ pin_subpackage("_openmp_mutex", max_pin=None) }}
      ignore_run_exports:
        - __glibc
    test:
      requires:
        - sysroot_{{ ctng_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: _openmp_mutex
    script: install-openmp_impl.sh
    version: {{ openmp_ver }}
    requirements:
      host:
        - {{ pin_subpackage('libgomp', exact=True) }}
      run:
        - _libgcc_mutex {{ _libgcc_mutex }}  # [linux64 or ppc64le or s390x]
        - libgomp >=7.5.0
      run_constrained:
        # conflict with previous name
        - openmp_impl 9999
    build:
      string: 1_gnu
      skip: True   # [target_platform != ctng_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-ng
    target: {{ ctng_target_platform }}
    build:
      skip: True   # [target_platform != ctng_target_platform]
    requirements:
      run:
        - libgfortran{{ libgfortran_soname }} {{ ctng_gcc }}.*
    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{{ libgfortran_soname }}
    target: {{ ctng_target_platform }}
    script: install-libgfortran.sh
    build:
      number: {{ build_num }}
      detect_binary_files_with_prefix: False
      binary_relocation: False
      skip: True   # [target_platform != ctng_target_platform]
      missing_dso_whitelist:
        - "*"
      ignore_run_exports:
        - __glibc
    requirements:
      host:
        - sysroot_{{ ctng_target_platform }}
      run_constrained:
        - libgfortran-ng {{ ctng_gcc }} *_{{ build_num | default(0) }}
    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

  {% if ctng_gdb is defined %}
  - name: gdb_{{ ctng_target_platform }}
    target: {{ ctng_target_platform }}
    version: {{ ctng_gdb }}
    script: install-gdb.sh
    build:
      number: {{ build_num }}
      missing_dso_whitelist:
        - "*"
    about:
      summary: The GNU Project Debugger
      home: https://www.gnu.org/software/gdb/
      license: GPL
  {% endif %}

  {% if ctng_duma is defined %}
  - name: duma_{{ ctng_target_platform }}
    target: {{ ctng_target_platform }}
    version: {{ ctng_duma }}
    script: install-duma.sh
    build:
      number: {{ build_num }}
      detect_binary_files_with_prefix: False
      binary_relocation:
        - 'bin/*'
        - 'lib/*.so*'
        - 'libexec/**/*.so*'
      missing_dso_whitelist:
        - "*"
    about:
      summary: DUMA is an open-source library to detect buffer overruns and under-runs in C and C++ programs.
      home: http://duma.sourceforge.net/
      license: GPL
  {% endif %}

# make the linter happy
about:
  summary: GNU Compiler Collection
  home: https://gcc.gnu.org/
  license: GPL-3.0-only WITH GCC-exception-3.1
  license_file:
    - build/src/gcc-{{ ctng_gcc }}/COPYING
    - build/src/gcc-{{ ctng_gcc }}/COPYING.lib
    - build/src/gcc-{{ ctng_gcc }}/COPYING.RUNTIME
    - build/src/gcc-{{ ctng_gcc }}/COPYING3
    - build/src/gcc-{{ ctng_gcc }}/COPYING3.lib

extra:
  recipe-maintainers:
    - isuruf
    - beckermr
