This repository has been archived by the owner on May 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile-libs.Inc
146 lines (118 loc) · 4.33 KB
/
Makefile-libs.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
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
PROJ_DIR := $(dir $(realpath $(firstword $(MAKEFILE_LIST))))
PROJ_DIR := $(subst \,/,$(PROJ_DIR))
BIN_DIR ?= $(PROJ_DIR)build/
export CGO_LDFLAGS := -L$(BIN_DIR)
export CGO_CFLAGS := -I$(PROJ_DIR)build/
export GOOS
export GOARCH
export GOARM
export BIN_DIR
CGO_TEST_LDFLAGS = $(CGO_LDFLAGS) -Wl,-rpath,$(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
ifeq ($(GOOS),windows)
platform := windows
export PATH := $(PATH):$(PROJ_DIR)build
EXE := .exe
CGO_LDFLAGS := $(CGO_LDFLAGS) -Wl,-Bstatic -lpthread -Wl,-Bdynamic
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
ifeq ($(GOARCH),arm64)
platform := linux-arm64
else
platform := linux
endif
CGO_LDFLAGS := $(CGO_LDFLAGS) -Wl,-rpath,$$ORIGIN
endif
endif
POSTRS_SETUP_REV = 0.7.8
POSTRS_SETUP_ZIP = libpost-$(platform)-v$(POSTRS_SETUP_REV).zip
POSTRS_SETUP_URL_ZIP ?= https://github.com/spacemeshos/post-rs/releases/download/v$(POSTRS_SETUP_REV)/$(POSTRS_SETUP_ZIP)
POSTRS_PROFILER_ZIP = profiler-$(platform)-v$(POSTRS_SETUP_REV).zip
POSTRS_PROFILER_URL ?= https://github.com/spacemeshos/post-rs/releases/download/v$(POSTRS_SETUP_REV)/$(POSTRS_PROFILER_ZIP)
POSTRS_SERVICE_ZIP = service-$(platform)-v$(POSTRS_SETUP_REV).zip
POSTRS_SERVICE_URL ?= https://github.com/spacemeshos/post-rs/releases/download/v$(POSTRS_SETUP_REV)/$(POSTRS_SERVICE_ZIP)
ifeq ($(platform), windows)
POSTRS_SETUP_LIBS = post.h post.dll
POSTRS_PROFILER_BIN = profiler.exe
POSTRS_SERVICE_BIN = service.exe
else
ifeq ($(platform), $(filter $(platform), macos macos-m1))
POSTRS_SETUP_LIBS = post.h libpost.dylib
else
POSTRS_SETUP_LIBS = post.h libpost.so
endif
POSTRS_PROFILER_BIN = profiler
POSTRS_SERVICE_BIN = service
endif
BINDIR_POSTRS_SETUP_LIBS = $(foreach X,$(POSTRS_SETUP_LIBS),$(BIN_DIR)$(X))
# file marking libpost version
$(BIN_DIR).libpost.version.$(POSTRS_SETUP_REV): $(PROJ_DIR)$(POSTRS_SETUP_ZIP)
rm -f $(BIN_DIR).libpost.version.*
mkdir -p $(dir $@)
touch $@
$(BINDIR_POSTRS_SETUP_LIBS): $(BIN_DIR).libpost.version.$(POSTRS_SETUP_REV)
mkdir -p $(dir $@)
unzip -DD -o -j $(PROJ_DIR)$(POSTRS_SETUP_ZIP) -d $(dir $@) $(notdir $@)
CURL_OPTIONS = --retry 10 --retry-max-time 120
CURL_VERSION = $(shell curl --version 2>/dev/null | head -n 1 | cut -d' ' -f2)
ifeq ($(shell expr "$(CURL_VERSION)" \>= 7.71.0),1)
CURL_OPTIONS := $(CURL_OPTIONS) --retry-all-errors
endif
$(PROJ_DIR)$(POSTRS_SETUP_ZIP):
curl -sSL $(CURL_OPTIONS) $(POSTRS_SETUP_URL_ZIP) -o $(PROJ_DIR)$(POSTRS_SETUP_ZIP)
$(PROJ_DIR)$(POSTRS_PROFILER_ZIP):
curl -sSL $(CURL_OPTIONS) $(POSTRS_PROFILER_URL) -o $(PROJ_DIR)$(POSTRS_PROFILER_ZIP)
# file marking profiler version
$(BIN_DIR)/.profiler.version.$(POSTRS_SETUP_REV): $(PROJ_DIR)$(POSTRS_PROFILER_ZIP)
rm -f $(BIN_DIR).profiler.version.*
mkdir -p $(dir $@)
touch $@
$(BIN_DIR)$(POSTRS_PROFILER_BIN): $(BIN_DIR)/.profiler.version.$(POSTRS_SETUP_REV)
unzip -DD -o -j $(PROJ_DIR)$(POSTRS_PROFILER_ZIP) -d $(BIN_DIR)
chmod +x $(BIN_DIR)$(POSTRS_PROFILER_BIN)
$(PROJ_DIR)$(POSTRS_SERVICE_ZIP):
curl -sSL $(CURL_OPTIONS) $(POSTRS_SERVICE_URL) -o $(PROJ_DIR)$(POSTRS_SERVICE_ZIP)
# file marking post-service version
$(BIN_DIR)/.service.version.$(POSTRS_SETUP_REV): $(PROJ_DIR)$(POSTRS_SERVICE_ZIP)
rm -f $(BIN_DIR).service.version.*
mkdir -p $(dir $@)
touch $@
$(BIN_DIR)$(POSTRS_SERVICE_BIN): $(BIN_DIR)/.service.version.$(POSTRS_SETUP_REV)
unzip -DD -o -j $(PROJ_DIR)$(POSTRS_SERVICE_ZIP) -d $(BIN_DIR)
chmod +x $(BIN_DIR)$(POSTRS_SERVICE_BIN)
get-postrs-lib: $(BINDIR_POSTRS_SETUP_LIBS)
get-postrs-profiler: $(BIN_DIR)$(POSTRS_PROFILER_BIN)
get-postrs-service: $(BIN_DIR)$(POSTRS_SERVICE_BIN)
go-env: get-postrs-lib
go env -w CGO_CFLAGS="$(CGO_CFLAGS)"
go env -w CGO_LDFLAGS="$(CGO_LDFLAGS)"
.PHONY: go-env
go-env-test: get-postrs-lib
go env -w CGO_CFLAGS="$(CGO_CFLAGS)"
go env -w CGO_LDFLAGS="$(CGO_TEST_LDFLAGS)"
.PHONY: go-env-test
print-env: get-postrs-lib
@echo CGO_CFLAGS="\"$(CGO_CFLAGS)\"" CGO_LDFLAGS="\"$(CGO_LDFLAGS)\""
.PHONY: print-env
print-test-env: get-postrs-lib
@echo CGO_CFLAGS="\"$(CGO_CFLAGS)\"" CGO_LDFLAGS="\"$(CGO_TEST_LDFLAGS)\""
.PHONY: print-test-env