-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
94 lines (73 loc) · 2.5 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
APP ?=for_each
ifdef DEBUG
OPT = -O1 -g -gdwarf
endif
OPT ?=-O3
CC = clang
CXX = clang++
GPU ?= gfx906
VENDOR ?= amdgcn-amd-amdhsa
bin: bin/$(APP)
target: bin
TMPOUT=temps/$(APP)
CFLAGS = -Wall -std=c++23 $(OPT) -Iinclude
CFLAGS += -stdlib=libc++ -fexperimental-library -I$(LLVMPATH)/bin/../include/c++/v1/ #-I/usr/include/sys/
#LDFLAGS = -L$(LLVMPATH)/lib/x86_64-unknown-linux-gnu/ -L/usr/include/tbb -ltbb
#LDFLAGS += -Wl,-rpath,$(LLVMPATH)/lib/x86_64-unknown-linux-gnu/ -Wl,-rpath,$(LLVMPATH)/lib #-Wl,-rpath,$(LLVMPATH)/lib/powerpc64le-unknown-linux-gnu/
LDFLAGS = -Wl,-rpath,$(LLVMPATH)/lib/,-rpath,$(LLVMPATH)/lib/x86_64-unknown-linux-gnu/ #-L$($(LLVMPATH))/lib -lomptarget
ifdef LEN
CFLAGS += -DLEN=$(LEN)
endif
ifdef OMP
CFLAGS += -fopenmp -fno-exceptions
ifdef OMPHOST
#CFLAGS += -fopenmp-targets=x86_64-pc-linux-gnu
else
CFLAGS += -fopenmp-targets=$(VENDOR) --offload-arch=$(GPU)
LDFLAGS += -L$(LLVMPATH)/lib -lomptarget
#CFLAGS += -fopenmp-targets=amdgcn-amd-amdhsa --offload-arch=gfx906 -D_LIBCPP_ENABLE_OPENMP_OFFLOAD -L$(LLVMPATH)/lib -lomptarget
#CFLAGS += -D_LIBCPP_PSTL_GPU_BACKEND_OMP_OFFLOAD
endif
LDFLAGS += -L$(LLVMPATH)/lib -lomp
else
CFLAGS += -fno-pie
LDFLAGS += -static
endif
SRC2 = $(wildcard src/$(APP)/*.cpp)
SRC1 = $(subst src/$(APP)/,,$(SRC2))
SRC = $(subst .cpp,,$(SRC1))
BINS = $(patsubst %, bin/$(APP)/%, $(SRC))
TEMPS = $(patsubst %, temps/$(APP)/%, $(SRC))
# Compiling source to binary
mkbin:
mkdir -p bin/$(APP)
mktemps:
mkdir -p $(TMPOUT)
bin/$(APP)/%: src/$(APP)/%.cpp
make mkbin
$(CXX) $(CFLAGS) $< -o $@ $(LDFLAGS)
temps/$(APP)/%: src/$(APP)/%.cpp
mkdir -p $(TMPOUT)/$(basename $(subst src/$(APP)/,,$<))
$(CXX) $(CFLAGS) -save-temps $(LDFLAGS) $< -o $@
mv $(NAME)*.o $(TMPOUT)/$(basename $(subst src/$(APP)/,,$<))
mv $(NAME)*.bc $(TMPOUT)/$(basename $(subst src/$(APP)/,,$<))
mv $(NAME)*.ii $(TMPOUT)/$(basename $(subst src/$(APP)/,,$<))
mv $(NAME)*.s $(TMPOUT)/$(basename $(subst src/$(APP)/,,$<))
mv $(NAME)*.out $(TMPOUT)/$(basename $(subst src/$(APP)/,,$<))
mv $(NAME)*.img $(TMPOUT)/$(basename $(subst src/$(APP)/,,$<))
llvm-dis $(TMPOUT)/$(basename $(subst src/$(APP)/,,$<))/*.bc
runtests:
for str in $(shell ls bin/$(APP)/*) ; do \
echo "Running test $$str" ; \
./$$str ; \
echo "" ; \
done
bin/$(APP): $(BINS)
.PHONY: clean ast ir
ir:
$(CXX) $(CFLAGS) -emit-llvm -S src/$(APP).cpp -o ir/$(APP).ll
ast:
$(CXX) $(CFLAGS) -Xclang -ast-dump src/$(APP).cpp &> ast/$(APP).ast
temps: mktemps $(TEMPS)
clean:
rm -rf bin/*/* ir/* *.core ast/* temps/*/*.* *.ii *.bc *.o *.s *.out