summaryrefslogtreecommitdiffstats
path: root/debian/rules
blob: c9c6a6c0d87967cb9c35ae37aea50bde33baeed3 (plain)
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/usr/bin/make -f
# This file is in the public domain.
# You may freely use, modify, distribute, and relicense it.

# We need DEB_HOST_ARCH, so include the needed makefile snippet
include /usr/share/dpkg/architecture.mk
# for DEB_VERSION_UPSTREAM
include /usr/share/dpkg/pkg-info.mk

# Ubuntu mangles png files by default, which can break the testdata.
export NO_PNG_PKG_MANGLE := 1

export GOVER := $(shell echo $(DEB_VERSION_UPSTREAM) | grep -oP '^([0-9]+\.[0-9]+)')

export GOROOT := $(CURDIR)
export GOROOT_FINAL := /usr/lib/go-$(GOVER)
export GOROOT_BOOTSTRAP := $(shell env -i GOPATH=$(GOPATH) go env GOROOT)

export GOPATH := $(CURDIR)/gopath/
# Go 1.12 needs a build cache, otherwise the build fails.
export GOCACHE := $(GOPATH)/gocache

# source files generated during building.
# especially zbootstrap.go has different defaultGOARM values on armhf and armel,
# since the value is set from debian/helpers/goenv.sh
#
# see also: src/cmd/distpack/pack.go
GENERATED_FILES := \
	src/cmd/go/internal/cfg/zdefaultcc.go \
	src/go/build/zcgo.go \
	src/runtime/internal/sys/zversion.go \
	src/time/tzdata/zzipdata.go \
	src/cmd/cgo/zdefaultcc.go \
	src/cmd/internal/objabi/zbootstrap.go \
	src/internal/buildcfg/zbootstrap.go

%:
	+dh $@ $(opt_no_act)

gencontrol:
	for file in control gbp.conf watch; do \
		{ \
			echo '#'; \
			echo '# WARNING: "debian/'$$file'" is generated via "debian/rules gencontrol" (sourced from "debian/'$$file'.in")'; \
			echo '#'; \
			echo; \
			sed -e 's/X.Y/$(GOVER)/g' debian/$$file.in; \
		} > debian/$$file; \
	done

# The signing key for the source tarballs is rotated yearly.
update_upstream_signing_key:
	wget -O debian/upstream/signing-key.asc https://dl.google.com/dl/linux/linux_signing_key.pub

override_dh_auto_clean:
	# remove autogenerated files
	rm -f -v $(GENERATED_FILES)
	# remove built objects
	rm -rf bin pkg
	# remove gopath
	rm -rf $(GOPATH)
	# remove generated files
	@set -e; cd debian; for x in golang-X.Y-*; do \
		rm -f -v golang-$(GOVER)-$${x##golang-X.Y-}; \
	done

execute_after_dh_prep:
	dh_prep
	@set -e; cd debian; for x in golang-X.Y-*; do \
		sed -e 's/X.Y/$(GOVER)/g' $$x > golang-$(GOVER)-$${x##golang-X.Y-}; \
	done

override_dh_compress-indep:
	dh_compress -Xusr/share/doc/golang-$(GOVER)-doc/html

execute_after_dh_install-arch:
	cp --parent -v $(GENERATED_FILES) debian/golang-$(GOVER)-go/usr/share/go-$(GOVER)/

execute_after_dh_install-indep:
	# Remove generated source files, they are installed in golang-$(GOVER)-go.
	cd debian/golang-$(GOVER)-src/usr/share/go-$(GOVER)/ && rm -v -f $(GENERATED_FILES)
	# Remove Plan9 rc(1) scripts
	find debian/golang-$(GOVER)-src/usr/share/go-$(GOVER)/src -type f -name '*.rc' -delete
	# Make scripts executable which have been missed by upstream
	find debian/golang-$(GOVER)-src/usr/share/go-$(GOVER)/src/ \
		\( -name '*.sh' -o -name '*.bash' \) \( -not -executable \) -exec chmod a+x {} \;

override_dh_strip:
	dh_strip -Xtestdata

# Do not run dh_dwz, as there is no debug information currently.
override_dh_dwz:

override_dh_strip_nondeterminism:
	dh_strip_nondeterminism -Xtestdata

override_dh_shlibdeps:
	dh_shlibdeps -Xtestdata -Xtest

override_dh_makeshlibs:
	dh_makeshlibs -Xtestdata -Xtest

override_dh_auto_build-arch:
	[ -f VERSION ] || echo "debian snapshot $(DEB_VERSION)" > VERSION

	cd $(CURDIR)/src \
	&& $(CURDIR)/debian/helpers/goenv.sh bash ./make.bash --no-banner

	# rm bootstrap dir
	rm -rf $(CURDIR)/bootstrap

override_dh_auto_test-arch:
	set -ex; \
		cd src; \
		export PATH="$(GOROOT)/bin:$$PATH"; \
		export GO_TEST_TIMEOUT_SCALE=10; \
		eval "$$(go tool dist env)"; \
		bash run.bash -k -no-rebuild;
	# -k           keep going even when error occurred
	# -no-rebuild  don't rebuild std and cmd packages

	# On linux/amd64 run.bash installs some race enabled standard library
	# packages. Delete them again to avoid accidentally including them in
	# the package.
	set -ex; \
		export PATH="$(GOROOT)/bin:$$PATH"; \
		eval "$$(go tool dist env)"; \
		rm -rf "$(GOROOT)/pkg/$${GOOS}_$${GOARCH}_race/"

opt_no_act :=
ifneq (,$(findstring n,$(MAKEFLAGS)))
	opt_no_act := --no-act
endif