aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDominic Letz <[email protected]>2021-10-06 17:16:17 +0200
committerLoïc Hoguin <[email protected]>2023-05-15 13:39:58 +0200
commite25fec8c0c0a50c3a92165ecfc018f0ce9bb0565 (patch)
tree0b2c5efbb4abc113057ab210482e26e8ff9d6bda
parentb7d8105ef0856bc30dfd018ccd357582a9f3f129 (diff)
downloaderlang.mk-e25fec8c0c0a50c3a92165ecfc018f0ce9bb0565.tar.gz
erlang.mk-e25fec8c0c0a50c3a92165ecfc018f0ce9bb0565.tar.bz2
erlang.mk-e25fec8c0c0a50c3a92165ecfc018f0ce9bb0565.zip
Added static compilation option for NIFs
-rw-r--r--plugins/c_src.mk26
1 files changed, 26 insertions, 0 deletions
diff --git a/plugins/c_src.mk b/plugins/c_src.mk
index 332b9fa..fd9c2d7 100644
--- a/plugins/c_src.mk
+++ b/plugins/c_src.mk
@@ -15,17 +15,24 @@ C_SRC_TYPE ?= shared
ifeq ($(PLATFORM),msys2)
C_SRC_OUTPUT_EXECUTABLE_EXTENSION ?= .exe
C_SRC_OUTPUT_SHARED_EXTENSION ?= .dll
+ C_SRC_OUTPUT_STATIC_EXTENSION ?= .lib
else
C_SRC_OUTPUT_EXECUTABLE_EXTENSION ?=
C_SRC_OUTPUT_SHARED_EXTENSION ?= .so
+ C_SRC_OUTPUT_STATIC_EXTENSION ?= .a
endif
ifeq ($(C_SRC_TYPE),shared)
C_SRC_OUTPUT_FILE = $(C_SRC_OUTPUT)$(C_SRC_OUTPUT_SHARED_EXTENSION)
+else ifeq ($(C_SRC_TYPE),static)
+ C_SRC_OUTPUT_FILE = $(C_SRC_OUTPUT)$(C_SRC_OUTPUT_STATIC_EXTENSION)
else
C_SRC_OUTPUT_FILE = $(C_SRC_OUTPUT)$(C_SRC_OUTPUT_EXECUTABLE_EXTENSION)
endif
+RANLIB ?= ranlib
+ARFLAGS ?= cr
+
ifeq ($(PLATFORM),msys2)
# We hardcode the compiler used on MSYS2. The default CC=cc does
# not produce working code. The "gcc" MSYS2 package also doesn't.
@@ -53,6 +60,11 @@ ifneq ($(PLATFORM),msys2)
CXXFLAGS += -fPIC
endif
+ifeq ($(C_SRC_TYPE),static)
+ CFLAGS += -DSTATIC_ERLANG_NIF=1
+ CXXFLAGS += -DSTATIC_ERLANG_NIF=1
+endif
+
CFLAGS += -I"$(ERTS_INCLUDE_DIR)" -I"$(ERL_INTERFACE_INCLUDE_DIR)"
CXXFLAGS += -I"$(ERTS_INCLUDE_DIR)" -I"$(ERL_INTERFACE_INCLUDE_DIR)"
@@ -69,6 +81,12 @@ cpp_verbose = $(cpp_verbose_$(V))
link_verbose_0 = @echo " LD " $(@F);
link_verbose = $(link_verbose_$(V))
+ar_verbose_0 = @echo " AR " $(@F);
+ar_verbose = $(ar_verbose_$(V))
+
+ranlib_verbose_0 = @echo " RANLIB" $(@F);
+ranlib_verbose = $(ranlib_verbose_$(V))
+
# Targets.
ifeq ($(wildcard $(C_SRC_DIR)),)
@@ -97,11 +115,19 @@ app:: $(C_SRC_ENV) $(C_SRC_OUTPUT_FILE)
test-build:: $(C_SRC_ENV) $(C_SRC_OUTPUT_FILE)
+ifneq ($(C_SRC_TYPE),static)
$(C_SRC_OUTPUT_FILE): $(OBJECTS)
$(verbose) mkdir -p $(dir $@)
$(link_verbose) $(CC) $(OBJECTS) \
$(LDFLAGS) $(if $(filter $(C_SRC_TYPE),shared),-shared) $(LDLIBS) \
-o $(C_SRC_OUTPUT_FILE)
+else
+$(C_SRC_OUTPUT_FILE): $(OBJECTS)
+ $(verbose) mkdir -p $(dir $@)
+ $(ar_verbose) $(AR) $(ARFLAGS) $(C_SRC_OUTPUT_FILE) $(OBJECTS)
+ $(ranlib_verbose) $(RANLIB) $(C_SRC_OUTPUT_FILE)
+endif
+
$(OBJECTS): $(MAKEFILE_LIST) $(C_SRC_ENV)