@@ -30,7 +30,7 @@ RCPPTSKIT_OBJECTS = $(RCPPTSKIT_C_SOURCES:.c=.o) $(RCPPTSKIT_CPP_SOURCES:.cpp=.o
3030OBJECTS = $(TSKIT_OBJECTS) $(RCPPTSKIT_OBJECTS)
3131# $(info OBJECTS = $(OBJECTS)) # for debugging, info is also a GNU extension
3232
33- # Include paths and preprocessor defines
33+ # *Preprocessor (CPP)* flags for include paths and defines
3434# * A bit complicated include/tskit structure due to how we include tskit headers
3535# * $(R_INCLUDE_DIR) is for <R_ext/Error.h>
3636PKG_CPPFLAGS = \
@@ -39,14 +39,25 @@ PKG_CPPFLAGS = \
3939 -I../inst/include/tskit/tskit \
4040 -I$(R_INCLUDE_DIR)
4141
42- # Compiler flags
43- PKG_CFLAGS = -DNDEBUG # to remove calls to assert() as per the R extensions manual
44- # PKG_CFLAGS = -DNDEBUG -DTSK_TRACE_ERRORS # to also enable error tracing in tskit C
45- # PKG_CXXFLAGS = -DTSK_TRACE_ERRORS # to also enable error tracing in tskit C as called from Rcpp
42+ # *Compiler (C/CXX)* flags
43+ # Uncomment for local debugging
44+ # TSK_TRACE_ERRORS enables tskit C error tracing
45+ SAN_FLAGS = -g -O1 -fno-omit-frame-pointer -fsanitize=address,undefined -fno-common
46+ RCPPTSKIT_CFLAGS = $(SAN_FLAGS) -DTSK_TRACE_ERRORS
47+ RCPPTSKIT_CXXFLAGS = $(SAN_FLAGS) -DTSK_TRACE_ERRORS
48+ RCPPTSKIT_LDFLAGS = -fsanitize=address,undefined
49+ # Uncomment for release builds
50+ # NDEBUG removes calls to assert()
51+ # RCPPTSKIT_CFLAGS = -DNDEBUG
52+ # RCPPTSKIT_CXXFLAGS = -DNDEBUG
53+ # RCPPTSKIT_LDFLAGS =
54+ # Use the above choices
55+ PKG_CFLAGS = $(RCPPTSKIT_CFLAGS)
56+ PKG_CXXFLAGS = $(RCPPTSKIT_CXXFLAGS)
4657
4758# Explicit compile rule for tskit C files
4859tskit/%.o: tskit/%.c
4960 $(CC) $(ALL_CPPFLAGS) $(PKG_CFLAGS) $(CFLAGS) $(CPICFLAGS) -c $< -o $@
5061
5162# Linking
52- PKG_LIBS = @RCPPTSKIT_LIB@
63+ PKG_LIBS = @RCPPTSKIT_LIB@ $(RCPPTSKIT_LDFLAGS)
0 commit comments