github.com/anonymouse64/snapd@v0.0.0-20210824153203-04c4c42d842d/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  	dh_clean
   127  	$(MAKE) -C data clean
   128  	# XXX: hacky
   129  	$(MAKE) -C cmd distclean || true
   130  
   131  override_dh_auto_build:
   132  	# usually done via `go generate` but that is not supported on powerpc
   133  	./mkversion.sh
   134  	# Build golang bits
   135  	mkdir -p _build/src/$(DH_GOPKG)/cmd/snap/test-data
   136  	cp -a cmd/snap/test-data/*.gpg _build/src/$(DH_GOPKG)/cmd/snap/test-data/
   137  	cp -a bootloader/assets/data _build/src/$(DH_GOPKG)/bootloader/assets
   138  
   139  	# exclude certain parts that won't be used by debian
   140  	find _build/src/$(DH_GOPKG)/cmd/snap-bootstrap -name "*.go" | xargs rm -f
   141  	find _build/src/$(DH_GOPKG)/gadget/install -name "*.go" | grep -vE '(params\.go|install_dummy\.go)'| xargs rm -f
   142  	# XXX: once dh-golang understands go build tags this would not be needed
   143  	find _build/src/$(DH_GOPKG)/secboot/ -name "*.go" | grep -Ev '(encrypt\.go|secboot_dummy\.go|secboot\.go|encrypt_dummy\.go)' | xargs rm -f
   144  	# and build
   145  	dh_auto_build -- $(BUILDFLAGS) -tags "$(TAGS)" $(GCCGOFLAGS)
   146  
   147  	(cd _build/bin && GOPATH=$$(pwd)/.. go build $(BUILDFLAGS) $(GCCGOFLAGS) -tags "$(SNAP_TAGS)" $(DH_GOPKG)/cmd/snap)
   148  
   149  	# (static linking on powerpc with cgo is broken)
   150  ifneq ($(shell dpkg-architecture -qDEB_HOST_ARCH),powerpc)
   151  	# Generate static snap-exec, snapctl and snap-update-ns - it somehow includes CGO so
   152  	# we must force a static build here. We need a static snap-{exec,update-ns}
   153  	# inside the core snap because not all bases will have a libc
   154  	(cd _build/bin && GOPATH=$$(pwd)/.. CGO_ENABLED=0 go build $(GCCGOFLAGS) -pkgdir=$$(pwd)/std $(DH_GOPKG)/cmd/snap-exec)
   155  	(cd _build/bin && GOPATH=$$(pwd)/.. CGO_ENABLED=0 go build $(GCCGOFLAGS) -pkgdir=$$(pwd)/std $(DH_GOPKG)/cmd/snapctl)
   156  	(cd _build/bin && GOPATH=$$(pwd)/.. go build --ldflags '-extldflags "-static"' $(GCCGOFLAGS) -pkgdir=$$(pwd)/std $(DH_GOPKG)/cmd/snap-update-ns)
   157  
   158  	# ensure we generated a static build
   159  	$(shell	if ldd _build/bin/snap-exec; then false "need static build"; fi)
   160  	$(shell	if ldd _build/bin/snap-update-ns; then false "need static build"; fi)
   161  	$(shell	if ldd _build/bin/snapctl; then false "need static build"; fi)
   162  endif
   163  
   164  	# ensure snap-seccomp is build with a static libseccomp on Ubuntu
   165  ifeq ($(shell dpkg-vendor --query Vendor),Ubuntu)
   166  	# (static linking on powerpc with cgo is broken)
   167   ifneq ($(shell dpkg-architecture -qDEB_HOST_ARCH),powerpc)
   168  	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
   169  	(cd _build/bin && GOPATH=$$(pwd)/.. CGO_LDFLAGS_ALLOW="/.*/libseccomp.a" go build $(GCCGOFLAGS) $(DH_GOPKG)/cmd/snap-seccomp)
   170  	# ensure that libseccomp is not dynamically linked
   171  	ldd _build/bin/snap-seccomp
   172  	test "$$(ldd _build/bin/snap-seccomp | grep libseccomp)" = ""
   173  	# revert again so that the subsequent tests work
   174  	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
   175   endif
   176  endif
   177  
   178  	# Build C bits, sadly manually
   179  	cd cmd && ( autoreconf -i -f )
   180  	cd cmd && ( ./configure --prefix=/usr --libexecdir=/usr/lib/snapd $(VENDOR_ARGS))
   181  	$(MAKE) -C cmd all
   182  
   183  	# Generate the real systemd/dbus/env config files
   184  	$(MAKE) -C data all
   185  
   186  override_dh_auto_test:
   187  	dh_auto_test -- $(BUILDFLAGS) -tags "$(TAGS)" $(GCCGOFLAGS)
   188  # a tested default (production) build should have no test keys
   189  ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
   190  	# check that only the main trusted account-keys are included
   191  	[ $$(strings _build/bin/snapd|grep -c -E "public-key-sha3-384: [a-zA-Z0-9_-]{64}") -eq 2 ]
   192  	strings _build/bin/snapd|grep -c "^public-key-sha3-384: -CvQKAwRQ5h3Ffn10FILJoEZUXOv6km9FwA80-Rcj-f-6jadQ89VRswHNiEB9Lxk$$"
   193  	strings _build/bin/snapd|grep -c "^public-key-sha3-384: d-JcZF9nD9eBw7bwMnH61x-bklnQOhQud1Is6o_cn2wTj8EYDi9musrIT9z2MdAa$$"
   194  	# same for snap-repair
   195  	[ $$(strings _build/bin/snap-repair|grep -c -E "public-key-sha3-384: [a-zA-Z0-9_-]{64}") -eq 3 ]
   196  	# common with snapd
   197  	strings _build/bin/snap-repair|grep -c "^public-key-sha3-384: -CvQKAwRQ5h3Ffn10FILJoEZUXOv6km9FwA80-Rcj-f-6jadQ89VRswHNiEB9Lxk$$"
   198  	strings _build/bin/snap-repair|grep -c "^public-key-sha3-384: d-JcZF9nD9eBw7bwMnH61x-bklnQOhQud1Is6o_cn2wTj8EYDi9musrIT9z2MdAa$$"
   199  	# repair-root
   200  	strings _build/bin/snap-repair|grep -c "^public-key-sha3-384: nttW6NfBXI_E-00u38W-KH6eiksfQNXuI7IiumoV49_zkbhM0sYTzSnFlwZC-W4t$$"
   201  endif
   202  ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
   203  	# run the snap-confine tests
   204  	$(MAKE) -C cmd check
   205  endif
   206  
   207  override_dh_install-indep:
   208  	# we do not need this in the package, its just needed during build
   209  	rm -rf ${CURDIR}/debian/tmp/usr/bin/xgettext-go
   210  	# toolbelt is not shippable
   211  	rm -f ${CURDIR}/debian/tmp/usr/bin/toolbelt
   212  	# we do not like /usr/bin/snappy anymore
   213  	rm -f ${CURDIR}/debian/tmp/usr/bin/snappy
   214  	# chrorder generator
   215  	rm -f ${CURDIR}/debian/tmp/usr/bin/chrorder
   216  	# bootloader assets generator
   217  	rm -f ${CURDIR}/debian/tmp/usr/bin/genasset
   218  	# docs generator
   219  	rm -f ${CURDIR}/debian/tmp/usr/bin/docs
   220  
   221  	dh_install
   222  
   223  override_dh_install-arch:
   224  	# we do not need this in the package, its just needed during build
   225  	rm -rf ${CURDIR}/debian/tmp/usr/bin/xgettext-go
   226  	# toolbelt is not shippable
   227  	rm -f ${CURDIR}/debian/tmp/usr/bin/toolbelt
   228  	# we do not like /usr/bin/snappy anymore
   229  	rm -f ${CURDIR}/debian/tmp/usr/bin/snappy
   230  	# i18n stuff
   231  	mkdir -p debian/snapd/usr/share
   232  	if [ -d share/locale ]; then \
   233  		cp -R share/locale debian/snapd/usr/share; \
   234  	fi
   235  	# chrorder generator
   236  	rm -f ${CURDIR}/debian/tmp/usr/bin/chrorder
   237  	# bootloader assets generator
   238  	rm -f ${CURDIR}/debian/tmp/usr/bin/genasset
   239  	# docs generator
   240  	rm -f ${CURDIR}/debian/tmp/usr/bin/docs
   241  
   242  	# Install snapd's systemd units / upstart jobs, done
   243  	# here instead of debian/snapd.install because the
   244  	# ubuntu/14.04 release branch adds/changes bits here
   245  	$(MAKE) -C data install DESTDIR=$(CURDIR)/debian/snapd/ \
   246  		SYSTEMDSYSTEMUNITDIR=$(SYSTEMD_UNITS_DESTDIR)
   247  	# We called this apps-bin-path.sh instead of snapd.sh, and
   248  	# it's a conf file so we're stuck with it
   249  	mv debian/snapd/etc/profile.d/snapd.sh debian/snapd/etc/profile.d/apps-bin-path.sh
   250  
   251  	$(MAKE) -C cmd install DESTDIR=$(CURDIR)/debian/tmp
   252  
   253  	# Rename the apparmor profile, see dh_apparmor call above for an explanation.
   254  	mv $(CURDIR)/debian/tmp/etc/apparmor.d/usr.lib.snapd.snap-confine $(CURDIR)/debian/tmp/etc/apparmor.d/usr.lib.snapd.snap-confine.real
   255  
   256  	# On Ubuntu and Debian we don't need to install the apparmor helper service.
   257  	rm $(CURDIR)/debian/snapd/$(SYSTEMD_UNITS_DESTDIR)/snapd.apparmor.service
   258  	rm $(CURDIR)/debian/tmp/usr/lib/snapd/snapd-apparmor
   259  
   260  	# Ouside of core we don't need to install the following files:
   261  	rm $(CURDIR)/debian/snapd/$(SYSTEMD_UNITS_DESTDIR)/snapd.autoimport.service
   262  	rm $(CURDIR)/debian/snapd/$(SYSTEMD_UNITS_DESTDIR)/snapd.core-fixup.service
   263  	rm $(CURDIR)/debian/snapd/$(SYSTEMD_UNITS_DESTDIR)/snapd.failure.service
   264  	rm $(CURDIR)/debian/snapd/$(SYSTEMD_UNITS_DESTDIR)/snapd.snap-repair.service
   265  	rm $(CURDIR)/debian/snapd/$(SYSTEMD_UNITS_DESTDIR)/snapd.snap-repair.timer
   266  	rm $(CURDIR)/debian/snapd/$(SYSTEMD_UNITS_DESTDIR)/snapd.system-shutdown.service
   267  	rm $(CURDIR)/debian/snapd/usr/lib/snapd/snapd.run-from-snap
   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)"