aboutsummaryrefslogtreecommitdiff
path: root/Makefile
blob: 3cac760b73bc24e81e9299e866efb4b6b329e8ab (plain)
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
include config.mk

INCLUDE_DIR := include
SOURCE_DIR := src
OBJECT_DIR := obj
LIBRARY_DIR := lib
BINARY_DIR := bin
DOCUMENTATION_DIR := doc

SOURCE_NAMES_LIB := sqlitepp.cpp
SOURCE_NAMES_TEST := sqlitepp_test.cpp
TARGETS := $(LIBRARY_DIR)/libsqlitepp.so $(BINARY_DIR)/sqlitepp_test

SOURCES_LIB := $(foreach source,$(SOURCE_NAMES_LIB),$(SOURCE_DIR)/$(source))
OBJECTS_LIB := $(SOURCES_LIB:$(SOURCE_DIR)/%.cpp=$(OBJECT_DIR)/%.o)
DEPENDS_LIB := $(OBJECTS_LIB:.o=.d)

SOURCES_TEST := $(foreach source,$(SOURCE_NAMES_TEST),$(SOURCE_DIR)/$(source))
OBJECTS_TEST := $(SOURCES_TEST:$(SOURCE_DIR)/%.cpp=$(OBJECT_DIR)/%.o)
DEPENDS_TEST := $(OBJECTS_TEST:.o=.d)

INCLUDES := $(INCLUDE_DIR)/sqlitepp/sqlitepp.h
OBJECTS := $(OBJECTS_LIB) $(OBJECTS_TEST)
DEPENDS := $(DEPENDS_LIB) $(DEPENDS_TEST)

CPPFLAGS += -MMD -MP -I$(INCLUDE_DIR)
CXXFLAGS += -fPIC
LDFLAGS += $(LDFLAGS_SQLITE3)
LDFLAGS_TEST += -L$(LIBRARY_DIR) -lsqlitepp $(LDFLAGS_GTEST)

ifdef VERBOSE
	QUIET :=
else
	QUIET := @
endif

.PHONY = all clean doc

all: $(TARGETS)

clean:
	$(info (RM)    $(OBJECT_DIR))
	$(QUIET)$(RM) -r $(OBJECT_DIR)
	$(info (RM)    $(LIBRARY_DIR))
	$(QUIET)$(RM) -r $(LIBRARY_DIR)
	$(info (RM)    $(BINARY_DIR))
	$(QUIET)$(RM) -r $(BINARY_DIR)
	$(info (RM)    $(DOCUMENTATION_DIR))
	$(QUIET)$(RM) -r $(DOCUMENTATION_DIR)

doc: $(INCLUDES)
	doxygen

$(LIBRARY_DIR)/libsqlitepp.so: $(OBJECTS_LIB)
	$(info (CXX)   $@)
	$(QUIET)mkdir -p $(LIBRARY_DIR)
	$(QUIET)$(CXX) -shared $(LDFLAGS) $(LDFLAGS_LIB) -o $@ $^

$(BINARY_DIR)/sqlitepp_test: $(OBJECTS_TEST)
	$(info (CXX)    $@)
	$(QUIET)mkdir -p $(BINARY_DIR)
	$(QUIET)$(CXX) $(LDFLAGS) $(LDFLAGS_TEST) $< -o $@

$(OBJECTS): $(OBJECT_DIR)/%.o: $(SOURCE_DIR)/%.cpp
	$(info (CXX)   $@)
	$(QUIET)mkdir -p $(OBJECT_DIR)
	$(QUIET)$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $< -o $@

-include $(DEPENDS)