Skip to content

Commit

Permalink
Merge pull request #20 from andyz-dev/makefile-cleanup
Browse files Browse the repository at this point in the history
Makefile cleanup
  • Loading branch information
iwilltry42 authored May 2, 2019
2 parents 5e28779 + ba80a91 commit 60c622e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
24 changes: 17 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 install-tools

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)

Expand All @@ -54,13 +63,14 @@ 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)

install-tools:
ifndef HAS_GOX
go get -u github.com/mitchellh/gox
(export GO111MODULE=off; go get -u $(PKG_GOX))
endif
ifndef HAS_GOLANGCI
go get -u github.com/golangci/golangci-lint/cmd/golangci-lint
endif
(export GO111MODULE=off; go get -u $(PKG_GOLANGCI_LINT))
endif
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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

Expand Down

0 comments on commit 60c622e

Please sign in to comment.