forked from dnsmkl/fsqlf
-
Notifications
You must be signed in to change notification settings - Fork 2
/
makefile
121 lines (99 loc) · 2.72 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
PRJNAME=fsqlf
CFLAGS+=-std=c99
CFLAGS+=-Wall
CFLAGS+=-pedantic-errors
CFLAGS+=-g
CFLAGS+=-Iinclude
OS := $(shell uname -s)
ifdef ComSpec
OS := Windows
endif
ifeq ($(OS), Windows)
BLD=builds/windows
OS_TARGET=windows
EXEC_CLI=$(BLD)/fsqlf.exe
CFLAGS+=-DBUILDING_LIBFSQLF
LDFLAGS=-static
FLEX=win_flex
PACKAGE_FILE=$(BLD)/$(PRJNAME)_windows.zip
PACKAGE_CMD=zip -j $(PACKAGE_FILE) $(EXEC_CLI) $(FSQLF_CONF)
else
BLD=builds/linux
OS_TARGET=linux
PREFIX=/usr/local
EXEC_CLI=$(BLD)/fsqlf
FLEX=flex
PACKAGE_FILE=$(BLD)/$(PRJNAME)_linux.tar.gz
PACKAGE_CMD=tar -czvf $(PACKAGE_FILE) -C $(BLD) $(notdir $(EXEC_CLI)) $(notdir $(FSQLF_CONF))
endif
CC=gcc
FSQLF_CONF=$(BLD)/formatting.conf
.PHONY: build clean package
build: $(EXEC_CLI) $(FSQLF_CONF)
#
# 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/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
$(BLD)/lex.yy.c: lib_fsqlf/formatter/fsqlf.lex lib_fsqlf/formatter/print_keywords.h
$(FLEX) -o $(BLD)/lex.yy.c --header-file=$(BLD)/lex.yy.h $<
$(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
#
# 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)
ifeq ($(OS), Windows)
$(EXEC_CLI): $(COBJ) $(LCOBJ) $(BLD)/lex.yy.o
$(CC) -o $@ $(CFLAGS) $(COBJ) $(LCOBJ) $(BLD)/lex.yy.o $(LDFLAGS)
else
$(EXEC_CLI): $(COBJ) $(LCOBJ) $(BLD)/lex.yy.o
$(CC) -o $@ $(CFLAGS) $^
endif
$(FSQLF_CONF): $(EXEC_CLI)
$(EXEC_CLI) --create-config-file $(FSQLF_CONF)
#
# OUT OF SOURCE BUILD FOLDERS
#
$(sort $(BLDDIRS)):
mkdir -p $@
#
# PACKAGE
#
package: build
$(PACKAGE_CMD)
#
# CLEANUP
#
clean:
rm -f -R builds/
# 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