From 6bb72b1fdc11983f77952ed56d7f9d212c6cb726 Mon Sep 17 00:00:00 2001 From: Andy Zhou Date: Wed, 1 May 2019 15:33:43 -0700 Subject: [PATCH 1/2] Makefile: Add extra-clean to help with testing Makefile The extra-clean target removes the dependent packages that k3d requires. This makes testing makefile rules that install those packages easier. This target helps to expose a bug that the next patch fixes. --- Makefile | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index b7b52c67..baf441b4 100644 --- a/Makefile +++ b/Makefile @@ -24,25 +24,34 @@ GOFLAGS := BINDIR := $(CURDIR)/bin BINARIES := k3d + +# Go Package required +PKG_GOX := github.com/mitchellh/gox +PKG_GOLANGCI_LINT := github.com/golangci/golangci-lint/cmd/golangci-lint + export GO111MODULE=on # go source files, ignore vendor directory SRC = $(shell find . -type f -name '*.go' -not -path "./*/*") -.PHONY: all build build-cross clean fmt simplify check +.PHONY: all build build-cross clean fmt simplify check extra-clean all: clean fmt check build -build: +build: $(GO) build -i $(GOFLAGS) -tags '$(TAGS)' -ldflags '$(LDFLAGS)' -o '$(BINDIR)/$(BINARIES)' build-cross: LDFLAGS += -extldflags "-static" -build-cross: +build-cross: CGO_ENABLED=0 gox -parallel=3 -output="_dist/$(BINARIES)-{{.OS}}-{{.Arch}}" -osarch='$(TARGETS)' $(GOFLAGS) $(if $(TAGS),-tags '$(TAGS)',) -ldflags '$(LDFLAGS)' clean: @rm -rf $(BINDIR) _dist/ +extra-clean: clean + go clean -i $(PKG_GOX) + go clean -i $(PKG_GOLANGCI_LINT) + fmt: @gofmt -l -w $(SRC) @@ -54,13 +63,13 @@ check: @golangci-lint run @go vet ${SRC} -# Check for required executables +# Check for required executables HAS_GOX := $(shell command -v gox 2> /dev/null) HAS_GOLANGCI := $(shell command -v golangci-lint 2> /dev/null) ifndef HAS_GOX - go get -u github.com/mitchellh/gox + go get -u $(PKG_GOX) endif ifndef HAS_GOLANGCI - go get -u github.com/golangci/golangci-lint/cmd/golangci-lint -endif \ No newline at end of file + go get -u $(PKG_GOLANGCI_LINT) +endif From ba80a9113c3f11801a7afd2e6939e042a0fc79de Mon Sep 17 00:00:00 2001 From: Andy Zhou Date: Wed, 1 May 2019 16:58:45 -0700 Subject: [PATCH 2/2] Makefile: Add the install-tools target ith a fresh checked out k3d tree without required tools installed, Any make command gives the following error message: Makefile:71: *** recipe commences before first target. Stop. Basically, the section around line 71 are not properly formed makefile rules. This error is hidden when required tools are installed. The error can be re-exposed with the "make extra-clean" command. The install-tools target is intended to be invoked when installing the development tree for the fist time. --- Makefile | 7 ++++--- README.md | 6 ++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index baf441b4..c3233627 100644 --- a/Makefile +++ b/Makefile @@ -34,7 +34,7 @@ export GO111MODULE=on # go source files, ignore vendor directory SRC = $(shell find . -type f -name '*.go' -not -path "./*/*") -.PHONY: all build build-cross clean fmt simplify check extra-clean +.PHONY: all build build-cross clean fmt simplify check extra-clean install-tools all: clean fmt check build @@ -67,9 +67,10 @@ check: HAS_GOX := $(shell command -v gox 2> /dev/null) HAS_GOLANGCI := $(shell command -v golangci-lint 2> /dev/null) +install-tools: ifndef HAS_GOX - go get -u $(PKG_GOX) + (export GO111MODULE=off; go get -u $(PKG_GOX)) endif ifndef HAS_GOLANGCI - go get -u $(PKG_GOLANGCI_LINT) + (export GO111MODULE=off; go get -u $(PKG_GOLANGCI_LINT)) endif diff --git a/README.md b/README.md index 3d12e9b7..b027ae47 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ This repository is based on [@zeerorg](https://github.com/zeerorg/)'s [zeerorg/k You have several options there: -- use the install script to grab the latest release: +- use the install script to grab the latest release: - wget: `wget -q -O - https://raw.githubusercontent.com/rancher/k3d/master/install.sh | bash` - curl: `curl -s https://raw.githubusercontent.com/rancher/k3d/master/install.sh | bash` - Grab a release from the [release tab](https://github.com/rancher/k3d/releases) and install it yourself. @@ -29,7 +29,9 @@ or... 1. Clone this repo, e.g. via `go get -u github.com/rancher/k3d` 2. Inside the repo run - - `make` to build for your current system + - 'make install-tools' to make sure required go packages are installed +3. Inside the repo run + - `make build` to build for your current system - `go install` to install it to your `GOPATH` - `make build-cross` to build for all systems