From 69ad0a83fa01a2401a967e28c6756efb5213e9b9 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Wed, 30 Mar 2022 13:27:51 -0700 Subject: [PATCH] Makefile: simplify for modern Go Quite a few changes, mostly removing old stuff though. 1. "GO111MODULE=off" is no longer required to be set by default (and it used to be overridden below anyway). 2. "go build" no longer requires explicit "-mod=vendor", as this is the default since go 1.14. 3. GOPROXY is set to proxy.golang.org by default since go 1.13. 4. Always use default GOPATH (which is $HOME/go since Go 1.8; earlier releases needed to set it explicitly). 5. Drop the code that handles multiple comma-separated GOPATH elements (when using modules, GOPATH is no longer used for resolving imports, which basically means using multiple paths is useless). 6. Fix go-get to use go install mod@latest, if available (Go >= 1.16), and fall back to go get -u (deprecated since Go 1.16). The fallback can later be removed. 7. Do not check if go-md2man is available, always installing it. This fixes the issue of using old version of installed go-md2man, and removes the need to have GOBIN make variable. 8. Remove GOPKGBASEDIR and GOPKGBASEDIR, defined by Makefile, were never used. Signed-off-by: Kir Kolyshkin --- Makefile | 37 +++++-------------------------------- 1 file changed, 5 insertions(+), 32 deletions(-) diff --git a/Makefile b/Makefile index c914ecc16..1e0c35892 100644 --- a/Makefile +++ b/Makefile @@ -1,38 +1,13 @@ -export GO111MODULE=off - GO ?= go GO_BUILD=$(GO) build -# Go module support: set `-mod=vendor` to use the vendored sources -ifeq ($(shell go help mod >/dev/null 2>&1 && echo true), true) - GO_BUILD=GO111MODULE=on $(GO) build -mod=vendor -endif BUILDTAGS := containers_image_openpgp,systemd,exclude_graphdriver_devicemapper DESTDIR ?= PREFIX := /usr/local CONFIGDIR := ${PREFIX}/share/containers PROJECT := github.com/containers/common -# Enforce the GOPROXY to make sure dependencies are resovled consistently -# across different environments. -export GOPROXY := https://proxy.golang.org - -# If GOPATH not specified, use one in the local directory -ifeq ($(GOPATH),) -export GOPATH := $(CURDIR)/_output -unexport GOBIN -endif -FIRST_GOPATH := $(firstword $(subst :, ,$(GOPATH))) -GOPKGDIR := $(FIRST_GOPATH)/src/$(PROJECT) -GOPKGBASEDIR ?= $(shell dirname "$(GOPKGDIR)") - -GOBIN := $(shell $(GO) env GOBIN) -ifeq ($(GOBIN),) -GOBIN := $(FIRST_GOPATH)/bin -endif - define go-get - env GO111MODULE=off \ - $(GO) get -u ${1} + go install ${1}@latest || env GO111MODULE=off $(GO) get -u ${1} endef define go-build @@ -90,9 +65,9 @@ vendor-in-container: .PHONY: vendor vendor: - GO111MODULE=on $(GO) mod tidy - GO111MODULE=on $(GO) mod vendor - GO111MODULE=on $(GO) mod verify + $(GO) mod tidy + $(GO) mod vendor + $(GO) mod verify .PHONY: install.tools install.tools: build/golangci-lint .install.md2man @@ -106,9 +81,7 @@ build/golangci-lint: .install.md2man: - if [ ! -x "$(GOBIN)/go-md2man" ]; then \ - $(call go-get,github.com/cpuguy83/go-md2man); \ - fi + $(call go-get,github.com/cpuguy83/go-md2man) .PHONY: install install: