github.com/chipaca/snappy@v0.0.0-20210104084008-1f06296fe8ad/packaging/ubuntu-16.04/rules (about) 1 #!/usr/bin/make -f 2 # -*- makefile -*- 3 # 4 # These rules should work for any debian-ish distro that uses systemd 5 # as init. That does _not_ include Ubuntu 14.04 ("trusty"); look for 6 # its own special rule file. 7 # 8 # Please keep the diff between that and this relatively small, even if 9 # it means having suboptimal code; these need to be kept in sync by 10 # sentient bags of meat. 11 12 #export DH_VERBOSE=1 13 export DH_OPTIONS 14 export DH_GOPKG := github.com/snapcore/snapd 15 #export DEB_BUILD_OPTIONS=nocheck 16 export DH_GOLANG_EXCLUDES=tests 17 export DH_GOLANG_GO_GENERATE=1 18 19 export PATH:=${PATH}:${CURDIR} 20 # make sure that correct go version is found on trusty 21 export PATH:=/usr/lib/go-1.10/bin:${PATH} 22 23 include /etc/os-release 24 25 # On 18.04 the released version of apt (1.6.1) has a bug that causes 26 # problem on "apt purge snapd". To ensure this won't happen add the 27 # right dependency on 18.04. 28 ifeq (${VERSION_ID},"18.04") 29 SUBSTVARS = -Vsnapd:Breaks="systemd (<< 237-3ubuntu10.24), apt (<< 1.6.3)" 30 endif 31 # Same as above for 18.10 just a different version. 32 ifeq (${VERSION_ID},"18.10") 33 SUBSTVARS = -Vsnapd:Breaks="apt (<< 1.7.0~alpha2)" 34 endif 35 36 # this is overridden in the ubuntu/14.04 release branch 37 SYSTEMD_UNITS_DESTDIR="lib/systemd/system/" 38 39 # The go tool does not fully support vendoring with gccgo, but we can 40 # work around that by constructing the appropriate -I flag by hand. 41 GCCGO := $(shell go tool dist env > /dev/null 2>&1 && echo no || echo yes) 42 43 BUILDFLAGS:=-pkgdir=$(CURDIR)/_build/std 44 # Disable -buildmode=pie mode on all our 32bit platforms 45 # (i386 and armhf). For i386 because of LP: #1711052 and for 46 # armhf because of LP: #1822738 47 ifeq ($(shell dpkg-architecture -qDEB_HOST_ARCH_BITS),64) 48 BUILDFLAGS+= -buildmode=pie 49 endif 50 51 GCCGOFLAGS= 52 ifeq ($(GCCGO),yes) 53 GOARCH := $(shell go env GOARCH) 54 GOOS := $(shell go env GOOS) 55 BUILDFLAGS:= 56 GCCGOFLAGS=-gccgoflags="-I $(CURDIR)/_build/pkg/gccgo_$(GOOS)_$(GOARCH)/$(DH_GOPKG)/vendor" 57 export DH_GOLANG_GO_GENERATE=0 58 # workaround for https://github.com/golang/go/issues/23721 59 export GOMAXPROCS=2 60 endif 61 62 # build with "tpm" support on ubuntu by default 63 # TAGS are the go build tags for all binaries, SNAP_TAGS are for snap and 64 # snap-bootstrap build only. 65 TAGS= 66 SNAP_TAGS= 67 # check if we need to include the testkeys in the binary 68 ifneq (,$(filter testkeys,$(DEB_BUILD_OPTIONS))) 69 TAGS=-tags withtestkeys 70 SNAP_TAGS=-tags "nomanagers withtestkeys" 71 else 72 SNAP_TAGS=-tags nomanagers 73 endif 74 75 DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH) 76 77 BUILT_USING_PACKAGES= 78 # export DEB_BUILD_MAINT_OPTIONS = hardening=+all 79 # DPKG_EXPORT_BUILDFLAGS = 1 80 # include /usr/share/dpkg/buildflags.mk 81 82 # Currently, we enable confinement for Ubuntu only, not for derivatives, 83 # because derivatives may have different kernels that don't support all the 84 # required confinement features and we don't to mislead anyone about the 85 # security of the system. Discuss a proper approach to this for downstreams 86 # if and when they approach us. 87 ifeq ($(shell dpkg-vendor --query Vendor),Ubuntu) 88 # On Ubuntu 16.04 we need to produce a build that can be used on wide 89 # variety of systems. As such we prefer static linking over dynamic linking 90 # for stability, predicability and easy of deployment. We need to link some 91 # things dynamically though: udev has no stable IPC protocol between 92 # libudev and udevd so we need to link with it dynamically. 93 VENDOR_ARGS=--enable-nvidia-multiarch --enable-static-libcap --enable-static-libapparmor --with-host-arch-triplet=$(DEB_HOST_MULTIARCH) 94 ifeq ($(shell dpkg-architecture -qDEB_HOST_ARCH),amd64) 95 VENDOR_ARGS+= --with-host-arch-32bit-triplet=$(shell dpkg-architecture -f -ai386 -qDEB_HOST_MULTIARCH) 96 endif 97 BUILT_USING_PACKAGES=libcap-dev libapparmor-dev libseccomp-dev 98 else 99 ifeq ($(shell dpkg-vendor --query Vendor),Debian) 100 BUILT_USING_PACKAGES=libcap-dev 101 else 102 VENDOR_ARGS=--disable-apparmor 103 endif 104 endif 105 BUILT_USING=$(shell dpkg-query -f '$${source:Package} (= $${source:Version}), ' -W $(BUILT_USING_PACKAGES)) 106 107 %: 108 ifneq ($(shell dpkg-architecture -qDEB_HOST_ARCH),powerpc) 109 dh $@ --buildsystem=golang --with=golang --fail-missing --with systemd --builddirectory=_build 110 else 111 # "powerpc" is not supported unfortunately, do nothing here 112 # See https://github.com/tianon/debian-runc/compare/70957b315f82170dc2ab7085d39c23835c0fa996...xenial for a more elaborate version of this idea. 113 # Note that snapd never really worked on powerpc (we never had a core 114 # snap there) so we don't need to show anything to the user 115 if [ "$@" = "clean" ]; then \ 116 rm -rf debian/snapd; \ 117 fi; \ 118 if [ "$@" = "binary" ] || [ "$@" = "binary-arch" ]; then \ 119 install -m755 -d debian/snapd/usr/share/doc/snapd/; \ 120 cp debian/README.powerpc debian/snapd/usr/share/doc/snapd/; \ 121 dh_installdeb; \ 122 dh_gencontrol; \ 123 dh_builddeb; \ 124 fi; 125 endif 126 127 override_dh_fixperms: 128 dh_fixperms -Xusr/lib/snapd/snap-confine 129 130 131 # The .real profile is a workaround for a bug in dpkg LP: #1673247 that causes 132 # ubiquity to crash. It allows us to "move" the snap-confine profile from 133 # snap-confine into snapd in a way that works with old dpkg that is in the live 134 # CD image. 135 # 136 # Because both the usual and the .real profile describe the same binary the 137 # .real profile takes priority (as it is loaded later). 138 # 139 # We need run dh_apparmor *before* dh_systemd_enable to ensure the postinst 140 # snippets are added in the right order (first the new apparmor profile 141 # is loaded, then we restart the service). 142 override_dh_systemd_enable: 143 dh_apparmor --profile-name=usr.lib.snapd.snap-confine.real -psnapd 144 dh_systemd_enable 145 146 override_dh_clean: 147 ifneq (,$(TEST_GITHUB_AUTOPKGTEST)) 148 # this will be set by the GITHUB webhook to trigger a autopkgtest 149 # we only need to run "govendor sync" here and then its ready 150 (export GOPATH="/tmp/go"; \ 151 mkdir -p /tmp/go/src/github.com/snapcore/; \ 152 cp -ar . /tmp/go/src/github.com/snapcore/snapd; \ 153 go get -u github.com/kardianos/govendor; \ 154 (cd /tmp/go/src/github.com/snapcore/snapd ; /tmp/go/bin/govendor sync); \ 155 cp -ar /tmp/go/src/github.com/snapcore/snapd/vendor/ .; \ 156 ) 157 endif 158 dh_clean 159 $(MAKE) -C data clean 160 # XXX: hacky 161 $(MAKE) -C cmd distclean || true 162 # XXX: hacky^2 163 (cd vendor/github.com/snapcore/squashfuse/src && rm -f snapfuse && make distclean || true ) 164 165 override_dh_auto_build: 166 # usually done via `go generate` but that is not supported on powerpc 167 ./mkversion.sh 168 # Build golang bits 169 mkdir -p _build/src/$(DH_GOPKG)/cmd/snap/test-data 170 cp -a cmd/snap/test-data/*.gpg _build/src/$(DH_GOPKG)/cmd/snap/test-data/ 171 cp -a bootloader/assets/data _build/src/$(DH_GOPKG)/bootloader/assets 172 173 # this is the main go build 174 SNAPD_VANILLA_GO=$$(which go) PATH="$$(pwd)/packaging/build-tools/:$$PATH" dh_auto_build -- $(BUILDFLAGS) $(TAGS) $(GCCGOFLAGS) 175 176 (cd _build/bin && GOPATH=$$(pwd)/.. GOCACHE=/tmp/go-build go build $(BUILDFLAGS) $(GCCGOFLAGS) $(SNAP_TAGS) $(DH_GOPKG)/cmd/snap) 177 (cd _build/bin && GOPATH=$$(pwd)/.. GOCACHE=/tmp/go-build go build $(BUILDFLAGS) $(GCCGOFLAGS) $(SNAP_TAGS) $(DH_GOPKG)/cmd/snap-bootstrap) 178 179 # Generate static snap-exec, snapctl and snap-update-ns - it somehow includes CGO so 180 # we must force a static build here. We need a static snap-{exec,update-ns}/snapctl 181 # inside the core snap because not all bases will have a libc 182 (cd _build/bin && GOPATH=$$(pwd)/.. GOCACHE=/tmp/go-build CGO_ENABLED=0 go build $(GCCGOFLAGS) $(DH_GOPKG)/cmd/snap-exec) 183 (cd _build/bin && GOPATH=$$(pwd)/.. GOCACHE=/tmp/go-build CGO_ENABLED=0 go build $(GCCGOFLAGS) $(DH_GOPKG)/cmd/snapctl) 184 (cd _build/bin && GOPATH=$$(pwd)/.. GOCACHE=/tmp/go-build go build --ldflags '-extldflags "-static"' $(GCCGOFLAGS) $(DH_GOPKG)/cmd/snap-update-ns) 185 186 # ensure we generated a static build 187 $(shell if ldd _build/bin/snap-exec; then false "need static build"; fi) 188 $(shell if ldd _build/bin/snap-update-ns; then false "need static build"; fi) 189 $(shell if ldd _build/bin/snapctl; then false "need static build"; fi) 190 191 # ensure snap-seccomp is build with a static libseccomp on Ubuntu 192 ifeq ($(shell dpkg-vendor --query Vendor),Ubuntu) 193 sed -i "s|#cgo LDFLAGS:|#cgo LDFLAGS: /usr/lib/$(shell dpkg-architecture -qDEB_TARGET_MULTIARCH)/libseccomp.a|" _build/src/$(DH_GOPKG)/cmd/snap-seccomp/main.go 194 (cd _build/bin && GOPATH=$$(pwd)/.. GOCACHE=/tmp/go-build CGO_LDFLAGS_ALLOW="/.*/libseccomp.a" go build $(GCCGOFLAGS) $(DH_GOPKG)/cmd/snap-seccomp) 195 # ensure that libseccomp is not dynamically linked 196 ldd _build/bin/snap-seccomp 197 test "$$(ldd _build/bin/snap-seccomp | grep libseccomp)" = "" 198 # revert again so that the subsequent tests work 199 sed -i "s|#cgo LDFLAGS: /usr/lib/$(shell dpkg-architecture -qDEB_TARGET_MULTIARCH)/libseccomp.a|#cgo LDFLAGS:|" _build/src/$(DH_GOPKG)/cmd/snap-seccomp/main.go 200 endif 201 202 # Build C bits, sadly manually 203 cd cmd && ( autoreconf -i -f ) 204 cd cmd && ( ./configure --prefix=/usr --libexecdir=/usr/lib/snapd $(VENDOR_ARGS)) 205 $(MAKE) -C cmd all 206 207 # Generate the real systemd/dbus/env config files 208 $(MAKE) -C data all 209 210 # build squashfuse and rename to snapfuse 211 (cd vendor/github.com/snapcore/squashfuse/src && mkdir -p autom4te.cache && ./autogen.sh --disable-demo && ./configure --disable-demo && make && mv squashfuse_ll snapfuse) 212 213 override_dh_auto_test: 214 dh_auto_test -- $(BUILDFLAGS) $(TAGS) $(GCCGOFLAGS) 215 # a tested default (production) build should have no test keys 216 ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS))) 217 # check that only the main trusted account-keys are included 218 for b in _build/bin/snapd _build/bin/snap-bootstrap _build/bin/snap-preseed; do \ 219 [ $$(strings $$b |grep -c -E "public-key-sha3-384: [a-zA-Z0-9_-]{64}") -eq 2 ] && \ 220 strings $$b |grep -c "^public-key-sha3-384: -CvQKAwRQ5h3Ffn10FILJoEZUXOv6km9FwA80-Rcj-f-6jadQ89VRswHNiEB9Lxk$$" && \ 221 strings $$b |grep -c "^public-key-sha3-384: d-JcZF9nD9eBw7bwMnH61x-bklnQOhQud1Is6o_cn2wTj8EYDi9musrIT9z2MdAa$$"; \ 222 done; 223 # same for snap-repair 224 [ $$(strings _build/bin/snap-repair|grep -c -E "public-key-sha3-384: [a-zA-Z0-9_-]{64}") -eq 3 ] 225 # common with snapd 226 strings _build/bin/snap-repair|grep -c "^public-key-sha3-384: -CvQKAwRQ5h3Ffn10FILJoEZUXOv6km9FwA80-Rcj-f-6jadQ89VRswHNiEB9Lxk$$" 227 strings _build/bin/snap-repair|grep -c "^public-key-sha3-384: d-JcZF9nD9eBw7bwMnH61x-bklnQOhQud1Is6o_cn2wTj8EYDi9musrIT9z2MdAa$$" 228 # repair-root 229 strings _build/bin/snap-repair|grep -c "^public-key-sha3-384: nttW6NfBXI_E-00u38W-KH6eiksfQNXuI7IiumoV49_zkbhM0sYTzSnFlwZC-W4t$$" 230 endif 231 ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS))) 232 # run the snap-confine tests 233 $(MAKE) -C cmd check 234 endif 235 236 override_dh_install: 237 # we do not need this in the package, its just needed during build 238 rm -rf ${CURDIR}/debian/tmp/usr/bin/xgettext-go 239 # toolbelt is not shippable 240 rm -f ${CURDIR}/debian/tmp/usr/bin/toolbelt 241 # we do not like /usr/bin/snappy anymore 242 rm -f ${CURDIR}/debian/tmp/usr/bin/snappy 243 # i18n stuff 244 mkdir -p debian/snapd/usr/share 245 if [ -d share/locale ]; then \ 246 cp -R share/locale debian/snapd/usr/share; \ 247 fi 248 # chrorder generator 249 rm -f ${CURDIR}/debian/tmp/usr/bin/chrorder 250 # bootloader assets generator 251 rm -f ${CURDIR}/debian/tmp/usr/bin/genasset 252 # docs generator 253 rm -f ${CURDIR}/debian/tmp/usr/bin/docs 254 255 # Install snapd's systemd units / upstart jobs, done 256 # here instead of debian/snapd.install because the 257 # ubuntu/14.04 release branch adds/changes bits here 258 $(MAKE) -C data install DESTDIR=$(CURDIR)/debian/snapd/ \ 259 SYSTEMDSYSTEMUNITDIR=$(SYSTEMD_UNITS_DESTDIR) 260 # We called this apps-bin-path.sh instead of snapd.sh, and 261 # it's a conf file so we're stuck with it 262 mv debian/snapd/etc/profile.d/snapd.sh debian/snapd/etc/profile.d/apps-bin-path.sh 263 264 $(MAKE) -C cmd install DESTDIR=$(CURDIR)/debian/tmp 265 266 # Rename the apparmor profile, see dh_apparmor call above for an explanation. 267 mv $(CURDIR)/debian/tmp/etc/apparmor.d/usr.lib.snapd.snap-confine $(CURDIR)/debian/tmp/etc/apparmor.d/usr.lib.snapd.snap-confine.real 268 269 dh_install 270 271 override_dh_auto_install: snap.8 272 dh_auto_install -O--buildsystem=golang 273 274 snap.8: 275 # fix reproducible builds as reported by: 276 # https://tests.reproducible-builds.org/debian/rb-pkg/unstable/amd64/snapd.html 277 # once golang-go-flags is fixed we can remove the "sed" expression 278 $(CURDIR)/_build/bin/snap help --man | sed '1 s/^.*/.TH snap 8 "$(shell date --reference=debian/changelog +"%d %B %Y")"/' > $@ 279 280 override_dh_auto_clean: 281 dh_auto_clean -O--buildsystem=golang 282 rm -vf snap.8 283 284 override_dh_gencontrol: 285 dh_gencontrol -- -VBuilt-Using="$(BUILT_USING)" $(SUBSTVARS)