-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
63 lines (46 loc) · 1.36 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
# Compiler flags
AR := ar rcs
LIBFLAGS := -g -O2 -std=c++11 -Wall -Werror -Wextra -Wconversion -Wpedantic
CXXFLAGS := -g -std=c++11
INCLUDES := -Iinclude
# Library variables
SRCDIR := ./src
BINDIR := ./bin
SRCBINDIR := $(SRCDIR)/bin
SRC := $(wildcard $(SRCDIR)/*.cpp)
OBJ := $(patsubst $(SRCDIR)/%.cpp, $(SRCBINDIR)/%.o, $(SRC))
LIBRARY := $(BINDIR)/libmathex++.a
# Testing variables
TESTDIR := ./test
TESTBINDIR := $(TESTDIR)/bin
TESTSRC := $(wildcard $(TESTDIR)/*.cpp)
TESTBIN := $(patsubst $(TESTDIR)/%.cpp, $(TESTBINDIR)/%, $(TESTSRC))
# Sample variables
SAMPLEDIR := ./sample
SAMPLEBINDIR := $(SAMPLEDIR)/bin
# Phonies
build: $(LIBRARY)
test: $(TESTBIN)
CODE=0; for test in $(TESTBIN); do $$test || CODE=$$?; done; exit $$CODE
clean:
$(RM) $(BINDIR)/* $(SRCBINDIR)/* $(TESTBINDIR)/* $(SAMPLEBINDIR)/*
# Library
$(LIBRARY): $(OBJ) | $(BINDIR)
$(AR) $(LIBRARY) $(OBJ)
$(SRCBINDIR)/%.o: $(SRCDIR)/%.cpp | $(SRCBINDIR)
$(CXX) $(LIBFLAGS) $(INCLUDES) -c $< -o $@
# Testing
$(TESTBINDIR)/%: $(TESTDIR)/%.cpp $(LIBRARY) | $(TESTBINDIR)
$(CXX) $(CXXFLAGS) $(INCLUDES) $< -o $@ -L$(BINDIR) -lmathex++ -lcriterion
# Samples
$(SAMPLEBINDIR)/%: $(SAMPLEDIR)/%.cpp $(LIBRARY) | $(SAMPLEBINDIR)
$(CXX) $(CXXFLAGS) $(INCLUDES) $< -o $@ -L$(BINDIR) -lmathex++
# Directories
$(BINDIR):
mkdir -p $@
$(SRCBINDIR):
mkdir -p $@
$(TESTBINDIR):
mkdir -p $@
$(SAMPLEBINDIR):
mkdir -p $@