1PWD := $(shell pwd) 2GOPATH := $(shell go env GOPATH) 3LDFLAGS := $(shell go run buildscripts/gen-ldflags.go) 4 5GOARCH := $(shell go env GOARCH) 6GOOS := $(shell go env GOOS) 7 8BUILD_LDFLAGS := '$(LDFLAGS)' 9 10VERSION ?= $(shell git describe --tags) 11TAG ?= "minio/mc:$(VERSION)" 12 13all: build 14 15checks: 16 @echo "Checking dependencies" 17 @(env bash $(PWD)/buildscripts/checkdeps.sh) 18 19getdeps: 20 @mkdir -p ${GOPATH}/bin 21 @echo "Installing golangci-lint" && curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOPATH)/bin v1.40.1 22 @which stringer 1>/dev/null || (echo "Installing stringer" && go install -v golang.org/x/tools/cmd/stringer@v0.1.5) 23 24crosscompile: 25 @(env bash $(PWD)/buildscripts/cross-compile.sh) 26 27verifiers: getdeps vet fmt lint 28 29docker: build 30 @docker build -t $(TAG) . -f Dockerfile.dev 31 32vet: 33 @echo "Running $@" 34 @GO111MODULE=on go vet github.com/minio/mc/... 35 36fmt: 37 @echo "Running $@" 38 @GO111MODULE=on gofmt -d cmd/ 39 @GO111MODULE=on gofmt -d pkg/ 40 41lint: 42 @echo "Running $@ check" 43 @GO111MODULE=on ${GOPATH}/bin/golangci-lint cache clean 44 @GO111MODULE=on ${GOPATH}/bin/golangci-lint run --timeout=5m --config ./.golangci.yml 45 46# Builds mc, runs the verifiers then runs the tests. 47check: test 48test: verifiers build 49 @echo "Running unit tests" 50 @GO111MODULE=on CGO_ENABLED=0 go test -tags kqueue ./... 1>/dev/null 51 @echo "Running functional tests" 52 @(env bash $(PWD)/functional-tests.sh) 53 54test-race: verifiers build 55 @echo "Running unit tests under -race" 56 @GO111MODULE=on go test -race -v --timeout 20m ./... 1>/dev/null 57 58# Verify mc binary 59verify: 60 @echo "Verifying build with race" 61 @GO111MODULE=on CGO_ENABLED=1 go build -race -tags kqueue -trimpath --ldflags "$(LDFLAGS)" -o $(PWD)/mc 1>/dev/null 62 @echo "Running functional tests" 63 @(env bash $(PWD)/functional-tests.sh) 64 65# Builds mc locally. 66build: checks 67 @echo "Building mc binary to './mc'" 68 @GO111MODULE=on CGO_ENABLED=0 go build -trimpath -tags kqueue --ldflags $(BUILD_LDFLAGS) -o $(PWD)/mc 69 70# Builds MinIO and installs it to $GOPATH/bin. 71install: build 72 @echo "Installing mc binary to '$(GOPATH)/bin/mc'" 73 @mkdir -p $(GOPATH)/bin && cp -f $(PWD)/mc $(GOPATH)/bin/mc 74 @echo "Installation successful. To learn more, try \"mc --help\"." 75 76clean: 77 @echo "Cleaning up all the generated files" 78 @find . -name '*.test' | xargs rm -fv 79 @find . -name '*~' | xargs rm -fv 80 @rm -rvf mc 81 @rm -rvf build 82 @rm -rvf release 83