github.com/chipaca/snappy@v0.0.0-20210104084008-1f06296fe8ad/packaging/snapd.mk (about) 1 # This makefile is designed to be invoked from a build tree, not from the 2 # source tree. This is particularly suited for building RPM packages. The goal 3 # of this makefile is to *reduce* the duplication, *avoid* unintended 4 # inconsistency between packaging of snapd across distributions. 5 # 6 # ----------------------------------------------------- 7 # Interface between snapd.mk and distribution packaging 8 # ----------------------------------------------------- 9 # 10 # Distribution packaging must generate snapd.defines.mk with a set of makefile 11 # variable definitions that are discussed below. This allows the packaging 12 # world to define directory layout and build configuration in one place and 13 # this makefile to simply obey and implement that configuration. 14 15 include snapd.defines.mk 16 17 # There are two sets of definitions expected: 18 # 1) variables defining various directory names 19 vars += bindir sbindir libexecdir mandir datadir localstatedir sharedstatedir unitdir 20 # 2) variables defining build options: 21 # with_testkeys: set to 1 to build snapd with test key built in 22 # with_apparmor: set to 1 to build snapd with apparmor support 23 # with_core_bits: set to 1 to build snapd with things needed for the core/snapd snap 24 # with_alt_snap_mount_dir: set to 1 to build snapd with alternate snap mount directory 25 vars += with_testkeys with_apparmor with_core_bits with_alt_snap_mount_dir 26 # Verify that none of the variables are empty. This may happen if snapd.mk and 27 # distribution packaging generating snapd.defines.mk get out of sync. 28 29 $(foreach var,$(vars),$(if $(value $(var)),,$(error $(var) is empty or unset, check snapd.defines.mk))) 30 31 # ------------------------------------------------ 32 # There are no more control knobs after this point 33 # ------------------------------------------------ 34 35 # Import path of snapd. 36 import_path = github.com/snapcore/snapd 37 38 39 # This is usually set by %make_install. It is defined here to avoid warnings or 40 # errors from referencing undefined variables. 41 DESTDIR? = 42 43 # Decide which of the two snap mount directories to use. This is not 44 # referencing localstatedir because the code copes with only those two values 45 # explicitly. 46 ifeq ($(with_alt_snap_mount_dir),1) 47 snap_mount_dir = /var/lib/snapd/snap 48 else 49 snap_mount_dir = /snap 50 endif 51 52 # The list of go binaries we are expected to build. 53 go_binaries = snap snapctl snap-seccomp snap-update-ns snap-exec snapd 54 55 # NOTE: This *depends* on building out of tree. Some of the built binaries 56 # conflict with directory names in the tree. 57 .PHONY: all 58 all: $(go_binaries) 59 60 snap: GO_TAGS += nomanagers 61 snap snap-seccomp: 62 go build $(if $(GO_TAGS),-tags $(GO_TAGS)) -buildmode=pie $(import_path)/cmd/$@ 63 64 # Those three need to be built as static binaries. They run on the inside of a 65 # nearly-arbitrary mount namespace that does not contain anything we can depend 66 # on (no standard library, for example). 67 snap-update-ns snap-exec snapctl: 68 # Explicit request to use an external linker, otherwise extldflags may not be 69 # used 70 go build -buildmode=default -ldflags '-linkmode external -extldflags "-static"' $(import_path)/cmd/$@ 71 72 # Snapd can be built with test keys. This is only used by the internal test 73 # suite to add test assertions. Do not enable this in distribution packages. 74 snapd: 75 ifeq ($(with_testkeys),1) 76 go build -buildmode=pie -tags withtestkeys $(import_path)/cmd/$@ 77 else 78 go build -buildmode=pie $(import_path)/cmd/$@ 79 endif 80 81 # Know how to create certain directories. 82 $(addprefix $(DESTDIR),$(libexecdir)/snapd $(bindir) $(mandir)/man8 /$(sharedstatedir)/snapd $(localstatedir)/cache/snapd $(snap_mount_dir)): 83 install -m 755 -d $@ 84 85 .PHONY: install 86 87 # Install snap into /usr/bin/. 88 install:: snap | $(DESTDIR)$(bindir) 89 install -m 755 $^ $| 90 91 # Install snapctl snapd, snap-{exec,update-ns,seccomp} into /usr/lib/snapd/ 92 install:: snapctl snapd snap-exec snap-update-ns snap-seccomp | $(DESTDIR)$(libexecdir)/snapd 93 install -m 755 $^ $| 94 95 # Ensure /usr/bin/snapctl is a symlink to /usr/lib/snapd/snapctl 96 install:: | $(DESTDIR)$(bindir) 97 ln -s $(libexecdir)/snapd/snapctl $|/snapctl 98 99 # Generate and install man page for snap command 100 install:: snap | $(DESTDIR)$(mandir)/man8 101 ./snap help --man > $|/snap.8 102 103 # Install the directory structure in /var/lib/snapd 104 install:: 105 install -m 755 -d $(DESTDIR)/$(sharedstatedir)/snapd/apparmor/profiles 106 install -m 755 -d $(DESTDIR)/$(sharedstatedir)/snapd/apparmor/snap-confine 107 install -m 755 -d $(DESTDIR)/$(sharedstatedir)/snapd/assertions 108 install -m 755 -d $(DESTDIR)/$(sharedstatedir)/snapd/cache 109 install -m 755 -d $(DESTDIR)/$(sharedstatedir)/snapd/cookie 110 install -m 755 -d $(DESTDIR)/$(sharedstatedir)/snapd/dbus-1/services 111 install -m 755 -d $(DESTDIR)/$(sharedstatedir)/snapd/dbus-1/system-services 112 install -m 755 -d $(DESTDIR)/$(sharedstatedir)/snapd/desktop/applications 113 install -m 755 -d $(DESTDIR)/$(sharedstatedir)/snapd/device 114 install -m 755 -d $(DESTDIR)/$(sharedstatedir)/snapd/hostfs 115 install -m 755 -d $(DESTDIR)/$(sharedstatedir)/snapd/inhibit 116 install -m 755 -d $(DESTDIR)/$(sharedstatedir)/snapd/lib/gl 117 install -m 755 -d $(DESTDIR)/$(sharedstatedir)/snapd/lib/gl32 118 install -m 755 -d $(DESTDIR)/$(sharedstatedir)/snapd/lib/glvnd 119 install -m 755 -d $(DESTDIR)/$(sharedstatedir)/snapd/lib/vulkan 120 install -m 755 -d $(DESTDIR)/$(sharedstatedir)/snapd/mount 121 install -m 755 -d $(DESTDIR)/$(sharedstatedir)/snapd/seccomp/bpf 122 install -m 755 -d $(DESTDIR)/$(sharedstatedir)/snapd/sequence 123 install -m 755 -d $(DESTDIR)/$(sharedstatedir)/snapd/snaps 124 125 # Touch files that are ghosted by the package. Those are _NOT_ installed but 126 # this way the package manager knows about them belonging to the package. 127 install:: | $(DESTDIR)/$(sharedstatedir)/snapd 128 touch $|/state.json 129 touch $|/system-key 130 131 install:: | $(DESTDIR)$(localstatedir)/cache/snapd 132 touch $|/sections 133 touch $|/names 134 touch $|/commands 135 136 install:: | $(DESTDIR)$(snap_mount_dir) 137 touch $|/README 138 139 140 # Install the /snap/bin directory 141 install:: 142 install -m 755 -d $(DESTDIR)$(snap_mount_dir)/bin 143 144 # Install misc directories: 145 install:: 146 install -m 755 -d $(DESTDIR)$(localstatedir)/cache/snapd 147 install -m 755 -d $(DESTDIR)$(datadir)/polkit-1/actions 148 149 # Remove traces of ubuntu-core-launcher. It is a phased-out executable that is 150 # still partially present in the tree but should be removed in the subsequent 151 # release. 152 install:: 153 rm -f $(DESTDIR)$(bindir)/ubuntu-core-launcher 154 155 # Do not ship snap-preseed. It is currently only useful on ubuntu and tailored 156 # for preseeding of ubuntu cloud images due to certain assumptions about 157 # runtime environment of the host and of the preseeded image. 158 install:: 159 rm -f $(DESTDIR)$(bindir)/snap-preseed 160 161 ifeq ($(with_core_bits),0) 162 # Remove systemd units that are only used on core devices. 163 install:: 164 rm -f $(addprefix $(DESTDIR)$(unitdir)/,snapd.autoimport.service snapd.system-shutdown.service snapd.snap-repair.timer snapd.snap-repair.service snapd.core-fixup.service snapd.recovery-chooser-trigger.service) 165 166 # Remove fixup script that is only used on core devices. 167 install:: 168 rm -f $(DESTDIR)$(libexecdir)/snapd/snapd.core-fixup.sh 169 170 # Remove system-shutdown helper that is only used on core devices. 171 install:: 172 rm -f $(DESTDIR)$(libexecdir)/snapd/system-shutdown 173 endif 174 175 ifeq ($(with_apparmor),0) 176 # Don't ship apparmor helper service when AppArmor is not enabled. 177 install:: 178 rm -f $(DESTDIR)$(unitdir)/snapd.apparmor.service 179 rm -f $(DESTDIR)$(libexecdir)/snapd/snapd-apparmor 180 endif 181 182 # Tests use C.UTF-8 because some some code depend on this for fancy Unicode 183 # output that unit tests do not mock. 184 .PHONY: check 185 check: 186 LC_ALL=C.UTF-8 go test $(import_path)/... 187 188 .PHONY: clean 189 clean: 190 rm -f $(go_binaries)