github.com/tompreston/snapd@v0.0.0-20210817193607-954edfcb9611/packaging/debian-sid/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 # GOCACHE is needed by go-1.13 21 export GOCACHE:=/tmp/go-build 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="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 # Disable -buildmode=pie mode on i386 as can panics in spectacular 44 # ways (LP: #1711052). 45 # See also https://forum.snapcraft.io/t/artful-i386-panics/ 46 # Note while the panic is only on artful, that's because artful 47 # detects it; the issue potentially there on older things. 48 BUILDFLAGS:=-pkgdir=$(CURDIR)/_build/std 49 ifneq ($(shell dpkg-architecture -qDEB_HOST_ARCH),i386) 50 BUILDFLAGS+= -buildmode=pie 51 endif 52 53 GCCGOFLAGS= 54 ifeq ($(GCCGO),yes) 55 GOARCH := $(shell go env GOARCH) 56 GOOS := $(shell go env GOOS) 57 BUILDFLAGS:= 58 GCCGOFLAGS=-gccgoflags="-I $(CURDIR)/_build/pkg/gccgo_$(GOOS)_$(GOARCH)/$(DH_GOPKG)/vendor" 59 export DH_GOLANG_GO_GENERATE=0 60 # workaround for https://github.com/golang/go/issues/23721 61 export GOMAXPROCS=2 62 endif 63 64 # check if we need to include the testkeys in the binary 65 # TAGS are the go build tags for all binaries, SNAP_TAGS are for snap 66 # build only. 67 TAGS=nosecboot 68 SNAP_TAGS=nosecboot nomanagers 69 ifneq (,$(filter testkeys,$(DEB_BUILD_OPTIONS))) 70 TAGS+= withtestkeys 71 SNAP_TAGS+= withtestkeys 72 endif 73 74 DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH) 75 76 BUILT_USING_PACKAGES= 77 # export DEB_BUILD_MAINT_OPTIONS = hardening=+all 78 # DPKG_EXPORT_BUILDFLAGS = 1 79 # include /usr/share/dpkg/buildflags.mk 80 81 # Currently, we enable confinement for Ubuntu only, not for derivatives, 82 # because derivatives may have different kernels that don't support all the 83 # required confinement features and we don't to mislead anyone about the 84 # security of the system. Discuss a proper approach to this for downstreams 85 # if and when they approach us. 86 ifeq ($(shell dpkg-vendor --query Vendor),Ubuntu) 87 # On Ubuntu 16.04 we need to produce a build that can be used on wide 88 # variety of systems. As such we prefer static linking over dynamic linking 89 # for stability, predicability and easy of deployment. We need to link some 90 # things dynamically though: udev has no stable IPC protocol between 91 # libudev and udevd so we need to link with it dynamically. 92 VENDOR_ARGS=--enable-nvidia-multiarch --enable-static-libcap --enable-static-libapparmor --enable-static-libseccomp --with-host-arch-triplet=$(DEB_HOST_MULTIARCH) 93 ifeq ($(shell dpkg-architecture -qDEB_HOST_ARCH),amd64) 94 VENDOR_ARGS+= --with-host-arch-32bit-triplet=$(shell dpkg-architecture -f -ai386 -qDEB_HOST_MULTIARCH) 95 endif 96 BUILT_USING_PACKAGES=libcap-dev libapparmor-dev libseccomp-dev 97 else 98 ifeq ($(shell dpkg-vendor --query Vendor),Debian) 99 VENDOR_ARGS=--enable-nvidia-multiarch 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 dh $@ --buildsystem=golang --with=golang --fail-missing --with systemd --builddirectory=_build 109 110 override_dh_fixperms: 111 dh_fixperms -Xusr/lib/snapd/snap-confine 112 113 114 # The .real profile is a workaround for a bug in dpkg LP: #1673247 that causes 115 # ubiquity to crash. It allows us to "move" the snap-confine profile from 116 # snap-confine into snapd in a way that works with old dpkg that is in the live 117 # CD image. 118 # 119 # Because both the usual and the .real profile describe the same binary the 120 # .real profile takes priority (as it is loaded later). 121 override_dh_installdeb: 122 dh_apparmor --profile-name=usr.lib.snapd.snap-confine.real -psnapd 123 dh_installdeb 124 125 override_dh_clean: 126 ifneq (,$(TEST_GITHUB_AUTOPKGTEST)) 127 # this will be set by the GITHUB webhook to trigger a autopkgtest 128 # we only need to run "govendor sync" here and then its ready 129 (export GOPATH="/tmp/go"; \ 130 mkdir -p /tmp/go/src/github.com/snapcore/; \ 131 cp -ar . /tmp/go/src/github.com/snapcore/snapd; \ 132 go get -u github.com/kardianos/govendor; \ 133 (cd /tmp/go/src/github.com/snapcore/snapd ; /tmp/go/bin/govendor sync); \ 134 cp -ar /tmp/go/src/github.com/snapcore/snapd/vendor/ .; \ 135 ) 136 endif 137 dh_clean 138 $(MAKE) -C data clean 139 # XXX: hacky 140 $(MAKE) -C cmd distclean || true 141 142 override_dh_auto_build: 143 # usually done via `go generate` but that is not supported on powerpc 144 ./mkversion.sh 145 # Build golang bits 146 mkdir -p _build/src/$(DH_GOPKG)/cmd/snap/test-data 147 cp -a cmd/snap/test-data/*.gpg _build/src/$(DH_GOPKG)/cmd/snap/test-data/ 148 cp -a bootloader/assets/data _build/src/$(DH_GOPKG)/bootloader/assets 149 150 # exclude certain parts that won't be used by debian 151 find _build/src/$(DH_GOPKG)/cmd/snap-bootstrap -name "*.go" | xargs rm -f 152 find _build/src/$(DH_GOPKG)/gadget/install -name "*.go" | grep -vE '(params\.go|install_dummy\.go)'| xargs rm -f 153 # XXX: once dh-golang understands go build tags this would not be needed 154 find _build/src/$(DH_GOPKG)/secboot/ -name "*.go" | grep -Ev '(encrypt\.go|secboot_dummy\.go|secboot\.go|encrypt_dummy\.go)' | xargs rm -f 155 # and build 156 dh_auto_build -- $(BUILDFLAGS) -tags "$(TAGS)" $(GCCGOFLAGS) 157 158 (cd _build/bin && GOPATH=$$(pwd)/.. go build $(BUILDFLAGS) $(GCCGOFLAGS) -tags "$(SNAP_TAGS)" $(DH_GOPKG)/cmd/snap) 159 160 # (static linking on powerpc with cgo is broken) 161 ifneq ($(shell dpkg-architecture -qDEB_HOST_ARCH),powerpc) 162 # Generate static snap-exec, snapctl and snap-update-ns - it somehow includes CGO so 163 # we must force a static build here. We need a static snap-{exec,update-ns} 164 # inside the core snap because not all bases will have a libc 165 (cd _build/bin && GOPATH=$$(pwd)/.. CGO_ENABLED=0 go build $(GCCGOFLAGS) -pkgdir=$$(pwd)/std $(DH_GOPKG)/cmd/snap-exec) 166 (cd _build/bin && GOPATH=$$(pwd)/.. CGO_ENABLED=0 go build $(GCCGOFLAGS) -pkgdir=$$(pwd)/std $(DH_GOPKG)/cmd/snapctl) 167 (cd _build/bin && GOPATH=$$(pwd)/.. go build --ldflags '-extldflags "-static"' $(GCCGOFLAGS) -pkgdir=$$(pwd)/std $(DH_GOPKG)/cmd/snap-update-ns) 168 169 # ensure we generated a static build 170 $(shell if ldd _build/bin/snap-exec; then false "need static build"; fi) 171 $(shell if ldd _build/bin/snap-update-ns; then false "need static build"; fi) 172 $(shell if ldd _build/bin/snapctl; then false "need static build"; fi) 173 endif 174 175 # ensure snap-seccomp is build with a static libseccomp on Ubuntu 176 ifeq ($(shell dpkg-vendor --query Vendor),Ubuntu) 177 # (static linking on powerpc with cgo is broken) 178 ifneq ($(shell dpkg-architecture -qDEB_HOST_ARCH),powerpc) 179 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 180 (cd _build/bin && GOPATH=$$(pwd)/.. CGO_LDFLAGS_ALLOW="/.*/libseccomp.a" go build $(GCCGOFLAGS) $(DH_GOPKG)/cmd/snap-seccomp) 181 # ensure that libseccomp is not dynamically linked 182 ldd _build/bin/snap-seccomp 183 test "$$(ldd _build/bin/snap-seccomp | grep libseccomp)" = "" 184 # revert again so that the subsequent tests work 185 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 186 endif 187 endif 188 189 # Build C bits, sadly manually 190 cd cmd && ( autoreconf -i -f ) 191 cd cmd && ( ./configure --prefix=/usr --libexecdir=/usr/lib/snapd $(VENDOR_ARGS)) 192 $(MAKE) -C cmd all 193 194 # Generate the real systemd/dbus/env config files 195 $(MAKE) -C data all 196 197 override_dh_auto_test: 198 dh_auto_test -- $(BUILDFLAGS) -tags "$(TAGS)" $(GCCGOFLAGS) 199 # a tested default (production) build should have no test keys 200 ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS))) 201 # check that only the main trusted account-keys are included 202 [ $$(strings _build/bin/snapd|grep -c -E "public-key-sha3-384: [a-zA-Z0-9_-]{64}") -eq 2 ] 203 strings _build/bin/snapd|grep -c "^public-key-sha3-384: -CvQKAwRQ5h3Ffn10FILJoEZUXOv6km9FwA80-Rcj-f-6jadQ89VRswHNiEB9Lxk$$" 204 strings _build/bin/snapd|grep -c "^public-key-sha3-384: d-JcZF9nD9eBw7bwMnH61x-bklnQOhQud1Is6o_cn2wTj8EYDi9musrIT9z2MdAa$$" 205 # same for snap-repair 206 [ $$(strings _build/bin/snap-repair|grep -c -E "public-key-sha3-384: [a-zA-Z0-9_-]{64}") -eq 3 ] 207 # common with snapd 208 strings _build/bin/snap-repair|grep -c "^public-key-sha3-384: -CvQKAwRQ5h3Ffn10FILJoEZUXOv6km9FwA80-Rcj-f-6jadQ89VRswHNiEB9Lxk$$" 209 strings _build/bin/snap-repair|grep -c "^public-key-sha3-384: d-JcZF9nD9eBw7bwMnH61x-bklnQOhQud1Is6o_cn2wTj8EYDi9musrIT9z2MdAa$$" 210 # repair-root 211 strings _build/bin/snap-repair|grep -c "^public-key-sha3-384: nttW6NfBXI_E-00u38W-KH6eiksfQNXuI7IiumoV49_zkbhM0sYTzSnFlwZC-W4t$$" 212 endif 213 ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS))) 214 # run the snap-confine tests 215 $(MAKE) -C cmd check 216 endif 217 218 override_dh_install-indep: 219 # we do not need this in the package, its just needed during build 220 rm -rf ${CURDIR}/debian/tmp/usr/bin/xgettext-go 221 # toolbelt is not shippable 222 rm -f ${CURDIR}/debian/tmp/usr/bin/toolbelt 223 # we do not like /usr/bin/snappy anymore 224 rm -f ${CURDIR}/debian/tmp/usr/bin/snappy 225 # chrorder generator 226 rm -f ${CURDIR}/debian/tmp/usr/bin/chrorder 227 # bootloader assets generator 228 rm -f ${CURDIR}/debian/tmp/usr/bin/genasset 229 # docs generator 230 rm -f ${CURDIR}/debian/tmp/usr/bin/docs 231 232 dh_install 233 234 override_dh_install-arch: 235 # we do not need this in the package, its just needed during build 236 rm -rf ${CURDIR}/debian/tmp/usr/bin/xgettext-go 237 # toolbelt is not shippable 238 rm -f ${CURDIR}/debian/tmp/usr/bin/toolbelt 239 # we do not like /usr/bin/snappy anymore 240 rm -f ${CURDIR}/debian/tmp/usr/bin/snappy 241 # i18n stuff 242 mkdir -p debian/snapd/usr/share 243 if [ -d share/locale ]; then \ 244 cp -R share/locale debian/snapd/usr/share; \ 245 fi 246 # chrorder generator 247 rm -f ${CURDIR}/debian/tmp/usr/bin/chrorder 248 # bootloader assets generator 249 rm -f ${CURDIR}/debian/tmp/usr/bin/genasset 250 # docs generator 251 rm -f ${CURDIR}/debian/tmp/usr/bin/docs 252 253 # Install snapd's systemd units / upstart jobs, done 254 # here instead of debian/snapd.install because the 255 # ubuntu/14.04 release branch adds/changes bits here 256 $(MAKE) -C data install DESTDIR=$(CURDIR)/debian/snapd/ \ 257 SYSTEMDSYSTEMUNITDIR=$(SYSTEMD_UNITS_DESTDIR) 258 # We called this apps-bin-path.sh instead of snapd.sh, and 259 # it's a conf file so we're stuck with it 260 mv debian/snapd/etc/profile.d/snapd.sh debian/snapd/etc/profile.d/apps-bin-path.sh 261 262 $(MAKE) -C cmd install DESTDIR=$(CURDIR)/debian/tmp 263 264 # Rename the apparmor profile, see dh_apparmor call above for an explanation. 265 mv $(CURDIR)/debian/tmp/etc/apparmor.d/usr.lib.snapd.snap-confine $(CURDIR)/debian/tmp/etc/apparmor.d/usr.lib.snapd.snap-confine.real 266 267 # On Ubuntu and Debian we don't need to install the apparmor helper service. 268 rm $(CURDIR)/debian/snapd/$(SYSTEMD_UNITS_DESTDIR)/snapd.apparmor.service 269 rm $(CURDIR)/debian/tmp/usr/lib/snapd/snapd-apparmor 270 271 # Ouside of core we don't need to install the following files: 272 rm $(CURDIR)/debian/snapd/$(SYSTEMD_UNITS_DESTDIR)/snapd.autoimport.service 273 rm $(CURDIR)/debian/snapd/$(SYSTEMD_UNITS_DESTDIR)/snapd.core-fixup.service 274 rm $(CURDIR)/debian/snapd/$(SYSTEMD_UNITS_DESTDIR)/snapd.failure.service 275 rm $(CURDIR)/debian/snapd/$(SYSTEMD_UNITS_DESTDIR)/snapd.snap-repair.service 276 rm $(CURDIR)/debian/snapd/$(SYSTEMD_UNITS_DESTDIR)/snapd.snap-repair.timer 277 rm $(CURDIR)/debian/snapd/$(SYSTEMD_UNITS_DESTDIR)/snapd.system-shutdown.service 278 rm $(CURDIR)/debian/snapd/usr/lib/snapd/snapd.run-from-snap 279 280 dh_install 281 282 override_dh_auto_install: snap.8 283 dh_auto_install -O--buildsystem=golang 284 285 snap.8: 286 # fix reproducible builds as reported by: 287 # https://tests.reproducible-builds.org/debian/rb-pkg/unstable/amd64/snapd.html 288 # once golang-go-flags is fixed we can remove the "sed" expression 289 $(CURDIR)/_build/bin/snap help --man | sed '1 s/^.*/.TH snap 8 "$(shell date --reference=debian/changelog +"%d %B %Y")"/' > $@ 290 291 override_dh_auto_clean: 292 dh_auto_clean -O--buildsystem=golang 293 rm -vf snap.8 294 295 override_dh_gencontrol: 296 dh_gencontrol -- -VBuilt-Using="$(BUILT_USING)"