feature: large_microzap
[zfs.git] / contrib / debian / rules.in
blobb3b6d9b921d379d67cb614924fd185c6b12fa6c5
1 #!/usr/bin/make -f
3 include /usr/share/dpkg/default.mk
5 LSB_DISTRIBUTOR := $(shell lsb_release -is)
6 NAME := $(shell awk '$$1 == "Name:" { print $$2; }' META)
7 LINUX_MIN := $(shell awk '/Linux-Minimum:/{print $$2}' META)
8 LINUX_NEXT := $(shell awk -F'[ .]' '/Linux-Maximum:/{print $$2 "." $$3+1}' META)
10 DKMSFILES := module include config zfs.release.in autogen.sh copy-builtin META AUTHORS \
11 COPYRIGHT LICENSE README.md CODE_OF_CONDUCT.md NEWS NOTICE RELEASES.md
13 ifndef KVERS
14 KVERS=$(shell uname -r)
15 endif
17 non_epoch_version=$(shell echo $(KVERS) | perl -pe 's/^\d+://')
18 PACKAGE=openzfs-zfs
19 pmodules = $(PACKAGE)-modules-$(non_epoch_version)
21 export DEB_BUILD_MAINT_OPTIONS = hardening=+all
23 NUM_CPUS = $(shell nproc 2>/dev/null)
24 PARALLEL = $(subst parallel=,,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
25 NJOBS = -j$(or $(PARALLEL),$(NUM_CPUS),1)
28 dh $@ --with autoreconf,dkms,python3,sphinxdoc
30 override_dh_autoreconf:
31 @# Embed the downstream version in the module.
32 @sed -e 's/^Version:.*/Version: $(DEB_VERSION_UPSTREAM)/' -i.orig META
34 dh_autoreconf
36 override_dh_auto_configure:
37 @# Build the userland, but don't build the kernel modules.
38 dh_auto_configure -- @CFGOPTS@ \
39 --bindir=/usr/bin \
40 --sbindir=/sbin \
41 --libdir=/lib/"$(DEB_HOST_MULTIARCH)" \
42 --with-udevdir=/lib/udev \
43 --with-zfsexecdir=/usr/lib/zfs-linux \
44 --enable-systemd \
45 --enable-pyzfs \
46 --with-python=python3 \
47 --with-pammoduledir='/lib/$(DEB_HOST_MULTIARCH)/security' \
48 --with-pkgconfigdir='/usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig' \
49 --with-systemdunitdir=/lib/systemd/system \
50 --with-systemdpresetdir=/lib/systemd/system-preset \
51 --with-systemdgeneratordir=/lib/systemd/system-generators \
52 --with-config=user
54 for i in $(wildcard $(CURDIR)/debian/*.install.in) ; do \
55 basename "$$i" | grep _KVERS_ && continue ; \
56 sed 's/@DEB_HOST_MULTIARCH@/$(DEB_HOST_MULTIARCH)/g' "$$i" > "$${i%%.in}" ; \
57 done
59 override_dh_gencontrol:
60 dh_gencontrol -- -Vlinux:Recommends="linux-libc-dev (<< $(LINUX_NEXT)~), linux-libc-dev (>= $(LINUX_MIN)~),"
62 override_dh_auto_build:
63 @# Get a bare copy of the source code for DKMS.
64 @# This creates the $(CURDIR)/$(NAME)-$(DEB_VERSION_UPSTREAM)/ tree, which does not
65 @# contain the userland sources. NB: Remove-userland-dist-rules.patch
66 $(MAKE) distdir
68 dh_auto_build
70 override_dh_auto_install:
71 @# Install the utilities.
72 $(MAKE) install DESTDIR='$(CURDIR)/debian/tmp'
74 # Move from bin_dir to /usr/sbin
75 # Remove suffix (.py) as per policy 10.4 - Scripts
76 # https://www.debian.org/doc/debian-policy/ch-files.html#s-scripts
77 mkdir -p '$(CURDIR)/debian/tmp/usr/sbin/'
78 mv '$(CURDIR)/debian/tmp/usr/bin/arc_summary' '$(CURDIR)/debian/tmp/usr/sbin/arc_summary'
79 mv '$(CURDIR)/debian/tmp/usr/bin/arcstat' '$(CURDIR)/debian/tmp/usr/sbin/arcstat'
80 mv '$(CURDIR)/debian/tmp/usr/bin/dbufstat' '$(CURDIR)/debian/tmp/usr/sbin/dbufstat'
81 mv '$(CURDIR)/debian/tmp/usr/bin/zilstat' '$(CURDIR)/debian/tmp/usr/sbin/zilstat'
83 @# Zed has dependencies outside of the system root.
84 mv '$(CURDIR)/debian/tmp/sbin/zed' '$(CURDIR)/debian/tmp/usr/sbin/zed'
86 @# Install the DKMS source.
87 @# We only want the files needed to build the modules
88 install -D -t '$(CURDIR)/debian/tmp/usr/src/$(NAME)-$(DEB_VERSION_UPSTREAM)/scripts' \
89 '$(CURDIR)/scripts/dkms.postbuild'
90 $(foreach file,$(DKMSFILES),mv '$(CURDIR)/$(NAME)-$(DEB_VERSION_UPSTREAM)/$(file)' '$(CURDIR)/debian/tmp/usr/src/$(NAME)-$(DEB_VERSION_UPSTREAM)' || exit 1;)
92 @# Only ever build Linux modules
93 echo 'SUBDIRS = linux' > '$(CURDIR)/debian/tmp/usr/src/$(NAME)-$(DEB_VERSION_UPSTREAM)/include/os/Makefile.am'
95 @# Hellish awk line:
96 @# * Deletes from configure.ac the parts not needed for building the kernel module
97 @# * It deletes from inside AC_CONFIG_FILES([]) everything except:
98 @# - Makefile$
99 @# - include/(Makefile|sys|os/(Makefile|linux))
100 @# - module/
101 @# - zfs.release$
102 @# * Takes care of spaces and tabs
103 @# * Remove reference to ZFS_AC_PACKAGE
104 awk '/^AC_CONFIG_FILES\(\[/,/^\]\)/ {\
105 if ($$0 !~ /^(AC_CONFIG_FILES\(\[([ \t]+)?$$|\]\)([ \t]+)?$$|([ \t]+)?(include\/(Makefile|sys|os\/(Makefile|linux))|module\/|Makefile([ \t]+)?$$|zfs\.release([ \t]+)?$$))/) \
106 {next} } {print}' \
107 '$(CURDIR)/$(NAME)-$(DEB_VERSION_UPSTREAM)/configure.ac' | sed '/ZFS_AC_PACKAGE/d' > '$(CURDIR)/debian/tmp/usr/src/$(NAME)-$(DEB_VERSION_UPSTREAM)/configure.ac'
108 @# Set "SUBDIRS = module include" for CONFIG_KERNEL and remove SUBDIRS for all other configs.
109 @# Do not regenerate zfs_gitrev.h during dkms build
110 sed '1,/CONFIG_KERNEL/s/SUBDIRS.*=.*//g;s/SUBDIRS.*=.*/SUBDIRS = module include/g;/make_gitrev.sh/d' \
111 '$(CURDIR)/$(NAME)-$(DEB_VERSION_UPSTREAM)/Makefile.am' > '$(CURDIR)/debian/tmp/usr/src/$(NAME)-$(DEB_VERSION_UPSTREAM)/Makefile.am'
112 @# Sanity test
113 grep -q 'SUBDIRS = module include' '$(CURDIR)/debian/tmp/usr/src/$(NAME)-$(DEB_VERSION_UPSTREAM)/Makefile.am'
114 sed -i '/rpm.Makefile/d' $(CURDIR)/debian/tmp/usr/src/$(NAME)-$(DEB_VERSION_UPSTREAM)/Makefile.am
115 sed -i '/cmd.Makefile/d' $(CURDIR)/debian/tmp/usr/src/$(NAME)-$(DEB_VERSION_UPSTREAM)/Makefile.am
116 sed -i '/contrib.Makefile/d' $(CURDIR)/debian/tmp/usr/src/$(NAME)-$(DEB_VERSION_UPSTREAM)/Makefile.am
117 sed -i '/etc.Makefile/d' $(CURDIR)/debian/tmp/usr/src/$(NAME)-$(DEB_VERSION_UPSTREAM)/Makefile.am
118 sed -i '/lib.Makefile/d' $(CURDIR)/debian/tmp/usr/src/$(NAME)-$(DEB_VERSION_UPSTREAM)/Makefile.am
119 sed -i '/man.Makefile/d' $(CURDIR)/debian/tmp/usr/src/$(NAME)-$(DEB_VERSION_UPSTREAM)/Makefile.am
120 sed -i '/scripts.Makefile/d' $(CURDIR)/debian/tmp/usr/src/$(NAME)-$(DEB_VERSION_UPSTREAM)/Makefile.am
121 sed -i '/tests.Makefile/d' $(CURDIR)/debian/tmp/usr/src/$(NAME)-$(DEB_VERSION_UPSTREAM)/Makefile.am
122 sed -i '/udev.Makefile/d' $(CURDIR)/debian/tmp/usr/src/$(NAME)-$(DEB_VERSION_UPSTREAM)/Makefile.am
123 @# Run autogen on the stripped source tree
124 cd '$(CURDIR)/debian/tmp/usr/src/$(NAME)-$(DEB_VERSION_UPSTREAM)'; ./autogen.sh
125 rm -fr '$(CURDIR)/debian/tmp/usr/src/$(NAME)-$(DEB_VERSION_UPSTREAM)/autom4te.cache'
127 for i in `ls $(CURDIR)/debian/tmp/lib/$(DEB_HOST_MULTIARCH)/*.so`; do \
128 ln -s '/lib/$(DEB_HOST_MULTIARCH)/'`readlink $${i}` '$(CURDIR)/debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/'`basename $${i}`; \
129 rm $${i}; \
130 done
132 chmod a-x '$(CURDIR)/debian/tmp/etc/zfs/zfs-functions'
133 chmod a-x '$(CURDIR)/debian/tmp/etc/default/zfs'
135 override_dh_python3:
136 dh_python3 -p openzfs-python3-pyzfs
138 override_dh_dkms:
139 '$(CURDIR)/scripts/dkms.mkconf' -n $(NAME) -v $(DEB_VERSION_UPSTREAM) -f '$(CURDIR)/scripts/zfs-dkms.dkms'
140 dh_dkms
141 rm -f '$(CURDIR)/scripts/zfs-dkms.dkms'
143 override_dh_makeshlibs:
144 dh_makeshlibs -a -V
146 override_dh_strip:
147 dh_strip
149 override_dh_auto_clean:
150 rm -rf zfs-$(DEB_VERSION_UPSTREAM)
151 dh_auto_clean
152 @if test -e META.orig; then mv META.orig META; fi
154 override_dh_install:
155 find debian/tmp/lib -name '*.la' -delete
156 dh_install
158 override_dh_missing:
159 dh_missing --fail-missing
161 override_dh_installinit:
162 dh_installinit -r --no-restart-after-upgrade --name zfs-import
163 dh_installinit -r --no-restart-after-upgrade --name zfs-mount
164 dh_installinit -r --no-restart-after-upgrade --name zfs-load-key
165 dh_installinit -R --name zfs-share
166 dh_installinit -R --name zfs-zed
168 override_dh_installsystemd:
169 mkdir -p debian/openzfs-zfsutils/lib/systemd/system
170 ln -sr /dev/null debian/openzfs-zfsutils/lib/systemd/system/zfs-import.service
171 dh_installsystemd --no-stop-on-upgrade -X zfs-zed.service
172 dh_installsystemd --name zfs-zed
174 override_dh_installdocs:
175 dh_installdocs -A
176 ifeq (,$(findstring nodoc, $(DEB_BUILD_OPTIONS)))
177 http_proxy='127.0.0.1:9' sphinx-build -N -bhtml "$(CURDIR)/contrib/pyzfs/docs/source/" debian/openzfs-pyzfs-doc/usr/share/doc/openzfs-pyzfs-doc/html/
178 endif
180 # ------------
182 override_dh_prep-deb-files:
183 for templ in $(wildcard $(CURDIR)/debian/*_KVERS_*.in); do \
184 sed -e 's/##KVERS##/$(KVERS)/g ; s/#KVERS#/$(KVERS)/g ; s/_KVERS_/$(KVERS)/g ; s/##KDREV##/$(KDREV)/g ; s/#KDREV#/$(KDREV)/g ; s/_KDREV_/$(KDREV)/g ; s/_ARCH_/$(DEB_HOST_ARCH)/' \
185 < $$templ > `echo $$templ | sed -e 's/_KVERS_/$(KVERS)/g ; s/_ARCH_/$(DEB_HOST_ARCH)/g ; s/\.in$$//'` ; \
186 done
187 sed -e 's/##KVERS##/$(KVERS)/g ; s/#KVERS#/$(KVERS)/g ; s/_KVERS_/$(KVERS)/g ; s/##KDREV##/$(KDREV)/g ; s/#KDREV#/$(KDREV)/g ; s/_KDREV_/$(KDREV)/g ; s/_ARCH_/$(DEB_HOST_ARCH)/g' \
188 < debian/control.modules.in > debian/control
190 override_dh_configure_modules: override_dh_configure_modules_stamp
191 override_dh_configure_modules_stamp:
192 ./configure @CFGOPTS@ \
193 --with-config=kernel \
194 --with-linux=$(KSRC) \
195 --with-linux-obj=$(KOBJ)
196 touch override_dh_configure_modules_stamp
198 override_dh_binary-modules: override_dh_prep-deb-files override_dh_configure_modules
199 dh_testdir
200 dh_testroot
201 dh_prep
203 $(MAKE) $(NJOBS) -C $(CURDIR)/module modules
205 dh_install -p${pmodules}
206 dh_installdocs -p${pmodules}
207 dh_installchangelogs -p${pmodules}
208 dh_compress -p${pmodules}
209 dh_strip -p${pmodules}
210 dh_fixperms -p${pmodules}
211 dh_installdeb -p${pmodules}
212 dh_gencontrol -p${pmodules}
213 dh_md5sums -p${pmodules}
214 dh_builddeb -p${pmodules}
216 debian-copyright:
217 cme update dpkg-copyright -file debian/copyright.cme