-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile.common
72 lines (58 loc) · 1.84 KB
/
Makefile.common
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
########################################
# MAKEFILE VARIABLES
OPACOMPILER ?= opa
OPA = $(OPACOMPILER) $(FLAG) $(OPAOPT)
PWD ?= $(shell pwd)
BUILDDIR ?= _build
export BUILDDIR
OPAGENAPI ?= $(OPACOMPILER) --api-only
DEPENDS = $(SRC) $(PCK:%=$(BUILDDIR)/%) $(PLUGIN:%=$(BUILDDIR)/%)
ifdef CONF_FILE
CONFIG = --conf $(CONF_FILE) --conf-opa-files
else
CONFIG =
endif
ifdef SystemRoot
RM = rmdir /s /q
RMFILE = del /s /q
else
RM = rm -rf
RMFILE = rm
endif
# Hack to bypass the lack of "make -p" on Windows:
_ = $(shell mkdir _build 2>/dev/null)
########################################
# MAIN RULE
exe : $(EXE)
pack : $(PACKNAME)
########################################
# MAIN PACKAGE BUILDING
$(PACKNAME) : $(BUILDDIR)/$(PACKNAME)
$(BUILDDIR)/$(PACKNAME) : $(DEPENDS)
@echo "### Building package $(PACKNAME)"
$(OPA) --autocompile $(SRC) $(PLUGIN:%=$(BUILDDIR)/%) --build-dir $(BUILDDIR) -I $(BUILDDIR) $(OPAOPT)
$(RM) $(BUILDDIR)/$(PACKNAME)
@mv $(PACKNAME) $(BUILDDIR)/
########################################
# SUBS PACKAGE/PLUGIN BUILDING
$(BUILDDIR)/%.opx :
make $(@:$(BUILDDIR)/%.opx=-C $(PCKDIR)/%) pack
$(BUILDDIR)/%.opp :
make $(@:$(BUILDDIR)/%.opp=-C $(PLUGINDIR)/%)
########################################
# EXECUTABLE BUILDING
$(EXE) : pack $(SRC) $(MAINSRC) $(DEPENDS) $(OTHER_DEPENDS)
@echo "### Building executable $(EXE) "
$(OPA) $(COMPILOPT) $(MAINSRC) $(CONFIG) $(PLUGIN:%=$(BUILDDIR)/%) -o $@ --build-dir $(BUILDDIR)/$(EXE)
$(EXE:%.exe=%.run) : $(EXE)
./$(EXE) -p $(PORT)
########################################
# Used by recursives makefile
pack.depends :
@echo $(PCK) $(PLUGIN)
########################################
# CLEANING
clean ::
@$(PCK:%.opx=make -C $(PCKDIR)/% clean &&) $(PLUGIN:%.opp=make -C $(PLUGINDIR)/% clean &&) echo "### Cleaning $(BUILDDIR)";
$(RM) $(BUILDDIR) 2>/dev/null
$(RMFILE) $(EXE) 2>/dev/null