You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
2.3 KiB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
  1. # Based on c_src.mk from erlang.mk by Loic Hoguin <essen@ninenines.eu>
  2. CURDIR := $(shell pwd)
  3. BASEDIR := $(abspath $(CURDIR)/..)
  4. PROJECT ?= $(notdir $(BASEDIR))
  5. PROJECT := $(strip $(PROJECT))
  6. ERTS_INCLUDE_DIR ?= $(shell erl -noshell -s init stop -eval "io:format(\"~ts/erts-~ts/include/\", [code:root_dir(), erlang:system_info(version)]).")
  7. ERL_INTERFACE_INCLUDE_DIR ?= $(shell erl -noshell -s init stop -eval "io:format(\"~ts\", [code:lib_dir(erl_interface, include)]).")
  8. ERL_INTERFACE_LIB_DIR ?= $(shell erl -noshell -s init stop -eval "io:format(\"~ts\", [code:lib_dir(erl_interface, lib)]).")
  9. C_SRC_DIR = $(CURDIR)
  10. C_SRC_OUTPUT ?= $(CURDIR)/../priv/$(PROJECT).so
  11. # System type and C compiler/flags.
  12. UNAME_SYS := $(shell uname -s)
  13. ifeq ($(UNAME_SYS), Darwin)
  14. CC ?= cc
  15. CFLAGS ?= -O3 -std=c99 -arch x86_64 -finline-functions -Wall -Wmissing-prototypes
  16. CXXFLAGS ?= -O3 -arch x86_64 -finline-functions -Wall
  17. LDFLAGS ?= -arch x86_64 -flat_namespace -undefined suppress
  18. else ifeq ($(UNAME_SYS), FreeBSD)
  19. CC ?= cc
  20. CFLAGS ?= -O3 -std=c99 -finline-functions -Wall -Wmissing-prototypes
  21. CXXFLAGS ?= -O3 -finline-functions -Wall
  22. else ifeq ($(UNAME_SYS), Linux)
  23. CC ?= gcc
  24. CFLAGS ?= -O3 -std=c99 -finline-functions -Wall -Wmissing-prototypes
  25. CXXFLAGS ?= -O3 -finline-functions -Wall
  26. endif
  27. CFLAGS += -fPIC -I $(ERTS_INCLUDE_DIR) -I $(ERL_INTERFACE_INCLUDE_DIR)
  28. CXXFLAGS += -fPIC -I $(ERTS_INCLUDE_DIR) -I $(ERL_INTERFACE_INCLUDE_DIR)
  29. LDLIBS += -L $(ERL_INTERFACE_LIB_DIR) -lerl_interface -lei
  30. LDFLAGS += -shared
  31. # Verbosity.
  32. c_verbose_0 = @echo " C " $(?F);
  33. c_verbose = $(c_verbose_$(V))
  34. cpp_verbose_0 = @echo " CPP " $(?F);
  35. cpp_verbose = $(cpp_verbose_$(V))
  36. link_verbose_0 = @echo " LD " $(@F);
  37. link_verbose = $(link_verbose_$(V))
  38. SOURCES := $(shell find $(C_SRC_DIR) -type f \( -name "*.c" -o -name "*.C" -o -name "*.cc" -o -name "*.cpp" \))
  39. OBJECTS = $(addsuffix .o, $(basename $(SOURCES)))
  40. COMPILE_C = $(c_verbose) $(CC) $(CFLAGS) $(CPPFLAGS) -c
  41. COMPILE_CPP = $(cpp_verbose) $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c
  42. $(C_SRC_OUTPUT): $(OBJECTS)
  43. @mkdir -p $(BASEDIR)/priv/
  44. $(link_verbose) $(CC) $(OBJECTS) $(LDFLAGS) $(LDLIBS) -o $(C_SRC_OUTPUT)
  45. %.o: %.c
  46. $(COMPILE_C) $(OUTPUT_OPTION) $<
  47. %.o: %.cc
  48. $(COMPILE_CPP) $(OUTPUT_OPTION) $<
  49. %.o: %.C
  50. $(COMPILE_CPP) $(OUTPUT_OPTION) $<
  51. %.o: %.cpp
  52. $(COMPILE_CPP) $(OUTPUT_OPTION) $<
  53. clean:
  54. @rm -f $(C_SRC_OUTPUT) $(OBJECTS)