-
Notifications
You must be signed in to change notification settings - Fork 6
/
Makefile
87 lines (74 loc) · 2.93 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
SHELL = /bin/bash
.SHELLFLAGS=-O globstar -c
ifndef GOMODCACHE
$(eval GOMODCACHE=$(shell go env | grep GOMODCACHE | sed -E 's/GOMODCACHE="(.*)"/\1/'))
endif
UID := $(shell id -u)
tmp/uplink-c:
mkdir -p tmp
git clone --branch v1.7.0 https://github.com/storj/uplink-c.git ./tmp/uplink-c
.PHONY: clean
clean:
rm -rf build tmp
build/libuplink-x86_64-linux.so tmp/uplink-c/.build/uplink/uplink.h tmp/uplink-c/.build/uplink/uplink_definitions.h: tmp/uplink-c
cd tmp/uplink-c && make build
mkdir -p build
cat tmp/uplink-c/.build/libuplink.so > build/libuplink-x86_64-linux.so
build/libuplink-aarch64-linux.so: tmp/uplink-c
docker run --rm \
-v /tmp/gomod:/go/pkg/mod \
-v $(PWD)/tmp:$(PWD)/tmp \
--workdir $(PWD)/tmp/uplink-c \
-e CGO_ENABLED=1 \
docker.elastic.co/beats-dev/golang-crossbuild:1.20.7-arm \
--build-cmd "useradd --create-home --uid $(UID) jenkins && chown -R jenkins /go/pkg/mod && su jenkins -c 'PATH=\$$PATH:/go/bin:/usr/local/go/bin make build'" \
-p "linux/arm64"
mkdir -p build
cat ./tmp/uplink-c/.build/libuplink.so > build/libuplink-aarch64-linux.so
build/libuplink-amd64-windows_nt.dll: tmp/uplink-c
docker run --rm \
-v /tmp/gomod:/go/pkg/mod \
-v $(PWD)/tmp:$(PWD)/tmp \
--workdir $(PWD)/tmp/uplink-c \
-e CGO_ENABLED=1 \
docker.elastic.co/beats-dev/golang-crossbuild:1.20.7-main-debian11 \
--build-cmd "useradd --create-home --uid $(UID) jenkins && chown -R jenkins /go/pkg/mod && su jenkins -c 'PATH=\$$PATH:/go/bin:/usr/local/go/bin make build'" \
-p "windows/amd64"
mkdir -p build
cat ./tmp/uplink-c/.build/libuplink.so > build/libuplink-amd64-windows_nt.dll
build/uplink-php.h: tmp/uplink-c/.build/uplink/uplink.h tmp/uplink-c/.build/uplink/uplink_definitions.h
## create C header file
cat ./tmp/uplink-c/.build/uplink/uplink_definitions.h \
./tmp/uplink-c/.build/uplink/uplink.h \
> build/uplink-php.h
## remove stuff PHP can't handle
sed -i 's/typedef __SIZE_TYPE__ GoUintptr;//g' build/uplink-php.h
sed -i 's/typedef float _Complex GoComplex64;//g' build/uplink-php.h
sed -i 's/typedef double _Complex GoComplex128;//g' build/uplink-php.h
sed -i 's/typedef _Fcomplex GoComplex64;//g' build/uplink-php.h
sed -i 's/typedef _Dcomplex GoComplex128;//g' build/uplink-php.h
sed -i 's/#ifdef __cplusplus//g' build/uplink-php.h
sed -i 's/extern "C" {//g' build/uplink-php.h
sed -i 's/#endif//g' build/uplink-php.h
sed -zi 's/}\n//g' build/uplink-php.h
.PHONY: build
build: build-x64 build-arm64 build-windows
.PHONY: build-x64
build-x64: build/libuplink-x86_64-linux.so build/uplink-php.h
.PHONY: build-arm64
build-arm64: build/libuplink-aarch64-linux.so build/uplink-php.h
.PHONY: build-windows
build-windows: build/libuplink-amd64-windows_nt.dll build/uplink-php.h
## declared without prerequites just to run it
release.zip:
zip release.zip \
LICENSE \
MAINTAINERS.md \
Makefile \
README.md \
build/*.so \
build/*.dll \
build/uplink-php.h \
composer.json \
src/**/*.php \
test/**/*.php