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