This repository has been archived by the owner on Mar 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Makefile
142 lines (107 loc) · 3.74 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
HOSTOS:=$(shell go env GOHOSTOS)
SRC_DIR=./src
DEPS_C = $(SRC_DIR)/*.h $(SRC_DIR)/*.hpp $(SRC_DIR)/*.c
DEPS_GO = $(SRC_DIR)/*.go gen_header.go go.mod go.sum
BUILD_MODE=-buildmode=c-shared
BUILD_MODE_STATIC=-buildmode=c-archive
GO_BUILD=go build
CC_WIN64=x86_64-w64-mingw32-gcc
CC_WIN32=i686-w64-mingw32-gcc
OSX_MIN_VERSION=10.7
OSX_CGO_CFLAGS=-mmacosx-version-min=${OSX_MIN_VERSION}
OSX_CGO_LDFLAGS=-mmacosx-version-min=${OSX_MIN_VERSION}
GEN_HEADER=go run gen_header.go -o
ifeq ("$(HOSTOS)", 'windows')
CP_HEADERS=copy $(SRC_DIR)/libuast.hpp
else
CP_HEADERS=cp $(SRC_DIR)/libuast.hpp
endif
OUT_NAME=libuast
OUT_HEADER=$(OUT_NAME).h
OUT_DIR=build
DIR_LINUX=linux-amd64
DIR_OSX=darwin-amd64
DIR_WINDOWS=windows-amd64
OUT_LINUX=$(OUT_DIR)/$(DIR_LINUX)
OUT_OSX=$(OUT_DIR)/$(DIR_OSX)
OUT_WINDOWS=$(OUT_DIR)/$(DIR_WINDOWS)
ifeq ("$(HOSTOS)", "windows")
OUT_WINDOWS=$(OUT_DIR)\\$(DIR_WINDOWS)
endif
build: build-$(HOSTOS)
.PHONY: build-all
ifeq ("$(HOSTOS)", "linux")
build-all: build-linux build-windows
else ifeq ("$(HOSTOS)", "windows")
build-all: build-windows
else ifeq ("$(HOSTOS)", "darwin")
build-all: build-darwin
endif
build-linux: $(DEPS_C) $(DEPS_GO)
mkdir -p $(OUT_LINUX) && \
GOOS=linux GOARCH=amd64 $(GO_BUILD) $(BUILD_MODE) -o=$(OUT_LINUX)/$(OUT_NAME).so $(SRC_DIR)/ && \
GOOS=linux GOARCH=amd64 $(GO_BUILD) $(BUILD_MODE_STATIC) -o=$(OUT_LINUX)/$(OUT_NAME).a $(SRC_DIR)/ && \
$(GEN_HEADER) $(OUT_LINUX)/$(OUT_HEADER) && \
$(CP_HEADERS) $(OUT_LINUX)/
build-darwin: $(DEPS_C) $(DEPS_GO)
mkdir -p $(OUT_OSX) && \
GOOS=darwin GOARCH=amd64 CGO_ENABLED=1 CGO_CFLAGS=$(OSX_CGO_CFLAGS) CGO_LDFLAGS=$(OSX_CGO_LDFLAGS) $(GO_BUILD) $(BUILD_MODE) -o=$(OUT_OSX)/$(OUT_NAME).so $(SRC_DIR)/ && \
GOOS=darwin GOARCH=amd64 CGO_ENABLED=1 CGO_CFLAGS=$(OSX_CGO_CFLAGS) CGO_LDFLAGS=$(OSX_CGO_LDFLAGS) $(GO_BUILD) $(BUILD_MODE_STATIC) -o=$(OUT_OSX)/$(OUT_NAME).a $(SRC_DIR)/ && \
$(GEN_HEADER) $(OUT_OSX)/$(OUT_HEADER) && \
$(CP_HEADERS) $(OUT_OSX)/
ifneq ("$(HOSTOS)", "windows")
build-windows: $(DEPS_C) $(DEPS_GO)
mkdir -p $(OUT_WINDOWS)
GOOS=windows GOARCH=amd64 CGO_ENABLED=1 CC=$(CC_WIN64) $(GO_BUILD) $(BUILD_MODE) -o=$(OUT_WINDOWS)/$(OUT_NAME).dll $(SRC_DIR)/
GOOS=windows GOARCH=amd64 CGO_ENABLED=1 CC=$(CC_WIN64) $(GO_BUILD) $(BUILD_MODE_STATIC) -o=$(OUT_WINDOWS)/$(OUT_NAME).lib $(SRC_DIR)/
$(GEN_HEADER) $(OUT_WINDOWS)/$(OUT_HEADER)
$(CP_HEADERS) $(OUT_WINDOWS)/
else
build-windows: $(DEPS_C) $(DEPS_GO)
mkdir -p $(OUT_WINDOWS)
set GOOS=windows
set GOARCH=amd64
$(GO_BUILD) $(BUILD_MODE) -o=$(OUT_WINDOWS)\\$(OUT_NAME).dll $(SRC_DIR)/
$(GEN_HEADER) $(OUT_WINDOWS)\\$(OUT_HEADER)
$(CP_HEADERS) $(OUT_WINDOWS)\\
endif
package: package-$(HOSTOS)
ifeq ("$(HOSTOS)", "linux")
package-all: build-all package-linux package-windows
else ifeq ("$(HOSTOS)", "windows")
package-all: build-all package-windows
else ifeq ("$(HOSTOS)", "darwin")
package-all: build-all package-darwin
endif
package-linux: build-linux
cd $(OUT_DIR) && \
tar -czf libuast-linux-amd64.tar.gz $(DIR_LINUX)
package-darwin: build-darwin
cd $(OUT_DIR) && \
tar -czf libuast-darwin-amd64.tar.gz $(DIR_OSX)
package-windows: build-windows
cd $(OUT_DIR) && \
tar -czf libuast-windows-amd64.tar.gz $(DIR_WINDOWS)
.PHONY: gotest
gotest: $(DEPS_GO)
go test -v $(SRC_DIR)/...
ifneq ("$(HOSTOS)", "darwin")
test: gotest
cd tests && cmake . && make && CTEST_OUTPUT_ON_FAILURE=1 make test
else
test: gotest
ln -s ../$(OUT_OSX)/libuast.so ./tests/libuast.so && \
cd tests && cmake . && make && CTEST_OUTPUT_ON_FAILURE=1 make test
endif
ifneq ("$(HOSTOS)", "darwin")
examples:
cd examples && cmake . && make
else
examples:
ln -s ../$(OUT_OSX)/libuast.so ./examples/libuast.so && \
cd examples && cmake . && make
endif
all: build-all package-all
.PHONY: clean build test examples install
clean:
rm -rf $(OUT_DIR)