forked from spacemeshos/go-spacemesh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile-gpu.Inc
120 lines (103 loc) · 3.43 KB
/
Makefile-gpu.Inc
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
PROJ_DIR := $(dir $(realpath $(firstword $(MAKEFILE_LIST))))
BIN_DIR ?= $(PROJ_DIR)build/
export GOOS
export GOARCH
export GOARM
export BIN_DIR
ifeq ($(OS),Windows_NT)
HOST_OS := windows
else
HOST_OS := $(shell uname | tr "[A-Z]" "[a-z]")
endif
ifeq ($(GOOS),)
GOOS := $(HOST_OS)
endif
ifeq ($(GOARCH),)
GOARCH := $(shell go env GOARCH)
endif
GOTAGS = # -tags ...
export CGO_LDFLAGS := -L$(BIN_DIR)
CGO_TEST_LDFLAGS := $(CGO_LDFLAGS) -Wl,-rpath,$(BIN_DIR)
ifeq ($(GOOS),windows)
platform := windows
export PATH := $(PATH):$(PROJ_DIR)build
EXE := .exe
else
TEMP := /tmp
ifeq ($(GOOS),darwin)
ifeq ($(GOARCH),arm64)
platform := macos-m1
else
platform := macos
endif
CGO_LDFLAGS := $(CGO_LDFLAGS) -Wl,-rpath,@loader_path
ULIMIT := ulimit -n 9999;
else
platform := linux
CGO_LDFLAGS := $(CGO_LDFLAGS) -Wl,-rpath,$$ORIGIN
endif
endif
ifneq ($(VERBOSE),)
$(info "OS: $(OS), HOST_OS: $(HOST_OS), GOOS: $(GOOS), GOARCH: $(GOARCH), BIN_DIR: $(BIN_DIR), platform: $(platform)")
endif
GPU_SETUP_REV = 0.1.24
GPU_SETUP_ZIP = libgpu-setup-$(platform)-$(GPU_SETUP_REV).zip
GPU_SETUP_URL_ZIP = https://github.com/spacemeshos/gpu-post/releases/download/v$(GPU_SETUP_REV)/$(GPU_SETUP_ZIP)
ifeq ($(platform), windows)
GPU_SETUP_LIBS = gpu-setup.dll
else
ifneq (,$(findstring macos,$(platform)))
GPU_SETUP_LIBS = libgpu-setup.dylib libMoltenVK.dylib libvulkan.1.dylib MoltenVK_icd.json
else
GPU_SETUP_LIBS = libgpu-setup.so
endif
endif
BINDIR_GPU_SETUP_LIBS = $(foreach X,$(GPU_SETUP_LIBS),$(BIN_DIR)$(X))
$(BINDIR_GPU_SETUP_LIBS): $(PROJ_DIR)$(GPU_SETUP_ZIP)
mkdir -p $(dir $@)
unzip -o $(PROJ_DIR)$(GPU_SETUP_ZIP) -d $(dir $@) $(notdir $@)
touch $@
$(PROJ_DIR)$(GPU_SETUP_ZIP):
curl -L $(GPU_SETUP_URL_ZIP) -o $(PROJ_DIR)$(GPU_SETUP_ZIP)
get-gpu-setup: $(PROJ_DIR)$(GPU_SETUP_ZIP) $(BINDIR_GPU_SETUP_LIBS)
.PHONY: get-gpu-setup
SUBDIRS_LVL1 := $(foreach X,$(wildcard $(dir $(PROJ_DIR))*/.), $(lastword $(subst /, ,$(dir $(X)))))
SUBDIRS_ONLY := $(sort \
$(foreach X,$(SUBDIRS_LVL1),\
$(foreach Y, $(wildcard $(X)/*_test.go), test-$(X)) ))
SUBDIRS_ALL := $(sort \
$(foreach X,$(SUBDIRS_LVL1),\
$(foreach Y, $(wildcard $(X)/*/*_test.go), test-$(X)-all ) \
$(foreach Y, $(wildcard $(X)/*_test.go), test-$(X)-all ) ))
SUBDIRS_LVL2 := $(sort \
$(foreach X,$(SUBDIRS_LVL1),\
$(foreach Y, $(wildcard $(X)/*/*_test.go), test-$(X)-$(lastword $(subst /, ,$(dir $(Y))) ))))
# defines test-* targets from subdirs level 1 and 2
$(SUBDIRS_ONLY): get-gpu-setup
$(ULIMIT) CGO_LDFLAGS="$(CGO_TEST_LDFLAGS)" go test -v ./$(@:test-%=%)
$(SUBDIRS_LVL2): get-gpu-setup
$(ULIMIT) CGO_LDFLAGS="$(CGO_TEST_LDFLAGS)" go test -v ./$(subst -,/,$(@:test-%=%))/...
$(SUBDIRS_ALL): get-gpu-setup
$(ULIMIT) CGO_LDFLAGS="$(CGO_TEST_LDFLAGS)" go test -v ./$(@:test-%-all=%)/...
print-test-targets:
@for i in test-all test-no-app-test test-only-app-test test-tidy test-fmt \
$(sort \
$(SUBDIRS_LVL2) \
$(foreach X, $(SUBDIRS_ALL), $(if $(filter $(SUBDIRS_ONLY),$(X:%-all=%)), \
$(X:%-all=%)[-all],\
$(X)))); \
do echo $$i; \
done
.PHONY: $(SUBDIRS_ALL) $(SUBDIRS_LVL2) $(SUBDIRS_ONLY) print-test-targets
go-env: get-gpu-setup
go env -w CGO_LDFLAGS="$(CGO_LDFLAGS)"
.PHONY: go-env
go-env-test: get-gpu-setup
go env -w CGO_LDFLAGS="$(CGO_TEST_LDFLAGS)"
.PHONY: go-env-test
print-ldflags: get-gpu-setup
@echo $(CGO_LDFLAGS)
.PHONY: print-ldflags
print-test-ldflags: get-gpu-setup
@echo $(CGO_TEST_LDFLAGS)
.PHONY: print-test-ldflags