-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
104 lines (76 loc) · 3.08 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# Based on c_src.mk from erlang.mk by Loic Hoguin <[email protected]>
CURDIR := $(shell pwd)
BASEDIR := $(abspath $(CURDIR)/..)
CFLAGS += -fPIC
CXXFLAGS += -fPIC
PKG_CONFIG_ERL_EI = $(shell pkg-config --exists erl_ei; echo $$?)
PKG_CONFIG_ERL_ERTS = $(shell pkg-config --exists erl_erts; echo $$?)
ifeq ($(PKG_CONFIG_ERL_EI), 0)
ERL_INTERFACE_INCLUDE_DIR = $(shell pkg-config --cflags erl_ei)
ERL_INTERFACE_LIB_DIR = $(shell pkg-config --libs erl_ei)
CFLAGS += $(ERL_INTERFACE_INCLUDE_DIR)
CXXFLAGS += $(ERL_INTERFACE_INCLUDE_DIR)
LDLIBS += $(ERL_INTERFACE_LIB_DIR)
else
ERL_INTERFACE_INCLUDE_DIR = $(shell erl -noshell -s init stop -eval "io:format(\"~ts\", [code:lib_dir(erl_interface, include)]).")
ERL_INTERFACE_LIB_DIR = $(shell erl -noshell -s init stop -eval "io:format(\"~ts\", [code:lib_dir(erl_interface, lib)]).")
CFLAGS += -I $(ERL_INTERFACE_INCLUDE_DIR)
CXXFLAGS += -I $(ERL_INTERFACE_INCLUDE_DIR)
LDLIBS += -L $(ERL_INTERFACE_LIB_DIR) -lei
endif
ifeq ($(PKG_CONFIG_ERL_ERTS), 0)
ERTS_INCLUDE_DIR = $(shell pkg-config --cflags erl_erts)
CFLAGS += $(ERTS_INCLUDE_DIR)
CXXFLAGS += $(ERTS_INCLUDE_DIR)
else
ERTS_INCLUDE_DIR = $(shell erl -noshell -s init stop -eval "io:format(\"~ts/erts-~ts/include/\", [code:root_dir(), erlang:system_info(version)]).")
CFLAGS += -I $(ERTS_INCLUDE_DIR)
CXXFLAGS += -I $(ERTS_INCLUDE_DIR)
endif
C_SRC_DIR = $(CURDIR)
C_SRC_OUTPUT_PORT_DRV ?= $(CURDIR)/priv/port_driver.so
# System type and C compiler/flags.
UNAME_SYS := $(shell uname -s)
ifeq ($(UNAME_SYS), Darwin)
CC ?= cc
CFLAGS ?= -O3 -std=c99 -arch x86_64 -finline-functions -Wall -Wmissing-prototypes
CXXFLAGS ?= -O3 -arch x86_64 -finline-functions -Wall
LDFLAGS ?= -arch x86_64 -flat_namespace -undefined suppress
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 $(ERTS_INCLUDE_DIR) $(ERL_INTERFACE_INCLUDE_DIR)
#CXXFLAGS += -fPIC -I $(ERTS_INCLUDE_DIR) -I $(ERL_INTERFACE_INCLUDE_DIR)
#LDLIBS += $(ERL_INTERFACE_LIB_DIR)
LDFLAGS += -shared
# Verbosity.
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))
SOURCES_PORT_DRV := src/port_driver.c
OBJECTS_PORT_DRV = $(addsuffix .o, $(basename $(SOURCES_PORT_DRV)))
COMPILE_C = $(c_verbose) $(CC) $(CFLAGS) $(CPPFLAGS) -c
COMPILE_CPP = $(cpp_verbose) $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c
all: $(C_SRC_OUTPUT_PORT_DRV)
$(C_SRC_OUTPUT_PORT_DRV): $(OBJECTS_PORT_DRV)
@mkdir -p $(CURDIR)/priv
$(link_verbose) $(CC) $(OBJECTS_PORT_DRV) $(LDFLAGS) $(LDLIBS) -o $(C_SRC_OUTPUT_PORT_DRV)
%.o: %.c
$(COMPILE_C) $(OUTPUT_OPTION) $<
%.o: %.cc
$(COMPILE_CPP) $(OUTPUT_OPTION) $<
%.o: %.C
$(COMPILE_CPP) $(OUTPUT_OPTION) $<
%.o: %.cpp
$(COMPILE_CPP) $(OUTPUT_OPTION) $<
clean:
@rm -f $(C_SRC_OUTPUT_PORT_DRV) $(OBJECTS_PORT_DRV)