-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
82 lines (65 loc) · 2.65 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
USE_CUDA = true
SRCDIR := src
OBJDIR := bin
DEPDIR := $(OBJDIR)/deps
TARGET := $(OBJDIR)/nbody.so
CXX := g++
NVCC := /usr/local/cuda/bin/nvcc
CUDA_INCLUDE_DIR := /usr/local/cuda/include
SHAREDFLAGS := -fPIC -Wall -std=c++17 -O2 -shared
CPPFLAGS = $(SHAREDFLAGS) $(PY_INC) -DBOOST_BIND_GLOBAL_PLACEHOLDERS -DBOOST_ALLOW_DEPRECATED_HEADERS
NVCCFLAGS = -std=c++17 -O2 -lineinfo $(PY_INC) -DBOOST_BIND_GLOBAL_PLACEHOLDERS -DBOOST_ALLOW_DEPRECATED_HEADERS --compiler-options "$(SHAREDFLAGS)"
LDFLAGS := -shared
LDLIBS = $(PY_LD) -lavcodec -lavutil -lpthread
ifeq ($(USE_CUDA), true)
CPPFLAGS += -DUSING_CUDA -I$(CUDA_INCLUDE_DIR)
NVCCFLAGS += -DUSING_CUDA -I$(CUDA_INCLUDE_DIR)
LD := $(NVCC)
CU_LANG := cu
LDFLAGS := --compiler-options $(LDFLAGS)
else
NVCCFLAGS := $(CPPFLAGS)
LD := $(CXX)
CU_LANG := c++
NVCC := $(CXX)
endif
SRCS := $(wildcard $(SRCDIR)/*.cpp)
OBJS := $(patsubst $(SRCDIR)/%,$(OBJDIR)/%.cpp.o,$(basename $(SRCS)))
DEPS := $(patsubst $(SRCDIR)/%,$(DEPDIR)/%.cpp.d,$(basename $(SRCS)))
CUDA_SRCS := $(wildcard $(SRCDIR)/*.cu)
CUDA_OBJS := $(patsubst $(SRCDIR)/%,$(OBJDIR)/%.cu.o,$(basename $(CUDA_SRCS)))
CUDA_DEPS := $(patsubst $(SRCDIR)/%,$(DEPDIR)/%.cu.d,$(basename $(CUDA_SRCS)))
STUB := $(patsubst %.so,%.pyi,$(TARGET))
PY_VERSION := $(wordlist 2,4,$(subst ., ,$(shell python3 --version 2>&1)))
PY_VERSION_MAJOR := $(word 1,${PY_VERSION})
PY_VERSION_MINOR := $(word 2,${PY_VERSION})
PY_INC := -I/usr/include/python$(PY_VERSION_MAJOR).$(PY_VERSION_MINOR)/
PY_LD := -lpython$(PY_VERSION_MAJOR).$(PY_VERSION_MINOR) -l:libboost_python$(PY_VERSION_MAJOR)$(PY_VERSION_MINOR).so -l:libboost_numpy$(PY_VERSION_MAJOR)$(PY_VERSION_MINOR).so
# create directories
$(shell mkdir -p $(OBJDIR) >/dev/null)
$(shell mkdir -p $(DEPDIR) >/dev/null)
all: $(OBJDIR)/ec $(TARGET)
.PHONY: clean
clean:
rm -f $(OBJS) $(CUDA_OBJS) $(DEPS) $(CUDA_DEPS) $(TARGET) $(STUB) $(OBJDIR)/ec
$(OBJDIR)/ec:
@echo "Verifying endianness"
@lscpu | grep Endian | grep -q "Little"
@touch $@
$(TARGET): $(OBJS) $(CUDA_OBJS)
$(LD) $(LDFLAGS) -o $@ $^ $(LDLIBS)
PYTHONPATH=$(shell realpath $(OBJDIR)) stubgen -m nbody -o $(OBJDIR)
$(OBJDIR)/%.cpp.o: $(SRCDIR)/%.cpp
$(OBJDIR)/%.cpp.o: $(SRCDIR)/%.cpp $(DEPDIR)/%.cu.d
$(CXX) -x c++ -MT $@ -MMD -MP -MF $(DEPDIR)/$*.cpp.Td $(CPPFLAGS) -c -o $@ $<
mv -f $(DEPDIR)/$*.cpp.Td $(DEPDIR)/$*.cpp.d && touch $@
$(OBJDIR)/%.cu.o: $(SRCDIR)/%.cu
$(OBJDIR)/%.cu.o: $(SRCDIR)/%.cu $(DEPDIR)/%.cu.d
$(NVCC) -x $(CU_LANG) -MT $@ -MMD -MP -MF $(DEPDIR)/$*.cu.Td $(NVCCFLAGS) -c -o $@ $<
mv -f $(DEPDIR)/$*.cu.Td $(DEPDIR)/$*.cu.d && touch $@
.PRECIOUS: $(DEPDIR)/%.cpp.d
$(DEPDIR)/%.cpp.d: ;
-include $(DEPS)
.PRECIOUS: $(DEPDIR)/%.cu.d
$(DEPDIR)/%.cu.d: ;
-include $(CUDA_DEPS)