This repository has been archived by the owner on Jun 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Makefile
97 lines (82 loc) · 3.72 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# Files are installed under $(DESTDIR)/$(PREFIX)
PREFIX ?= /usr/local
DEST := $(shell echo "$(DESTDIR)/$(PREFIX)" | sed 's:///*:/:g; s://*$$::')
VERSION ?=$(shell git describe --match 'v[0-9]*' --dirty='.m' --always --tags)
PACKAGE := github.com/reproducible-containers/repro-get
export CGO_ENABLED ?= 0
export DOCKER_BUILDKIT := 1
export SOURCE_DATE_EPOCH ?= $(shell git log -1 --pretty=%ct)
GO ?= go
GO_BUILD ?= $(GO) build -trimpath -ldflags="-s -w -X $(PACKAGE)/pkg/version.Version=$(VERSION)"
DOCKER ?= docker
DOCKER_BUILD ?= $(DOCKER) build
UPX ?= upx --best --lzma
TAR ?= tar
# FROM https://reproducible-builds.org/docs/archives/
TAR_C ?= $(TAR) -c --sort=name --owner=0 --group=0 --numeric-owner --pax-option=exthdr.name=%d/PaxHeaders/%f,delete=atime,delete=ctime --mtime=@$(SOURCE_DATE_EPOCH)
.PHONY: all
all: binaries
.PHONY: binaries
binaries: _output/bin/repro-get
.PHONY: _output/bin/repro-get
_output/bin/repro-get:
$(GO_BUILD) -o $@ ./cmd/repro-get
.PHONY: install
install: uninstall
mkdir -p "$(DEST)"
install _output/bin/repro-get "$(DEST)/bin/repro-get"
.PHONY: uninstall
uninstall:
rm -rf "$(DEST)/bin/repro-get"
.PHONY: clean
clean:
rm -rf _output _artifacts
.PHONY: generate
generate:
$(MAKE) -C examples
.PHONY: integration
integration:
$(DOCKER_BUILD) -f Makefile.d/Dockerfile.integration .
.PHONY: artifacts
artifacts: clean artifacts-linux artifacts-misc
(cd _artifacts ; sha256sum *) > SHA256SUMS
mv SHA256SUMS _artifacts/SHA256SUMS
touch -d @$(SOURCE_DATE_EPOCH) _artifacts/SHA256SUMS
.PHONY: artifacts-linux
artifacts-linux:
@# Filename convention: "repro-get-${VERSION}.${TARGETOS}-${TARGETARCH}${TARGETVARIANT:+-${TARGETVARIANT}}" .
@# TARGETOS, TARGETARCH, and TARETVARIANT are Dockerfile's built-in variables.
mkdir -p _artifacts
export GOOS=linux
# Docker: "linux/amd64", Debian: "amd64"
GOARCH=amd64 $(GO_BUILD) -o _artifacts/repro-get-$(VERSION).linux-amd64 ./cmd/repro-get
# Docker: "linux/arm/v7", Debian: "armhf"
GOARCH=arm GOARM=7 $(GO_BUILD) -o _artifacts/repro-get-$(VERSION).linux-arm-v7 ./cmd/repro-get
# Docker: "linux/arm64", Debian: "arm64"
GOARCH=arm64 $(GO_BUILD) -o _artifacts/repro-get-$(VERSION).linux-arm64 ./cmd/repro-get
# Docker: "linux/ppc64le", Debian: "ppc64el
GOARCH=ppc64le $(GO_BUILD) -o _artifacts/repro-get-$(VERSION).linux-ppc64le ./cmd/repro-get
# Docker: "linux/riscv64", Debian: riscv64"
GOARCH=riscv64 $(GO_BUILD) -o _artifacts/repro-get-$(VERSION).linux-riscv64 ./cmd/repro-get
# Docker: "linux/s390x", Debian: s390x"
GOARCH=s390x $(GO_BUILD) -o _artifacts/repro-get-$(VERSION).linux-s390x ./cmd/repro-get
$(UPX) -o _artifacts/repro-get-$(VERSION).linux-amd64.upx _artifacts/repro-get-$(VERSION).linux-amd64
$(UPX) -o _artifacts/repro-get-$(VERSION).linux-arm-v7.upx _artifacts/repro-get-$(VERSION).linux-arm-v7
$(UPX) -o _artifacts/repro-get-$(VERSION).linux-arm64.upx _artifacts/repro-get-$(VERSION).linux-arm64
$(UPX) -o _artifacts/repro-get-$(VERSION).linux-ppc64le.upx _artifacts/repro-get-$(VERSION).linux-ppc64le
# No UPX for riscv64 and s390x
touch -d @$(SOURCE_DATE_EPOCH) ./_artifacts/repro-get-$(VERSION).linux-*
.PHONY: artifacts-misc
artifacts-misc:
mkdir -p _artifacts
# TODO: create the go-mod-vendor archive deterministically
# rm -rf vendor
# go mod vendor
# $(TAR_C) -f _artifacts/repro-get-$(VERSION).go-mod-vendor.tar go.mod go.sum vendor
# touch -d @$(SOURCE_DATE_EPOCH) _artifacts/repro-get-$(VERSION).go-mod-vendor.*
echo $(VERSION) >_artifacts/VERSION
echo $(SOURCE_DATE_EPOCH) >_artifacts/SOURCE_DATE_EPOCH
touch -d @$(SOURCE_DATE_EPOCH) _artifacts/VERSION _artifacts/SOURCE_DATE_EPOCH
.PHONY: artifacts.docker
artifacts.docker:
$(DOCKER_BUILD) --output=./_artifacts --target=artifacts .