forked from fourier/libkv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTupfile
71 lines (55 loc) · 2.1 KB
/
Tupfile
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
# -*- Mode: tup; -*-
# Copyright (C) 2015 Alexey Veretennikov (alexey dot veretennikov at gmail.com)
#
# This file is part of libkv.
#
# libkv is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# libkv is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with libkv. If not, see <http://www.gnu.org/licenses/>.
CC = gcc
AR = ar
LEX = flex
YACC = bison
CFLAGS = -ansi -pedantic -Wall -Wextra -Wmissing-include-dirs -Wswitch-default -Wswitch-enum -Wdeclaration-after-statement -Wmissing-declarations
GEN_CFLAGS =
ifeq (@(RELEASE),0)
CFLAGS += -ggdb -pg
GEN_CFLAGS += -ggdb -pg
else
CFLAGS += -O3
GEN_CFLAGS += -O3
endif
INCLUDES = -I src -I .
LINKFLAGS = -L. -lkv
OUTPUT = kvtest
OUTPUT_LIB = libkv.a
LIBRARY_SRCS = src/*.c
TEST_SRCS = testsrc/*.c
LEX_HEADER = libkv.yy.h
YACC_HEADER = libkv.tab.h
LEX_SOURCE = libkv.yy.c
YACC_SOURCE = libkv.tab.c
!cc = |> $(CC) $(CFLAGS) $(INCLUDES) -c %f -o %o |> %B.o
# lex file
: src/grammar.l |> $(LEX) --header-file=$(LEX_HEADER) -f -o %o %f |> $(LEX_SOURCE) | $(LEX_HEADER) {LEXES}
# yacc file
: src/grammar.y |> $(YACC) -y --defines=$(YACC_HEADER) -o %o %f |> $(YACC_SOURCE) | $(YACC_HEADER) {YACES}
# compile lex and yacc output sources
: foreach $(LEX_SOURCE) $(YACC_SOURCE) | $(LEX_HEADER) $(YACC_HEADER) |> $(CC) -c $(GEN_CFLAGS) $(INCLUDES) %f -o %o |> %B.o {GENERATED_OBJECTS}
# library objects
: foreach $(LIBRARY_SRCS) | $(YACC_HEADER) $(LEX_HEADER) |> !cc |> {LIB_OBJS}
# library binary
: {LIB_OBJS} {GENERATED_OBJECTS} |> $(AR) cr %o %f ; ranlib %o |> $(OUTPUT_LIB)
# test object
: foreach $(TEST_SRCS) |> !cc |> {TEST_OBJ}
# test binary
: {TEST_OBJ} | $(OUTPUT_LIB) |> $(CC) %f -o %o $(LINKFLAGS) |> $(OUTPUT)