-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGNUmakefile
164 lines (141 loc) · 5.35 KB
/
GNUmakefile
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
# Set the compiler/linker for the build:
ifeq ($(strip $(COMPILER)),clang)
CC=clang
else ifeq ($(strip $(COMPILER)),gcc)
CC=g++
else
CC=clang
endif
AR=ar rcs
LNKSO=$(CC) -shared
# Set a timer for make test/check
ifeq ($(subst 1,Y,$(subst YES,Y,$(strip $(TIME)))),Y)
TIMECMD=/usr/bin/time -f "%C running %e seconds"
else
TIMECMD=
endif
# Debug and release flags, RELEASE=Y highest optimization level else create debug symbols and buil with lowest optimization level
ifeq ($(subst 1,Y,$(subst YES,Y,$(strip $(RELEASE)))),Y)
DEBUGOPTFLAGS:=-O3
else
ifeq ($(strip $(CC)),clang)
DEBUGOPTFLAGS:=-ggdb -g3 -O0 -fstandalone-debug
else
DEBUGOPTFLAGS:=-ggdb -g3 -O0
endif
endif
# Flag for using an allocator always throwing bad_alloc as upstream memory resource for the monotonic buffer resource
# used for structures intended to be allocated on the stack. This must not be set in a release build and not in all cases of a debug build.
ifeq ($(subst 1,Y,$(subst YES,Y,$(strip $(TESTLOCALMEM)))),Y)
DEBUGOPTFLAGS:=$(DEBUGOPTFLAGS) -DMEWA_TEST_LOCAL_MEMORY_RESOURCE
endif
# Switch verbosity on for build and make test/check
ifeq ($(subst 1,Y,$(subst YES,Y,$(strip $(VERBOSE)))),Y)
CXXVBFLAGS :=-v
TSTVBFLAGS :=-V
endif
# Set default PREFIX and installation dir of manpage
ifeq ($(strip $(PREFIX)),/usr)
MANPAGES := `man --path | awk '1' RS=":" | grep /usr/share | awk 'NR==1{print $1}'`
else ifeq ($(strip $(PREFIX)),/usr/local)
MANPAGES := `man --path | awk '1' RS=":" | grep /usr/local | awk 'NR==1{print $1}'`
else ifeq ($(strip $(PREFIX)),)
MANPAGES := `man --path | awk '1' RS=":" | grep /usr/local | awk 'NR==1{print $1}'`
PREFIX := /usr/local
else
MANPAGES := $(PREFIX)/man
endif
# Include path variables for Lua in file generated by ./configure
ifeq ($(wildcard Lua.inc),)
$(error File Lua.inc not found. Please run ./configure first!)
endif
ifeq ($(wildcard Platform.inc),)
$(error File Platform.inc not found. Please run ./configure first!)
endif
include Lua.inc
include Platform.inc
# Project settings:
BUILDDIR := build
DESTINATION := $(PREFIX)/bin
INCDEST := $(PREFIX)/include
MAKEDEP := Lua.inc configure
SRCDIR := src
INCDIR := include
TESTDIR := tests
DOCDIR := doc
STDFLAGS := -std=c++17
CXXFLAGS := -c $(STDFLAGS) $(CXXVBFLAGS) -fPIC -Wall -Wshadow -pedantic -Wfatal-errors -fvisibility=hidden -pthread
INCFLAGS := -I$(SRCDIR) -I$(LUAINC) -I$(INCDIR)
LDFLAGS := -g -pthread
LDLIBS := -lm -lstdc++
LIBOBJS := $(BUILDDIR)/lexer.o \
$(BUILDDIR)/automaton.o $(BUILDDIR)/automaton_tostring.o $(BUILDDIR)/languagedef_tostring.o \
$(BUILDDIR)/automaton_structs.o $(BUILDDIR)/automaton_parser.o \
$(BUILDDIR)/typedb.o \
$(BUILDDIR)/fileio.o $(BUILDDIR)/strings.o $(BUILDDIR)/error.o
MODOBJS := $(BUILDDIR)/lualib_mewa.o \
$(BUILDDIR)/lua_load_automaton.o $(BUILDDIR)/lua_run_compiler.o \
$(BUILDDIR)/lua_serialize.o $(BUILDDIR)/lua_parameter.o
LIBRARY := $(BUILDDIR)/libmewa.a
MODULE := $(BUILDDIR)/mewa.so
TESTPRG := $(BUILDDIR)/testError $(BUILDDIR)/testLexer $(BUILDDIR)/testScope $(BUILDDIR)/testRandomScope \
$(BUILDDIR)/testRandomIdentMap $(BUILDDIR)/testAutomaton \
$(BUILDDIR)/testTypeDb $(BUILDDIR)/testRandomTypeDb
PROGRAM := $(BUILDDIR)/mewa
# Build targets:
all : build $(LIBRARY) $(PROGRAM) $(MODULE) $(TESTPRG) $(MAKEDEP)
clean: build
rm -f $(BUILDDIR)/* .depend
build:
mkdir -p $(BUILDDIR)
# Generate include dependencies:
SOURCES := $(wildcard $(SRCDIR)/*.cpp)
TESTSRC := $(wildcard $(TESTDIR)/*.cpp)
depend: .depend
.depend: $(SOURCES) $(TESTSRC)
$(CC) $(STDFLAGS) $(INCFLAGS) -MM $^ | sed -E 's@^([^: ]*[:])@\$(BUILDDIR)/\1@' > .depend
include .depend
# Build rules:
$(BUILDDIR)/%.o: $(SRCDIR)/%.cpp $(MAKEDEP)
$(CC) $(CXXFLAGS) $(DEBUGOPTFLAGS) $(INCFLAGS) -c $< -o $@
$(BUILDDIR)/%.o: $(TESTDIR)/%.cpp $(MAKEDEP)
$(CC) $(CXXFLAGS) $(DEBUGOPTFLAGS) $(INCFLAGS) -c $< -o $@
$(LIBRARY): $(LIBOBJS)
$(AR) $(LIBRARY) $(LIBOBJS)
$(PROGRAM) $(TESTPRG): $(LIBRARY)
$(BUILDDIR)/%: $(BUILDDIR)/%.o
$(CC) $(LDFLAGS) $(LDLIBS) -o $@ $< $(LIBRARY)
$(MODULE): $(LIBRARY) $(MODOBJS)
$(LNKSO) $(LUALIBS) $(LDLIBS) -o $@ $(MODOBJS) $(LIBRARY)
test : all
$(TIMECMD) $(BUILDDIR)/testError $(TSTVBFLAGS)
$(TIMECMD) $(BUILDDIR)/testLexer $(TSTVBFLAGS)
$(TIMECMD) $(BUILDDIR)/testScope $(TSTVBFLAGS)
$(TIMECMD) $(BUILDDIR)/testRandomScope $(TSTVBFLAGS)
$(TIMECMD) $(BUILDDIR)/testRandomIdentMap $(TSTVBFLAGS)
$(TIMECMD) $(BUILDDIR)/testAutomaton $(TSTVBFLAGS)
$(TIMECMD) $(BUILDDIR)/testTypeDb $(TSTVBFLAGS)
$(TIMECMD) $(BUILDDIR)/testRandomTypeDb $(TSTVBFLAGS)
tests/luatest.sh "$(LUABIN)" "$(TARGET)"
check: test
longtest : all
tests/luatest.sh "$(LUABIN)" "$(TARGET)" "DEBUG"
install: all
cp $(PROGRAM) $(DESTINATION)
mkdir -p $(INCDEST)/mewa
mkdir -p $(MANPAGES)/man1
cp MANPAGE $(MANPAGES)/man1/mewa.1
gzip -f $(MANPAGES)/man1/mewa.1
cp $(MODULE) $(CMODPATH)
uninstall:
rm -f $(CMODPATH)/mewa.so
rm -f $(MANPAGES)/man1/mewa.1.gz
rm -f $(INCDEST)/mewa/*.hpp
rm -f $(DESTINATION)/mewa
# ONLY FOR DEVELOPERS (All generated files of make doc are checked in, so you only have to run this if you edit the docs or sources):
DOCSRC := $(wildcard $(DOCDIR)/*.md.in)
doc: all $(DOCSRC)
@echo "Create documentation of program mewa from its man page ..."
groff -mandoc -T pdf MANPAGE > $(DOCDIR)/program_mewa.pdf
@echo "Substitute some .in files in $(DOCDIR) with verified examples. Needs perl installed ..."
. $(TESTDIR)/luaenv.sh && perl doc/gen/map_md_in.pl $(TSTVBFLAGS) --luabin=$(LUABIN)