[Pkg-golang-commits] [golang] 01/01: Refactor "debian/rules" to utilize debhelper more effectively, especially for arch vs indep building (mostly backported from the 1.5+ changes)
Tianon Gravi
tianon at debian.org
Sat Sep 26 20:44:40 UTC 2015
This is an automated email from the git hooks/post-receive script.
tianon pushed a commit to branch debian-sid
in repository golang.
commit 0dc5e051fb4707fe4600a00c6993aa0eb2a266a8
Author: Tianon Gravi <tianon at debian.org>
Date: Sat Sep 26 13:44:27 2015 -0700
Refactor "debian/rules" to utilize debhelper more effectively, especially for arch vs indep building (mostly backported from the 1.5+ changes)
---
debian/changelog | 2 +
debian/control | 2 +-
debian/control.base | 2 +-
debian/golang-go.postinst | 11 ++-
debian/helpers/goenv.sh | 54 ++++++++++++++
debian/rules | 179 ++++++++++++----------------------------------
debian/test.bash | 4 --
7 files changed, 113 insertions(+), 141 deletions(-)
diff --git a/debian/changelog b/debian/changelog
index 90e7651..dd7a5d6 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,6 +1,8 @@
golang (2:1.4.3-2) UNRELEASED; urgency=medium
* Update Recommends/Suggests, especially to add gcc, etc.
+ * Refactor "debian/rules" to utilize debhelper more effectively, especially
+ for arch vs indep building (mostly backported from the 1.5+ changes).
-- Tianon Gravi <tianon at debian.org> Sat, 26 Sep 2015 13:37:05 -0700
diff --git a/debian/control b/debian/control
index b845cb8..f028f48 100644
--- a/debian/control
+++ b/debian/control
@@ -8,7 +8,7 @@ Uploaders: Michael Stapelberg <stapelberg at debian.org>,
Tianon Gravi <tianon at debian.org>
Vcs-Browser: https://anonscm.debian.org/cgit/pkg-golang/golang.git
Vcs-Git: git://anonscm.debian.org/pkg-golang/golang.git
-Build-Depends: bison, debhelper (>= 7.4.10), ed, mawk | awk, netbase, perl
+Build-Depends: bison, debhelper (>= 8.9.7), ed, mawk | awk, netbase, perl
Standards-Version: 3.9.6
Homepage: https://golang.org
diff --git a/debian/control.base b/debian/control.base
index 6df2a08..73be5bd 100644
--- a/debian/control.base
+++ b/debian/control.base
@@ -7,7 +7,7 @@ Uploaders: Michael Stapelberg <stapelberg at debian.org>,
Tianon Gravi <tianon at debian.org>
Vcs-Browser: https://anonscm.debian.org/cgit/pkg-golang/golang.git
Vcs-Git: git://anonscm.debian.org/pkg-golang/golang.git
-Build-Depends: bison, debhelper (>= 7.4.10), ed, mawk | awk, netbase, perl
+Build-Depends: bison, debhelper (>= 8.9.7), ed, mawk | awk, netbase, perl
Standards-Version: 3.9.6
Homepage: https://golang.org
diff --git a/debian/golang-go.postinst b/debian/golang-go.postinst
index f705515..1c3d879 100644
--- a/debian/golang-go.postinst
+++ b/debian/golang-go.postinst
@@ -6,8 +6,15 @@ case "$1" in
# Very ugly hack to set timestamps same as /usr/lib/go/bin/go
find /usr/lib/go/pkg -exec touch -r /usr/lib/go/bin/go {} \;
# Setup alternatives
- # Priority: base of 100 + go version; 1.4.2 = 100 + 42)
- go=$(/usr/lib/go/bin/go version | awk '{ gsub(/^go1|[.]/, "", $3); print $3 }')
+ # Priority: base of 100 + go version; 1.4.2 = 100 + 42; 1.5 = 100 + 50
+ go=$(/usr/lib/go/bin/go version | awk '{
+ gsub(/^go1|[.]/, "", $3);
+ gsub(/([^0-9.]+.*)$/, "", $3);
+ if ($3 ~ /^[0-9]$/) {
+ $3 = $3 "0";
+ };
+ print $3;
+ }')
priority=$(( 100 + $go ))
update-alternatives \
--install /usr/bin/go go /usr/lib/go/bin/go $priority \
diff --git a/debian/helpers/goenv.sh b/debian/helpers/goenv.sh
new file mode 100755
index 0000000..4722d1c
--- /dev/null
+++ b/debian/helpers/goenv.sh
@@ -0,0 +1,54 @@
+#!/bin/sh
+set -e
+
+__goos__deb_arch_os() {
+ case "$1" in
+ kfreebsd) echo freebsd ;;
+ linux) echo "$1" ;;
+ *) echo >&2 "error: unrecongized DEB_*_ARCH_OS: $1"; exit 1 ;;
+ esac
+}
+
+__goarch__deb_arch_cpu() {
+ case "$1" in
+ amd64|arm|arm64|ppc64) echo "$1" ;;
+ i386) echo 386 ;;
+ ppc64el) echo ppc64le ;;
+ *) echo >&2 "error: unrecongized DEB_*_ARCH_CPU: $1"; exit 1 ;;
+ esac
+}
+
+# build machine
+# The machine the package is built on.
+#
+# host machine
+# The machine the package is built for.
+
+export GOHOSTOS="$(__goos__deb_arch_os "$(dpkg-architecture -qDEB_BUILD_ARCH_OS 2>/dev/null)")"
+export GOOS="$(__goos__deb_arch_os "$(dpkg-architecture -qDEB_HOST_ARCH_OS 2>/dev/null)")"
+
+export GOHOSTARCH="$(__goarch__deb_arch_cpu "$(dpkg-architecture -qDEB_BUILD_ARCH_CPU 2>/dev/null)")"
+export GOARCH="$(__goarch__deb_arch_cpu "$(dpkg-architecture -qDEB_HOST_ARCH_CPU 2>/dev/null)")"
+
+if [ -z "$GOHOSTOS" -o -z "$GOOS" -o -z "$GOHOSTARCH" -o -z "$GOARCH" ]; then
+ exit 1
+fi
+
+# Always use the 387 floating point unit instead of sse2. This is important to
+# ensure that the binaries we build (both when compiling golang on the buildds
+# and when users cross-compile for 386) can actually run on older CPUs (where
+# old means e.g. an AMD Athlon XP 2400+). See http://bugs.debian.org/753160 and
+# https://code.google.com/p/go/issues/detail?id=8152
+export GO386=387
+
+unset GOARM
+if [ "$GOARCH" = 'arm' ]; then
+ # start with GOARM=5 for maximum compatibility (see note about GO386 above)
+ GOARM=5
+ case "$(dpkg-architecture -qDEB_HOST_ARCH 2>/dev/null)" in
+ armhf) GOARM=6 ;;
+ esac
+fi
+export GOARM
+
+eval "$@"
diff --git a/debian/rules b/debian/rules
index b2545c2..fd7c96e 100755
--- a/debian/rules
+++ b/debian/rules
@@ -2,11 +2,13 @@
# This file is in the public domain.
# You may freely use, modify, distribute, and relicense it.
-PACKAGE = golang
+export GOROOT := $(CURDIR)
+export GOROOT_FINAL := /usr/lib/go
+export GOHOSTOS := $(shell ./debian/helpers/goenv.sh echo '$$GOHOSTOS')
+export GOHOSTARCH := $(shell ./debian/helpers/goenv.sh echo '$$GOHOSTARCH')
-libexecdir := /usr/lib/go
-datadir := /usr/share/go
-bindir := /bin
+%:
+ +dh --parallel $(opt_no_act) $@
# We loop over supported operating systems and architectures multiple times,
# so these two variables contain a centralized version of that code.
@@ -17,30 +19,24 @@ FOR_GO_ARCH := for os in $$(echo linux freebsd windows darwin netbsd); do \
for arch in $$(echo $$archs); do
FOR_GO_ARCH_END := done; done
-build-arch build-indep build clean install binary-arch binary-indep binary: debian/control
- +dh --parallel $(opt_no_act) $@
-
override_dh_auto_clean:
- rm -rf bin pkg
# golang-go-$os-$arch.install files are auto-generated in override_dh_install
rm -f debian/golang-go-*.install
- rm -f debian/*+
- rm -f debian/build.stamp
- rm -f test/pass.out test/run.out test/times.out
- rm -rf debian/home
-
-override_dh_auto_build: debian/build.stamp
+ #rm -f debian/*+
+ #rm -f debian/build.stamp
+ #rm -f test/pass.out test/run.out test/times.out
+ #rm -rf debian/home
+ rm -rf bin pkg
-override_dh_auto_test:
-ifeq ($(RUN_TEST), true)
- cd $(CURDIR)/src && \
- $(CURDIR)/debian/test.bash $(GOROOT)/pkg/tool/$(GOHOSTOS)_$(GOHOSTARCH);
-else
- :
-endif
+override_dh_auto_test-arch:
+ set -ex; \
+ cd src; \
+ export PATH="$(GOROOT)/bin:$$PATH"; \
+ eval "$$(go tool dist env)"; \
+ bash run.bash --no-rebuild;
-override_dh_compress:
- dh_compress -Xusr/share/doc/$(PACKAGE)-doc/html -Xusr/share/doc/$(PACKAGE)-doc/godoc
+override_dh_compress-indep:
+ dh_compress -Xusr/share/doc/golang-doc/html -Xusr/share/doc/golang-doc/godoc
# Generates debian/control from debian/control.base and debian/control.cross.
# In the latter, @OS@ and @ARCH@ are replaced with every supported combination
@@ -58,35 +54,34 @@ gencontrol:
override_dh_install:
-${FOR_GO_ARCH} \
echo "pkg/$${os}_$${arch} /usr/lib/go/pkg/" > debian/golang-go-$$os-$$arch.install; \
- [ "$$arch" = "amd64" ] && [ "$$os" = "linux" ] && echo "pkg/linux_amd64_race /usr/lib/go/pkg" >> debian/golang-go-$$os-$$arch.install; \
+ [ "$$arch" = "amd64" ] && [ "$$os" = "linux" ] \
+ && echo "pkg/$${os}_$${arch}_race /usr/lib/go/pkg/" >> debian/golang-go-$$os-$$arch.install; \
echo "golang-go-$$os-$$arch: arch-independent-package-contains-binary-or-object" > debian/golang-go-$$os-$$arch.lintian-overrides; \
${FOR_GO_ARCH_END}
# Install the native runtime/cgo.a to the golang-go package.
# runtime/cgo is only built for the native architecture, but the
# golang-go-OS-ARCH packages are built on one particular buildd, which
# might either be i386 or amd64.
- echo "listing of $$(pwd):"; ls -hlR .
- echo "listing of GOBIN: ($(GOBIN))"; ls -hlR $(GOBIN)
- for file in $$(cd pkg/ && ls */runtime/cgo.a); do \
- mkdir -p $(CURDIR)/debian/golang-go/usr/lib/go/pkg/$$(dirname $$file); \
- mv pkg/$$file $(CURDIR)/debian/golang-go/usr/lib/go/pkg/$$file; \
+ for file in pkg/*/runtime/cgo.a; do \
+ mkdir -p debian/golang-go/usr/lib/go/$$(dirname $$file); \
+ mv $$file debian/golang-go/usr/lib/go/$$file; \
done
dh_install --fail-missing
# Remove .syso files of the race detector; it is not used yet and the files are arch-dependent.
- find $(CURDIR)/debian/golang-src/usr/share/go/src/runtime/race -type f -name '*.syso' -delete
+ find debian/golang-src/usr/share/go/src/runtime/race -type f -name '*.syso' -delete
# Remove Plan9 rc(1) scripts
- find $(CURDIR)/debian/golang-src/usr/share/go/src -type f -name "*.rc" -delete
+ find debian/golang-src/usr/share/go/src -type f -name '*.rc' -delete
# Remove empty /usr/share/go/src from golang-go, it is provided by golang-src
- find $(CURDIR)/debian/golang-go/usr/share/go/src -type d -delete
+ find debian/golang-go/usr/share/go/src -type d -delete
# Subsequently, /usr/share/go is empty, too, so remove
- find $(CURDIR)/debian/golang-go/usr/share/go -type d -delete
+ find debian/golang-go/usr/share/go -type d -delete
# For some reason, Go cross-compiles a handful of tools: {yacc,fix,api,vet,cgo}.
# Delete those, as they cannot be ran anyway.
# This is tracked upstream at https://code.google.com/p/go/issues/detail?id=5667
- (cd $(CURDIR)/debian/golang-go/usr/lib/go/pkg/tool && find . -depth -path "./$(GOHOSTOS)_$(GOHOSTARCH)*" -prune -o -delete)
+ (cd debian/golang-go/usr/lib/go/pkg/tool && find . -depth -path "./$(GOHOSTOS)_$(GOHOSTARCH)*" -prune -o -delete)
# Touch built and installed files and directories to have same timestamp
- touch $(CURDIR)/debian/golang-go/usr/lib/go/pkg
- find $(CURDIR)/debian/golang-go/usr/lib/go/pkg -exec touch -r $(CURDIR)/debian/golang-go/usr/lib/go/pkg {} \;
+ touch debian/golang-go/usr/lib/go/pkg
+ find debian/golang-go/usr/lib/go/pkg -exec touch -r $(CURDIR)/debian/golang-go/usr/lib/go/pkg {} \;
override_dh_strip:
# strip disabled as golang upstream doesn't support it and it makes go
@@ -96,17 +91,15 @@ override_dh_prep:
dh_prep
echo 'go:Hostarch=$(GOHOSTARCH)' >> debian/golang-go.substvars
-override_dh_builddeb:
- dh_builddeb -- -Zxz
-
override_dh_shlibdeps:
dh_shlibdeps -Xtestdata -Xtest
-debian/build.stamp:
- rm -f debian/build.stamp
- mkdir -p $(GOBIN)
+override_dh_auto_build:
+ [ -f VERSION ] || echo "debian snapshot +$$(dpkg-parsechangelog -SVersion)" > VERSION
# Build native tools first, then bootstrap all other GOOS/GOARCH combinations.
- cd src && bash ./make.bash --no-banner
+ cd src \
+ && $(CURDIR)/debian/helpers/goenv.sh \
+ bash ./make.bash --no-banner
# For the race detector to work (go test -race), we need to install the
# std library with the race detector enabled. This will result in
# having an additional “architecture” directory, e.g. linux_amd64_race.
@@ -114,98 +107,18 @@ debian/build.stamp:
# The race detector currently only works on linux/amd64. The check within
# the following loop works precisely the same way src/race.bash does.
-${FOR_GO_ARCH} \
- export GOARCH=$$arch; \
- export GOOS=$$os; \
- cd src && bash ./make.bash --no-clean; \
- [ "$$arch" = "amd64" ] && [ "$$os" = "linux" ] && $(GOBIN)/go install -race std; \
+ cd src \
+ && $(CURDIR)/debian/helpers/goenv.sh \
+ GOARCH=$$arch GOOS=$$os \
+ bash ./make.bash --no-clean --no-banner; \
+ if [ "$$arch" = "amd64" -a "$$os" = "linux" ]; then \
+ $(GOROOT)/bin/go install -race cmd/cgo; \
+ $(GOROOT)/bin/go install -race std; \
+ fi; \
cd ..; \
${FOR_GO_ARCH_END}
- >debian/build.stamp
-
-opt_no_act =
-RUN_TEST := true
-
-ifneq (,$(filter noopt,$(DEB_BUILD_OPTIONS)))
- $(warning no support for disabling optimization)
-endif
+opt_no_act :=
ifneq (,$(findstring n,$(MAKEFLAGS)))
- opt_no_act = --no-act
+ opt_no_act := --no-act
endif
-
-ifneq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
- RUN_TEST := false
-endif
-
-GOROOT := $(CURDIR)
-GOROOT_FINAL := $(libexecdir)
-GOBIN := $(CURDIR)$(bindir)
-GOARM :=
-
-# Always use the 387 floating point unit instead of sse2. This is important to
-# ensure that the binaries we build (both when compiling golang on the buildds
-# and when users cross-compile for 386) can actually run on older CPUs (where
-# old means e.g. an AMD Athlon XP 2400+). See http://bugs.debian.org/753160 and
-# https://code.google.com/p/go/issues/detail?id=8152
-GO386 := 387
-
-DEB_HOST_ARCH := $(shell dpkg-architecture -qDEB_HOST_ARCH 2>/dev/null)
-DEB_HOST_ARCH_OS := $(shell dpkg-architecture -qDEB_HOST_ARCH_OS 2>/dev/null)
-DEB_HOST_ARCH_CPU := $(shell dpkg-architecture -qDEB_HOST_ARCH_CPU 2>/dev/null)
-DEB_BUILD_ARCH_OS := $(shell dpkg-architecture -qDEB_BUILD_ARCH_OS 2>/dev/null)
-DEB_BUILD_ARCH_CPU := $(shell dpkg-architecture -qDEB_BUILD_ARCH_CPU 2>/dev/null)
-
-ifeq ($(DEB_BUILD_ARCH_OS), kfreebsd)
- RUN_TEST := false
- GOHOSTOS := freebsd
-else ifeq ($(DEB_BUILD_ARCH_OS), linux)
- GOHOSTOS := linux
-else
- $(error unrecongized build host kernel $(DEB_BUILD_ARCH_OS)!)
-endif
-
-ifeq ($(DEB_HOST_ARCH_OS), kfreebsd)
- RUN_TEST := false
- GOOS := freebsd
-else ifeq ($(DEB_HOST_ARCH_OS), linux)
- GOOS := linux
-else
- $(error unrecognized kernel $(DEB_HOST_ARCH_OS)!)
-endif
-
-ifeq ($(DEB_BUILD_ARCH_CPU), i386)
- GOHOSTARCH := 386
-else ifeq ($(DEB_BUILD_ARCH_CPU), amd64)
- GOHOSTARCH := amd64
-else ifeq ($(DEB_BUILD_ARCH_CPU), arm)
- GOHOSTARCH := arm
-else ifeq ($(DEB_BUILD_ARCH_CPU), armhf)
- GOHOSTARCH := arm
-else
- $(error unrecognized build host instruction set $(DEB_HOST_ARCH_CPU)!)
-endif
-
-ifeq ($(DEB_HOST_ARCH_CPU), i386)
- GOARCH := 386
- GOPREFIX := 8
-else ifeq ($(DEB_HOST_ARCH_CPU), amd64)
- GOARCH := amd64
- GOPREFIX := 6
-else ifeq ($(DEB_HOST_ARCH_CPU), arm)
- GOARCH := arm
- GOPREFIX := 5
-ifeq ($(DEB_HOST_ARCH), armel)
- RUN_TEST := false
- GOARM := 5
-else ifeq ($(DEB_HOST_ARCH), armhf)
- GOARM := 6
-else
- $(error unrecognized arm architecture $(DEB_HOST_ARCH)!)
-endif
-else
- $(error unrecognized instruction set $(DEB_HOST_ARCH_CPU)!)
-endif
-
-export GOROOT GOROOT_FINAL GOOS GOARCH GOARM GOBIN GOHOSTARCH GOHOSTOS GO386
-
-.PHONY: build clean install binary-arch binary-indep binary
diff --git a/debian/test.bash b/debian/test.bash
deleted file mode 100755
index d8f6c05..0000000
--- a/debian/test.bash
+++ /dev/null
@@ -1,4 +0,0 @@
-#!/usr/bin/env bash
-set -e
-eval $($1/dist env -p)
-bash run.bash --no-rebuild --banner
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-golang/golang.git
More information about the pkg-golang-commits
mailing list