-
Notifications
You must be signed in to change notification settings - Fork 1
/
makefile
executable file
·170 lines (133 loc) · 4.54 KB
/
makefile
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# ====================
# Display introduction
# ====================
$(info escrido makefile 1.1)
$(info Copyright (C) 2017 Gunnar Schulze)
$(info )
# ===============================
# Compiler and linker executables
# ===============================
CPP := g++
LINK := g++
# =====================================
# Lexical scanner and parser executable
# =====================================
LEX := lex
YACC := yacc
# =========================
# Compiler and linker flags
# =========================
# Compiler flag options:
# For useing valgrind use here: CPPFLAGS="-std=c++11 -O0 -g -w"
CPPFLAGS := -std=c++11 -O3 -w
# Linker flag options:
LINKFLAGS := -std=c++11
# Additional compiler flag (can be overwritten by calling user):
ARG :=
# Define for OS selection in module 'filesys.h'.
# This needs to be changed for targeting different OSs:
OSDEF := -D FILESYS_UNIX
# ===========
# Directories
# ===========
# Binary directory:
BINDIR := bin
# Target directory for .o and .a files:
LIBDIR := lib
# Directory for generic source files:
GENDIR := generic
# List of directories of all source files:
SRCDIRS := src \
src/independent \
$(GENDIR)
# Generate a list of include directories for the compiler call:
INCLUDEDIRS := $(addprefix -I./, $(SRCDIRS))
# Generate lists of all source files:
SRCFILES_C := $(foreach directory, $(SRCDIRS), $(wildcard $(directory)/*.c))
SRCFILES_CPP := $(foreach directory, $(SRCDIRS), $(wildcard $(directory)/*.cpp))
# Generate a list of all object files:
OBJFILES := $(addprefix $(LIBDIR)/, $(notdir $(SRCFILES_C:.c=.o) $(SRCFILES_CPP:.cpp=.o)))
OBJFILES := $(OBJFILES) $(LIBDIR)/lescrido.o $(LIBDIR)/yescrido.o
#$(info $(OBJFILES))
# =================
# Build main target
# =================
# Main target created by linking.
$(BINDIR)/escrido: $(OBJFILES)
@echo "Linking all modules ..."
$(LINK) $(LINKFLAGS) -o $(BINDIR)/escrido $(OBJFILES)
@echo
# Modelling dependency of module 'main' from the generic header files
# 'interpargs.h' (of the command line argument parser) and 'yescrido.h' (of the
# yacc parser)
$(LIBDIR)/main.o: $(GENDIR)/interpargs.h $(GENDIR)/yescrido.h
# =========================
# Build object file targets
# =========================
# Reminder: input of the rule is '$<', output is '$@'
# Pattern templates for compiling a single module.
# (This is packed into a 'define' statement to generate a pattern for
# each source directory of SRCDIRS.)
# (Double dollar signs '$' are required to work inside 'define'
# environment.)
define C_COMPILE_RULE_TEMPLATE
$$(LIBDIR)/%.o: $(1)/%.c
@echo "Compiling module '$$<' ..."
$$(CPP) $$(INCLUDEDIRS) $$(CPPFLAGS) $$(ARG) $$(OSDEF) -c -o $$@ $$<
@echo
endef
define CPP_COMPILE_RULE_TEMPLATE
$$(LIBDIR)/%.o: $(1)/%.cpp
@echo "Compiling module '$$<' ..."
$$(CPP) $$(INCLUDEDIRS) $$(CPPFLAGS) $$(ARG) $$(OSDEF) -c -o $$@ $$<
@echo
endef
# Generate pattern for each source directory out of SRCDIRS.
$(foreach directory, $(sort $(SRCDIRS)), $(eval $(call C_COMPILE_RULE_TEMPLATE,$(directory))))
$(foreach directory, $(sort $(SRCDIRS)), $(eval $(call CPP_COMPILE_RULE_TEMPLATE,$(directory))))
# ============================
# Build command line arguments
# ============================
# Check that blue-footed-booby is available and eventually compile it.
tools/bb/bb: tools/bb/sources/bb.cpp
@echo "Compiling blue-footed booby ..."
$(CPP) -std=c++11 -O3 tools/bb/sources/bb.cpp -o tools/bb/bb
@echo
# Generate command line file using the blue-footed-booby.
$(GENDIR)/interpargs.h: tools/bb/bb grammar/escrido.bb
@echo "Generating command line parser ..."
tools/bb/bb grammar/escrido.bb $(GENDIR)/interpargs.h
@echo
# =================
# Build yacc parser
# =================
# Rule for building the yacc parser output files yescrido.h and
# yescrido.c from input file escrido.y:
$(GENDIR)/yescrido.h \
$(GENDIR)/yescrido.c: grammar/escrido.y
@echo "Building yacc parser ..."
$(YACC) -d -o $(GENDIR)/yescrido.c grammar/escrido.y
@echo
# Rule for building the lexer output files lescrido.c from input files
# files yescrido.h and escrido.l:
$(GENDIR)/lescrido.c: $(GENDIR)/yescrido.h grammar/escrido.l
@echo "Building lexical analyzer ..."
$(LEX) -o $(GENDIR)/lescrido.c grammar/escrido.l
@echo
# ==============
# "clean" target
# ==============
.PHONY: clean
clean:
rm -f $(BINDIR)/escrido
rm -f $(LIBDIR)/*.o
rm -f $(GENDIR)/*
rm -f tools/bb/bb
# ============
# "win" target
# ============
.PHONY: win
win: OSDEF := -D FILESYS_WINDOWS
win: CPPFLAGS := -std=gnu++11 -O3 -w
win: LINKFLAGS := -std=gnu++11 -pthread -static-libgcc -static-libstdc++
win: $(BINDIR)/escrido