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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
|
#!/usr/bin/make -f
# This file is in the public domain.
# You may freely use, modify, distribute, and relicense it.
PACKAGE = golang
libexecdir := /usr/lib/go
datadir := /usr/share/go
bindir := /bin
# We loop over supported operating systems and architectures multiple times,
# so these two variables contain a centralized version of that code.
# The variables $$os and $$arch can be used inside such a loop.
FOR_GO_ARCH := for os in $$(echo solaris linux freebsd windows darwin netbsd); do \
archs="amd64 386"; \
[ "$$os" = "linux" ] || [ "$$os" = "freebsd" ] && archs="amd64 arm 386"; \
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
override_dh_auto_test:
ifeq ($(RUN_TEST), true)
cd $(CURDIR)/src && \
$(CURDIR)/debian/test.bash $(GOROOT)/pkg/tool/$(GOHOSTOS)_$(GOHOSTARCH);
else
:
endif
override_dh_compress:
dh_compress -Xusr/share/doc/$(PACKAGE)-doc/html -Xusr/share/doc/$(PACKAGE)-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
# of operating system and architecture (e.g. linux_amd64, linux_386, …).
gencontrol:
echo "# DO NOT EDIT THIS FILE. EDIT debian/control.* instead!" > debian/control.tmp
cat debian/control.base >> debian/control.tmp
${FOR_GO_ARCH} \
BUILDARCHS=all; \
[ "$$os" = "linux" ] && BUILDARCHS="i386 amd64 armel armhf"; \
sed -e "s,@OS@,$$os,g; s,@ARCH@,$$arch,g; s,@BUILDARCHS@,$$BUILDARCHS,g" debian/control.cross >> debian/control.tmp; \
${FOR_GO_ARCH_END}
mv debian/control.tmp debian/control
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; \
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; \
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
# Remove Plan9 rc(1) scripts
find $(CURDIR)/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
# Subsequently, /usr/share/go is empty, too, so remove
find $(CURDIR)/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)
# 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 {} \;
override_dh_strip:
# strip disabled as golang upstream doesn't support it and it makes go
# crash. See http://bugs.debian.org/717172
override_dh_prep:
dh_prep
echo 'go:Hostarch=$(GOHOSTARCH)' >> debian/golang-go.substvars
echo 'go:Hostos=$(GOHOSTOS)' >> 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)
# Build native tools first, then bootstrap all other GOOS/GOARCH combinations.
cd src && 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.
#
# 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 ..; \
${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
ifneq (,$(findstring n,$(MAKEFLAGS)))
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 ifeq ($(DEB_BUILD_ARCH_OS), illumos)
GOHOSTOS := solaris
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 ifeq ($(DEB_HOST_ARCH_OS), illumos)
GOOS := solaris
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
|