TINYCC_DIR = ../inst/tinycc
PKG_CPPFLAGS = -I$(TINYCC_DIR)/include -I$(TINYCC_DIR)/lib/tcc/include
PKG_CFLAGS = $(PKG_CPPFLAGS)

LIBTCC_SO    := $(wildcard $(TINYCC_DIR)/lib/libtcc.so)
LIBTCC_DYLIB := $(wildcard $(TINYCC_DIR)/lib/libtcc.dylib)

# Determine platform rpath flag for dynamic linking
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
RPATH = -Wl,-rpath,@loader_path/../tinycc/lib
else
RPATH = -Wl,-rpath,'$$ORIGIN/../tinycc/lib'
endif

ifneq ($(LIBTCC_SO),)
		PKG_LIBS = $(LIBTCC_SO) $(RPATH)
else ifneq ($(LIBTCC_DYLIB),)
		PKG_LIBS = $(LIBTCC_DYLIB) $(RPATH)
else
		PKG_LIBS = -L$(TINYCC_DIR)/lib -ltcc
endif

all: $(SHLIB)

