mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-19 17:26:28 +00:00
make: Fix for local builds outside of GOPATH
Go can be weird about tools having to run in a directory with go.mod. This commit moves the linuxkit makefile to the same directory as the code. It also changes the semantics of the local-build target. You can now use STATIC=0 for dynamic builds or PIE=1 to use --buildmode=pie. The binaries we were producing in local-static weren't actually static so I fixed that too Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
This commit is contained in:
parent
a8797a5e0f
commit
93ada489f9
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
@ -57,7 +57,7 @@ jobs:
|
|||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
run: |
|
run: |
|
||||||
make GOARCH=${{matrix.target.arch}} GOOS=${{matrix.target.os}} LOCAL_TARGET=bin/linuxkit-${{matrix.target.suffix}} local-build
|
make GOARCH=${{matrix.target.arch}} GOOS=${{matrix.target.os}} LOCAL_TARGET=$(pwd)/bin/linuxkit-${{matrix.target.suffix}} local-build
|
||||||
file bin/linuxkit-${{matrix.target.suffix}}
|
file bin/linuxkit-${{matrix.target.suffix}}
|
||||||
env:
|
env:
|
||||||
GOPATH: ${{runner.workspace}}
|
GOPATH: ${{runner.workspace}}
|
||||||
|
59
Makefile
59
Makefile
@ -1,14 +1,11 @@
|
|||||||
VERSION="v0.8+"
|
VERSION="v0.8+"
|
||||||
GIT_COMMIT=$(shell git rev-list -1 HEAD)
|
|
||||||
|
|
||||||
GO_COMPILE=linuxkit/go-compile:7b1f5a37d2a93cd4a9aa2a87db264d8145944006
|
GO_COMPILE=linuxkit/go-compile:7b1f5a37d2a93cd4a9aa2a87db264d8145944006
|
||||||
|
|
||||||
ifeq ($(OS),Windows_NT)
|
ifeq ($(OS),Windows_NT)
|
||||||
LINUXKIT?=bin/linuxkit.exe
|
|
||||||
RTF?=bin/rtf.exe
|
RTF?=bin/rtf.exe
|
||||||
GOOS?=windows
|
GOOS?=windows
|
||||||
else
|
else
|
||||||
LINUXKIT?=bin/linuxkit
|
|
||||||
RTF?=bin/rtf
|
RTF?=bin/rtf
|
||||||
GOOS?=$(shell uname -s | tr '[:upper:]' '[:lower:]')
|
GOOS?=$(shell uname -s | tr '[:upper:]' '[:lower:]')
|
||||||
endif
|
endif
|
||||||
@ -22,10 +19,14 @@ endif
|
|||||||
|
|
||||||
PREFIX?=/usr/local
|
PREFIX?=/usr/local
|
||||||
|
|
||||||
|
LOCAL_TARGET?=$(CURDIR)/bin/linuxkit
|
||||||
|
|
||||||
|
export VERSION GO_COMPILE GOOS GOARCH LOCAL_TARGET
|
||||||
|
|
||||||
.DELETE_ON_ERROR:
|
.DELETE_ON_ERROR:
|
||||||
|
|
||||||
.PHONY: default all
|
.PHONY: default all
|
||||||
default: $(LINUXKIT) $(RTF)
|
default: linuxkit $(RTF)
|
||||||
all: default
|
all: default
|
||||||
|
|
||||||
RTF_COMMIT=2351267f358ce6621c0c0d9a069f361268dba5fc
|
RTF_COMMIT=2351267f358ce6621c0c0d9a069f361268dba5fc
|
||||||
@ -50,56 +51,26 @@ bin/manifest-tool: tmp_mt_bin.tar | bin
|
|||||||
tmp_mt_bin.tar: Makefile
|
tmp_mt_bin.tar: Makefile
|
||||||
docker run --rm --log-driver=none -e http_proxy=$(http_proxy) -e https_proxy=$(https_proxy) $(CROSS) $(GO_COMPILE) --clone-path github.com/estesp/manifest-tool --clone $(MT_REPO) --commit $(MT_COMMIT) --package github.com/estesp/manifest-tool --ldflags "-X main.gitCommit=$(MT_COMMIT)" -o bin/manifest-tool > $@
|
docker run --rm --log-driver=none -e http_proxy=$(http_proxy) -e https_proxy=$(https_proxy) $(CROSS) $(GO_COMPILE) --clone-path github.com/estesp/manifest-tool --clone $(MT_REPO) --commit $(MT_COMMIT) --package github.com/estesp/manifest-tool --ldflags "-X main.gitCommit=$(MT_COMMIT)" -o bin/manifest-tool > $@
|
||||||
|
|
||||||
LINUXKIT_DEPS=$(wildcard src/cmd/linuxkit/*.go) $(wildcard src/cmd/linuxkit/*/*.go) Makefile
|
.PHONY: linuxkit
|
||||||
$(LINUXKIT): tmp_linuxkit_bin.tar
|
linuxkit:
|
||||||
tar xf $<
|
make -C ./src/cmd/linuxkit
|
||||||
rm $<
|
|
||||||
touch $@
|
|
||||||
|
|
||||||
tmp_linuxkit_bin.tar: $(LINUXKIT_DEPS)
|
|
||||||
tar cf - -C src/cmd/linuxkit . | docker run --rm --net=none --log-driver=none -i $(CROSS) $(GO_COMPILE) --package github.com/linuxkit/linuxkit/src/cmd/linuxkit --ldflags "-X github.com/linuxkit/linuxkit/src/cmd/linuxkit/version.GitCommit=$(GIT_COMMIT) -X github.com/linuxkit/linuxkit/src/cmd/linuxkit/version.Version=$(VERSION)" -o $(LINUXKIT) > $@
|
|
||||||
|
|
||||||
.PHONY: test-cross
|
.PHONY: test-cross
|
||||||
test-cross:
|
test-cross:
|
||||||
$(MAKE) clean
|
make -C ./src/cmd/linuxkit test-cross
|
||||||
$(MAKE) -j 3 GOOS=darwin tmp_rtf_bin.tar tmp_mt_bin.tar tmp_linuxkit_bin.tar
|
|
||||||
$(MAKE) clean
|
|
||||||
$(MAKE) -j 3 GOOS=windows tmp_rtf_bin.tar tmp_mt_bin.tar tmp_linuxkit_bin.tar
|
|
||||||
$(MAKE) clean
|
|
||||||
$(MAKE) -j 3 GOOS=linux tmp_rtf_bin.tar tmp_mt_bin.tar tmp_linuxkit_bin.tar
|
|
||||||
$(MAKE) clean
|
|
||||||
|
|
||||||
LOCAL_LDFLAGS += -X github.com/linuxkit/linuxkit/src/cmd/linuxkit/version.GitCommit=$(GIT_COMMIT) -X github.com/linuxkit/linuxkit/src/cmd/linuxkit/version.Version=$(VERSION)
|
.PHONY: local local-%
|
||||||
LOCAL_TARGET ?= $(LINUXKIT)
|
local:
|
||||||
|
make -C ./src/cmd/linuxkit local
|
||||||
|
|
||||||
.PHONY: local-check local-build local-test local-static-pie local-static local-dynamic local
|
local-%:
|
||||||
local-check: $(LINUXKIT_DEPS)
|
make -C ./src/cmd/linuxkit $@
|
||||||
@echo gofmt... && o=$$(gofmt -s -l $(filter %.go,$(LINUXKIT_DEPS))) && if [ -n "$$o" ] ; then echo $$o ; exit 1 ; fi
|
|
||||||
@echo govet... && go vet -printf=false ./src/cmd/linuxkit/...
|
|
||||||
@echo golint... && set -e ; for i in $(filter %.go,$(LINUXKIT_DEPS)); do golint $$i ; done
|
|
||||||
@echo ineffassign... && ineffassign ./src/cmd/linuxkit/...
|
|
||||||
|
|
||||||
local-build: local-static
|
|
||||||
|
|
||||||
local-static-pie: $(LINUXKIT_DEPS) | bin
|
|
||||||
CGO_ENABLED=0 go build -o $(LOCAL_TARGET) --buildmode pie --ldflags "-s -w -extldflags \"-static\" $(LOCAL_LDFLAGS)" github.com/linuxkit/linuxkit/src/cmd/linuxkit
|
|
||||||
|
|
||||||
local-static: $(LINUXKIT_DEPS) | bin
|
|
||||||
CGO_ENABLED=0 go build -o $(LOCAL_TARGET) --ldflags "$(LOCAL_LDFLAGS)" github.com/linuxkit/linuxkit/src/cmd/linuxkit
|
|
||||||
|
|
||||||
local-dynamic: $(LINUXKIT_DEPS) | bin
|
|
||||||
go build -o $(LOCAL_TARGET) --ldflags "$(LOCAL_LDFLAGS)" github.com/linuxkit/linuxkit/src/cmd/linuxkit
|
|
||||||
|
|
||||||
local-test: $(LINUXKIT_DEPS)
|
|
||||||
go test $(shell go list github.com/linuxkit/linuxkit/src/cmd/linuxkit/... | grep -v ^github.com/linuxkit/linuxkit/src/cmd/linuxkit/vendor/)
|
|
||||||
|
|
||||||
local: local-check local-build local-test
|
|
||||||
|
|
||||||
bin:
|
bin:
|
||||||
mkdir -p $@
|
mkdir -p $@
|
||||||
|
|
||||||
install:
|
install:
|
||||||
cp -R ./bin/* $(PREFIX)/bin
|
cp -R bin/* $(PREFIX)/bin
|
||||||
|
|
||||||
.PHONY: test
|
.PHONY: test
|
||||||
test:
|
test:
|
||||||
|
89
src/cmd/linuxkit/Makefile
Normal file
89
src/cmd/linuxkit/Makefile
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
VERSION?="v0.0-dev"
|
||||||
|
GIT_COMMIT=$(shell git rev-list -1 HEAD)
|
||||||
|
GO_COMPILE?=linuxkit/go-compile:7b1f5a37d2a93cd4a9aa2a87db264d8145944006
|
||||||
|
export GO_FLAGS=-mod=vendor
|
||||||
|
|
||||||
|
ifeq ($(OS),Windows_NT)
|
||||||
|
LINUXKIT?=bin/linuxkit.exe
|
||||||
|
GOOS?=windows
|
||||||
|
else
|
||||||
|
LINUXKIT?=bin/linuxkit
|
||||||
|
GOOS?=$(shell uname -s | tr '[:upper:]' '[:lower:]')
|
||||||
|
endif
|
||||||
|
GOARCH?=amd64
|
||||||
|
ifneq ($(GOOS),linux)
|
||||||
|
CROSS+=-e GOOS=$(GOOS)
|
||||||
|
endif
|
||||||
|
ifneq ($(GOARCH),amd64)
|
||||||
|
CROSS+=-e GOARCH=$(GOARCH)
|
||||||
|
endif
|
||||||
|
|
||||||
|
.DELETE_ON_ERROR:
|
||||||
|
|
||||||
|
.PHONY: default all
|
||||||
|
default: $(LINUXKIT)
|
||||||
|
all: default
|
||||||
|
|
||||||
|
LINUXKIT_DEPS=$(wildcard *.go) $(wildcard */*.go) Makefile
|
||||||
|
$(LINUXKIT): tmp_linuxkit_bin.tar | bin
|
||||||
|
tar xf $<
|
||||||
|
rm $<
|
||||||
|
touch $@
|
||||||
|
|
||||||
|
tmp_linuxkit_bin.tar: $(LINUXKIT_DEPS)
|
||||||
|
tar cf - -C . . | docker run --rm --net=none --log-driver=none -i $(CROSS) $(GO_COMPILE) --package github.com/linuxkit/linuxkit/src/cmd/linuxkit --ldflags "-X github.com/linuxkit/linuxkit/src/cmd/linuxkit/version.GitCommit=$(GIT_COMMIT) -X github.com/linuxkit/linuxkit/src/cmd/linuxkit/version.Version=$(VERSION)" -o $(LINUXKIT) > $@
|
||||||
|
|
||||||
|
.PHONY: test-cross
|
||||||
|
test-cross:
|
||||||
|
$(MAKE) clean
|
||||||
|
$(MAKE) -j 3 GOOS=darwin tmp_linuxkit_bin.tar
|
||||||
|
$(MAKE) clean
|
||||||
|
$(MAKE) -j 3 GOOS=windows tmp_linuxkit_bin.tar
|
||||||
|
$(MAKE) clean
|
||||||
|
$(MAKE) -j 3 GOOS=linux tmp_linuxkit_bin.tar
|
||||||
|
$(MAKE) clean
|
||||||
|
|
||||||
|
LOCAL_LDFLAGS += -X github.com/linuxkit/linuxkit/src/cmd/linuxkit/version.GitCommit=$(GIT_COMMIT) -X github.com/linuxkit/linuxkit/src/cmd/linuxkit/version.Version=$(VERSION)
|
||||||
|
|
||||||
|
STATIC?=1
|
||||||
|
CGO_ENABLED?=1
|
||||||
|
BUILD_FLAGS=
|
||||||
|
PIE?=0
|
||||||
|
|
||||||
|
ifeq ($(STATIC), 1)
|
||||||
|
CGO_ENABLED=0
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(PIE), 1)
|
||||||
|
CGO_ENABLED=0
|
||||||
|
BUILD_FLAGS+= --buildmode pie
|
||||||
|
LOCAL_LDFLAGS+= -linkmode=external -s -w -extldflags \"-static-pie\"
|
||||||
|
endif
|
||||||
|
|
||||||
|
LOCAL_TARGET ?= $(LINUXKIT)
|
||||||
|
|
||||||
|
.PHONY: local-check local-build local-test local
|
||||||
|
local-check: $(LINUXKIT_DEPS)
|
||||||
|
@echo gofmt... && o=$$(gofmt -s -l $(filter %.go,$(LINUXKIT_DEPS))) && if [ -n "$$o" ] ; then echo $$o ; exit 1 ; fi
|
||||||
|
@echo govet... && go vet -printf=false ./...
|
||||||
|
@echo golint... && set -e ; for i in $(filter %.go,$(LINUXKIT_DEPS)); do golint $$i ; done
|
||||||
|
@echo ineffassign... && ineffassign ./...
|
||||||
|
|
||||||
|
local-build:
|
||||||
|
@mkdir -p $(dir LOCAL_TARGET)
|
||||||
|
CGO_ENABLED=$(CGO_ENABLED) go build -o $(LOCAL_TARGET) $(BUILD_FLAGS) --ldflags "$(LOCAL_LDFLAGS)"
|
||||||
|
|
||||||
|
local-test: $(LINUXKIT_DEPS)
|
||||||
|
go test -mod=vendor ./...
|
||||||
|
|
||||||
|
local: local-check local-build local-test
|
||||||
|
|
||||||
|
bin:
|
||||||
|
mkdir -p $@
|
||||||
|
|
||||||
|
install:
|
||||||
|
cp -R ./bin/* $(PREFIX)/bin
|
||||||
|
|
||||||
|
.PHONY: clean
|
||||||
|
clean:
|
||||||
|
rm -rf bin *.log *-kernel *-cmdline *-state *.img *.iso *.gz *.qcow2 *.vhd *.vmx *.vmdk *.tar *.raw
|
Loading…
Reference in New Issue
Block a user