{% set native = 'm2w64-' if win else '' %}
{% set posix = 'm2-' if win else '' %}
{% set version = "4.5.2" %}

package:
  name: r-base-split
  version: {{ version }}

source:
  - url: https://cran.r-project.org/src/base/R-4/R-{{ version }}.tar.gz
    sha256: 0d71ff7106ec69cd7c67e1e95ed1a3cee355880931f2eb78c530014a9e379f20
    patches:
      - 0001-Darwin-Remove-unicode-elipsis-character-from-grDevic.patch
      - 0002-Fix-trio-config.h-include-depth-issue.patch
      - 0003-Win32-Do-not-link-static-libgcc.patch
      - 0004-Win32-Prevent-conversion-of-R_ARCH-to-abs-Windows-pa.patch
      - 0005-Darwin-Avoid-setting-DYLD_FALLBACK_LIBRARY_PATH.patch
      - 0006-Linux-Do-not-modify-LD_LIBRARY_PATH.patch
      - 0007-javareconf-Do-not-fail-on-compile-fail.patch
      - 0008-Revert-part-of-9b818c6dc00143ff18775a4015a3f43b5196f.patch
      - 0009-javareconf-macOS-Continue-to-allow-system-Java-lt-9-.patch
      # - 0010-Allow-rpath-in-tcltk-dylib-LC_LOAD_DYLIB-command.patch
      - 0011-Check-for-changes-then-forcibly-mv-in-javareconf.in.patch
      - 0012-Use-LAPACK_LDFLAGS-in-Rlapack_la_LIBADD.patch
      - 0014-Use-conda-s-tzdata-package.patch
      - 0015-Win32-Fix-COMPILED_BY-for-custom-GCC-pkgversion.patch
      - 0018-Fix-path-to-TCL-TK.patch

build:
  number: 1
  no_link:
    - lib/R/doc/html/packages.html

outputs:
  - name: r-base
    script: build-r-base.sh  # [not win]
    script: bld-r-base.bat  # [win]
    build:
      rpaths:
        - lib/R/lib/
        - lib/
      no_link:
        # These files are modified by R CMD javareconf and can
        # point to different Java implementations in each env.
        - lib/R/etc/Makeconf
        - lib/R/etc/ldpaths
        - lib/R/etc/javaconf
        - lib/R/etc/x64/Makeconf
        - lib/R/etc/x64/ldpaths
        - lib/R/etc/x64/javaconf
      detect_binary_files_with_prefix: true
      run_exports:
        weak:
          - {{ pin_subpackage("r-base", min_pin="x.x", max_pin="x.x") }}
        noarch:
          - {{ pin_subpackage("r-base", min_pin="x.x", max_pin="x.x") }}
    requirements:
      build:
        - gnuconfig                          # [unix]
        - {{ stdlib('c') }}
        - {{ compiler('c') }}
        - {{ compiler('cxx') }}
        - {{ compiler('fortran') }}
        - gfortran_impl_{{ build_platform }} {{ fortran_compiler_version }}  # [build_platform != target_platform]
        - {{ cdt('xorg-x11-proto-devel') }}  # [linux]
        - {{ cdt('libxrender') }}            # [linux]
        - {{ cdt('libxext') }}               # [linux]
        - {{ cdt('libsm-devel') }}           # [linux]
        - {{ cdt('libice-devel') }}          # [linux]
        - {{ cdt('libx11-devel') }}          # [linux]
        - {{ cdt('libxt') }}                 # [linux]
        - {{ cdt('libxt-devel') }}           # [linux]
        - {{ cdt('libxcb') }}                # [linux]
        - {{ cdt('libxau') }}                # [linux]
        - {{ cdt('java-1.7.0-openjdk') }}    # [linux]
        - {{ posix }}pkg-config
        - m2-base                            # [win]
        - m2-diffutils                       # [win]
        - m2-make                            # [win]
        - m2-tar                             # [win]
        - m2-unzip                           # [win]
        - m2-texinfo-tex                     # [win]
        - m2-texinfo                         # [win]
        - m2-curl                            # [win]
        - m2-p7zip                           # [win]
        - miktex                             # [win]
        #- texlive-core                       # [unix]
        - texinfo                            # [unix]
        - openjdk
        - autoconf >=2.72                    # [unix]
        - m2-autoconf2.72                    # [win] 2.71
        - m2-automake-wrapper                # [win]
        - create-forwarder-dll               # [win]
        - automake                           # [not win]
        - make                               # [not win]
        # shellcheck is used to check activation scripts; it is not yet built for linux-ppc64le.
        - shellcheck                         # [unix and build_platform != "linux-ppc64le"]
        - libcurl                            # [not win]
        - readline                            # [build_platform != target_platform]
        - libcurl                             # [build_platform != target_platform]
        - liblzma-devel                                  # [build_platform != target_platform]
        - libpng                              # [build_platform != target_platform]
        - bzip2                               # [build_platform != target_platform]
        - cairo                               # [build_platform != target_platform]
        - libjpeg-turbo                       # [build_platform != target_platform]
        - libiconv                            # [unix and (build_platform != target_platform)]
        - glib                                # [unix and (build_platform != target_platform)]
        - bwidget                             # [build_platform != target_platform]
        - tktable                             # [build_platform != target_platform]
        - expat                               # [build_platform != target_platform]
        - pango                               # [build_platform != target_platform]
        - xorg-xproto                         # [build_platform != target_platform]
        - xorg-kbproto                        # [build_platform != target_platform]
        - xorg-xextproto                      # [build_platform != target_platform]
        - xorg-renderproto                    # [build_platform != target_platform]
        - icu                                 # [build_platform != target_platform]
        - pcre2                               # [build_platform != target_platform]
        - tk                                  # [build_platform != target_platform]
        - zlib                                # [build_platform != target_platform]
        - libtiff                             # [build_platform != target_platform]
        - libblas                             # [build_platform != target_platform]
        - liblapack                           # [build_platform != target_platform]
        - libdeflate                          # [build_platform != target_platform]
        - llvm-openmp                         # [osx]
        - libgomp                             # [linux]
      host:
        - llvm-openmp                         # [osx]
        - libgomp                             # [linux]
        - readline                           # [not win]
        - libcurl
        - liblzma-devel
        - libpng
        - bzip2
        - cairo
        - gettext                            # [osx]
        - fontconfig                         # [osx or win]
        - libjpeg-turbo
        - libdeflate
        - libiconv
        - libuuid                            # [linux]
        - glib                               # [unix]
        - bwidget
        - tktable
        - expat                              # [not win]
        - pango                              # [not win]
        - icu
        - pcre2
        - tk
        - zlib
        - gsl
        - libtiff
        - libblas
        - liblapack
        - tzdata
        # sed is in host env because its path is recorded in R's shell wrapper
        - sed                                # [linux]
      run:
        - _r-mutex 1.* anacondar_1
        # Needed by R CMD javareconf
        - make                               # [not win]
        - gcc_impl_{{ target_platform }}  >={{ c_compiler_version|default("0") }}    # [linux or win]
        - gxx_impl_{{ target_platform }}  >={{ cxx_compiler_version|default("0") }}  # [linux or win]
        - gfortran_impl_{{ target_platform }}  # [linux or win]
        - {{ c_compiler|default("blah") }}_{{ target_platform }} >={{ c_compiler_version|default("0") }}      # [osx]
        - {{ cxx_compiler|default("blah") }}_{{ target_platform }} >={{ cxx_compiler_version|default("0") }}  # [osx]
        - {{ compiler('fortran') }}  # [osx]
        - {{ pin_compatible('llvm-openmp', max_pin=None) }}      # [osx]
        - curl
        - libuuid                              # [linux]
        - xorg-libxt                           # [linux]
        - bwidget
        - tktable
        - tk
        # Update the lower bound with the version used in the internal tzdata
        - tzdata >=2024a
        - sed                                  # [linux]

    test:
      commands:
        - echo on  # [win]
        - R -h
        - R --version
        # Ensure the shared library extension on macOS is also .so
        # for better compatibility with pre-compiled binary macOS packages (similar to wheels in python).
        - R -e 'print(.Platform$dynlib.ext)' | grep -F -- ".so"  # [not win]
        - R -e "print(.Platform$dynlib.ext)" | findstr "/C:%SHLIB_EXT%"   # [win]
        - Rscript --version
        - Rscript -e 'cat("ok\n")' | grep -xF ok         # [not win]
        - Rscript -e "cat('ok\n')" | findstr /X "/C:ok"  # [win]
        - xvfb-run Rscript -e "library('tcltk');quit(status=is.logical(tclRequire('Tktable')))"  # [linux]
        - Rscript -e "library('tcltk');quit(status=is.logical(tclRequire('Tktable')))"           # [not linux]
        # Report on the optional features compiled into this build of R.
        - R -e "capabilities()"
        # Show third-party graphics software available
        - R -e "grSoftVersion()"
        # Show environment variables set by R wrapper
        - env | R -s -e "env <- Sys.getenv(names=TRUE); writeLines(setdiff(paste(names(env), env, sep='='), readLines(file('stdin'))))"  # [not win]
        - set | R -s -e "env <- Sys.getenv(names=TRUE); writeLines(setdiff(paste(names(env), env, sep='='), readLines(file('stdin'))))"  # [win]
        # Show configure variables
        - R CMD config --all
        # TODO does not work on windows, because winCairo.dll is missing
        - Rscript test-svg.R                 # [not win]
        - open                               # [win]
         # There doesn't seem to be a way to test this one
         # - RSetReg                         # [win]
        - Rfe --help                         # [win]
        - Rterm --help                       # [win]
        - Rterm --version                    # [win]
        # Prevent regression mentioned in https://github.com/conda-forge/r-base-feedstock/issues/50
        - Rscript -e "stopifnot(capabilities('jpeg'), TRUE)"
        - Rscript -e "stopifnot(capabilities('png'), TRUE)"
        - if not exist %PREFIX%\\Lib\\R\\bin\\x64\\R.lib exit 1  # [win]
        # Verify internal-tzcode works without warnings
        # See https://stat.ethz.ch/pipermail/r-devel/2014-April/068745.html
        - R -e "options(warn=2);Sys.time()"
        # check that tzdata version is at least 2024
        - R -e "stopifnot(strtoi(substr(attr(OlsonNames(), 'Version'), 1, 4)) >= 2024)"
      files:
        - test-svg.R


  - name: cross-r-base
    build:
      skip: true  # [win]
    script: install-cross-activate.sh
    requirements:
      build:
        # shellcheck is used to check activation scripts; it is not yet built for linux-ppc64le.
        - shellcheck  # [build_platform != "linux-ppc64le"]
      run:
        - {{ pin_subpackage("r-base", exact=True) }}
        - rsync
    test:
      commands:
        - test -f $PREFIX/etc/conda/activate.d/activate-cross-r-base.sh

about:
  home: http://www.r-project.org/
  license: GPL-2.0-or-later
  license_family: GPL
  license_file: COPYING
  summary: R is a free software environment for statistical computing and graphics.

extra:
  feedstock-name: r-base
  recipe-maintainers:
    - conda-forge/r
    - isuruf
    - mbargull
    - mingwandroid
    - ocefpaf
    - sodre
    - xhochy
