From 73e4844066c7e898aefbf4eb697eccb26440f45e Mon Sep 17 00:00:00 2001 From: Slava Yurin Date: Thu, 20 Nov 2014 12:04:31 +0600 Subject: plugin/c_src: compile C++ source Add compile .cc,.cpp,.C files as C++. Compile each source file to .o. Link all .o object to .so. Delete .o on clean target. --- erlang.mk | 39 ++++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) (limited to 'erlang.mk') diff --git a/erlang.mk b/erlang.mk index e553926..e979093 100644 --- a/erlang.mk +++ b/erlang.mk @@ -594,23 +594,33 @@ UNAME_SYS := $(shell uname -s) ifeq ($(UNAME_SYS), Darwin) CC ?= cc CFLAGS ?= -O3 -std=c99 -arch x86_64 -flat_namespace -undefined suppress -finline-functions -Wall -Wmissing-prototypes + CXXFLAGS ?= -O3 -arch x86_64 -flat_namespace -undefined suppress -finline-functions -Wall else ifeq ($(UNAME_SYS), FreeBSD) CC ?= cc CFLAGS ?= -O3 -std=c99 -finline-functions -Wall -Wmissing-prototypes + CXXFLAGS ?= -O3 -finline-functions -Wall else ifeq ($(UNAME_SYS), Linux) CC ?= gcc CFLAGS ?= -O3 -std=c99 -finline-functions -Wall -Wmissing-prototypes + CXXFLAGS ?= -O3 -finline-functions -Wall endif CFLAGS += -fPIC -I $(ERTS_INCLUDE_DIR) -I $(ERL_INTERFACE_INCLUDE_DIR) +CXXFLAGS += -fPIC -I $(ERTS_INCLUDE_DIR) -I $(ERL_INTERFACE_INCLUDE_DIR) LDLIBS += -L $(ERL_INTERFACE_LIB_DIR) -lerl_interface -lei LDFLAGS += -shared # Verbosity. -c_src_verbose_0 = @echo " C_SRC " $(?F); -c_src_verbose = $(c_src_verbose_$(V)) +c_verbose_0 = @echo " C " $(?F); +c_verbose = $(c_verbose_$(V)) + +cpp_verbose_0 = @echo " CPP " $(?F); +cpp_verbose = $(cpp_verbose_$(V)) + +link_verbose_0 = @echo " LD " $(@F); +link_verbose = $(link_verbose_$(V)) # Targets. @@ -623,14 +633,29 @@ clean:: $(MAKE) -C $(C_SRC_DIR) clean else -SOURCE := $(shell find $(C_SRC_DIR) -type f -name \*.c) +SOURCES := $(shell find $(C_SRC_DIR) -type f -regex ".*\.\(C\|cc?\|cpp\)") +OBJECTS = $(addsuffix .o, $(basename $(SOURCES))) + +COMPILE_C = $(c_verbose) $(CC) $(CFLAGS) $(CPPFLAGS) $(C_SRC_OPTS) -c +COMPILE_CPP = $(cpp_verbose) $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(C_SRC_OPTS) -c app:: $(C_SRC_ENV) $(C_SRC_OUTPUT) -$(C_SRC_OUTPUT): $(SOURCE) +$(C_SRC_OUTPUT): $(OBJECTS) @mkdir -p priv/ - $(c_src_verbose) $(CC) $(CFLAGS) $(SOURCE) \ - $(LDFLAGS) $(LDLIBS) -o $(C_SRC_OUTPUT) $(C_SRC_OPTS) + $(link_verbose) $(CC) $(OBJECTS) $(LDFLAGS) $(LDLIBS) -o $(C_SRC_OUTPUT) + +%.o: %.c + $(COMPILE_C) $(OUTPUT_OPTION) $< + +%.o: %.cc + $(COMPILE_CPP) $(OUTPUT_OPTION) $< + +%.o: %.C + $(COMPILE_CPP) $(OUTPUT_OPTION) $< + +%.o: %.cpp + $(COMPILE_CPP) $(OUTPUT_OPTION) $< $(C_SRC_ENV): @erl -noshell -noinput -eval "file:write_file(\"$(C_SRC_ENV)\", \ @@ -646,7 +671,7 @@ $(C_SRC_ENV): clean:: clean-c_src clean-c_src: - $(gen_verbose) rm -f $(C_SRC_OUTPUT) + $(gen_verbose) rm -f $(C_SRC_OUTPUT) $(OBJECTS) distclean:: distclean-c_src-env -- cgit v1.2.3 From edb63def754834c1e3654a8fd2681a7ec1f97a65 Mon Sep 17 00:00:00 2001 From: Slava Yurin Date: Thu, 20 Nov 2014 18:01:36 +0600 Subject: plugin/c_src: remove C_SRC_OPTS We can just LDFLAGS += and whatnot. --- erlang.mk | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'erlang.mk') diff --git a/erlang.mk b/erlang.mk index e979093..5b07ef8 100644 --- a/erlang.mk +++ b/erlang.mk @@ -585,7 +585,6 @@ list-templates: C_SRC_DIR = $(CURDIR)/c_src C_SRC_ENV ?= $(C_SRC_DIR)/env.mk -C_SRC_OPTS ?= C_SRC_OUTPUT ?= $(CURDIR)/priv/$(PROJECT).so # System type and C compiler/flags. @@ -636,8 +635,8 @@ else SOURCES := $(shell find $(C_SRC_DIR) -type f -regex ".*\.\(C\|cc?\|cpp\)") OBJECTS = $(addsuffix .o, $(basename $(SOURCES))) -COMPILE_C = $(c_verbose) $(CC) $(CFLAGS) $(CPPFLAGS) $(C_SRC_OPTS) -c -COMPILE_CPP = $(cpp_verbose) $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(C_SRC_OPTS) -c +COMPILE_C = $(c_verbose) $(CC) $(CFLAGS) $(CPPFLAGS) -c +COMPILE_CPP = $(cpp_verbose) $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c app:: $(C_SRC_ENV) $(C_SRC_OUTPUT) -- cgit v1.2.3