debian/rules: fix man pages on non-x86
[deb_dpdk.git] / debian / rules
1 #!/usr/bin/make -f
2 # See debhelper(7) (uncomment to enable)
3 # output every command that modifies files on the build system.
4 export DH_VERBOSE=1
5 export DH_OPTIONS=-v
6
7 VERSION := $(shell dpkg-parsechangelog | sed -nr '/^Version:/s/Version: (.*:)?(.*)-(.*)/\2/p')
8
9 # see EXAMPLES in dpkg-buildflags(1) and read /usr/share/dpkg/*
10 include /usr/share/dpkg/default.mk
11
12 DEB_HOST_GNU_CPU := $(shell dpkg-architecture -qDEB_HOST_GNU_CPU)
13
14 # see FEATURE AREAS in dpkg-buildflags(1)
15 export DEB_BUILD_MAINT_OPTIONS = hardening=+all,-pie
16
17 # see ENVIRONMENT in dpkg-buildflags(1)
18 DPKG_EXPORT_BUILDFLAGS = 1
19 include /usr/share/dpkg/buildflags.mk
20
21 # Support backporting to jessie
22 dpkg_version_lt = $(shell dpkg --compare-versions $$(dpkg --status dpkg-dev | grep Version | cut -d' ' -f2) lt-nl "1.18.11" && echo yes)
23 ifeq (yes, $(dpkg_version_lt))
24         # package maintainers to append CFLAGS
25         # For Debian, dpkg-dev >= 1.18.11 and gcc 6.x, dpkg-buildflags and gcc
26         # handle -fPIC and related flags relying on specs files
27         # (/usr/share/dpkg/*specs)
28         export DEB_CFLAGS_MAINT_APPEND  = -fPIC
29         export EXTRA_CFLAGS=$(CFLAGS)
30         export EXTRA_CPPFLAGS=$(CPPFLAGS)
31         export HOST_EXTRA_CFLAGS=$(CFLAGS)
32         export HOST_EXTRA_CPPFLAGS=$(CPPFLAGS)
33         # need to be stripped as DPDK build system adds them and it would be -Wl,-Wl,opt
34         export EXTRA_LDFLAGS=$(shell echo $(LDFLAGS) | sed 's/-Wl,//g')
35         # HOST_CC build system does not add -Wl ...
36         export EXTRA_HOST_LDFLAGS=$(LDFLAGS)
37 endif
38
39 export RTE_DEVEL_BUILD=n
40
41 # People rebuilding this package can overwrite DPDK_CONFIG, RTE_MACHINE and
42 # RTE_TARGET via DEB_BUILD_OPTIONS if they like
43 ifneq (,$(filter dpdk_config=%,$(DEB_BUILD_OPTIONS)))
44     DPDK_CONFIG ?= $(patsubst dpdk_config=%,%,$(filter dpdk_config=%,$(DEB_BUILD_OPTIONS)))
45 endif
46 ifneq (,$(filter rte_machine=%,$(DEB_BUILD_OPTIONS)))
47     RTE_MACHINE ?= $(patsubst rte_machine=%,%,$(filter rte_machine=%,$(DEB_BUILD_OPTIONS)))
48 endif
49 ifneq (,$(filter rte_target=%,$(DEB_BUILD_OPTIONS)))
50     RTE_TARGET ?= $(patsubst rte_target=%,%,$(filter rte_target=%,$(DEB_BUILD_OPTIONS)))
51 endif
52
53 ifneq (,$(filter $(DEB_HOST_ARCH), arm64))
54 DPDK_CONFIG ?= "arm64-armv8a-linuxapp-gcc"
55 RTE_MACHINE ?= "armv8a"
56 RTE_TARGET ?= "arm64-armv8a-linuxapp-gcc"
57 else
58 ifneq (,$(filter $(DEB_HOST_ARCH), ppc64el))
59 DPDK_CONFIG ?= "ppc_64-power8-linuxapp-gcc"
60 RTE_MACHINE ?= "power8"
61 RTE_TARGET ?= "ppc_64-power8-linuxapp-gcc"
62 else
63 DPDK_CONFIG ?= "$(DEB_HOST_GNU_CPU)-native-linuxapp-gcc"
64 RTE_MACHINE ?= "default"
65 RTE_TARGET ?= "$(DEB_HOST_GNU_CPU)-default-linuxapp-gcc"
66 endif
67 endif
68 DPDK_STATIC_DIR = "debian/build/static-root"
69 DPDK_SHARED_DIR = "debian/build/shared-root"
70
71 # now stable with parallel comilation, so support -j
72 ifneq (,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
73     PAR := $(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
74 else
75     PAR := "1"
76 endif
77
78 ifneq (,$(findstring nodocs,$(DEB_BUILD_OPTIONS)))
79 BUILD_DOCS=n
80 else
81 BUILD_DOCS=y
82 endif
83
84 ifneq (,$(findstring nostatic,$(DEB_BUILD_OPTIONS)))
85 BUILD_STATIC_LIB=n
86 else
87 BUILD_STATIC_LIB=y
88 endif
89
90 # kernel_modules can be passed via DEB_BUILD_OPTIONS to enable building the
91 # optional binary kernel modules package. By default it will be built against
92 # the current kernel, or ksrc can be passed with a path to the target kernel
93 # sources instead.
94 ifeq (,$(findstring kernel_modules,$(DEB_BUILD_OPTIONS)))
95 DPDK_CONFIG_BUILD_KMOD=n
96 KSRC=""
97 else
98 ifneq (,$(filter ksrc=%,$(DEB_BUILD_OPTIONS)))
99     KSRC := $(patsubst ksrc=%,%,$(filter ksrc=%,$(DEB_BUILD_OPTIONS)))
100 else
101     KSRC := /lib/modules/$(shell uname -r)/build
102 endif
103
104 KVERS := $(shell perl debian/kernel-version $(KSRC))
105 export KVERS
106 export MODULE_CFLAGS=-fno-PIE
107
108 DPDK_CONFIG_BUILD_KMOD=y
109
110 # Since the binary module package is generated at build time depending on the
111 # local kernel version, we have to append the new package in d/control.
112 # We cannot use a separate control file since that wouldn't work with
113 # dpkg-genchanges, and also would require a lot of overrides for debhelpers.
114 get_built_using ?= $(filter-out (=),$(shell dpkg-query -f='$${source:Package} (=$${source:Version})' -W $1))
115
116 override_dh_gencontrol:
117         dh_gencontrol
118         dh_gencontrol -p dpdk-modules-$(KVERS) -- \
119                 -v`cat debian/VERSION` \
120                 -V'built:using:kernel=$(call get_built_using,linux-headers-$(KVERS))'
121
122 build:
123         @if [ x"$(KVERS)" = x ] ; then \
124             echo 'No version in $(KSRC)/include/linux/version.h' >&2; \
125             exit 1; \
126         fi
127         sh debian/prep-modules $(KSRC)
128         cat debian/control.modules >> debian/control
129         dh $@ --with python2,dkms
130 endif
131
132 %:
133         dh $@ --with python2,dkms
134
135 override_dh_auto_clean:
136         rm -rf debian/build debian/tmp debian/dpdk-modules-* \
137                 debian/control.modules debian/VERSION
138         sed -i '/Package: dpdk-modules-/,/`tail -n1 debian/control.modules.in`/d' debian/control
139         test -L config/defconfig_$(DPDK_CONFIG) && rm -f config/defconfig_$(DPDK_CONFIG) || true
140
141 override_dh_clean:
142         dh_clean
143         rm -f debian/libethdev4.links
144         rm -f debian/librte-cryptodev1.links
145         rm -f debian/librte-eal2.links
146
147 override_dh_auto_configure:
148         # Add support for a custom defconfig file in the debian directory.
149 ifneq (,$(filter dpdk_config=%,$(DEB_BUILD_OPTIONS)))
150         test -e config/defconfig_$(DPDK_CONFIG) || ln -fs ../debian/defconfig_$(DPDK_CONFIG) config/defconfig_$(DPDK_CONFIG)
151 endif
152         # report dpkg-buildflags status to build log
153         dpkg-buildflags --status
154         echo EXTRA_CFLAGS $$EXTRA_CFLAGS
155         echo EXTRA_LDFLAGS: $$EXTRA_LDFLAGS
156         $(MAKE) V=$(DH_VERBOSE) O=$(DPDK_STATIC_DIR) T=$(DPDK_CONFIG) config
157 ifeq (,$(filter dpdk_config=%,$(DEB_BUILD_OPTIONS)))
158         sed -ri -e 's,(RTE_MACHINE=).*,\1$(RTE_MACHINE),' \
159                 -e 's,(RTE_NEXT_ABI=).*,\1n,' \
160                 -e 's,(CONFIG_RTE_EAL_IGB_UIO=).*,\1$(DPDK_CONFIG_BUILD_KMOD),' \
161                 -e 's,(CONFIG_RTE_KNI_KMOD=).*,\1$(DPDK_CONFIG_BUILD_KMOD),' \
162                 -e 's,(LIBRTE_PMD_PCAP=).*,\1y,' \
163                 -e 's,(LIBRTE_PMD_XENVIRT=).*,\1y,' \
164                 -e 's,(CONFIG_RTE_EAL_PMD_PATH=).*,\1"/usr/lib/$(shell dpkg-architecture -qDEB_HOST_MULTIARCH)/dpdk-pmds/",' \
165                 $(DPDK_STATIC_DIR)/.config
166         # xen not available on ppc64el
167 ifneq (,$(filter $(DEB_HOST_ARCH), ppc64el))
168         sed -ri -e 's,(LIBRTE_PMD_XENVIRT=).*,\1n,' $(DPDK_STATIC_DIR)/.config
169 endif
170 endif
171         dh_auto_configure
172
173 override_dh_auto_build-indep:
174 ifeq (y,$(BUILD_DOCS))
175         $(MAKE) -j $(PAR) V=$(DH_VERBOSE) O=$(DPDK_STATIC_DIR) doc-api-html doc-guides-html
176 endif
177
178 override_dh_auto_install-indep:
179         # Package: dpdk-doc
180         # All files based on the install-doc rule (includes examples)
181 ifeq (y,$(BUILD_DOCS))
182         $(MAKE) V=$(DH_VERBOSE) O=$(DPDK_STATIC_DIR) prefix=/usr \
183                 DESTDIR=debian/dpdk-doc install-doc
184 endif
185
186 override_dh_auto_build-arch:
187 ifeq (y,$(BUILD_STATIC_LIB))
188         $(MAKE) -j $(PAR) V=$(DH_VERBOSE) O=$(DPDK_STATIC_DIR) RTE_KERNELDIR=$(KSRC) build
189 endif
190         # Unfortunately the decision about having static or shared libraries is
191         # made for the whole build, which then produces only .a or .so files
192         # (but not both).
193         # And the target layout for target selection has no field for the
194         # type of library.
195         # Right now I hack this by doing a second build which only differs in
196         # the selection of shared libs.
197         # Shared libs should be default, so the previous static build is only
198         # used to get static libraries.
199         cp -a $(DPDK_STATIC_DIR) $(DPDK_SHARED_DIR)
200         sed -ri 's,(RTE_BUILD_SHARED_LIB=).*,\1y,' \
201                 $(DPDK_SHARED_DIR)/.config
202         $(MAKE) -j $(PAR) V=$(DH_VERBOSE) O=$(DPDK_SHARED_DIR) RTE_KERNELDIR=$(KSRC) build
203 ifeq (y,$(BUILD_DOCS))
204         # need to be around for dh_installman to be picked up
205         $(MAKE) -j $(PAR) V=$(DH_VERBOSE) O=$(DPDK_SHARED_DIR) RTE_KERNELDIR=$(KSRC) doc-guides-man
206 endif
207
208 override_dh_auto_install-arch: LIBDIR=/usr/lib/$(shell dpkg-architecture -qDEB_HOST_MULTIARCH)
209 override_dh_auto_install-arch:
210         # Package: dpdk (runtime)
211 ifeq (y,$(BUILD_STATIC_LIB))
212         $(MAKE) V=$(DH_VERBOSE) O=$(DPDK_STATIC_DIR) prefix=/usr libdir=$(LIBDIR) \
213                 DESTDIR=debian/dpdk install-runtime
214 endif
215         $(MAKE) V=$(DH_VERBOSE) O=$(DPDK_SHARED_DIR) prefix=/usr libdir=$(LIBDIR) \
216                 DESTDIR=debian/dpdk install-runtime
217         mkdir -p debian/dpdk/etc/dpdk
218         cp debian/dpdk.interfaces debian/dpdk/etc/dpdk/interfaces
219         rm debian/dpdk/usr/sbin/dpdk-devbind
220         mkdir -p debian/dpdk/sbin
221         ln -s /usr/share/dpdk/tools/dpdk-devbind.py \
222                 debian/dpdk/sbin/dpdk-devbind
223         # Package: dpdk-dev (build environment)
224         # workaround to fix symbolic link creation
225         mkdir -p debian/dpdk-dev/$(LIBDIR)
226         $(MAKE) V=$(DH_VERBOSE) O=$(DPDK_SHARED_DIR) prefix=/usr libdir=$(LIBDIR) \
227                 DESTDIR=debian/dpdk-dev install-sdk
228         # remove workaround
229         rm -fr debian/dpdk-dev/usr/lib
230         cp $(DPDK_SHARED_DIR)/.config debian/dpdk-dev/usr/share/dpdk/config
231         sed -e 's/SDK_TARGET/$(RTE_TARGET)/' debian/dpdk-sdk-env.sh.in > \
232                 debian/dpdk-dev/usr/share/dpdk/dpdk-sdk-env.sh
233         # include the bundled autotest suite to be usable from the dpdk-dev package
234         mkdir -p debian/dpdk-dev/usr/share/dpdk/test
235         cp -a app/test/autotest* debian/dpdk-dev/usr/share/dpdk/test
236         cp $(DPDK_SHARED_DIR)/app/test debian/dpdk-dev/usr/share/dpdk/test/
237         # since we move libs to multiarch dirs update the non aware symlink
238         rm debian/dpdk-dev/usr/share/dpdk/$(RTE_TARGET)/lib
239         ln -rs debian/dpdk-dev/$(LIBDIR)/ \
240                 debian/dpdk-dev/usr/share/dpdk/$(RTE_TARGET)/lib
241         # Package: libdpdk-dev (bare headers, static devel libs and linker
242         # script)
243         mkdir -p debian/libdpdk-dev/$(LIBDIR)
244         # linker script
245         mv debian/dpdk/$(LIBDIR)/libdpdk.so debian/libdpdk-dev/$(LIBDIR)/
246         # includes
247         mkdir -p debian/libdpdk-dev/usr/include
248         mv debian/dpdk-dev/usr/include/dpdk debian/libdpdk-dev/usr/include/
249         # all static libs are in the dev package
250 ifeq (y,$(BUILD_STATIC_LIB))
251         mv debian/dpdk/$(LIBDIR)/lib*.a debian/libdpdk-dev/$(LIBDIR)/
252 endif
253         # symlinks to last .so's are in the non versioned libdpdk-dev as well
254         # this allows multiple libdpdk-<NAME><VER> at different VER concurrently
255         # libdpdk-dev depends on all sublibs so symlinks are never broken
256         mv debian/dpdk/$(LIBDIR)/*.so debian/libdpdk-dev/$(LIBDIR)/
257         # Package(s): libdpdk-<NAME><VER> (bare runtime libs)
258         for lib in $$(ls -1 debian/dpdk/$(LIBDIR)/*.so.*); do \
259           BN=$$(basename $${lib}); \
260           VER=$$(echo $${BN} | sed -e 's/^.*\.so\.//'); \
261           LN=$$(echo $${BN} | sed -e 's/\.so\.[0-9]*$$//' | tr '_' '-'); \
262           if echo $${LN} | grep -q ".*[0-9]$$"; then \
263             PKG=$${LN}-$${VER}; \
264           else \
265             PKG=$${LN}$${VER}; \
266           fi; \
267           LIBF="$$(basename $${lib})"; \
268           LIBD="debian/$${PKG}/$(LIBDIR)"; \
269           echo "moving $${lib} for library $${PKG}"; \
270           mkdir -p $${LIBD}; \
271           mv $${lib} $${LIBD}; \
272           if [ "$${LIBF#librte_pmd_}x" != "$${LIBF}x" ]; then \
273             mkdir -p $${LIBD}/dpdk-pmds; \
274             echo "PMD: linking $${LIBF} into RTE_EAL_PMD_PATH at $${LIBD}/dpdk-pmds/"; \
275             ln -s --relative --target-directory=$${LIBD}/dpdk-pmds/ $${LIBD}/$${LIBF}; \
276           fi; \
277           if [ "$${LIBF#librte_eal}x" != "$${LIBF}x" ]; then \
278             mkdir -p $${LIBD}/dpdk-pmds; \
279           fi; \
280         done
281         # pkg-config
282         mkdir -p debian/libdpdk-dev/$(LIBDIR)/pkgconfig
283         LIBS=$$(sed -e 's/GROUP ( \(.*\) )/\1/' -e 's/lib/-l/g' -e 's/\.so//g' \
284                 $(CURDIR)/debian/libdpdk-dev/$(LIBDIR)/libdpdk.so); \
285         sed -e "s/@DPDK_LIBS@/$${LIBS}/" -e "s/@VERSION@/$(VERSION)/" \
286                 -e "s|@LIBDIR@|$(LIBDIR)|" \
287                 debian/libdpdk.pc.in > debian/libdpdk-dev/$(LIBDIR)/pkgconfig/libdpdk.pc
288         # Package: dpdk-igb-uio-dkms
289         mkdir -p debian/dpdk-igb-uio-dkms/usr/src/dpdk-igb-uio-$(VERSION)
290         cp lib/librte_eal/linuxapp/igb_uio/* \
291                 debian/dpdk-igb-uio-dkms/usr/src/dpdk-igb-uio-$(VERSION)
292         # Package: dpdk-rte-kni-dkms
293         mkdir -p debian/dpdk-rte-kni-dkms/usr/src/dpdk-rte-kni-$(VERSION)
294         cp -a lib/librte_eal/linuxapp/kni/* \
295                 debian/dpdk-rte-kni-dkms/usr/src/dpdk-rte-kni-$(VERSION)
296 ifneq (,$(KVERS))
297         # Package: dpdk-modules-<kernel version>
298         $(MAKE) V=$(DH_VERBOSE) O=$(DPDK_SHARED_DIR) \
299                 kerneldir=/lib/modules/$(KVERS)/extra/dpdk \
300                 DESTDIR=debian/dpdk-modules-$(KVERS) install-kmod
301 endif
302
303 debian/libethdev4.links: debian/libethdev4.links.in
304         sed -e 's/@DEB_HOST_MULTIARCH@/$(DEB_HOST_MULTIARCH)/g' < $< > $@
305 debian/librte-cryptodev1.links: debian/librte-cryptodev1.links.in
306         sed -e 's/@DEB_HOST_MULTIARCH@/$(DEB_HOST_MULTIARCH)/g' < $< > $@
307 debian/librte-eal2.links: debian/librte-eal2.links.in
308         sed -e 's/@DEB_HOST_MULTIARCH@/$(DEB_HOST_MULTIARCH)/g' < $< > $@
309 override_dh_link: debian/libethdev4.links debian/librte-cryptodev1.links debian/librte-eal2.links
310         dh_link
311
312 override_dh_dkms:
313         dh_dkms -V $(VERSION)
314
315 override_dh_installinit:
316         dh_installinit --no-start --no-restart-on-upgrade
317
318 override_dh_systemd_start:
319         dh_systemd_start --no-start --no-restart-on-upgrade
320
321 override_dh_auto_test:
322