-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMakefile
64 lines (49 loc) · 1.67 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
DIR_INC := ./inc
DIR_SRC := ./src
DIR_OBJ := ./obj
DIR_TEST := ./test
PREFIX ?= /usr/local
BINDIR ?= $(PREFIX)/bin
INCLUDE_DIRS ?= /opt/homebrew/include
LIBRARY_DIRS ?= /opt/homebrew/lib
SRC := $(wildcard ${DIR_SRC}/*.cpp)
TEST := $(wildcard ${DIR_TEST}/*.cpp)
OBJ := $(patsubst %.cpp,${DIR_OBJ}/%.o,$(notdir ${SRC}))
TEST_OBJ := $(patsubst %.cpp,${DIR_OBJ}/%.o,$(notdir ${TEST}))
TARGET := fastplong
BIN_TARGET := ${TARGET}
TEST_TARGET := bin/fastplong_unittest
CXX ?= g++
CXXFLAGS := -std=c++14 -pthread -g -O3 -MP -MD -I${DIR_INC} -I${DIR_SRC} $(foreach includedir,$(INCLUDE_DIRS),-I$(includedir)) ${CXXFLAGS}
LIBS := -lisal -ldeflate -lpthread -lhwy
STATIC_FLAGS := -static -Wl,--no-as-needed -pthread
LD_FLAGS := $(foreach librarydir,$(LIBRARY_DIRS),-L$(librarydir)) $(LIBS) $(LD_FLAGS)
STATIC_LD_FLAGS := $(foreach librarydir,$(LIBRARY_DIRS),-L$(librarydir)) $(STATIC_FLAGS) $(LIBS) $(STATIC_LD_FLAGS)
${BIN_TARGET}:${OBJ}
$(CXX) $(OBJ) -o $@ $(LD_FLAGS)
static:${OBJ}
$(CXX) $(OBJ) -o ${BIN_TARGET} $(STATIC_LD_FLAGS)
${DIR_OBJ}/%.o:${DIR_SRC}/%.cpp
@mkdir -p $(@D)
$(CXX) -c $< -o $@ $(CXXFLAGS)
.PHONY:clean
.PHONY:static
clean:
@rm -rf $(DIR_OBJ)
@rm -f $(TARGET)
@rm -f $(TEST_TARGET)
install:
install $(TARGET) $(BINDIR)/$(TARGET)
@echo "Installed."
${DIR_OBJ}/%.o:${DIR_TEST}/%.cpp
@mkdir -p $(@D)
$(CXX) -c $< -o $@ $(CXXFLAGS)
test-static: ${TEST_OBJ} ${OBJ}
@mkdir -p bin
$(CXX) $(TEST_OBJ) ${OBJ:./obj/main.o=} -o ${TEST_TARGET} $(STATIC_LD_FLAGS) -lgtest -lgtest_main
./${TEST_TARGET}
test:${TEST_OBJ} ${OBJ}
@mkdir -p bin
$(CXX) $(TEST_OBJ) ${OBJ:./obj/main.o=} -o ${TEST_TARGET} $(LD_FLAGS) -lgtest -lgtest_main
./${TEST_TARGET}
-include $(OBJ:.o=.d)