-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
90 lines (71 loc) · 2.23 KB
/
Makefile
File metadata and controls
90 lines (71 loc) · 2.23 KB
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
# Variables
CPUS := $(shell getconf _NPROCESSORS_ONLN 2>/dev/null || sysctl -n hw.ncpu)
PREFIX = $(MIX_APP_PATH)/priv
# Erlang-specific settings
ERL_CFLAGS ?= -I$(ERTS_INCLUDE_DIR)
ERL_LDFLAGS ?= -L$(ERL_INTERFACE_LIB_DIR)
LDFLAGS += -shared
CFLAGS += -fPIC
CFLAGS ?= -O2 -Wall -Wextra -Wno-unused-parameter -std=c99
ifeq ($(CROSSCOMPILE),)
ifeq ($(shell uname),Darwin)
LDFLAGS += -undefined dynamic_lookup
endif
endif
NIF = $(PREFIX)/exrdkafka_nif.so
# C source settings
C_SRC_DIR = $(shell pwd)/c_src
C_SRC_ENV ?= $(C_SRC_DIR)/env.mk
# Targets
.PHONY: all get_deps compile_nif clean_nif cpplint cppcheck
all: compile_nif $(NIF)
get_deps:
@./build_deps.sh
compile_nif: get_deps
@make V=0 -C c_src -j $(CPUS)
c_src/%.o: c_src/%.c | $(PREFIX)
@echo " CC $(notdir $@)"
$(CC) -c $(ERL_CFLAGS) $(CFLAGS) -o $@ $<
$(NIF): c_src/exrdkafka_nif.o c_src/exrdkafka_producer.o | $(PREFIX)
@echo " LD $(notdir $@)"
$(CC) $^ $(ERL_LDFLAGS) $(LDFLAGS) -o $@
$(PREFIX):
mkdir -p $@
clean: clean_nif
clean_nif:
@make -C c_src clean
$(RM) $(NIF)
$(RM) c_src/*.o
cpplint:
cpplint --counting=detailed \
--filter=-legal/copyright,-build/include_subdir,-build/include_order,-whitespace/blank_line,-whitespace/braces,-whitespace/indent,-whitespace/parens,-whitespace/newline \
--linelength=300 \
--exclude=c_src/*.o --exclude=c_src/*.mk \
c_src/*.*
cppcheck:
cppcheck -j $(CPUS) \
-I /usr/local/opt/openssl/include \
-I deps/librdkafka/src \
-I $(ERTS_INCLUDE_DIR) \
-I $(ERL_INTERFACE_INCLUDE_DIR) \
--force \
--enable=all \
--xml-version=2 \
--output-file=cppcheck_results.xml \
c_src/
# Generate env.mk
ifneq ($(wildcard $(C_SRC_DIR)),)
GEN_ENV ?= $(shell erl -noshell -s init stop -eval "file:write_file(\"$(C_SRC_ENV)\", \
io_lib:format( \
\"ERTS_INCLUDE_DIR ?= ~s/erts-~s/include/~n\" \
\"ERL_INTERFACE_INCLUDE_DIR ?= ~s~n\" \
\"ERL_INTERFACE_LIB_DIR ?= ~s~n\", \
[code:root_dir(), erlang:system_info(version), \
code:lib_dir(erl_interface, include), \
code:lib_dir(erl_interface, lib)])), \
halt().")
$(GEN_ENV)
endif
include $(C_SRC_ENV)
# Don't echo commands unless the caller exports "V=1"
${V}.SILENT: