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