aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/c_src.mk
diff options
context:
space:
mode:
authorSlava Yurin <[email protected]>2014-11-20 12:04:31 +0600
committerSlava Yurin <[email protected]>2014-11-20 17:59:22 +0600
commit73e4844066c7e898aefbf4eb697eccb26440f45e (patch)
tree466d04c71b6c2ec48cd7ef909a8fc4d3353714df /plugins/c_src.mk
parent2babb150053941bd44f32bd19655484e353738ed (diff)
downloaderlang.mk-73e4844066c7e898aefbf4eb697eccb26440f45e.tar.gz
erlang.mk-73e4844066c7e898aefbf4eb697eccb26440f45e.tar.bz2
erlang.mk-73e4844066c7e898aefbf4eb697eccb26440f45e.zip
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.
Diffstat (limited to 'plugins/c_src.mk')
-rw-r--r--plugins/c_src.mk39
1 files changed, 32 insertions, 7 deletions
diff --git a/plugins/c_src.mk b/plugins/c_src.mk
index 0b4064a..1861c79 100644
--- a/plugins/c_src.mk
+++ b/plugins/c_src.mk
@@ -17,23 +17,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.
@@ -46,14 +56,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)\", \
@@ -69,7 +94,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