{% set build_num = ctng_gcc_build_number %}

package:
  name: compilers_{{ ctng_target_platform }}
  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 }}
  # The CentOS6 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 >=1.23.0.442_g622d059
  # Need something here so that build does not get installed to a long prefix
  # as that breaks on some systems.
  host:
    - crosstool-ng >=1.23.0.442_g622d059

outputs:
  - 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-conda_cos6-linux-gnu/sysroot/lib/libpthread-2.12.2.so"
    requirements:
      run:
        - {{ pin_subpackage("binutils_impl_" ~ ctng_target_platform, exact=True) }}
        # libstdcxx-ng is a runtime dep of gcc because LTO requires it.
        - {{ pin_subpackage("libstdcxx-ng", max_pin=None) }}
        - {{ pin_subpackage("libgcc-ng", max_pin=None) }}
    run_exports:
      # impose this requirement across the build/host boundary
      strong:
        - {{ pin_subpackage("libgcc-ng", max_pin=None) }}
    test:
      files:
        - tests
      commands:
        - CC=$(${PREFIX}/bin/*-gcc -dumpmachine)-gcc
        - ${CC} -Wall tests/aligned_alloc.c -o c_aligned
        - ./c_aligned
    about:
      summary: GNU C Compiler
      home: https://gcc.gnu.org/
      license: GPL

  - 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:
        - "*"
    requirements:
      build:
        # 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) }}
    run_exports:
      # impose this requirement across the build/host boundary
      strong:
        - {{ pin_subpackage("libstdcxx-ng", max_pin=None) }}
    test:
      files:
        - tests
      commands:
        - CXX=$(${PREFIX}/bin/*-gcc -dumpmachine)-g++
        - ${CXX} -Wall tests/aligned_alloc.cpp -o cpp_aligned --std=c++17
        - ./cpp_aligned
    about:
      summary: GNU C++ Compiler
      home: https://gcc.gnu.org/
      license: GPL

  - 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:
        - "*"
    requirements:
      build:
        # For cpp and crt{i,n}.o
        - {{ pin_subpackage("gcc_impl_" ~ ctng_target_platform, exact=True) }}
      run:
        # For cpp and crt{i,n}.o
        - gcc_impl_{{ ctng_target_platform }} >=7.2.0
        - {{ pin_subpackage("libgfortran-ng") }}
        - {{ pin_subpackage("libgcc-ng", max_pin=None) }}
    run_exports:
      # impose this requirement across the build/host boundary
      strong:
        - {{ pin_subpackage("libgfortran-ng") }}
        - {{ pin_subpackage("libgcc-ng", max_pin=None) }}
    test:
      requires:
        - cmake >=3.11
      commands:
        - find $PREFIX/lib -iname omp_lib.mod | grep '.'
        - find $PREFIX/lib -iname omp_lib.h | grep '.'
        - pushd tests/fortomp
        - sh test_fort.sh
      files:
        - tests/fortomp/*
    about:
      summary: GNU Fortran Compiler
      home: https://gcc.gnu.org/
      license: GPL

  - 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:
        - "*"
    about:
      summary: The GNU Binutils are a collection of binary tools.
      home: https://www.gnu.org/software/binutils/
      license: GPL

  - name: libstdcxx-ng
    target: {{ ctng_target_platform }}
    script: install-libstdc++.sh
    build:
      number: {{ build_num }}
      detect_binary_files_with_prefix: False
      binary_relocation: False
      missing_dso_whitelist:
        - "*"
    about:
      summary: The GNU C++ Runtime Library
      home: https://gcc.gnu.org/
      license: GPL3 with runtime exception

  - name: libgcc-ng
    target: {{ ctng_target_platform }}
    script: install-libgcc.sh
    build:
      number: {{ build_num }}
      detect_binary_files_with_prefix: False
      binary_relocation: False
      missing_dso_whitelist:
        - "*"
    about:
      summary: The GCC low-level runtime library
      home: https://gcc.gnu.org/onlinedocs/gccint/Libgcc.html
      license: GPL

  - name: libgfortran-ng
    target: {{ ctng_target_platform }}
    script: install-libgfortran.sh
    build:
      number: {{ build_num }}
      detect_binary_files_with_prefix: False
      binary_relocation: False
      missing_dso_whitelist:
        - "*"
    about:
      summary: The GNU Fortran Runtime Library
      home: https://gcc.gnu.org/
      license: GPL

  {% 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 %}

  - 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
