-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
128 lines (96 loc) · 3.58 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# A Makefile based on the Google Test sample Makefile
# https://github.com/google/googletest/blob/master/googletest/make/Makefile
#
# Modified with the help of http://nuclear.mutantstargoat.com/articles/make/
#
# SYNOPSIS:
#
# make - makes the main file.
# make clean - removes all files generated by make.
# Create a build directory
BUILD_DIR = build
dummy_build_folder := $(shell mkdir -p $(BUILD_DIR))
# Which compilers to use
CC=g++ -std=c++11
C=gcc
# Points to the root of Google Test, relative to where this file is.
# Remember to tweak this if you move this file.
GTEST_DIR = lib/googletest-release-1.8.0/googletest
# Where to find user code.
USER_DIR = src
# Test code
TEST_DIR = tests
# Where to find build objects
BUILD_DIR = build
# The working directory
CURRENT_DIR = $(shell pwd)
# Dependency header files
DEP_HEADERS = $(USER_DIR)/*.h
TEST_HEADERS = $(TEST_DIR)/*.h
VPATH = $(USER_DIR):$(BUILD_DIR)
# Flags passed to the preprocessor.
# Set Google Test's header directory as a system directory, such that
# the compiler doesn't generate warnings in Google Test headers.
CPPFLAGS += -isystem $(GTEST_DIR)/include
# Flags passed to the C++ compiler.
CXXFLAGS += -g -Wall -Wextra -pthread
# Graphics flags
GRAPHICSFLAGS = -lglut -lGL -lGLU
# Flags for building shared library
SHAREDFLAGS = -fpic -shared
# Flags for using shared library
CUBELIBFLAGS = -Lbuild -lRubiksCube
# The Makefile's run command
RUN = $(BUILD_DIR)/main
# All Google Test headers. Usually you shouldn't change this
# definition.
GTEST_HEADERS = $(GTEST_DIR)/include/gtest/*.h \
$(GTEST_DIR)/include/gtest/internal/*.h
# Build targets.
.PHONY: all
all : $(RUN)
LD_LIBRARY_PATH=$(CURRENT_DIR)/build ./build/main 0
.PHONY: clean
clean :
rm -f $(BUILD_DIR)/*
.PHONY: test
test :
LD_LIBRARY_PATH=$(CURRENT_DIR)/build ./build/main 1
# Builds Google test dependencies
GTEST_SRCS_ = $(GTEST_DIR)/src/*.cc $(GTEST_DIR)/src/*.h $(GTEST_HEADERS)
$(BUILD_DIR)/gtest-all.o : $(GTEST_SRCS_)
$(CC) $(CPPFLAGS) -I$(GTEST_DIR) $(CXXFLAGS) -c \
$(GTEST_DIR)/src/gtest-all.cc -o $@
$(BUILD_DIR)/gtest_main.o : $(GTEST_SRCS_)
$(CC) $(CPPFLAGS) -I$(GTEST_DIR) $(CXXFLAGS) -c \
$(GTEST_DIR)/src/gtest_main.cc -o $@
$(BUILD_DIR)/gtest.a : gtest-all.o
$(AR) $(ARFLAGS) $@ $^ -o $@
$(BUILD_DIR)/gtest_main.a : gtest-all.o gtest_main.o
$(AR) $(ARFLAGS) $@ $^ -o $@
# Builds the main file.
OBJ = $(BUILD_DIR)/main.o \
$(BUILD_DIR)/Graphics.o $(BUILD_DIR)/RubiksCube.o $(BUILD_DIR)/CubeFace.o \
$(BUILD_DIR)/CubeFaceTest.o $(BUILD_DIR)/RubiksCubeTest.o $(BUILD_DIR)/ConnectorTest.o \
$(BUILD_DIR)/Dfs.o \
$(BUILD_DIR)/Utils.o $(BUILD_DIR)/Shared.o $(BUILD_DIR)/Thread.o \
$(BUILD_DIR)/Connector.so
$(BUILD_DIR)/main : $(OBJ) gtest_main.a
$(CC) $(CPPFLAGS) $(CXXFLAGS) -lpthread $^ -o $@ $(GRAPHICSFLAGS) $(CUBELIBFLAGS)
# Builds the dependency object files.
$(BUILD_DIR)/main.o : $(USER_DIR)/main.cpp $(DEP_HEADERS) $(GTEST_HEADERS)
$(CC) $(CPPFLAGS) $(CXXFLAGS) -c $< -o $@
# Builds cpp files in src/
$(BUILD_DIR)/%.o : $(USER_DIR)/%.cpp $(USER_DIR)/%.h
$(CC) $(CPPFLAGS) $(CXXFLAGS) -c $< -o $@
# Builds cpp files in tests/
$(BUILD_DIR)/%.o : $(TEST_DIR)/%.cpp $(DEP_HEADERS) $(TEST_HEADERS) $(GTEST_HEADERS)
$(CC) $(CPPFLAGS) $(CXXFLAGS) -c $< -o $@
# Builds c files in src/
$(BUILD_DIR)/%.o : $(USER_DIR)/%.c $(USER_DIR)/%.h $(DEP_HEADERS)
$(C) -c $< -o $@ $(CUBELIBFLAGS)
# Builds the shared connector files
$(BUILD_DIR)/libRubiksCube.so : $(USER_DIR)/RubiksCube.cpp
$(CC) $(SHAREDFLAGS) $< -o $@
$(BUILD_DIR)/Connector.so : $(USER_DIR)/Connector.cpp $(BUILD_DIR)/libRubiksCube.so
$(CC) $(SHAREDFLAGS) $< -o $@ $(CUBELIBFLAGS)