ef7af4022c49b862372f238b837256762b517ef8
[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 # see EXAMPLES in dpkg-buildflags(1) and read /usr/share/dpkg/*
8 include /usr/share/dpkg/default.mk
9
10 DPDK_ABI := $(shell echo $(DEB_VERSION_UPSTREAM) | cut -d '-' -f1 | cut -d '.'  -f1-2 | cut -d '~' -f1)
11
12 # see FEATURE AREAS in dpkg-buildflags(1)
13 export DEB_BUILD_MAINT_OPTIONS = hardening=+all,-pie
14
15 # see ENVIRONMENT in dpkg-buildflags(1)
16 DPKG_EXPORT_BUILDFLAGS = 1
17 include /usr/share/dpkg/buildflags.mk
18
19 # Support backporting to jessie
20 dpkg_version_lt = $(shell dpkg --compare-versions $$(dpkg --status dpkg-dev | grep Version | cut -d' ' -f2) lt-nl "1.18.11" && echo yes)
21 ifeq (yes, $(dpkg_version_lt))
22         # package maintainers to append CFLAGS
23         # For Debian, dpkg-dev >= 1.18.11 and gcc 6.x, dpkg-buildflags and gcc
24         # handle -fPIC and related flags relying on specs files
25         # (/usr/share/dpkg/*specs)
26         export DEB_CFLAGS_MAINT_APPEND  = -fPIC
27         export EXTRA_CFLAGS=$(CFLAGS)
28         export EXTRA_CPPFLAGS=$(CPPFLAGS)
29         export HOST_EXTRA_CFLAGS=$(CFLAGS)
30         export HOST_EXTRA_CPPFLAGS=$(CPPFLAGS)
31         # need to be stripped as DPDK build system adds them and it would be -Wl,-Wl,opt
32         export EXTRA_LDFLAGS=$(shell echo $(LDFLAGS) | sed 's/-Wl,//g')
33         # HOST_CC build system does not add -Wl ...
34         export EXTRA_HOST_LDFLAGS=$(LDFLAGS)
35 endif
36
37 export RTE_DEVEL_BUILD=n
38 export EXTRA_CFLAGS+=-g
39
40 # People rebuilding this package can overwrite DPDK_CONFIG, RTE_MACHINE and
41 # RTE_TARGET via DEB_BUILD_OPTIONS if they like
42 ifneq (,$(filter dpdk_config=%,$(DEB_BUILD_OPTIONS)))
43     DPDK_CONFIG ?= $(patsubst dpdk_config=%,%,$(filter dpdk_config=%,$(DEB_BUILD_OPTIONS)))
44 endif
45 ifneq (,$(filter rte_machine=%,$(DEB_BUILD_OPTIONS)))
46     RTE_MACHINE ?= $(patsubst rte_machine=%,%,$(filter rte_machine=%,$(DEB_BUILD_OPTIONS)))
47 endif
48 ifneq (,$(filter rte_target=%,$(DEB_BUILD_OPTIONS)))
49     RTE_TARGET ?= $(patsubst rte_target=%,%,$(filter rte_target=%,$(DEB_BUILD_OPTIONS)))
50 endif
51
52 ifneq (,$(filter $(DEB_HOST_ARCH), arm64))
53 DPDK_CONFIG ?= "arm64-armv8a-linuxapp-gcc"
54 RTE_MACHINE ?= "armv8a"
55 RTE_TARGET ?= "arm64-armv8a-linuxapp-gcc"
56 INCLUDE_ARCH := arm
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 INCLUDE_ARCH := ppc_64
63 else
64 DPDK_CONFIG ?= "$(DEB_HOST_GNU_CPU)-native-linuxapp-gcc"
65 RTE_MACHINE ?= "default"
66 RTE_TARGET ?= "$(DEB_HOST_GNU_CPU)-default-linuxapp-gcc"
67 INCLUDE_ARCH := x86
68 endif
69 endif
70 DPDK_STATIC_DIR = "debian/build/static-root"
71 DPDK_SHARED_DIR = "debian/build/shared-root"
72
73 # now stable with parallel comilation, so support -j
74 ifneq (,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
75     PAR := $(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
76     MAKEFLAGS += -j$(PAR)
77 endif
78
79 ifneq (,$(findstring nodoc,$(DEB_BUILD_OPTIONS)))
80 BUILD_DOCS=n
81 else
82 BUILD_DOCS=y
83 endif
84
85 ifneq (,$(findstring nostatic,$(DEB_BUILD_OPTIONS)))
86 BUILD_STATIC_LIB=n
87 else
88 BUILD_STATIC_LIB=y
89 endif
90
91 # kernel_modules can be passed via DEB_BUILD_OPTIONS to enable building the
92 # optional binary kernel modules package. By default it will be built against
93 # the current kernel, or ksrc can be passed with a path to the target kernel
94 # sources instead.
95 ifeq (,$(findstring kernel_modules,$(DEB_BUILD_OPTIONS)))
96 DPDK_CONFIG_BUILD_KMOD=n
97 KSRC=""
98 else
99 ifneq (,$(filter ksrc=%,$(DEB_BUILD_OPTIONS)))
100     KSRC := $(patsubst ksrc=%,%,$(filter ksrc=%,$(DEB_BUILD_OPTIONS)))
101 else
102     KSRC := /lib/modules/$(shell uname -r)/build
103 endif
104
105 KVERS := $(shell perl debian/kernel-version $(KSRC))
106 export KVERS
107 export MODULE_CFLAGS=-fno-PIE
108
109 DPDK_CONFIG_BUILD_KMOD=y
110
111 # Since the binary module package is generated at build time depending on the
112 # local kernel version, we have to append the new package in d/control.
113 # We cannot use a separate control file since that wouldn't work with
114 # dpkg-genchanges, and also would require a lot of overrides for debhelpers.
115 get_built_using ?= $(filter-out (=),$(shell dpkg-query -f='$${source:Package} (=$${source:Version})' -W $1))
116
117 build:
118         @if [ x"$(KVERS)" = x ] ; then \
119             echo 'No version in $(KSRC)/include/linux/version.h' >&2; \
120             exit 1; \
121         fi
122         sh debian/prep-modules $(KSRC)
123         cat debian/control.modules >> debian/control
124         dh $@ --with python3,dkms,systemd
125 endif
126
127 %:
128         dh $@ --with python3,dkms,systemd
129
130 override_dh_gencontrol:
131         dh_gencontrol
132         # debian/files will not exist until dh_gencontrol has ran at least once,
133         # so we need to run gencontrol for libdpdk-dev and libdpdk-dbgsym after.
134         # The list of libraries and PMDs is everchanging, so generate the dependency
135         # list for libdpdk-dev to avoid having to maintain it manually.
136         # Same for the recommends list for dpdk, were we want the PMDs and the mempools.
137         dh_gencontrol -p libdpdk-dev -- -V"librte:Depends=`grep -E 'librte-*' ./debian/files | grep -v dbgsym | tr '_' ' ' | awk '{ print $$1,"(=",$$2 ")" }' | paste -sd ',' - | sed -e 's/,/, /g'`"
138         dh_gencontrol -p dpdk -- -V"librte:Recommends=`grep -E 'librte-(pmd|mempool).*' ./debian/files | grep -v dbgsym | tr '_' ' ' | awk '{ print $$1,"(=",$$2 ")" }' | paste -sd ',' - | sed -e 's/,/, /g'`"
139 ifneq (,$(findstring kernel_modules,$(DEB_BUILD_OPTIONS)))
140         dh_gencontrol -p dpdk-modules-$(KVERS) -- \
141                 -v`cat debian/VERSION` \
142                 -V'built:using:kernel=$(call get_built_using,linux-headers-$(KVERS))'
143 endif
144 ifneq (,$(findstring dbgsym_meta,$(DEB_BUILD_OPTIONS)))
145         ./debian/dh-dbgsym-metapkg libdpdk$(DPDK_ABI)-dbgsym
146 endif
147
148 # dbgsym_meta can be passed via DEB_BUILD_OPTIONS to enable building the
149 # optional dbgsym meta package libdpdk<ABI>-dbgsym.
150 # This is not built by default as it would go in main but depend on
151 # packages in the debian-debug archive.
152 # Debian Developers and FTP masters strongly discourage this.
153 # We provide this optional flag as a convenience for rebuilders.
154 ifneq (,$(findstring dbgsym_meta,$(DEB_BUILD_OPTIONS)))
155 override_dh_builddeb:
156         dh_builddeb
157         dh_builddeb -plibdpdk$(DPDK_ABI)-dbgsym
158 endif
159
160 override_dh_auto_clean:
161         rm -rf debian/build debian/tmp debian/dpdk-modules-* \
162                 debian/control.modules debian/VERSION
163         sed -i '/Package: dpdk-modules-/,/`tail -n1 debian/control.modules.in`/d' debian/control
164         test -L config/defconfig_$(DPDK_CONFIG) && rm -f config/defconfig_$(DPDK_CONFIG) || true
165         rm -f debian/dpdk-igb-uio-dkms.dkms debian/dpdk-rte-kni-dkms.dkms
166         rm -f debian/dpdk-dev.preinst
167
168 override_dh_auto_configure:
169         # Add support for a custom defconfig file in the debian directory.
170 ifneq (,$(filter dpdk_config=%,$(DEB_BUILD_OPTIONS)))
171         test -e config/defconfig_$(DPDK_CONFIG) || ln -fs ../debian/defconfig_$(DPDK_CONFIG) config/defconfig_$(DPDK_CONFIG)
172 endif
173         # report dpkg-buildflags status to build log
174         dpkg-buildflags --status
175         echo EXTRA_CFLAGS $$EXTRA_CFLAGS
176         echo EXTRA_LDFLAGS: $$EXTRA_LDFLAGS
177         $(MAKE) V=$(DH_VERBOSE) O=$(DPDK_STATIC_DIR) T=$(DPDK_CONFIG) config
178 ifeq (,$(filter dpdk_config=%,$(DEB_BUILD_OPTIONS)))
179         sed -ri -e 's,(RTE_MACHINE=).*,\1$(RTE_MACHINE),' \
180                 -e 's,(RTE_NEXT_ABI=).*,\1n,' \
181                 -e 's,(CONFIG_RTE_EAL_IGB_UIO=).*,\1$(DPDK_CONFIG_BUILD_KMOD),' \
182                 -e 's,(CONFIG_RTE_KNI_KMOD=).*,\1$(DPDK_CONFIG_BUILD_KMOD),' \
183                 -e 's,(LIBRTE_PMD_PCAP=).*,\1y,' \
184                 -e 's,(CONFIG_RTE_EAL_PMD_PATH=).*,\1"/usr/lib/$(DEB_HOST_MULTIARCH)/dpdk-pmds/",' \
185                 $(DPDK_STATIC_DIR)/.config
186 endif
187         echo "CONFIG_RTE_MAJOR_ABI=\"$(DPDK_ABI)\"" >> \
188                 $(DPDK_STATIC_DIR)/.config
189         dh_auto_configure
190
191 override_dh_auto_build-indep:
192 ifeq (y,$(BUILD_DOCS))
193         $(MAKE) V=$(DH_VERBOSE) O=$(DPDK_STATIC_DIR) doc-api-html doc-guides-html
194 endif
195
196 override_dh_auto_install-indep:
197         # Package: dpdk-doc
198         # All files based on the install-doc rule (includes examples)
199 ifeq (y,$(BUILD_DOCS))
200         $(MAKE) V=$(DH_VERBOSE) O=$(DPDK_STATIC_DIR) prefix=/usr \
201                 DESTDIR=debian/dpdk-doc install-doc
202 endif
203
204 override_dh_auto_build-arch:
205 ifeq (y,$(BUILD_STATIC_LIB))
206         $(MAKE) V=$(DH_VERBOSE) O=$(DPDK_STATIC_DIR) RTE_KERNELDIR=$(KSRC) build
207 endif
208         # Unfortunately the decision about having static or shared libraries is
209         # made for the whole build, which then produces only .a or .so files
210         # (but not both).
211         # And the target layout for target selection has no field for the
212         # type of library.
213         # Right now I hack this by doing a second build which only differs in
214         # the selection of shared libs.
215         # Shared libs should be default, so the previous static build is only
216         # used to get static libraries.
217         cp -a $(DPDK_STATIC_DIR) $(DPDK_SHARED_DIR)
218         sed -ri 's,(RTE_BUILD_SHARED_LIB=).*,\1y,' \
219                 $(DPDK_SHARED_DIR)/.config
220         $(MAKE) V=$(DH_VERBOSE) O=$(DPDK_SHARED_DIR) RTE_KERNELDIR=$(KSRC) build
221 ifeq (y,$(BUILD_DOCS))
222         # need to be around for dh_installman to be picked up
223         $(MAKE) V=$(DH_VERBOSE) O=$(DPDK_SHARED_DIR) RTE_KERNELDIR=$(KSRC) doc-guides-man
224 endif
225         $(MAKE) V=$(DH_VERBOSE) O=$(DPDK_SHARED_DIR) RTE_KERNELDIR=$(KSRC) test-build
226
227 override_dh_auto_install-arch: LIBDIR=/usr/lib/$(DEB_HOST_MULTIARCH)
228 override_dh_auto_install-arch:
229         # Package: dpdk (runtime)
230 ifeq (y,$(BUILD_STATIC_LIB))
231         $(MAKE) V=$(DH_VERBOSE) O=$(DPDK_STATIC_DIR) prefix=/usr libdir=$(LIBDIR) \
232                 DESTDIR=debian/dpdk install-runtime
233 endif
234         $(MAKE) V=$(DH_VERBOSE) O=$(DPDK_SHARED_DIR) prefix=/usr libdir=$(LIBDIR) \
235                 DESTDIR=debian/dpdk install-runtime
236         mkdir -p debian/dpdk/etc/dpdk
237         cp debian/dpdk.interfaces debian/dpdk/etc/dpdk/interfaces
238         rm debian/dpdk/usr/sbin/dpdk-devbind
239         mkdir -p debian/dpdk/sbin
240         ln -s /usr/share/dpdk/usertools/dpdk-devbind.py \
241                 debian/dpdk/sbin/dpdk-devbind
242         # Package: dpdk-dev (build environment)
243         # workaround to fix symbolic link creation
244         mkdir -p debian/dpdk-dev/$(LIBDIR)
245         $(MAKE) V=$(DH_VERBOSE) O=$(DPDK_SHARED_DIR) prefix=/usr libdir=$(LIBDIR) \
246                 DESTDIR=debian/dpdk-dev install-sdk
247         # remove workaround
248         rm -fr debian/dpdk-dev/usr/lib
249         cp $(DPDK_SHARED_DIR)/.config debian/dpdk-dev/usr/share/dpdk/config
250         sed -e 's/SDK_TARGET/$(RTE_TARGET)/' debian/dpdk-sdk-env.sh.in > \
251                 debian/dpdk-dev/usr/share/dpdk/dpdk-sdk-env.sh
252         # include the bundled autotest suite to be usable from the dpdk-dev package
253         if grep -qs 'CONFIG_RTE_APP_TEST=y' $(DPDK_SHARED_DIR)/.config; then \
254                 mkdir -p debian/dpdk-dev/usr/share/dpdk/test; \
255                 cp -a test/test/autotest* debian/dpdk-dev/usr/share/dpdk/test; \
256                 cp $(DPDK_SHARED_DIR)/app/test debian/dpdk-dev/usr/share/dpdk/test/; \
257                 cp $(DPDK_SHARED_DIR)/app/testacl debian/dpdk-dev/usr/share/dpdk/test/; \
258                 cp $(DPDK_SHARED_DIR)/app/testpipeline debian/dpdk-dev/usr/share/dpdk/test/; \
259         fi
260         # since we move libs to multiarch dirs update the non aware symlink
261         rm debian/dpdk-dev/usr/share/dpdk/$(RTE_TARGET)/lib
262         ln -rs debian/dpdk-dev/$(LIBDIR)/ \
263                 debian/dpdk-dev/usr/share/dpdk/$(RTE_TARGET)/lib
264         # Package: libdpdk-dev (bare headers, static devel libs and linker
265         # script)
266         mkdir -p debian/libdpdk-dev/$(LIBDIR)
267         # linker script
268         mv debian/dpdk/$(LIBDIR)/libdpdk.so debian/libdpdk-dev/$(LIBDIR)/
269         # includes
270         # Some headers have architecture-specific content, but the upstream build
271         # system installs them in the same directory, breaking multiarch.
272         # Move them in /usr/include/<arch>/dpdk instead.
273         mkdir -p debian/libdpdk-dev/usr/include/$(DEB_HOST_MULTIARCH)/dpdk
274         # Before moving the files, remove the symlink in usr/share/dpdk and copy them over,
275         # as the SDK subdir is architecture specific and requires the arch-specific headers
276         # in the top level
277         rm -f debian/dpdk-dev/usr/share/dpdk/$(RTE_TARGET)/include
278         mkdir -p debian/dpdk-dev/usr/share/dpdk/$(RTE_TARGET)/include
279         cp -r debian/dpdk-dev/usr/include/dpdk/* debian/dpdk-dev/usr/share/dpdk/$(RTE_TARGET)/include
280         # genereate the preinst to deal with the symlink -> directory transition smoothly
281         sed "s/@@RTE_TARGET@@/$(RTE_TARGET)/g" debian/dpdk-dev.preinst.in > debian/dpdk-dev.preinst
282         mv $(addprefix debian/dpdk-dev/usr/include/dpdk/,$(notdir $(wildcard lib/librte_eal/common/include/arch/$(INCLUDE_ARCH)/*.h))) \
283                 debian/libdpdk-dev/usr/include/$(DEB_HOST_MULTIARCH)/dpdk/
284         mv debian/dpdk-dev/usr/include/dpdk/rte_config.h \
285                 debian/libdpdk-dev/usr/include/$(DEB_HOST_MULTIARCH)/dpdk/
286         mv debian/dpdk-dev/usr/include/dpdk debian/libdpdk-dev/usr/include/
287         rmdir debian/dpdk-dev/usr/include
288         # backward compatibility: to ease things for the majority of users,
289         # which are on x86_64, symlink the x86 headers into the global
290         # directory.
291 ifeq (x86_64-linux-gnu,$(DEB_HOST_MULTIARCH))
292         ln -rs debian/libdpdk-dev/usr/include/$(DEB_HOST_MULTIARCH)/dpdk/*.h \
293                 debian/libdpdk-dev/usr/include/dpdk
294 endif
295         # have the DKMS build include the correct per-arch directory
296         sed "s/@@DEB_HOST_MULTIARCH@@/$(DEB_HOST_MULTIARCH)/g" debian/dpdk-igb-uio-dkms.dkms.in > debian/dpdk-igb-uio-dkms.dkms
297         sed "s/@@DEB_HOST_MULTIARCH@@/$(DEB_HOST_MULTIARCH)/g" debian/dpdk-rte-kni-dkms.dkms.in > debian/dpdk-rte-kni-dkms.dkms
298         # all static libs are in the dev package
299 ifeq (y,$(BUILD_STATIC_LIB))
300         mv debian/dpdk/$(LIBDIR)/lib*.a debian/libdpdk-dev/$(LIBDIR)/
301 endif
302         # symlinks to last .so's are in the non versioned libdpdk-dev as well
303         # this allows multiple libdpdk-<NAME><VER> at different VER concurrently
304         # libdpdk-dev depends on all sublibs so symlinks are never broken
305         mv debian/dpdk/$(LIBDIR)/*.so debian/libdpdk-dev/$(LIBDIR)/
306         # Package(s): libdpdk-<NAME><VER> (bare runtime libs)
307         for lib in $$(ls -1 debian/dpdk/$(LIBDIR)/*.so.*); do \
308           BN=$$(basename $${lib}); \
309           LN=$$(echo $${BN} | sed -e 's/\.so\.[0-9\.]*$$//' | tr '_' '-'); \
310           if echo $${LN} | grep -q ".*[0-9]$$"; then \
311             PKG=$${LN}-$(DPDK_ABI); \
312           else \
313             PKG=$${LN}$(DPDK_ABI); \
314           fi; \
315           LIBF="$$(basename $${lib})"; \
316           LIBD="debian/$${PKG}/$(LIBDIR)"; \
317           echo "moving $${lib} to dir $${LIBD} (PKG=$${PKG} BN=$${BN} LN={$${LN} LIBF=$${LIBF} LIBD=$${LIBD})"; \
318           mkdir -p $${LIBD}; \
319           mv $${lib} $${LIBD}; \
320           if [ "$${LIBF#librte_pmd_}x" != "$${LIBF}x" ]; then \
321             mkdir -p $${LIBD}/dpdk-pmds; \
322             echo "PMD: linking $${LIBF} into RTE_EAL_PMD_PATH at $${LIBD}/dpdk-pmds/"; \
323             ln -s --relative --target-directory=$${LIBD}/dpdk-pmds/ $${LIBD}/$${LIBF}; \
324           fi; \
325           if [ "$${LIBF#librte_mempool_}x" != "$${LIBF}x" ]; then \
326             mkdir -p $${LIBD}/dpdk-pmds; \
327             echo "MEMPOOL: linking $${LIBF} into RTE_EAL_PMD_PATH at $${LIBD}/dpdk-pmds/"; \
328             ln -s --relative --target-directory=$${LIBD}/dpdk-pmds/ $${LIBD}/$${LIBF}; \
329           fi; \
330           if [ "$${LIBF#librte_eal}x" != "$${LIBF}x" ]; then \
331             mkdir -p $${LIBD}/dpdk-pmds; \
332           fi; \
333         done
334         # pkg-config
335         mkdir -p debian/libdpdk-dev/$(LIBDIR)/pkgconfig
336         LIBS=$$(sed -e 's/GROUP ( \(.*\) )/\1/' -e 's/lib/-l/g' -e 's/\.so//g' \
337                 $(CURDIR)/debian/libdpdk-dev/$(LIBDIR)/libdpdk.so); \
338         sed -e "s/@DPDK_LIBS@/$${LIBS}/" -e "s/@VERSION@/$(DEB_VERSION_UPSTREAM)/" \
339                 -e "s|@DEB_HOST_MULTIARCH@|$(DEB_HOST_MULTIARCH)|g" \
340                 debian/libdpdk.pc.in > debian/libdpdk-dev/$(LIBDIR)/pkgconfig/libdpdk.pc
341         # Package: dpdk-igb-uio-dkms
342         mkdir -p debian/dpdk-igb-uio-dkms/usr/src/dpdk-igb-uio-$(DEB_VERSION_UPSTREAM)
343         cp lib/librte_eal/linuxapp/igb_uio/* \
344                 debian/dpdk-igb-uio-dkms/usr/src/dpdk-igb-uio-$(DEB_VERSION_UPSTREAM)
345         # Package: dpdk-rte-kni-dkms
346         mkdir -p debian/dpdk-rte-kni-dkms/usr/src/dpdk-rte-kni-$(DEB_VERSION_UPSTREAM)
347         cp -a lib/librte_eal/linuxapp/kni/* \
348                 debian/dpdk-rte-kni-dkms/usr/src/dpdk-rte-kni-$(DEB_VERSION_UPSTREAM)
349 ifneq (,$(KVERS))
350         # Package: dpdk-modules-<kernel version>
351         $(MAKE) V=$(DH_VERBOSE) O=$(DPDK_SHARED_DIR) \
352                 kerneldir=/lib/modules/$(KVERS)/extra/dpdk \
353                 DESTDIR=debian/dpdk-modules-$(KVERS) install-kmod
354 endif
355
356 override_dh_dkms:
357         dh_dkms -V $(DEB_VERSION_UPSTREAM)
358
359 override_dh_installinit:
360         dh_installinit --no-start --no-restart-on-upgrade
361
362 override_dh_systemd_start:
363         dh_systemd_start --no-start --no-restart-on-upgrade
364
365 override_dh_auto_test:
366