-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile.mac
150 lines (112 loc) · 3.75 KB
/
Makefile.mac
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
TARGET_EXEC ?= rbm
TARGET_UNITTEST ?= unittest
BUILD_DIR ?= build
SRC_DIRS ?= src
TEST_DIR ?= test
INC_DIRS ?= include
MAT_BACKEND ?= BLAS
# PFAPACK
INC_DIRS += deps/pfapack/c_interface
PFAPACK = $(BUILD_DIR)/pfapack/libpfapack.a
PFAPACKC = $(BUILD_DIR)/pfapack/libcpfapack.a
# MINRES QLP
INC_DIRS += deps/minresqlp
MINRESQLP = $(BUILD_DIR)/minresqlp/libminresqlp.a
DESTDIR ?= /usr/local/bin/
SRCS := $(shell find $(SRC_DIRS) -name *.cpp -type f)
OBJS := $(SRCS:%=$(BUILD_DIR)/%.o)
DEPS := $(OBJS:.o=.d)
TEST_SRCS := $(shell find $(TEST_DIR) -name *.cpp -type f)
TEST_OBJS := $(TEST_SRCS:%=$(BUILD_DIR)/%.o)
TEST_OBJS += $(filter-out $(BUILD_DIR)/src/main.cpp.o,$(OBJS))
# INDCLUDE DIRS
INC_DIRS += /usr/local/include/eigen3/
INC_DIRS += /usr/local/opt/openblas/include/
INC_DIRS += /usr/local/include/
INC_DIRS += $(HOME)/googletest/googletest/include/
INC_FLAGS := $(addprefix -I,$(INC_DIRS))
CPPFLAGS += $(INC_FLAGS) -MMD -MP -Wall -std=c++14 -O3 -march=native
OMP = -fopenmp
ifeq ($(notdir $(CXX)), clang++)
LDFLAGS += -L/usr/local/opt/llvm/lib/
endif
ifneq (,$(findstring gcc,$(CXX)))
LDFLAGS := -L$(HOME)/boost-gcc/lib $(LDFLAGS)
CPPFLAGS := -I$(HOME)/boost-gcc/include $(CPPFLAGS)
endif
# HANDLE DIFFERENT MATH BACKENDS
ifeq ($(MAT_BACKEND),BLAS)
CPPFLAGS += -DEIGEN_USE_BLAS
$(info using BLAS)
else ifeq ($(MAT_BACKEND),MKL)
ifeq ($(MKLROOT),)
$(error MKL ENV not sourced! Run source /opt/intel/oneapi/mkl/latest/env/vars.sh)
endif
CPPFLAGS += -DEIGEN_USE_MKL_ALL -DMKL_ILP64 -m64 -I"${MKLROOT}/include"
LDFLAGS += -L/opt/intel/oneapi/compiler/latest/mac/compiler/lib/
LDFLAGS += -L${MKLROOT}/lib -Wl,-rpath,${MKLROOT}/lib -lmkl_intel_ilp64 -lmkl_intel_thread -lmkl_core -liomp5 -lpthread -lm -ldl
$(info using MKL)
else
$(info using EIGEN)
endif
# LINK BLAS IF NOT USE MKL
ifneq ($(METHOD),MKL)
LDFLAGS += -L/usr/local/opt/openblas/lib/
LDFLAGS += -lblas -llapack -lopenblas -lpthread
endif
LDFLAGS += -lboost_program_options
LDFLAGS += $(PFAPACK) $(PFAPACKC) $(MINRESQLP) -lgfortran
TEST_LDFLAGS = $(HOME)/googletest/build/lib/libgtest.a $(HOME)/googletest/build/lib/libgtest_main.a
# USE MPI
MPI = $(shell mpic++ -show | cut -d' ' -f2-)
install: all
cp $(BUILD_DIR)/$(TARGET_EXEC) $(DESTDIR)/$(TARGET_EXEC)
cp $(BUILD_DIR)/$(TARGET_EXEC) $(DESTDIR)/$(TARGET_EXEC)p
cp tools/* $(DESTDIR)/
all: $(BUILD_DIR)/$(TARGET_EXEC)
$(BUILD_DIR)/$(TARGET_EXEC): $(OBJS) $(PFAPACK) $(PFAPACKC) $(MINRESQLP)
@echo "[ LD ] $@"
@$(CXX) $(OMP) $(MPI) $(LDFLAGS) $^ -o $@
$(BUILD_DIR)/$(TARGET_UNITTEST): $(TEST_OBJS) $(PFAPACK) $(PFAPACKC) $(MINRESQLP)
@echo "[ LD ] $@"
@$(CXX) $(OMP) $(MPI) $(LDFLAGS) $(TEST_LDFLAGS) $^ -o $@
# c++ source
$(BUILD_DIR)/%.cpp.o: %.cpp
@$(MKDIR_P) $(dir $@)
@echo "[ $(notdir $(CXX)) ] $<"
@$(CXX) $(OMP) $(MPI) $(CPPFLAGS) -c $< -o $@
.PHONY: install all clean
test: $(BUILD_DIR)/$(TARGET_UNITTEST)
@env DYLD_LIBRARY_PATH=$(HOME)/boost-gcc/lib $(BUILD_DIR)/$(TARGET_UNITTEST)
clean:
$(RM) -r $(BUILD_DIR)
$(PFAPACK):
cd deps/pfapack/fortran/ && make
@mkdir -p $(BUILD_DIR)/pfapack
cp deps/pfapack/fortran/libpfapack.a $(PFAPACK)
$(PFAPACKC):
cd deps/pfapack/c_interface && make
@mkdir -p $(BUILD_DIR)/pfapack
cp deps/pfapack/c_interface/libcpfapack.a $(PFAPACKC)
$(MINRESQLP):
cd deps/minresqlp/ && make
@mkdir -p $(BUILD_DIR)/minresqlp
cp deps/minresqlp/build/$(notdir $(MINRESQLP)) $(MINRESQLP)
build_pfapack: $(PFAPACK) $(PFAPACKC)
build_minresqlp: $(MINRESQLP)
clean_pfapack:
cd deps/pfapack/fortran/ && make clean
cd deps/pfapack/c_interface && make clean
rm -r build/pfapack
clean_minresqlp:
cd deps/minresqlp/ && make clean
rm -r build/minresqlp
doc:
mv README.md README.md.tmp
./.md2dox
cd docs && make html && cd ..
mv README.md.tmp README.md
lsp:
@compiledb make --always-make --dry-run
-include $(DEPS)
MKDIR_P ?= mkdir -p