CXX_STD = CXX17
PKG_CPPFLAGS = -I.

# F7.1 — OpenMP, portable across gcc / clang / Rtools.
#
# $(SHLIB_OPENMP_CXXFLAGS) is the flag R itself resolves for the active
# toolchain (it runs the compiler detection internally): -fopenmp on
# gcc / Rtools gcc, "-Xclang -fopenmp" on the macOS clang R ships, and
# *empty* when the toolchain has no OpenMP. This is the mechanism
# Writing R Extensions mandates; hard-coding -fopenmp instead trips a
# CRAN portability flag.
#
# Fallback without OpenMP: when the variable is empty the package builds
# single-threaded and every `#pragma omp` is ignored by the compiler.
# The C++ that touches the runtime is guarded by `#ifdef _OPENMP`, so
# the library links and runs identically with or without it. This single
# Makevars also serves Windows (Rtools gcc honours the same variable),
# so no separate Makevars.win is required.
#
# The F0.1-era `-O3 -Wall` were CRAN-flagged as non-portable and were
# scheduled for removal in F7.1: optimisation level is left to R's
# Makeconf default (-O2) and developer warnings belong in a personal
# ~/.R/Makevars, not the shipped package. PKG_CXXFLAGS now carries only
# the R-resolved (portable) OpenMP flag.
PKG_CXXFLAGS = $(SHLIB_OPENMP_CXXFLAGS)
PKG_LIBS = $(SHLIB_OPENMP_CXXFLAGS)

# Layered build (F0.4 / F0.5):
#   RcppExports.cpp       generated by Rcpp::compileAttributes().
#   rcpp_bindings.cpp     thin Rcpp wrappers over src/core/ (top-level
#                         so compileAttributes() can discover them).
#   core/*.cpp            pure C++17 engine, no R/Rcpp headers.
#
# R only auto-compiles top-level src/, so subdirectory objects are
# listed explicitly. New top-level .cpp files are still autodetected;
# only new core/ sources require updating CORE_OBJECTS below.
CORE_OBJECTS = \
    core/pedigree.o \
    core/marker.o \
    core/mutation_models.o \
    core/cpt_engine.o \
    core/kl_engine.o \
    core/lr_dist.o \
    core/nongenetic_lr.o \
    core/evidence_combine.o \
    core/concentration.o \
    core/decision.o \
    core/linkage.o

OBJECTS = RcppExports.o rcpp_bindings.o $(CORE_OBJECTS)

# R's default Makeconf provides only suffix rules (.cpp.o:) which do
# not match targets carrying a directory prefix like `core/foo.o`. The
# pattern rule below teaches make how to build the subdirectory
# objects; flags mirror Makeconf's .cpp.o rule.
%.o: %.cpp
	$(CXX) $(ALL_CPPFLAGS) $(ALL_CXXFLAGS) -c $< -o $@
