| 1 |
PKG_CPPFLAGS = -I"include" -I"quickjs" -D_GNU_SOURCE |
| 2 |
PKG_LIBS = libquickjs.o |
| 3 |
|
| 4 |
ifeq ($(OS),Windows_NT) |
| 5 |
DLL := .dll |
| 6 |
else |
| 7 |
DLL := .so |
| 8 |
endif |
| 9 |
|
| 10 |
ifdef R_HOME |
| 11 |
R_CC := $(shell $(R_HOME)/bin$(R_ARCH_BIN)/R CMD config CC) |
| 12 |
R_CXX := $(shell $(R_HOME)/bin$(R_ARCH_BIN)/R CMD config CXX) |
| 13 |
else |
| 14 |
R_CC := $(CC) |
| 15 |
R_CXX := $(CXX) |
| 16 |
endif |
| 17 |
|
| 18 |
CLANG_CHECK := $(shell echo | $(R_CC) -dM -E - | grep -i __clang__) |
| 19 |
|
| 20 |
ifneq (,$(CLANG_CHECK)) |
| 21 |
# Clang on armel needs libatomic |
| 22 |
ifeq ($(shell uname -m), armv7l) |
| 23 |
CC_TARGET := $(shell $(R_CXX) -v 2>&1 | grep Target | cut -d ' ' -f 2) |
| 24 |
ifeq ($(findstring gnueabihf,$(CC_TARGET)),) |
| 25 |
PKG_LIBS += -latomic |
| 26 |
endif |
| 27 |
endif |
| 28 |
else |
| 29 |
# Explicit -latomic is needed for 32-bit builds only on GCC |
| 30 |
ifeq ($(shell getconf LONG_BIT), 32) |
| 31 |
PKG_LIBS += -latomic |
| 32 |
endif |
| 33 |
endif |
| 34 |
|
| 35 |
SOURCES = quickjsr.cpp init.cpp |
| 36 |
OBJECTS = $(SOURCES:.cpp=.o) |
| 37 |
|
| 38 |
$(SHLIB): $(OBJECTS) |
| 39 |
$(OBJECTS): build-static |
| 40 |
|
| 41 |
build-static: |
| 42 |
# @mkdir -p ../inst/include/quickjs |
| 43 |
# @cp $(wildcard quickjs/*.h) ../inst/include/quickjs |
| 44 |
$(R_CC) $(ALL_CPPFLAGS) $(ALL_CFLAGS) -funsigned-char -std=gnu11 -c libquickjs.c |
| 45 |
# @mkdir -p ../inst/lib/$(R_ARCH) |
| 46 |
# $(AR) -rs ../inst/lib/$(R_ARCH)/libquickjs.a libquickjs.o |
| 47 |
|
| 48 |
clean: |
| 49 |
$(RM) libquickjs.o $(OBJECTS) |
| 50 |
$(RM) -r ../inst/lib ../inst/include/quickjs |