-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathmakefile
284 lines (221 loc) · 7.22 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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
PRJNAME=fsqlf
CFLAGS+=-std=c99
CFLAGS+=-Wall
CFLAGS+=-pedantic-errors
CFLAGS+=-g
CFLAGS+=-Iinclude
CXXFLAGS+=-DVERSION=\"$(VERSION)\"
CXXFLAGS+=-Iinclude
ifdef WIN
BLD=builds/make-win-x86-64
OS_TARGET=windows
EXEC_CLI=$(BLD)/fsqlf.exe
EXEC_GUI=$(BLD)/wx_fsqlf.exe
UTIL_TXT2H=$(BLD)/text_to_header.exe
CFLAGS+=-DBUILDING_LIBFSQLF
# i686
# https://myonlineusb.wordpress.com/2011/06/08/what-is-the-difference-between-i386-i486-i586-i686-i786/
# CC=i586-mingw32msvc-gcc
# CXX=i586-mingw32msvc-g++
# CXXFLAGS+= `/usr/i586-mingw32msvc/bin/wx-config --cxxflags | sed 's/-mthreads//'`
# LDFLAGS+= `/usr/i586-mingw32msvc/bin/wx-config --libs | sed 's/-mthreads//'`
CC=i686-w64-mingw32-gcc
CXX=i686-w64-mingw32-g++
CXXFLAGS+= `/usr/i686-w64-mingw32/bin/wx-config --cxxflags | sed 's/-mthreads//'`
LDFLAGS+=-static-libgcc -static-libstdc++
LDFLAGS+= `/usr/i686-w64-mingw32/bin/wx-config --libs | sed 's/-mthreads//'`
# Option "-mthreads" needs to be removed, so mingwm10.dll would not be needed
# (http://old.nabble.com/mingwm10.dll-ts8920679.html)
else
BLD=builds/make-linux
OS_TARGET=linux
PREFIX=/usr/local
EXEC_CLI=$(BLD)/fsqlf
EXEC_GUI=$(BLD)/wx_fsqlf
UTIL_TXT2H=$(BLD)/text_to_header
CC=gcc
CXX=g++
CXXFLAGS+= `wx-config --cxxflags`
LDFLAGS+= `wx-config --libs`
ifneq (Darwin, ${_system_type})
CFLAGS+=-m32
else
CFLAGS+=-m64
endif
endif
ifeq (Darwin, ${_system_type})
LIBNAME=$(BLD)/libfsqlf.dylib
LIBFLAGS=-dynamiclib
else
ifdef WIN
LIBNAME=$(BLD)/libfsqlf.dll
LIBNAME2=$(BLD)/libfsqlf.lib
LIBFLAGS=-shared -Wl,--out-implib,$(LIBNAME2)
else
LIBNAME=$(BLD)/libfsqlf.so
LIBFLAGS=-shared
endif
endif
.PHONY: all clean zip test install uninstall
all: $(EXEC_CLI) $(EXEC_GUI)
#
# BUILD LIB
#
LCOBJ += $(BLD)/lib_fsqlf/conf_file/conf_file_create.o
LCOBJ += $(BLD)/lib_fsqlf/conf_file/conf_file_read.o
LCOBJ += $(BLD)/lib_fsqlf/formatter/lex_wrapper.o
LCOBJ += $(BLD)/lib_fsqlf/formatter/print_keywords.o
LCOBJ += $(BLD)/lib_fsqlf/formatter/tokque.o
LCOBJ += $(BLD)/lib_fsqlf/kw/kw.o
LCOBJ += $(BLD)/lib_fsqlf/kw/kwmap.o
LCOBJ += $(BLD)/lib_fsqlf/kw/is_word.o
LCOBJ += $(BLD)/lib_fsqlf/lex/token.o
LCOBJ += $(BLD)/utils/queue/queue.o
LCOBJ += $(BLD)/utils/stack/stack.o
LCOBJ += $(BLD)/utils/string/read_int.o
BLDDIRS += $(dir $(LCOBJ))
$(LCOBJ): $(BLD)/%.o: ./%.c | $(BLDDIRS)
$(CC) -o $@ -c $< $(CFLAGS) -I$(BLD) -Ilib_fsqlf/formatter
$(BLD)/lex.yy.o: $(BLD)/lex.yy.c
$(CC) -o $@ -c $< $(CFLAGS) -Ilib_fsqlf/formatter
$(filter lib_fsqlf/%,$(LCOBJ)): $(BLDP)%.o: ./%.c include/lib_fsqlf.h
$(LIBNAME): $(LCOBJ) $(BLD)/lex.yy.o
$(CC) -o $@ $^ $(CFLAGS) $(LIBFLAGS)
$(BLD)/lib_fsqlf/conf_file/conf_file_read.o: utils/string/read_int.h
$(BLD)/lib_fsqlf/formatter/lex_wrapper.o: $(BLD)/lex.yy.h
$(BLD)/lex.yy.h: $(BLD)/lex.yy.c
$(BLD)/lex.yy.c: lib_fsqlf/formatter/fsqlf.lex lib_fsqlf/formatter/print_keywords.h
# flex options (e.g. `-o`) has to be before input file
flex -o $@ --header-file=$(BLD)/lex.yy.h $<
#
# BUILD CLI
#
COBJ += $(BLD)/cli/main.o
COBJ += $(BLD)/cli/cli.o
BLDDIRS += $(dir $(COBJ))
$(COBJ): $(BLD)/%.o: ./%.c include/lib_fsqlf.h | $(BLDDIRS)
$(CC) -o $@ -c $< $(CFLAGS)
INTUTIL = $(BLD)/utils/string/read_int.o
$(EXEC_CLI): $(COBJ) $(INTUTIL) $(LIBNAME)
$(CC) -o $@ $(CFLAGS) $(COBJ) $(INTUTIL) -L$(BLD) -lfsqlf -Wl,-rpath,.
#
# BUILD GUI
#
CXXOBJ += $(BLD)/gui/wx_fsqlf.o
CXXOBJ += $(BLD)/gui/basic_notepad.o
CXXOBJ += $(BLD)/gui/dnd_target.o
BLDDIRS += $(dir $(CXXOBJ))
$(CXXOBJ): $(BLD)/%.o: ./%.cpp ./%.hpp | $(BLDDIRS)
$(CXX) -o $@ -c $< $(CXXFLAGS) -I$(BLD)
$(EXEC_GUI): $(CXXOBJ) $(LIBNAME)
$(CXX) -o $@ $^ $(CXXFLAGS) $(LDFLAGS) -L$(BLD) -lfsqlf -Wl,-rpath,.
$(BLD)/gui/wx_fsqlf.o: gui/basic_notepad.hpp
$(BLD)/gui/basic_notepad.o: gui/dnd_target.hpp $(BLD)/license_text.h
$(UTIL_TXT2H): utils/text_to_header/text_to_header.c
$(CC) -o $@ $< $(CFLAGS)
$(BLD)/license_text.h: LICENSE $(UTIL_TXT2H)
$(UTIL_TXT2H) $< $@ LICENSE_TEXT
#
# TESTING
#
# Simple regression testing - testing against gold (pre-saved correct output)
# Given certain input to `fsqlf`, actual output (lead) is compared
# against to it's predefined expected output (gold).
# TF stands for "test file".
TSTOBJ += $(BLD)/tests/tools/file_compare.o
TSTOBJ += $(BLD)/tests/format_files_test.o
BLDDIRS += $(dir $(TSTOBJ))
BLDDIRS += $(BLD)/tests/cases
test: $(EXEC_CLI) $(BLD)/tests/format_files_test
$(BLD)/tests/format_files_test
$(TSTOBJ): $(BLD)/%.o: ./%.c | $(BLDDIRS)
$(CC) -o $@ -c $< $(CFLAGS) \
-D PATH_FSQLF_CLI=\"$(EXEC_CLI)\" \
-D PATH_FSQLF_LIB=\"$(BLD)\" \
-D PATH_TC_STATICSQL=\"tests/cases/\" \
-D PATH_TC_GENERATED=\"$(BLD)/tests/cases/\"
$(BLD)/tests/format_files_test: $(TSTOBJ)
$(CC) -o $@ $^ $(CFLAGS)
#
# OUT OF SOURCE BUILD FOLDERS
#
$(sort $(BLDDIRS)):
mkdir -p $@
#
# CLEANUP
#
clean:
rm -f -R builds/
#
# BUILD ARCHIVE (source and binaries for publishing)
#
$(BLD)/formatting.conf: lib_fsqlf/kw/kwmap_defaults.def $(EXEC_CLI)
LD_LIBRARY_PATH=$(BLD) ./$(EXEC_CLI) --create-config-file $(BLD)/formatting.conf
VERSION:=$(shell git describe master)
PKGAREA:=builds/packaging
ZIP_NAME:=$(PKGAREA)/$(PRJNAME).$(VERSION).zip
zip: tmp_folder
rm -f $(ZIP_NAME)
git archive master -o $(ZIP_NAME) --format=zip --prefix='$(PRJNAME)/source/'
cd $(PKGAREA) && zip -r ../../$(ZIP_NAME) $(PRJNAME)
tmp_folder: LICENSE README.md
make prep_bin
make prep_bin WIN=1
cp -t $(PKGAREA)/$(PRJNAME) $^
prep_bin: $(EXEC_CLI) $(EXEC_GUI) $(LIBNAME) $(BLD)/formatting.conf
rm -Rf $(PKGAREA)/$(PRJNAME)/$(OS_TARGET)
mkdir -p $(PKGAREA)/$(PRJNAME)/$(OS_TARGET)
cp -t $(PKGAREA)/$(PRJNAME)/$(OS_TARGET) $^ $(LIBNAME2)
#
# INSTALLATION
#
ifeq ($(OS_TARGET),linux)
install: $(EXEC_CLI) $(EXEC_GUI) $(BLD)/formatting.conf
install -d $(PREFIX)/bin
install $(EXEC_CLI) $(EXEC_GUI) $(PREFIX)/bin
install -d $(PREFIX)/share/fsqlf
install -m 644 $(BLD)/formatting.conf $(PREFIX)/share/fsqlf/formatting.conf.example
install -d $(PREFIX)/lib
install $(LIBNAME) $(PREFIX)/lib
uninstall:
ifdef EXEC_CLI
rm -vf $(PREFIX)/bin/$(EXEC_CLI)
endif
ifdef EXEC_GUI
rm -vf $(PREFIX)/bin/$(EXEC_GUI)
endif
ifdef LIBNAME
rm -vf $(PREFIX)/lib/$(LIBNAME)
endif
rm -vf $(PREFIX)/share/fsqlf/formatting.conf.example
rm -vfd $(PREFIX)/share/fsqlf
endif
#
# CMake
#
CMREL:=-DCMAKE_BUILD_TYPE=RELEASE
CMTLINUX32:=-DCMAKE_TOOLCHAIN_FILE=../../cmake/toolchain-linux-x86-gcc.cmake
CMTLINUX64:=-DCMAKE_TOOLCHAIN_FILE=../../cmake/toolchain-linux-x86-64-gcc.cmake
CMTWIN32:=-DCMAKE_TOOLCHAIN_FILE=../../cmake/toolchain-windows-x86-mingw.cmake
cmake-linux-x86:
mkdir -p builds/cmake-linux-x86
cd builds/cmake-linux-x86 && cmake $(CMREL) $(CMTLINUX32) ../.. && make && make test
cmake-linux-x86-64:
mkdir -p builds/cmake-linux-x86-64
cd builds/cmake-linux-x86-64 && cmake $(CMREL) $(CMTLINUX64) ../.. && make && make test
cmake-win-x86:
mkdir -p builds/cmake-win-x86
cd builds/cmake-win-x86 && cmake $(CMREL) $(CMTWIN32) ../.. && make && make test
ninja-linux-x86:
mkdir -p builds/ninja-linux-x86
cd builds/ninja-linux-x86 && cmake $(CMREL) $(CMTLINUX32) -G Ninja ../.. && ninja
# makefile reference
# $@ - target
# $+ - all prerequisites
# $^ - all prerequisites, but list each name only once
# $< - first prerequisite
# $? - all prerequisites newer than target
# $| - order only prerequisites
#
# See also:
# http://www.gnu.org/software/make/manual/make.html#Automatic-Variables