Skip to content

Commit

Permalink
updated Makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
hedzr committed Oct 12, 2020
1 parent 31634e6 commit c7f54fe
Showing 1 changed file with 46 additions and 19 deletions.
65 changes: 46 additions & 19 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ GOBIN = $(GOBASE)/bin
GOFILES = $(wildcard *.go)
SRCS = $(shell git ls-files '*.go')
PKGS = $(shell go list ./...)
GIT_VERSION := $(shell git describe --tags --abbrev=0)
GIT_VERSION := $(shell git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
GIT_REVISION := $(shell git rev-parse --short HEAD)
#GITHASH = $(shell git rev-parse HEAD)
#BUILDTIME := $(shell date "+%Y%m%d_%H%M%S")
Expand All @@ -36,7 +36,7 @@ GOYOLO = $(BIN)/yolo


# GO111MODULE = on
GOPROXY = $(or $(GOPROXY_CUSTOM),https://athens.azurefd.net)
GOPROXY = $(or $(GOPROXY_CUSTOM),direct)

# Redirect error output to a file, so we can show it in development mode.
STDERR = $(or $(STDERR_CUSTOM),/tmp/.$(PROJECTNAME)-stderr.txt)
Expand All @@ -52,7 +52,7 @@ goarch=amd64
W_PKG=github.com/hedzr/cmdr/conf
LDFLAGS := -s -w \
-X '$(W_PKG).Buildstamp=$(BUILDTIME)' \
-X '$(W_PKG).Githash=$(GITREVISION)' \
-X '$(W_PKG).Githash=$(GIT_REVISION)' \
-X '$(W_PKG).GoVersion=$(GOVERSION)' \
-X '$(W_PKG).Version=$(VERSION)'
# -X '$(W_PKG).AppName=$(APPNAME)'
Expand Down Expand Up @@ -175,30 +175,35 @@ build-freebsd:
build-riscv:
@-$(MAKE) -s go-build-task os=linux goarchset=riscv64

## build-ci: run build-ci task. just for CI tools
build-ci:
@echo " > Building binaries in CI flow..."
$(foreach os, linux darwin windows, \
@-$(MAKE) -s go-build-task os=$(os) goarchset="386 amd64" \
)
@echo " < All Done."
@ls -la $(LS_OPT) $(GOBIN)/*

go-build-task:
@echo " > Building $(os)/$(goarchset) binary..."
@#echo " > LDFLAGS = $(LDFLAGS)"
# unsupported GOOS/GOARCH pair nacl/386 ??
$(foreach an, $(MAIN_APPS), \
echo " > APP NAMEs = appname:$(APPNAME)|projname:$(PROJECTNAME)|an:$(an)"; \
$(eval ANAME := $(shell for an in $(MAIN_APPS); do \
if [[ $$an == cli ]]; then echo $(APPNAME); \
else echo $$an; \
fi; \
done)) \
$(foreach goarch, $(goarchset), \
echo " >> Building $(GOBIN)/$(an)_$(os)_$(goarch)...$(os)" >/dev/null; \
$(GO) build -ldflags "$(LDFLAGS)" -o $(GOBIN)/$(an)_$(os)_$(goarch) $(GOBASE)/$(MAIN_BUILD_PKG)/$(an); \
chmod +x $(GOBIN)/$(an)_$(os)_$(goarch)*; \
ls -la $(LS_OPT) $(GOBIN)/$(an)_$(os)_$(goarch)*; \
echo " >> Building (-trimpath) $(GOBIN)/$(ANAME)_$(os)_$(goarch)...$(os)" >/dev/null; \
$(GO) build -ldflags "$(LDFLAGS)" -o $(GOBIN)/$(ANAME)_$(os)_$(goarch) $(GOBASE)/$(MAIN_BUILD_PKG)/$(an); \
chmod +x $(GOBIN)/$(ANAME)_$(os)_$(goarch)*; \
ls -la $(LS_OPT) $(GOBIN)/$(ANAME)_$(os)_$(goarch)*; \
) \
)
#@ls -la $(LS_OPT) $(GOBIN)/*linux*

## build-ci: run build-ci task. just for CI tools
build-ci:
@echo " > Building binaries in CI flow..."
$(foreach os, linux darwin windows, \
@-$(MAKE) -s go-build-task os=$(os) goarchset="386 amd64" \
)
@echo " < All Done."
@ls -la $(LS_OPT) $(GOBIN)/*




Expand All @@ -223,6 +228,16 @@ clean:

# go-compile: go-clean go-generate go-build

ooo:
$(eval ANAME := $(shell for an in $(MAIN_APPS); do \
if [[ $$an == cli ]]; then A=$(APPNAME); echo $(APPNAME); \
else A=$$an; echo $$an; \
fi; \
done))
@echo "ANAME = $(ANAME), $$ANAME, $$A"

ox: go-clean go-generate
$(MAKE) -s go-build

## run: go run xxx
run:
Expand All @@ -232,9 +247,14 @@ go-build:
@echo " > Building binary '$(GOBIN)/$(APPNAME)'..."
# demo short wget-demo
$(foreach an, $(MAIN_APPS), \
echo " +race. APPNAME = $(APPNAME)|$(an), LDFLAGS = $(LDFLAGS)"; \
$(GO) build -v -race -ldflags "$(LDFLAGS)" -o $(GOBIN)/$(an) $(GOBASE)/$(MAIN_BUILD_PKG)/$(an); \
ls -la $(LS_OPT) $(GOBIN)/$(an); \
$(eval ANAME := $(shell for an in $(MAIN_APPS); do \
if [[ $$an == cli ]]; then echo $(APPNAME); \
else echo $$an; \
fi; \
done)) \
echo " +race. -trimpath. APPNAME = $(APPNAME)|$(an) -> $(ANAME), LDFLAGS = $(LDFLAGS)"; \
$(GO) build -v -race -ldflags "$(LDFLAGS)" -o $(GOBIN)/$(ANAME) $(GOBASE)/$(MAIN_BUILD_PKG)/$(an); \
ls -la $(LS_OPT) $(GOBIN)/$(ANAME); \
)
ls -la $(LS_OPT) $(GOBIN)/
# go build -o $(GOBIN)/$(APPNAME) $(GOFILES)
Expand Down Expand Up @@ -382,6 +402,13 @@ linux-test:
$(MAKE) -f ./ci/linux_test/Makefile all 2> $(STDERR)
@cat $(STDERR) | sed -e '1s/.*/\nError:\n/' 1>&2


## docker: docker build
docker:
@echo " > docker build ..."
docker build --build-arg CN=1 --build-arg GOPROXY="https://gocenter.io,direct" -t $(APPNAME):latest -t $(APPNAME):$(VERSION) .


## rshz: rsync to my TP470P
rshz:
@echo " > sync to hz-pc ..."
Expand Down

0 comments on commit c7f54fe

Please sign in to comment.