]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/debian/rules.in
contrib: debian: drop bashcompletion mangling after install
[FreeBSD/FreeBSD.git] / contrib / debian / rules.in
1 #!/usr/bin/make -f
2
3 include /usr/share/dpkg/default.mk
4
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)
9
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
12
13 ifndef KVERS
14 KVERS=$(shell uname -r)
15 endif
16
17 non_epoch_version=$(shell echo $(KVERS) | perl -pe 's/^\d+://')
18 PACKAGE=openzfs-zfs
19 pmodules = $(PACKAGE)-modules-$(non_epoch_version)
20
21 export DEB_BUILD_MAINT_OPTIONS = hardening=+all
22
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)
26
27 %:
28         dh $@ --with autoreconf,dkms,python3,sphinxdoc
29
30 override_dh_autoreconf:
31         @# Embed the downstream version in the module.
32         @sed -e 's/^Version:.*/Version:       $(DEB_VERSION_UPSTREAM)/' -i.orig META
33
34         dh_autoreconf
35
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
53
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
58
59 override_dh_gencontrol:
60         dh_gencontrol -- -Vlinux:Recommends="linux-libc-dev (<< $(LINUX_NEXT)~), linux-libc-dev (>= $(LINUX_MIN)~),"
61
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
67
68         dh_auto_build
69
70 override_dh_auto_install:
71         @# Install the utilities.
72         $(MAKE) install DESTDIR='$(CURDIR)/debian/tmp'
73
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'
82
83         @# Zed has dependencies outside of the system root.
84         mv '$(CURDIR)/debian/tmp/sbin/zed' '$(CURDIR)/debian/tmp/usr/sbin/zed'
85
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/enum-extract.pl' \
90                 '$(CURDIR)/scripts/dkms.postbuild'
91         $(foreach file,$(DKMSFILES),mv '$(CURDIR)/$(NAME)-$(DEB_VERSION_UPSTREAM)/$(file)' '$(CURDIR)/debian/tmp/usr/src/$(NAME)-$(DEB_VERSION_UPSTREAM)' || exit 1;)
92
93         @# Only ever build Linux modules
94         echo 'SUBDIRS = linux' > '$(CURDIR)/debian/tmp/usr/src/$(NAME)-$(DEB_VERSION_UPSTREAM)/include/os/Makefile.am'
95
96         @# Hellish awk line:
97         @#  * Deletes from configure.ac the parts not needed for building the kernel module
98         @#     * It deletes from inside AC_CONFIG_FILES([]) everything except:
99         @#        - Makefile$
100         @#        - include/(Makefile|sys|os/(Makefile|linux))
101         @#        - module/
102         @#        - zfs.release$
103         @#  * Takes care of spaces and tabs
104         @#  * Remove reference to ZFS_AC_PACKAGE
105         awk '/^AC_CONFIG_FILES\(\[/,/^\]\)/ {\
106                 if ($$0 !~ /^(AC_CONFIG_FILES\(\[([ \t]+)?$$|\]\)([ \t]+)?$$|([ \t]+)?(include\/(Makefile|sys|os\/(Makefile|linux))|module\/|Makefile([ \t]+)?$$|zfs\.release([ \t]+)?$$))/) \
107                 {next} } {print}' \
108                 '$(CURDIR)/$(NAME)-$(DEB_VERSION_UPSTREAM)/configure.ac' | sed '/ZFS_AC_PACKAGE/d' > '$(CURDIR)/debian/tmp/usr/src/$(NAME)-$(DEB_VERSION_UPSTREAM)/configure.ac'
109         @# Set "SUBDIRS = module include" for CONFIG_KERNEL and remove SUBDIRS for all other configs.
110         @# Do not regenerate zfs_gitrev.h during dkms build
111         sed '1,/CONFIG_KERNEL/s/SUBDIRS.*=.*//g;s/SUBDIRS.*=.*/SUBDIRS = module include/g;/make_gitrev.sh/d' \
112                 '$(CURDIR)/$(NAME)-$(DEB_VERSION_UPSTREAM)/Makefile.am' > '$(CURDIR)/debian/tmp/usr/src/$(NAME)-$(DEB_VERSION_UPSTREAM)/Makefile.am'
113         @# Sanity test
114         grep -q 'SUBDIRS = module include' '$(CURDIR)/debian/tmp/usr/src/$(NAME)-$(DEB_VERSION_UPSTREAM)/Makefile.am'
115         sed -i '/rpm.Makefile/d' $(CURDIR)/debian/tmp/usr/src/$(NAME)-$(DEB_VERSION_UPSTREAM)/Makefile.am
116         sed -i '/cmd.Makefile/d' $(CURDIR)/debian/tmp/usr/src/$(NAME)-$(DEB_VERSION_UPSTREAM)/Makefile.am
117         sed -i '/contrib.Makefile/d' $(CURDIR)/debian/tmp/usr/src/$(NAME)-$(DEB_VERSION_UPSTREAM)/Makefile.am
118         sed -i '/etc.Makefile/d' $(CURDIR)/debian/tmp/usr/src/$(NAME)-$(DEB_VERSION_UPSTREAM)/Makefile.am
119         sed -i '/lib.Makefile/d' $(CURDIR)/debian/tmp/usr/src/$(NAME)-$(DEB_VERSION_UPSTREAM)/Makefile.am
120         sed -i '/man.Makefile/d' $(CURDIR)/debian/tmp/usr/src/$(NAME)-$(DEB_VERSION_UPSTREAM)/Makefile.am
121         sed -i '/scripts.Makefile/d' $(CURDIR)/debian/tmp/usr/src/$(NAME)-$(DEB_VERSION_UPSTREAM)/Makefile.am
122         sed -i '/tests.Makefile/d' $(CURDIR)/debian/tmp/usr/src/$(NAME)-$(DEB_VERSION_UPSTREAM)/Makefile.am
123         sed -i '/udev.Makefile/d' $(CURDIR)/debian/tmp/usr/src/$(NAME)-$(DEB_VERSION_UPSTREAM)/Makefile.am
124         @# Run autogen on the stripped source tree
125         cd '$(CURDIR)/debian/tmp/usr/src/$(NAME)-$(DEB_VERSION_UPSTREAM)'; ./autogen.sh
126         rm -fr '$(CURDIR)/debian/tmp/usr/src/$(NAME)-$(DEB_VERSION_UPSTREAM)/autom4te.cache'
127
128         for i in `ls $(CURDIR)/debian/tmp/lib/$(DEB_HOST_MULTIARCH)/*.so`; do \
129                 ln -s '/lib/$(DEB_HOST_MULTIARCH)/'`readlink $${i}` '$(CURDIR)/debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/'`basename $${i}`; \
130                 rm $${i}; \
131         done
132
133         chmod a-x '$(CURDIR)/debian/tmp/etc/zfs/zfs-functions'
134         chmod a-x '$(CURDIR)/debian/tmp/etc/default/zfs'
135
136 override_dh_python3:
137         dh_python3 -p openzfs-python3-pyzfs
138
139 override_dh_dkms:
140         '$(CURDIR)/scripts/dkms.mkconf' -n $(NAME) -v $(DEB_VERSION_UPSTREAM) -f '$(CURDIR)/scripts/zfs-dkms.dkms'
141         dh_dkms
142         rm -f '$(CURDIR)/scripts/zfs-dkms.dkms'
143
144 override_dh_makeshlibs:
145         dh_makeshlibs -a -V
146
147 override_dh_strip:
148         dh_strip
149
150 override_dh_auto_clean:
151         rm -rf zfs-$(DEB_VERSION_UPSTREAM)
152         dh_auto_clean
153         @if test -e META.orig; then mv META.orig META; fi
154
155 override_dh_install:
156         find debian/tmp/lib -name '*.la' -delete
157         dh_install
158
159 override_dh_missing:
160         dh_missing --fail-missing
161
162 override_dh_installinit:
163         dh_installinit -r --no-restart-after-upgrade --name zfs-import
164         dh_installinit -r --no-restart-after-upgrade --name zfs-mount
165         dh_installinit -r --no-restart-after-upgrade --name zfs-load-key
166         dh_installinit -R --name zfs-share
167         dh_installinit -R --name zfs-zed
168
169 override_dh_installsystemd:
170         mkdir -p debian/openzfs-zfsutils/lib/systemd/system
171         ln -sr /dev/null debian/openzfs-zfsutils/lib/systemd/system/zfs-import.service
172         dh_installsystemd --no-stop-on-upgrade -X zfs-zed.service
173         dh_installsystemd --name zfs-zed
174
175 override_dh_installdocs:
176         dh_installdocs -A
177 ifeq (,$(findstring nodoc, $(DEB_BUILD_OPTIONS)))
178         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/
179 endif
180
181 # ------------
182
183 override_dh_prep-deb-files:
184         for templ in $(wildcard $(CURDIR)/debian/*_KVERS_*.in); do \
185                 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)/' \
186                 < $$templ > `echo $$templ | sed -e 's/_KVERS_/$(KVERS)/g ; s/_ARCH_/$(DEB_HOST_ARCH)/g ; s/\.in$$//'` ; \
187         done
188         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' \
189         < debian/control.modules.in > debian/control
190
191 override_dh_configure_modules: override_dh_configure_modules_stamp
192 override_dh_configure_modules_stamp:
193         ./configure @CFGOPTS@ \
194                 --with-config=kernel \
195                 --with-linux=$(KSRC) \
196                 --with-linux-obj=$(KOBJ)
197         touch override_dh_configure_modules_stamp
198
199 override_dh_binary-modules: override_dh_prep-deb-files override_dh_configure_modules
200         dh_testdir
201         dh_testroot
202         dh_prep
203
204         $(MAKE) $(NJOBS) -C $(CURDIR)/module modules
205
206         dh_install -p${pmodules}
207         dh_installdocs -p${pmodules}
208         dh_installchangelogs -p${pmodules}
209         dh_compress -p${pmodules}
210         dh_strip -p${pmodules}
211         dh_fixperms -p${pmodules}
212         dh_installdeb -p${pmodules}
213         dh_gencontrol -p${pmodules}
214         dh_md5sums -p${pmodules}
215         dh_builddeb -p${pmodules}
216
217 debian-copyright:
218         cme update dpkg-copyright -file debian/copyright.cme