{% set name = "binutils" %}
{% set version = "2.40" %}

package:
  name: binutils_split
  version: {{ version }}

source:
  - url: https://ftp.gnu.org/gnu/binutils/binutils-{{ version }}.tar.bz2
    sha256: f8298eb153a4b37d112e945aa5cb2850040bcf26a3ea65b5a715c83afe05e48a
    patches:
      - patches/0001-fallback-sysroot.diff

build:
  number: 3
  skip: True  # [win64 and cross_target_platform != "win-64"]
  detect_binary_files_with_prefix: false

requirements:
  build:
    - {{ compiler('cxx') }}   # [not win]
    - {{ stdlib('c') }}       # [not win]
    - gcc_impl_{{ build_platform }}   # [win]
    - gcc_impl_{{ target_platform }}  # [win]
    - make                    # [osx]
  host:
  run:

outputs:
  - name: ld_impl_{{ cross_target_platform }}
    script: install_ld.sh
    build:
      merge_build_host: false
      detect_binary_files_with_prefix: false
      ignore_run_exports_from:    # [linux]
        - {{ compiler('cxx') }}   # [linux]
    requirements:
      build:
        - {{ compiler('cxx') }}   # [not win]
        - {{ stdlib('c') }}       # [not win]
      host:
      run:
      run_constrained:
        - binutils_impl_{{ cross_target_platform }} {{ version }}
    test:
      commands:
        - {{ triplet }}-ld --help
        - echo "{{ ctng_vendor }}"

  - name: binutils_impl_{{ cross_target_platform }}
    script: install_binutils.sh
    build:
      merge_build_host: false
      detect_binary_files_with_prefix: false
      ignore_run_exports:
        - __glibc
      ignore_run_exports_from:    # [linux]
        - {{ compiler('cxx') }}   # [linux]
    requirements:
      build:
        - {{ compiler('cxx') }}   # [not win]
        - {{ stdlib('c') }}       # [not win]
      host:
        - ld_impl_{{ cross_target_platform }} {{ version }}
      run:
        - {{ pin_subpackage("ld_impl_" ~ cross_target_platform, exact=True) }}
        - sysroot_{{ cross_target_platform }}  # [cross_target_platform != "win-64"]
        - m2w64-sysroot_{{ cross_target_platform }} >=12.0.0.r0  # [cross_target_platform == "win-64"]
    test:
      downstreams:
        - gfortran_impl_{{ cross_target_platform }}  # [cross_target_platform != "win-64"]
        - gcc_impl_{{ cross_target_platform }}       # [cross_target_platform != "win-64"]
      commands:
        - {{ triplet }}-addr2line --help
        - {{ triplet }}-ar --help
        - {{ triplet }}-as --help
        - {{ triplet }}-c++filt --help
        - {{ triplet }}-elfedit --help
        - {{ triplet }}-gprof --help
        - {{ triplet }}-ld --help
        - {{ triplet }}-ld.bfd --help
        - {{ triplet }}-ld.gold --help  # [cross_target_platform != "win-64"]
        - {{ triplet }}-nm --help
        - {{ triplet }}-objcopy --help
        - {{ triplet }}-objdump --help
        - {{ triplet }}-ranlib --help
        - {{ triplet }}-readelf --help
        - {{ triplet }}-size --help
        - {{ triplet }}-strings --help
        - {{ triplet }}-strip --help

  - name: binutils
    script: install_binutils_symlinks.sh
    build:
      merge_build_host: false
      detect_binary_files_with_prefix: false
      skip: true  # [cross_target_platform != target_platform]
    requirements:
      build:
      host:
        - binutils_impl_{{ cross_target_platform }}
      run:
        - {{ pin_subpackage("binutils_impl_" ~ cross_target_platform, max_pin="x.x.x") }}
    test:
      commands:
        - $PREFIX/bin/addr2line --help
        - $PREFIX/bin/ar --help
        - $PREFIX/bin/as --help
        - $PREFIX/bin/c++filt --help
        - $PREFIX/bin/elfedit --help
        - $PREFIX/bin/gold --help  # [cross_target_platform != "win-64"]
        - $PREFIX/bin/gprof --help
        - $PREFIX/bin/ld --help
        - $PREFIX/bin/ld.bfd --help
        - $PREFIX/bin/ld.gold --help  # [cross_target_platform != "win-64"]
        - $PREFIX/bin/nm --help
        - $PREFIX/bin/objcopy --help
        - $PREFIX/bin/objdump --help
        - $PREFIX/bin/ranlib --help
        - $PREFIX/bin/readelf --help
        - $PREFIX/bin/size --help
        - $PREFIX/bin/strings --help
        - $PREFIX/bin/strip --help

about:
  home: https://www.gnu.org/software/binutils/
  license: GPL-3.0-only
  license_file:
    - COPYING
    - COPYING.LIB
    - COPYING3
    - COPYING3.LIB
  summary: |
    A set of programming tools for creating and managing binary programs, object files,
    libraries, profile data, and assembly source code.

extra:
  recipe-maintainers:
    - frol
    - isuruf
    - jjhelmus
    - beckermr
