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
|
#MAKEFLAGS += --no-builtin-rules
# This variable can be overwritten to show executed commands
Q ?= @
# Default output path. This is used when output (writable) directory is different
# than project directory. You shouldn't be setting it by hand, but it is used in
# external Makefiles.
O ?= .
# Load configuration
-include $(O)/.config.mk
.PHONY: all
all: $(O)/turris-lcd
ifeq ($(DEBUG),yes)
CFLAGS += -ggdb -DDEBUG
endif
CFLAGS += -Wall
CFLAGS += -Iliblcd -include $(O)/build/config.h
# Apply CPREFIX
CXX:=$(CPREFIX)$(CXX)
### Source files list ###########################
SRC = turris-lcd.cpp
### End of source files list ####################
CSRC = $(patsubst %,src/%,$(filter %.cpp,$(SRC)))
OBJ = $(patsubst src/%.cpp,$(O)/build/%.o,$(CSRC))
DEP = $(patsubst src/%.cpp,$(O)/build/%.d,$(CSRC))
.PHONY: help
help:
@echo "General extendable macro language make targets:"
@echo " turris-lcd - Build geml executable"
@echo " help - Prints this text help."
@echo " clean - Cleans builded files"
@echo " prune - Same as clean but also removes configuration."
@echo "Some enviroment variables to be defined:"
@echo " Q - Define emty to show executed commands"
# Cleaning
.PHONY: clean
clean::
@echo " CLEAN build"
$(Q)$(RM) -r $(O)/build
$(Q)$(RM) $(O)/.config.mk
@echo " CLEAN turris-lcd"
$(Q)$(RM) $(O)/turris-lcd
.PHONY: prune
prune:: clean
@echo " CLEAN configuration"
$(Q)$(RM) $(O)/.config $(O)/.config.mk
@echo " CLEAN liblcd"
$(Q)$(MAKE) -C liblcd clean
$(Q)$(RM) liblcd/libliquidcrystali2c.a
## Building targets ##
ifeq (,$(filter clean prune help \
,$(MAKECMDGOALS))) # Ignore build targets if goal is not building
ifeq ($(DEBUG),yes)
-include $(DEP) # If developing, use dependencies from source files
.PHONY: dependency dep
dependency dep:: $(DEP)
$(DEP): $(O)/build/%.d: src/%.cpp
@mkdir -p "$(@D)"
@echo " DEP $@"
$(Q)$(CXX) -MM -MG -MT '$*.o $@' $(CFLAGS) $< -MF $@
endif # DEBUG
$(O)/turris-lcd: $(OBJ) liblcd/libliquidcrystali2c.a
@echo " LD $@"
$(Q)$(CXX) $(LDFLAGS) $^ -o $@
$(OBJ): $(O)/build/%.o: src/%.cpp $(O)/build/config.h
@mkdir -p "$(@D)"
@echo " CXX $@"
$(Q)$(CXX) -c $(CFLAGS) $< -o $@
$(O)/build/config.h: $(O)/.config
@mkdir -p "$(@D)"
@echo " CONF $@"
$(Q)$(O)/configure --op-h > $@
liblcd/libliquidcrystali2c.a:
$(Q)$(MAKE) -C liblcd static
endif
## Configuation files ##
$(O)/.config:
$(error Please run configure script first)
$(O)/.config.mk: $(O)/.config
@echo " CONF $@"
$(Q)$(O)/configure --op-makefile > $@
|