## This file uses GNU make syntax ($(shell ...) and ifeq) so we need
## to have "SystemRequirements: GNU make" in the DESCRIPTION file.
## See "Writing portable packages" in the "Writing R Extensions" manual:
##   https://cran.r-project.org/doc/manuals/r-release/R-exts.html

include Makevars.common

HTSLIB_MAKEFILE=Makefile.Rhtslib

## Linker options. Make sure the Rhtslib::pkgconfig() function (defined in
## R/zzz.R) produces the same PKG_LIBS value.
PKG_LIBS+=-lcurl

## Even though we should try to avoid using GNU 'make' extensions (for por-
## tability), we use one here to detect the platform :-/ Is there a more
## portable way to do this?
platform := $(shell uname -s)

ifeq (${platform},Darwin)

populate-usrlib-dir: htslib mk-usrlib-dir
	cd "${HTSLIB_SOURCE_DIR}" && cp libhts.a "${USRLIB_DIR}"

else

populate-usrlib-dir: htslib mk-usrlib-dir
	cd "${HTSLIB_SOURCE_DIR}" && cp libhts.so libhts.a "${USRLIB_DIR}"
	cd "${USRLIB_DIR}" && ln -s libhts.so libhts.so.2

endif
