forked from alexandervanrenen/gda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
79 lines (74 loc) · 3.18 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
## -------------------------------------------------------------------------------------------------
##
## This file is part of the gda cpp utility library.
## Copyright (c) 2012 Alexander van Renen. All rights reserved.
##
## Purpose - Used to build the project.
## -------------------------------------------------------------------------------------------------
## Define constants
all: libgda
GTEST_INCLUDE := libs/gtest/include
GTEST_LIB := libs/gtest/libgtest.a
TARGET_DIR := bin
CF := -g0 -O2 -std=c++11 -Werror -Wextra -Wall -ffast-math -Iinclude $(addprefix -I,$(GTEST_INCLUDE))
LF := -g0 -O2 -Werror -Wextra -Wall -ffast-math
CCCACHE_USE?=
CXX?= g++
CXX:= $(CCCACHE_USE) $(CXX)
BUILD_DIR = @mkdir -p $(dir $@)
## -------------------------------------------------------------------------------------------------
## Track dependencies
-include $(TARGET_DIR)/*.P
-include $(TARGET_DIR)/*/*.P
-include $(TARGET_DIR)/*/*/*.P
-include $(TARGET_DIR)/*/*/*/*.P
## -------------------------------------------------------------------------------------------------
## Grab all files relevant for the build
src_obj := $(patsubst src/%,$(TARGET_DIR)/src/%, $(patsubst %.cpp,%.o,$(shell find src -name "*.cpp")))
test_obj := $(patsubst test/%,$(TARGET_DIR)/test/%, $(patsubst %.cpp,%.o,$(shell find test -name "*.cpp")))
## -------------------------------------------------------------------------------------------------
## Build the library itself
libgda: $(src_obj)
@rm -rf libgda.a
@for f in `find bin/src -name *.o`; do \
if [ `nm $$f 2> /dev/null | wc -l` != 0 ]; then \
ar -r libgda.a $$f; \
fi \
done
## -------------------------------------------------------------------------------------------------
## Build tests for the library
tester: libgda libs/gtest $(test_obj)
$(CXX) -o tester $(test_obj) $(GTEST_LIB) $(LF) libgda.a -lpthread
## -------------------------------------------------------------------------------------------------
## Build individual files and track dependencies
$(TARGET_DIR)/%.o: %.cpp
$(BUILD_DIR)
@if [ $(VERBOSE) ]; then echo $(CXX) -MD -c -o $@ $< $(CF); else echo $(CXX) $@; fi
@$(CXX) -MD -c -o $@ $< $(CF)
@cp $(TARGET_DIR)/$*.d $(TARGET_DIR)/$*.P; \
sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
-e '/^$$/ d' -e 's/$$/ :/' < $(TARGET_DIR)/$*.d >> $(TARGET_DIR)/$*.P; \
rm -f $(objDir)$*.d
## -------------------------------------------------------------------------------------------------
## Build gtest library
libs/gtest:
$(BUILD_DIR)
cd libs/ ;\
rm googletest -rf ;\
rm gtest -rf ;\
git clone https://github.com/google/googletest.git;\
cd googletest/googletest;\
mkdir -p build ;\
cd build ;\
cmake -G"Unix Makefiles" .. ;\
make
mkdir -p libs/gtest/include/gtest
mv libs/googletest/googletest/include/gtest/* libs/gtest/include/gtest
mv libs/googletest/googletest/build/libgtest.a libs/gtest/
rm -rf libs/googletest
## -------------------------------------------------------------------------------------------------
## Clean up the hole mess
clean:
rm -rf $(TARGET_DIR)
find . -name '*.o' -delete -o -name 'libgda.a' -delete -o -name 'tester' -delete
## -------------------------------------------------------------------------------------------------