Skip to content

Commit

Permalink
add Makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
sunny0826 committed Jan 20, 2020
1 parent b940e72 commit 4faed26
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
dist/
kubecm

target
3 changes: 1 addition & 2 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Make sure to check the documentation at http://goreleaser.com
builds:
- env:
- CGO_ENABLED=0
- CGO_ENABLED=1
ldflags: -s -X github.com/sunny0826/kubecm/cmd.kubecmVersion={{.Version}} -X github.com/sunny0826/kubecm/cmd.gitCommit={{.Commit}} -X github.com/sunny0826/kubecm/cmd.buildDate={{.Date}}
goos:
- linux
Expand All @@ -25,6 +25,5 @@ release:
github:
owner: sunny0826
name: kubecm

name_template: '{{.ProjectName}}-v{{.Version}}'

43 changes: 43 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
.PHONY: build clean

# get tag of kubecm
KUBECM_VERSION=$(shell git describe --tags `git rev-list --tags --max-count=1`)

GITVERSION:=$(shell git --version | grep ^git | sed 's/^.* //g')
GITCOMMIT:=$(shell git rev-parse HEAD)

UNAME := $(shell uname)
BUILD_TARGET=target
BUILD_TARGET_DIR_NAME=kubecm-$(KUBECM_VERSION)
BUILD_TARGET_PKG_DIR=$(BUILD_TARGET)/kubecm-$(KUBECM_VERSION)
BUILD_TARGET_PKG_NAME=$(BUILD_TARGET)/kubecm-$(KUBECM_VERSION).tar.gz
BUILD_TARGET_PKG_FILE_PATH=$(BUILD_TARGET)/$(BUILD_TARGET_DIR_NAME)

GO_ENV=CGO_ENABLED=1
GO_MODULE=GO111MODULE=on
VERSION_PKG=github.com/sunny0826/kubecm/cmd
GO_FLAGS=-ldflags="-X ${VERSION_PKG}.kubecmVersion=$(KUBECM_VERSION) -X ${VERSION_PKG}.gitCommit=$(GITCOMMIT) -X '${VERSION_PKG}.buildDate=`date`'"
GO=env $(GO_ENV) $(GO_MODULE) go

ifeq ($(GOOS), linux)
GO_FLAGS=-ldflags="-linkmode external -extldflags -static -X ${VERSION_PKG}.kubecmVersion=$(KUBECM_VERSION) -X ${VERSION_PKG}.gitCommit=$(GITCOMMIT) -X '${VERSION_PKG}.buildDate=`date`'"
endif

build: pre_build
# build kubecm
$(GO) build $(GO_FLAGS) -o $(BUILD_TARGET_PKG_DIR)/kubecm .
# PTAH:$(BUILD_TARGET_PKG_DIR)/kubecm

pre_build:mkdir_build_target
# clean target
rm -rf $(BUILD_TARGET_PKG_DIR) $(BUILD_TARGET_PKG_FILE_PATH)

# create cache dir
mkdir_build_target:
ifneq ($(BUILD_TARGET_CACHE), $(wildcard $(BUILD_TARGET_CACHE)))
mkdir -p $(BUILD_TARGET_CACHE)
endif

clean:
$(GO) clean ./...
rm -rf $(BUILD_TARGET)

0 comments on commit 4faed26

Please sign in to comment.