-
Notifications
You must be signed in to change notification settings - Fork 9
/
Makefile
116 lines (86 loc) · 2.94 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
# This file is part of PyCI.
#
# PyCI is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your
# option) any later version.
#
# PyCI is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
#
# You should have received a copy of the GNU General Public License
# along with PyCI. If not, see <http://www.gnu.org/licenses/>.
# Setup
# -----
# Set C compiler executable
CC ?= cc
export CC
# Set C++ compiler executable
CXX ?= c++
export CXX
# Set Python executable
PYTHON ?= python3
# Set C++ compile flags
CFLAGS := -std=c++14 -Wall -Wextra -pipe -O3
CFLAGS += -fPIC -flto=auto -fvisibility=hidden
CFLAGS += -pthread
CFLAGS += -Ipyci/include
ifneq ($(MAKE_NATIVE),)
CFLAGS += -mavx -mavx2 -msse4.2 -march=native -mtune=native
endif
# Set Python include directories
CFLAGS += $(shell $(PYTHON) tools/python_include_dirs.py)
# Set external projects and their include directories
DEPS := $(addprefix deps/,eigen spectra parallel-hashmap pybind11)
CFLAGS += $(addprefix -Ideps/,eigen spectra/include parallel-hashmap pybind11/include)
# This C++ compile flag is needed in order for Macs to find system libraries
ifeq ($(shell uname -s),Darwin)
CFLAGS += -undefined dynamic_lookup
endif
# Set PyCI version number
VERSION_MAJOR := 0
VERSION_MINOR := 6
VERSION_PATCH := 1
PYCI_VERSION := $(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_PATCH)
# Set preprocessor directives
DEFS := -D_PYCI_VERSION='$(PYCI_VERSION)'
DEFS += -D_GIT_BRANCH='$(shell git rev-parse --abbrev-ref HEAD)'
DEFS += -D_BUILD_TIME='$(shell date -u +%F\ %T)'
DEFS += -D_COMPILER_VERSION='$(shell $(CXX) --version | head -n 1)'
# Set objects
OBJECTS := $(patsubst %.cpp,%.o,$(wildcard pyci/src/*.cpp))
# Make commands
# -------------
.PHONY: all
all: pyci/_pyci.so.$(PYCI_VERSION) pyci/_pyci.so.$(VERSION_MAJOR) pyci/_pyci.so
.PHONY: test
test:
$(PYTHON) -m pytest -sv ./pyci
.PHONY: clean
clean:
rm -rf pyci/src/*.o pyci/_pyci.so*
.PHONY: cleandeps
cleandeps:
rm -rf deps
# Make targets
# ------------
compile_flags.txt:
echo "$(CFLAGS)" | tr ' ' '\n' > $(@)
pyci/src/%.o: pyci/src/%.cpp pyci/include/pyci.h $(DEPS)
$(CXX) $(CFLAGS) $(DEFS) -c $(<) -o $(@)
pyci/_pyci.so.$(PYCI_VERSION): $(OBJECTS)
$(CXX) $(CFLAGS) $(DEFS) -shared $(^) -o $(@)
pyci/_pyci.so.$(VERSION_MAJOR): pyci/_pyci.so.$(PYCI_VERSION)
ln -sf $(notdir $(<)) $(@)
pyci/_pyci.so: pyci/_pyci.so.$(PYCI_VERSION)
ln -sf $(notdir $(<)) $(@)
deps/eigen:
@git clone https://gitlab.com/libeigen/eigen.git $(@)
deps/spectra:
@git clone https://github.com/yixuan/spectra.git $(@)
deps/parallel-hashmap:
@git clone https://github.com/greg7mdp/parallel-hashmap.git $(@)
deps/pybind11:
@git clone https://github.com/pybind/pybind11.git $(@)