-
Notifications
You must be signed in to change notification settings - Fork 56
/
Makefile
118 lines (99 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
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
NAME = libtorrent-go
GO_PACKAGE = github.com/steeve/$(NAME)
CC = cc
CXX = c++
PKG_CONFIG = pkg-config
DOCKER = docker
DOCKER_IMAGE = steeve/$(NAME)
PLATFORMS = android-arm \
darwin-x64 \
linux-x86 \
linux-x64 \
linux-arm \
windows-x86 \
windows-x64
include platform_host.mk
ifneq ($(CROSS_TRIPLE),)
CC := $(CROSS_TRIPLE)-$(CC)
CXX := $(CROSS_TRIPLE)-$(CXX)
endif
include platform_target.mk
ifeq ($(TARGET_ARCH),x86)
GOARCH = 386
else ifeq ($(TARGET_ARCH),x64)
GOARCH = amd64
else ifeq ($(TARGET_ARCH),arm)
GOARCH = arm
GOARM = 6
endif
ifeq ($(TARGET_OS), windows)
GOOS = windows
else ifeq ($(TARGET_OS), darwin)
GOOS = darwin
else ifeq ($(TARGET_OS), linux)
GOOS = linux
else ifeq ($(TARGET_OS), android)
GOOS = android
GOARM = 7
endif
ifneq ($(CROSS_ROOT),)
CROSS_CFLAGS = -I$(CROSS_ROOT)/include -I$(CROSS_ROOT)/$(CROSS_TRIPLE)/include
CROSS_LDFLAGS = -L$(CROSS_ROOT)/lib
PKG_CONFIG_PATH = $(CROSS_ROOT)/lib/pkgconfig
endif
LIBTORRENT_CFLAGS = $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) $(PKG_CONFIG) --cflags libtorrent-rasterbar)
LIBTORRENT_LDFLAGS = $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) $(PKG_CONFIG) --static --libs libtorrent-rasterbar)
DEFINE_IGNORES = __STDC__|_cdecl|__cdecl|_fastcall|__fastcall|_stdcall|__stdcall|__declspec
CC_DEFINES = $(shell echo | $(CC) -dM -E - | grep -v -E "$(DEFINE_IGNORES)" | sed -E "s/\#define[[:space:]]+([a-zA-Z0-9_()]+)[[:space:]]+(.*)/-D\1="\2"/g" | tr '\n' ' ')
ifeq ($(TARGET_OS), windows)
CC_DEFINES += -DSWIGWIN
CC_DEFINES += -D_WIN32_WINNT=0x0501
ifeq ($(TARGET_ARCH), x64)
CC_DEFINES += -DSWIGWORDSIZE32
endif
else ifeq ($(TARGET_OS), darwin)
CC_DEFINES += -DSWIGMAC
CC_DEFINES += -DBOOST_HAS_PTHREADS
endif
OUT_PATH = $(shell go env GOPATH)/pkg/$(GOOS)_$(GOARCH)
OUT_LIBRARY = $(OUT_PATH)/$(GO_PACKAGE).a
ifeq ($(TARGET_OS), windows)
OUT_LIBRARY_SHARED = $(OUT_PATH)/$(GO_PACKAGE).dll
SONAME = $(shell basename $(OUT_LIBRARY_SHARED))
endif
all: install
ifeq ($(TARGET_OS), windows)
install: install_all fix_windows
else
install: install_all
endif
.PHONY: dockerbuild
install_all:
SWIG_FLAGS='$(CC_DEFINES) $(LIBTORRENT_CFLAGS)' \
SONAME=$(SONAME) \
CC=$(CC) CXX=$(CXX) \
PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) \
CGO_ENABLED=1 \
GOOS=$(GOOS) GOARCH=$(GOARCH) GOARM=$(GOARM) \
PATH=.:$$PATH \
go install -v -x
fix_windows:
mv $(OUT_LIBRARY) $(OUT_LIBRARY).raw
cd `mktemp -d` && \
pwd && \
ar x $(OUT_LIBRARY).raw && \
go tool pack r $(OUT_LIBRARY) `ar t $(OUT_LIBRARY).raw | grep -v _wrap` && \
$(CXX) -shared -static-libgcc -static-libstdc++ -o $(OUT_LIBRARY_SHARED) *_wrap $(LIBTORRENT_LDFLAGS) && \
rm -rf `pwd`
rm -rf $(OUT_LIBRARY).raw
clean:
rm -rf $(OUT_LIBRARY) $(OUT_LIBRARY_SHARED)
re: clean all
build-envs:
for i in $(PLATFORMS); do \
$(DOCKER) build -t $(DOCKER_IMAGE):$$i $$i ; \
done
alldist:
for i in $(PLATFORMS); do \
$(DOCKER) run --rm -v $(HOME):$(HOME) -e GOPATH=$(shell go env GOPATH) -w $(shell pwd) $(DOCKER_IMAGE):$$i make re; \
done