/
modules.mk
90 lines (78 loc) · 2.26 KB
/
modules.mk
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
# List of built-in modules
modules_TARGETS := hints \
stats \
cachectl
# Memcached
ifeq ($(HAS_libmemcached),yes)
modules_TARGETS += kmemcached
endif
# Redis
ifeq ($(HAS_hiredis),yes)
modules_TARGETS += redis
endif
# List of Lua modules
ifeq ($(HAS_lua),yes)
modules_TARGETS += ketcd \
graphite \
policy \
view \
predict \
dns64 \
renumber
endif
# List of Golang modules
ifeq ($(HAS_go),yes)
ifeq ($(HAS_geoip),yes)
modules_TARGETS += tinyweb
endif
endif
# Make C module
define make_c_module
$(1)-install: moduledir
$(eval $(call make_module,$(1),modules/$(1)))
endef
# Make Lua module
define make_lua_module
$(eval $(call lua_target,$(1),modules/$(1)))
endef
# Lua target definition
define lua_target
$(1) := $$(addprefix $(2)/,$$($(1)_SOURCES))
$(1)-clean:
$(1)-install: $$(addprefix $(2)/,$$($(1)_SOURCES)) moduledir
$(INSTALL) -m 0644 $$(addprefix $(2)/,$$($(1)_SOURCES)) $(PREFIX)/$(MODULEDIR)
.PHONY: $(1) $(1)-install $(1)-clean
endef
# Make Go module
define make_go_module
$(eval $(call go_target,$(1),modules/$(1)))
endef
# Filter CGO flags
CGO_CFLAGS := $(filter-out -flto,$(BUILD_CFLAGS))
# Go target definition
define go_target
$(1) := $(2)/$(1)$(LIBEXT)
$(2)/$(1)$(LIBEXT): $$($(1)_SOURCES) $$($(1)_DEPEND)
@echo " GO $(2)"; CGO_CFLAGS="$(CGO_CFLAGS)" CGO_LDFLAGS="$$($(1)_LIBS) $(CFLAGS)" $(GO) build -buildmode=c-shared -o $$@ $$($(1)_SOURCES)
$(1)-clean:
$(RM) -r $(2)/$(1).h $(2)/$(1)$(LIBEXT)
ifeq ($$(strip $$($(1)_INSTALL)),)
$(1)-dist:
$(INSTALL) -d $(PREFIX)/$(MODULEDIR)
else
$(1)-dist: $$($(1)_INSTALL)
$(INSTALL) -d $(PREFIX)/$(MODULEDIR)/$(1)
$(INSTALL) -m 0644 $$^ $(PREFIX)/$(MODULEDIR)/$(1)
endif
$(1)-install: $(2)/$(1)$(LIBEXT) $(1)-dist moduledir
$(INSTALL) $(2)/$(1)$(LIBEXT) $(PREFIX)/$(MODULEDIR)
.PHONY: $(1)-clean $(1)-install $(1)-dist
endef
# Include modules
$(foreach module,$(modules_TARGETS),$(eval include modules/$(module)/$(module).mk))
$(eval modules = $(foreach module,$(modules_TARGETS),$$($(module))))
# Targets
modules: $(modules)
modules-clean: $(addsuffix -clean,$(modules_TARGETS))
modules-install: $(addsuffix -install,$(modules_TARGETS))
.PHONY: modules modules-clean modules-install