-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
50 lines (41 loc) · 1.98 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
NAME := siliconcloud
VERSION := v0.0.1
GOOS ?= $(shell go env GOOS)
OUTPUT_BIN ?= execs/${GOOS}/${NAME}-${VERSION}
PACKAGE := github.com/siliconflow/${NAME}-cli
CGO_ENABLED?=0
GO_FLAGS ?=
GIT_REV ?= $(shell git rev-parse --short HEAD)
GO_TAGS ?= netgo
SOURCE_DATE_EPOCH ?= $(shell date +%s)
ifeq ($(shell uname), Darwin)
DATE ?= $(shell TZ=GMT date -j -f "%s" ${SOURCE_DATE_EPOCH} +"%Y-%m-%dT%H:%M:%SZ")
else
DATE ?= $(shell date -u -d @${SOURCE_DATE_EPOCH} +"%Y-%m-%dT%H:%M:%SZ")
endif
deps:
go mod tidy
clean:
rm -rf execs/*
build: deps
@CGO_ENABLED=${CGO_ENABLED} go build ${GO_FLAGS} \
-ldflags "-w -s -X '${PACKAGE}/meta.Version=${VERSION}' -X '${PACKAGE}/meta.Commit=${GIT_REV}' -X '${PACKAGE}/meta.BuildDate=${DATE}'" \
-a -tags=${GO_TAGS} -o execs/${NAME} main.go
install: build
cp execs/${NAME} /usr/local/bin/${NAME}
build_windows:
@CGO_ENABLED=${CGO_ENABLED} GOOS=windows GOARCH=amd64 go build ${GO_FLAGS} \
-ldflags "-w -s -X ${PACKAGE}/meta.Version=${VERSION} -X ${PACKAGE}/meta.Commit=${GIT_REV} -X ${PACKAGE}/meta.BuildDate=${DATE}" \
-a -tags=${GO_TAGS} -o execs/windows/${NAME}-${VERSION}.exe main.go
build_linux:
@CGO_ENABLED=${CGO_ENABLED} GOOS=linux GOARCH=amd64 go build ${GO_FLAGS} \
-ldflags "-w -s -X ${PACKAGE}/meta.Version=${VERSION} -X ${PACKAGE}/meta.Commit=${GIT_REV} -X ${PACKAGE}/meta.BuildDate=${DATE}" \
-a -tags=${GO_TAGS} -o execs/linux/${NAME}-${VERSION} main.go
build_mac:
@CGO_ENABLED=${CGO_ENABLED} GOOS=darwin GOARCH=amd64 go build ${GO_FLAGS} \
-ldflags "-w -s -X ${PACKAGE}/meta.Version=${VERSION} -X ${PACKAGE}/meta.Commit=${GIT_REV} -X ${PACKAGE}/meta.BuildDate=${DATE}" \
-a -tags=${GO_TAGS} -o execs/mac/${NAME}-${VERSION} main.go
build_linux_arm64:
@CGO_ENABLED=${CGO_ENABLED} GOOS=linux GOARCH=arm64 go build ${GO_FLAGS} \
-ldflags "-w -s -X ${PACKAGE}/meta.Version=${VERSION} -X ${PACKAGE}/meta.Commit=${GIT_REV} -X ${PACKAGE}/meta.BuildDate=${DATE}" \
-a -tags=${GO_TAGS} -o execs/linux_arm64/${NAME}-${VERSION} main.go