Skip to content

Commit 54ff711

Browse files
committed
Enable out of source building with makefile
Since build is done out-of-source, then .gitignore can be made much simpler. One leftover - formatting.conf, which currently is always created in working dir. (will be dealt separately)
1 parent 7196656 commit 54ff711

File tree

2 files changed

+97
-121
lines changed

2 files changed

+97
-121
lines changed

.gitignore

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,4 @@
1-
# files that are intentionaly not tracked by git
2-
3-
4-
# Executables
5-
fsqlf
6-
fsqlf.exe
7-
wx_fsqlf
8-
wx_fsqlf.exe
9-
text_to_header
10-
tests/format_files_test
11-
12-
131
# Generated files
14-
lib_fsqlf/formatter/lex.yy.c
15-
lib_fsqlf/formatter/lex.yy.h
16-
gui/license_text.h
17-
*.o
18-
*.so
19-
formatting.conf
20-
tests/cases/*_actual.sql
212
build*
223

234

@@ -30,10 +11,3 @@ build*
3011

3112
#archive for uploading
3213
*.zip
33-
34-
35-
# Temporary stuff
36-
tmp
37-
tmp/*
38-
testing/*output_lead.sql
39-
*/*/a.out

makefile

Lines changed: 97 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
PROJECTFOLDER=fsqlf
1+
PRJNAME=fsqlf
22

33
CFLAGS+=-std=c99
44
CFLAGS+=-Wall
@@ -10,9 +10,12 @@ CXXFLAGS+=-DVERSION=\"$(VERSION)\"
1010
CXXFLAGS+=-Iinclude
1111

1212
ifdef WIN
13+
BLD=builds/windows
1314
OS_TARGET=windows
14-
EXEC_CLI=fsqlf.exe
15-
EXEC_GUI=wx_fsqlf.exe
15+
EXEC_CLI=$(BLD)/fsqlf.exe
16+
EXEC_GUI=$(BLD)/wx_fsqlf.exe
17+
UTIL_TXT2H=$(BLD)/text_to_header.exe
18+
CFLAGS+=-DBUILDING_LIBFSQLF
1619
# i686
1720
# https://myonlineusb.wordpress.com/2011/06/08/what-is-the-difference-between-i386-i486-i586-i686-i786/
1821
# CC=i586-mingw32msvc-gcc
@@ -26,10 +29,12 @@ ifdef WIN
2629
# Option "-mthreads" needs to be removed, so mingwm10.dll would not be needed
2730
# (http://old.nabble.com/mingwm10.dll-ts8920679.html)
2831
else
32+
BLD=builds/linux
2933
OS_TARGET=linux
3034
PREFIX=/usr/local
31-
EXEC_CLI=fsqlf
32-
EXEC_GUI=wx_fsqlf
35+
EXEC_CLI=$(BLD)/fsqlf
36+
EXEC_GUI=$(BLD)/wx_fsqlf
37+
UTIL_TXT2H=$(BLD)/text_to_header
3338
CC=gcc
3439
CXX=g++
3540
CXXFLAGS+= `wx-config --cxxflags`
@@ -41,99 +46,101 @@ else
4146
endif
4247
endif
4348

44-
45-
4649
ifeq (Darwin, ${_system_type})
47-
LIBNAME=libfsqlf.dylib
50+
LIBNAME=$(BLD)/libfsqlf.dylib
4851
LIBFLAGS=-dynamiclib
4952
else
5053
ifdef WIN
51-
LIBNAME=libfsqlf.dll
54+
LIBNAME=$(BLD)/libfsqlf.dll
5255
LIBFLAGS=-shared -Wl,--out-implib,libfsqlf.a
5356
else
54-
LIBNAME=libfsqlf.so
57+
LIBNAME=$(BLD)/libfsqlf.so
5558
LIBFLAGS=-shared
5659
endif
5760
endif
5861

5962

60-
.PHONY: all clean zip test test-print test-gold clean_obj clean_test install uninstall
63+
64+
.PHONY: all clean zip test install uninstall
6165

6266

6367

64-
all: $(EXEC_CLI) $(EXEC_GUI)
68+
all: $(EXEC_CLI) $(EXEC_GUI)
6569

6670

6771

6872
#
6973
# BUILD LIB
7074
#
71-
LCOBJ += lib_fsqlf/conf_file/conf_file_create.o
72-
LCOBJ += lib_fsqlf/conf_file/conf_file_read.o
73-
LCOBJ += lib_fsqlf/formatter/lex.yy.o
74-
LCOBJ += lib_fsqlf/formatter/lex_wrapper.o
75-
LCOBJ += lib_fsqlf/formatter/print_keywords.o
76-
LCOBJ += lib_fsqlf/formatter/tokque.o
77-
LCOBJ += lib_fsqlf/kw/kw.o
78-
LCOBJ += lib_fsqlf/kw/kwmap.o
79-
LCOBJ += lib_fsqlf/lex/token.o
80-
LCOBJ += utils/queue/queue.o
81-
LCOBJ += utils/stack/stack.o
82-
LCOBJ += utils/string/read_int.o
83-
84-
$(LCOBJ): %.o: %.c
85-
$(CC) $(CFLAGS) -c $< -o $@
86-
87-
$(filter lib_fsqlf/%,$(LCOBJ)): %.o: %.c include/lib_fsqlf.h
88-
89-
$(LIBNAME): $(LCOBJ)
90-
$(CC) $(CFLAGS) $(LIBFLAGS) $^ -o $@
91-
92-
lib_fsqlf/conf_file/conf_file_read.o: utils/string/read_int.h
93-
lib_fsqlf/formatter/lex_wrapper.o: lib_fsqlf/formatter/lex.yy.h
94-
lib_fsqlf/formatter/lex.yy.h: lib_fsqlf/formatter/lex.yy.c
95-
lib_fsqlf/formatter/lex.yy.c: lib_fsqlf/formatter/fsqlf.lex lib_fsqlf/formatter/print_keywords.h
75+
LCOBJ += $(BLD)/lib_fsqlf/conf_file/conf_file_create.o
76+
LCOBJ += $(BLD)/lib_fsqlf/conf_file/conf_file_read.o
77+
LCOBJ += $(BLD)/lib_fsqlf/formatter/lex_wrapper.o
78+
LCOBJ += $(BLD)/lib_fsqlf/formatter/print_keywords.o
79+
LCOBJ += $(BLD)/lib_fsqlf/formatter/tokque.o
80+
LCOBJ += $(BLD)/lib_fsqlf/kw/kw.o
81+
LCOBJ += $(BLD)/lib_fsqlf/kw/kwmap.o
82+
LCOBJ += $(BLD)/lib_fsqlf/lex/token.o
83+
LCOBJ += $(BLD)/utils/queue/queue.o
84+
LCOBJ += $(BLD)/utils/stack/stack.o
85+
LCOBJ += $(BLD)/utils/string/read_int.o
86+
BLDDIRS += $(dir $(LCOBJ))
87+
88+
$(LCOBJ): $(BLD)/%.o: ./%.c | $(BLDDIRS)
89+
$(CC) -o $@ -c $< $(CFLAGS) -I$(BLD) -Ilib_fsqlf/formatter
90+
$(BLD)/lex.yy.o: $(BLD)/lex.yy.c
91+
$(CC) -o $@ -c $< $(CFLAGS) -Ilib_fsqlf/formatter
92+
93+
$(filter lib_fsqlf/%,$(LCOBJ)): $(BLDP)%.o: ./%.c include/lib_fsqlf.h
94+
95+
$(LIBNAME): $(LCOBJ) $(BLD)/lex.yy.o
96+
$(CC) -o $@ $^ $(CFLAGS) $(LIBFLAGS)
97+
98+
$(BLD)/lib_fsqlf/conf_file/conf_file_read.o: utils/string/read_int.h
99+
$(BLD)/lib_fsqlf/formatter/lex_wrapper.o: $(BLD)/lex.yy.h
100+
$(BLD)/lex.yy.h: $(BLD)/lex.yy.c
101+
$(BLD)/lex.yy.c: lib_fsqlf/formatter/fsqlf.lex lib_fsqlf/formatter/print_keywords.h
96102
# flex options (e.g. `-o`) has to be before input file
97-
flex -o $@ --header-file=lib_fsqlf/formatter/lex.yy.h $<
103+
flex -o $@ --header-file=$(BLD)/lex.yy.h $<
98104

99105

100106

101107
#
102108
# BUILD CLI
103109
#
104-
COBJ += cli/main.o
105-
COBJ += cli/cli.o
110+
COBJ += $(BLD)/cli/main.o
111+
COBJ += $(BLD)/cli/cli.o
112+
BLDDIRS += $(dir $(COBJ))
106113

107-
$(COBJ): %.o: %.c include/lib_fsqlf.h
108-
$(CC) $(CFLAGS) -c $< -o $@
114+
$(COBJ): $(BLD)/%.o: ./%.c include/lib_fsqlf.h | $(BLDDIRS)
115+
$(CC) -o $@ -c $< $(CFLAGS)
109116

110-
$(EXEC_CLI): $(COBJ) $(LIBNAME)
111-
$(CC) $(CFLAGS) $(COBJ) -L. -lfsqlf -Wl,-rpath,. -o $@
112-
# strip $@
117+
INTUTIL = $(BLD)/utils/string/read_int.o
118+
$(EXEC_CLI): $(COBJ) $(INTUTIL) $(LIBNAME)
119+
$(CC) -o $@ $(CFLAGS) $(COBJ) $(INTUTIL) -L$(BLD) -lfsqlf -Wl,-rpath,.
113120

114121

115122

116123
#
117124
# BUILD GUI
118125
#
119-
$(EXEC_GUI): wx_fsqlf.o basic_notepad.o dnd_target.o $(LIBNAME)
120-
$(CXX) $^ -o $@ $(CXXFLAGS) $(LDFLAGS) -L. -lfsqlf -Wl,-rpath,.
121-
strip $@
126+
CXXOBJ += $(BLD)/gui/wx_fsqlf.o
127+
CXXOBJ += $(BLD)/gui/basic_notepad.o
128+
CXXOBJ += $(BLD)/gui/dnd_target.o
129+
BLDDIRS += $(dir $(CXXOBJ))
122130

123-
# generic rule for C++ building
124-
CXXOBJ = wx_fsqlf.o basic_notepad.o dnd_target.o
131+
$(CXXOBJ): $(BLD)/%.o: ./%.cpp ./%.hpp | $(BLDDIRS)
132+
$(CXX) -o $@ -c $< $(CXXFLAGS) -I$(BLD)
125133

126-
$(CXXOBJ): %.o: gui/%.cpp gui/%.hpp
127-
$(CXX) -c $< -o $@ $(CXXFLAGS)
134+
$(EXEC_GUI): $(CXXOBJ) $(LIBNAME)
135+
$(CXX) -o $@ $^ $(CXXFLAGS) $(LDFLAGS) -L$(BLD) -lfsqlf -Wl,-rpath,.
128136

129-
wx_fsqlf.o: gui/basic_notepad.hpp
130-
basic_notepad.o: gui/dnd_target.hpp gui/license_text.h
137+
$(BLD)/gui/wx_fsqlf.o: gui/basic_notepad.hpp
138+
$(BLD)/gui/basic_notepad.o: gui/dnd_target.hpp $(BLD)/license_text.h
131139

132-
gui/license_text.h: LICENSE text_to_header
133-
./text_to_header $< $@ LICENSE_TEXT
134-
135-
text_to_header: utils/text_to_header/text_to_header.c
136-
$(CC) $(CFLAGS) $< -o $@
140+
$(UTIL_TXT2H): utils/text_to_header/text_to_header.c
141+
$(CC) -o $@ $< $(CFLAGS)
142+
$(BLD)/license_text.h: LICENSE $(UTIL_TXT2H)
143+
$(UTIL_TXT2H) $< $@ LICENSE_TEXT
137144

138145

139146

@@ -144,71 +151,66 @@ text_to_header: utils/text_to_header/text_to_header.c
144151
# Given certain input to `fsqlf`, actual output (lead) is compared
145152
# against to it's predefined expected output (gold).
146153
# TF stands for "test file".
147-
test: test-format-files
148-
149-
test-format-files: $(EXEC_CLI) tests/format_files_test
150-
cd tests && ./format_files_test
154+
TSTOBJ += $(BLD)/tests/tools/file_compare.o
155+
TSTOBJ += $(BLD)/tests/format_files_test.o
156+
BLDDIRS += $(dir $(TSTOBJ))
157+
BLDDIRS += $(BLD)/tests/cases
151158

152-
tests/tools/file_compare.o: tests/tools/file_compare.c
153-
$(CC) $(CFLAGS) -c $< -o $@
159+
test: $(EXEC_CLI) $(BLD)/tests/format_files_test
160+
$(BLD)/tests/format_files_test
154161

155-
tests/format_files_test.o: tests/format_files_test.c
156-
$(CC) $(CFLAGS) -c $< -o $@
162+
$(TSTOBJ): $(BLD)/%.o: ./%.c | $(BLDDIRS)
163+
$(CC) -o $@ -c $< $(CFLAGS) \
164+
-D PATH_FSQLF_CLI=\"$(EXEC_CLI)\" \
165+
-D PATH_FSQLF_LIB=\"$(BLD)\" \
166+
-D PATH_TC_STATICSQL=\"tests/cases/\" \
167+
-D PATH_TC_GENERATED=\"$(BLD)/tests/cases/\"
157168

158-
tests/format_files_test: tests/format_files_test.o tests/tools/file_compare.o
159-
$(CC) $(CFLAGS) $^ -o $@
169+
$(BLD)/tests/format_files_test: $(TSTOBJ)
170+
$(CC) -o $@ $^ $(CFLAGS)
160171

161172

162173

163174
#
164-
# CLEANUP
175+
# OUT OF SOURCE BUILD FOLDERS
165176
#
166-
TMP_BAKUPS=$(wildcard */*~) $(wildcard *~) $(TEST_TMP_ORIGINAL) $(TEST_TMP_FORMATED)
177+
$(sort $(BLDDIRS)):
178+
mkdir -p $@
167179

168-
clean: clean_local clean_win clean_obj clean_test
169180

170-
clean_local:
171-
rm -R -f $(EXEC_GUI) $(EXEC_CLI) lib_fsqlf/formatter/lex.yy.c $(TMP_BAKUPS) \
172-
lib_fsqlf/formatter/lex.yy.h \
173-
$(LIBNAME) libfsqlf.a \
174-
$(wildcard $(PROJECTFOLDER)*.zip) tmp gui/license_text.h $(CONF_FILE) \
175-
text_to_header builds
176-
make clean_obj
177181

178-
clean_win:
179-
make clean_local WIN=1
180-
181-
clean_obj:
182-
rm -f *.o lib_fsqlf/*.o lib_fsqlf/*/*.o utils/*/*.o cli/*.o
183-
184-
clean_test:
185-
rm -f tests/format_files_test tests/*.o tests/tools/*.o tests/cases/*_actual.sql
182+
#
183+
# CLEANUP
184+
#
185+
clean:
186+
rm -f -R builds/
186187

187188

188189

189190
#
190191
# BUILD ARCHIVE (source and binaries for publishing)
191192
#
192193
formatting.conf: lib_fsqlf/kw/kwmap_defaults.def $(EXEC_CLI)
193-
./$(EXEC_CLI) --create-config-file
194+
LD_LIBRARY_PATH=$(BLD) ./$(EXEC_CLI) --create-config-file
194195

195196
VERSION:=$(shell git describe master)
196-
ZIP_NAME:=$(PROJECTFOLDER).$(VERSION).zip
197+
PKGAREA:=builds/packaging
198+
ZIP_NAME:=$(PKGAREA)/$(PRJNAME).$(VERSION).zip
197199

198200
zip: tmp_folder
199201
rm -f $(ZIP_NAME)
200-
git archive master -o $(ZIP_NAME) --format=zip --prefix='$(PROJECTFOLDER)/source/'
201-
cd tmp/ && zip -r ../$(ZIP_NAME) $(PROJECTFOLDER)
202+
git archive master -o $(ZIP_NAME) --format=zip --prefix='$(PRJNAME)/source/'
203+
zip -r $(ZIP_NAME) $(PKGAREA)/$(PRJNAME)
202204

203205
tmp_folder: LICENSE README.md
204206
make prep_bin
205-
make clean_obj # to ensure that object files are for needed OS
206207
make prep_bin WIN=1
207-
cp -t tmp/$(PROJECTFOLDER) $^
208+
cp -t $(PKGAREA)/$(PRJNAME) $^
208209

209210
prep_bin: $(EXEC_CLI) $(EXEC_GUI) $(LIBNAME) formatting.conf
210-
mkdir -p tmp/$(PROJECTFOLDER)/$(OS_TARGET)
211-
cp -t tmp/$(PROJECTFOLDER)/$(OS_TARGET) $^
211+
rm -Rf $(PKGAREA)/$(PRJNAME)/$(OS_TARGET)
212+
mkdir -p $(PKGAREA)/$(PRJNAME)/$(OS_TARGET)
213+
cp -t $(PKGAREA)/$(PRJNAME)/$(OS_TARGET) $^
212214

213215

214216

0 commit comments

Comments
 (0)