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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
# vim:ts=4:sw=4:noexpandtab
MAKEFLAGS += --no-builtin-rules
# Default output path. Can be changed by enviroment to compile to different folder
# than default.
O ?= .
# This variable can be overwritten to show executed commands
Q = @
# Load configuration
-include $(O)/.config.mk
# TODO add CROSS_COMPILE support
BISON ?= bison
CC ?= gcc
# TODO also other tools
.PHONY: all
all: $(O)/geml
# TODO modules
ifeq ($(DEBUG),yes)
CFLAGS += -ggdb -DDEBUG
endif
CFLAGS += -Wall
CFLAGS += -Iinclude -include $(O)/build/config.h
### Source files list ###########################
SRC = geml.c \
utils.c \
io.c \
command.c \
parser.c
### End of source files list ####################
CSRC = $(patsubst %,src/%,$(filter %.c,$(SRC)))
YSRC = $(patsubst %,src/%,$(filter %.y,$(SRC)))
CYSRC = $(patsubst %,%.c,$(YSRC))
HYSRC = $(patsubst %,%.h,$(YSRC))
CSRC += $(CYSRC)
GPERFSRC = $(patsubst %,src/%,$(filter %.gperf,$(SRC)))
HGPERFSRC = $(patsubst %,%.h,$(GPERFSRC))
OBJ = $(patsubst src/%.c,$(O)/build/%.o,$(CSRC))
DEP = $(patsubst src/%.c,$(O)/build/%.d,$(CSRC))
.PHONY: help
help:
@echo "Simple general preprocessor make targets:"
@echo " all|geml - Build geml executable"
@echo " help - Prints this text help."
@echo " install - Install geml to you system"
@echo " uninstall - Revert install target actions on your system"
@echo " clean - Cleans builded files"
@echo " distclean - Same as clean but also removes distributed generated files"
@echo " docs - Build html documentation"
@echo " serve-docs - Start html server with documentation on localhost:4000"
@echo " clean-docs - Removes generated documentation"
@echo "Some enviroment variables to be defined:"
@echo " CROSS_COMPILE - Specifies installation prefix. Default is /usr/local"
@echo " Q - Define emty to show executed commands"
.PHONY: install
install:
#TODO
.PHONY: uninstall
uninstall:
#TODO
# Cleaning
.PHONY: clean
clean::
@echo " CLEAN build"
$(Q)$(RM) -r $(O)/build
@echo " CLEAN geml"
$(Q)$(RM) $(O)/geml
.PHONY: distclean
distclean:: clean
@echo " CLEAN distributed"
$(Q)$(RM) $(CYSRC)
$(Q)$(RM) $(HYSRC)
$(Q)$(RM) $(HGPERFSRC)
@echo " CLEAN configuration"
$(Q)$(RM) $(O)/.config
docs/%.dot.png: docs/%.dot
@echo " DOT $@"
$(Q)dot -Tpng -O $<
.PHONY: docs
docs: docs/parser-states.dot.png
@echo " DOC $@"
$(Q)mkdocs build
.PHONY: serve-docs
serve-docs: docs/parser-states.dot.png
$(Q)mkdocs serve
.PHONY: clean-docs
clean-docs:
@echo " CLEAN docs"
$(Q)$(RM) docs/parser-states.dot.png
$(Q)$(RM) -r site
ifeq (,$(filter clean distclean help docs serve-docs clean-docs \
,$(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/%.c
@mkdir -p "$(@D)"
@echo " DEP $@"
$(Q)$(CC) -MM -MG -MT '$*.o $@' $(CFLAGS) $< -MF $@
endif # DEBUG
$(O)/geml: $(OBJ)
@echo " LD $@"
$(Q)$(CC) $(CFLAGS) $^ -o $@
$(OBJ): $(O)/build/%.o: src/%.c $(O)/build/config.h
@mkdir -p "$(@D)"
@echo " CC $@"
$(Q)$(CC) -c $(CFLAGS) $< -o $@
$(O)/build/config.h: $(O)/.config
@mkdir -p "$(@D)"
@echo " CONF $@"
$(Q)./configure --op-h > $@
$(HGPERFSRC): %.y.h: %.y.c
@
$(CYSRC): %.y.c: %.y
@echo " BISON $@"
$(Q)$(BISON) -d -o $@ $<
$(HGPERFSRC): %.h: %
@echo " GPERF $@"
$(Q)$(GPERF) --output-file=$@ $<
endif
# Configuation files
$(O)/.config:
$(error Please run configure script first)
$(O)/.config.mk: $(O)/.config
@echo " CONF $@"
$(Q)./configure --op-makefile > $@
|