diff options
-rw-r--r-- | erlang.mk | 39 | ||||
-rw-r--r-- | plugins/c_src.mk | 39 |
2 files changed, 64 insertions, 14 deletions
@@ -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 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 |