-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
77 lines (61 loc) · 1.76 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
# ------------------------------------------------
# Generic Makefile
#
# Author: [email protected]
# Date : 2011-08-10
#
# Changelog :
# 2010-11-05 - first version
# 2011-08-10 - added structure : sources, objects, binaries
# thanks to http://stackoverflow.com/users/128940/beta
# ------------------------------------------------
# ------------------------------------------------
#
# Edited at
# Author: [email protected]
# Date : 2015-10-15
#
# Changelog:
# 2015-10-15 - add gtest
#
# ------------------------------------------------
# project name (generate executable with this name)
TARGET = xnsh
TEST_BIN = test_xnsh
GTEST_DIR = gtest
# change these to set the proper directories where each files should be
SRCDIR = src
OBJDIR = obj
BINDIR = bin
INCDIR = include
TESTDIR = unittest
CXX = g++
# compiling flags here
CXXFLAGS = -g -std=c++11 -Wall -Wextra -pthread -I$(INCDIR)
# linking flags here
LDFLAGS = -Wall -lm -lpthread
SRCS := $(wildcard $(SRCDIR)/*.cpp)
OBJS := $(SRCS:$(SRCDIR)/%.cpp=$(OBJDIR)/%.o)
TEST_SRCS := $(wildcard $(TESTDIR)/*.cpp)
TEST_OBJS := $(TEST_SRCS:$(TESTDIR)/%.cpp=$(OBJDIR)/%.o)
rm = rm -f
all: init $(BINDIR)/$(TARGET)
init:
@mkdir -p obj
@mkdir -p bin
.PHONY: test
test: $(BINDIR)/$(TEST_BIN)
$(BINDIR)/$(TEST_BIN): $(TEST_OBJS) $(filter-out $(OBJDIR)/main.o, $(OBJS))
$(CXX) -o $@ $(CXXFLAGS) $^ $(GTEST_DIR)/gtest_main.a $(LDFLAGS) && $@
$(BINDIR)/$(TARGET): $(OBJS)
$(CXX) -o $@ $(CXXFLAGS) $^ $(LDFLAGS)
$(OBJS): $(OBJDIR)/%.o : $(SRCDIR)/%.cpp
$(CXX) $(CXXFLAGS) -c $< -o $@
$(TEST_OBJS): $(OBJDIR)/%.o : $(TESTDIR)/%.cpp
$(CXX) $(CXXFLAGS) -c $< -o $@ -isystem $(GTEST_DIR)/include
.PHONY: clean
clean:
$(rm) $(OBJDIR)/*
.PHONY: remove
remove: clean
$(rm) $(BINDIR)/*