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