不需要设定GOPATH 自动编译go程序的makefile的写法
GO ?= go
GOFMT ?= gofmt "-s"
PACKAGES ?= $(shell $(GO) list ./...)
VETPACKAGES ?= $(shell $(GO) list ./... | grep -v /examples/)
GOFILES := $(shell find . -name "*.go")
TESTFOLDER := $(shell $(GO) list ./... | grep -E 'gin$$|binding$$|render$$' | grep -v examples)
TESTTAGS ?= ""
TARGET ?= "XWebServer"
PATHTEMP=$(shell pwd)
PATHTEMP1=$(subst /src/XWebServer,, $(PATHTEMP))
# 设置 src 的上一层目录为 GOPATH 路径
export GOPATH =$(shell echo $(PATHTEMP1))
.PHONY: all
all:
#echo $(PATHTEMP1)
# native compiler linux amd64
#GOPATH=/home/kong/go/3
GOROOT=/usr/local/go
#GOBIN=$GOPATH/bin
GOARCH=amd64
GOOS=linux
CGO_ENABLED=1
go build -o $(TARGET)
.PHONY: win64
win64:
GOROOT=/usr/local/go
GOARCH=amd64
GOOS=windows
go build -o XWebServer.exe
.PHONY: fmt
fmt:
$(GOFMT) -w $(GOFILES)
.PHONY: pack
pack:
#bee pack在编译之后压缩的的时候会默认忽略这三种文件:.go:.DS_Store:.tmp。因此我们只需要忽略其他的文件即可。使用命令-exr用正则表达式忽略文件:
./bee pack -be GOOS=linux GOARCH=amd64
.PHONY: pwin64
pwin64:
./bee pack -be GOOS=windows GOARCH=amd64