Remove old compatibility transitional packages
[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 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
15 # see FEATURE AREAS in dpkg-buildflags(1)
16 export DEB_BUILD_MAINT_OPTIONS = hardening=+all,-pie
17
18 # see ENVIRONMENT in dpkg-buildflags(1)
19 DPKG_EXPORT_BUILDFLAGS = 1
20 include /usr/share/dpkg/buildflags.mk
21
22 # Support backporting to jessie
23 dpkg_version_lt = $(shell dpkg --compare-versions $$(dpkg --status dpkg-dev | grep Version | cut -d' ' -f2) lt-nl "1.18.11" && echo yes)
24 ifeq (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)
38 endif
39
40 export 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
44 ifneq (,$(filter dpdk_config=%,$(DEB_BUILD_OPTIONS)))
45     DPDK_CONFIG ?= $(patsubst dpdk_config=%,%,$(filter dpdk_config=%,$(DEB_BUILD_OPTIONS)))
46 endif
47 ifneq (,$(filter rte_machine=%,$(DEB_BUILD_OPTIONS)))
48     RTE_MACHINE ?= $(patsubst rte_machine=%,%,$(filter rte_machine=%,$(DEB_BUILD_OPTIONS)))
49 endif
50 ifneq (,$(filter rte_target=%,$(DEB_BUILD_OPTIONS)))
51     RTE_TARGET ?= $(patsubst rte_target=%,%,$(filter rte_target=%,$(DEB_BUILD_OPTIONS)))
52 endif
53
54 ifneq (,$(filter $(DEB_HOST_ARCH), arm64))
55 DPDK_CONFIG ?= "arm64-armv8a-linuxapp-gcc"
56 RTE_MACHINE ?= "armv8a"
57 RTE_TARGET ?= "arm64-armv8a-linuxapp-gcc"
58 else
59 ifneq (,$(filter $(DEB_HOST_ARCH), ppc64el))
60 DPDK_CONFIG ?= "ppc_64-power8-linuxapp-gcc"
61 RTE_MACHINE ?= "power8"
62 RTE_TARGET ?= "ppc_64-power8-linuxapp-gcc"
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 endif
68 endif
69 DPDK_STATIC_DIR = "debian/build/static-root"
70 DPDK_SHARED_DIR = "debian/build/shared-root"
71
72 # now stable with parallel comilation, so support -j
73 ifneq (,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
74     PAR := $(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
75     MAKEFLAGS += -j$(PAR)
76 endif
77
78 ifneq (,$(findstring nodoc,$(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 build:
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
124 endif
125
126 %:
127         dh $@ --with python2,dkms
128
129 override_dh_gencontrol:
130         dh_gencontrol
131         # debian/files will not exist until dh_gencontrol has ran at least once,
132         # so we need to run gencontrol for libdpdk-dev and libdpdk-dbgsym after.
133         # The list of libraries and PMDs is everchanging, so generate the dependency
134         # list for libdpdk-dev to avoid having to maintain it manually.
135         # Same for the recommends list for dpdk, were we want the PMDs and the mempools.
136         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'`"
137         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'`"
138 ifneq (,$(findstring kernel_modules,$(DEB_BUILD_OPTIONS)))
139         dh_gencontrol -p dpdk-modules-$(KVERS) -- \
140                 -v`cat debian/VERSION` \
141                 -V'built:using:kernel=$(call get_built_using,linux-headers-$(KVERS))'
142 endif
143 ifneq (,$(findstring dbgsym_meta,$(DEB_BUILD_OPTIONS)))
144         ./debian/dh-dbgsym-metapkg libdpdk$(DPDK_ABI)-dbgsym
145 endif
146
147 # dbgsym_meta can be passed via DEB_BUILD_OPTIONS to enable building the
148 # optional dbgsym meta package libdpdk<ABI>-dbgsym.
149 # This is not built by default as it would go in main but depend on
150 # packages in the debian-debug archive.
151 # Debian Developers and FTP masters strongly discourage this.
152 # We provide this optional flag as a convenience for rebuilders.
153 ifneq (,$(findstring dbgsym_meta,$(DEB_BUILD_OPTIONS)))
154 override_dh_builddeb:
155         dh_builddeb
156         dh_builddeb -plibdpdk$(DPDK_ABI)-dbgsym
157 endif
158
159 override_dh_auto_clean:
160         rm -rf debian/build debian/tmp debian/dpdk-modules-* \
161                 debian/control.modules debian/VERSION
162         sed -i '/Package: dpdk-modules-/,/`tail -n1 debian/control.modules.in`/d' debian/control
163         test -L config/defconfig_$(DPDK_CONFIG) && rm -f config/defconfig_$(DPDK_CONFIG) || true
164
165 override_dh_auto_configure:
166         # Add support for a custom defconfig file in the debian directory.
167 ifneq (,$(filter dpdk_config=%,$(DEB_BUILD_OPTIONS)))
168         test -e config/defconfig_$(DPDK_CONFIG) || ln -fs ../debian/defconfig_$(DPDK_CONFIG) config/defconfig_$(DPDK_CONFIG)
169 endif
170         # report dpkg-buildflags status to build log
171         dpkg-buildflags --status
172         echo EXTRA_CFLAGS $$EXTRA_CFLAGS
173         echo EXTRA_LDFLAGS: $$EXTRA_LDFLAGS
174         $(MAKE) V=$(DH_VERBOSE) O=$(DPDK_STATIC_DIR) T=$(DPDK_CONFIG) config
175 ifeq (,$(filter dpdk_config=%,$(DEB_BUILD_OPTIONS)))
176         sed -ri -e 's,(RTE_MACHINE=).*,\1$(RTE_MACHINE),' \
177                 -e 's,(RTE_NEXT_ABI=).*,\1n,' \
178                 -e 's,(CONFIG_RTE_EAL_IGB_UIO=).*,\1$(DPDK_CONFIG_BUILD_KMOD),' \
179                 -e 's,(CONFIG_RTE_KNI_KMOD=).*,\1$(DPDK_CONFIG_BUILD_KMOD),' \
180                 -e 's,(LIBRTE_PMD_PCAP=).*,\1y,' \
181                 -e 's,(LIBRTE_PMD_XENVIRT=).*,\1y,' \
182                 -e 's,(CONFIG_RTE_EAL_PMD_PATH=).*,\1"/usr/lib/$(shell dpkg-architecture -qDEB_HOST_MULTIARCH)/dpdk-pmds/",' \
183                 $(DPDK_STATIC_DIR)/.config
184         # xen not available on ppc64el
185 ifneq (,$(filter $(DEB_HOST_ARCH), ppc64el))
186         sed -ri -e 's,(LIBRTE_PMD_XENVIRT=).*,\1n,' $(DPDK_STATIC_DIR)/.config
187 endif
188 endif
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
226 override_dh_auto_install-arch: LIBDIR=/usr/lib/$(shell dpkg-architecture -qDEB_HOST_MULTIARCH)
227 override_dh_auto_install-arch:
228         # Package: dpdk (runtime)
229 ifeq (y,$(BUILD_STATIC_LIB))
230         $(MAKE) V=$(DH_VERBOSE) O=$(DPDK_STATIC_DIR) prefix=/usr libdir=$(LIBDIR) \
231                 DESTDIR=debian/dpdk install-runtime
232 endif
233         $(MAKE) V=$(DH_VERBOSE) O=$(DPDK_SHARED_DIR) prefix=/usr libdir=$(LIBDIR) \
234                 DESTDIR=debian/dpdk install-runtime
235         mkdir -p debian/dpdk/etc/dpdk
236         cp debian/dpdk.interfaces debian/dpdk/etc/dpdk/interfaces
237         rm debian/dpdk/usr/sbin/dpdk-devbind
238         mkdir -p debian/dpdk/sbin
239         ln -s /usr/share/dpdk/tools/dpdk-devbind.py \
240                 debian/dpdk/sbin/dpdk-devbind
241         # Package: dpdk-dev (build environment)
242         # workaround to fix symbolic link creation
243         mkdir -p debian/dpdk-dev/$(LIBDIR)
244         $(MAKE) V=$(DH_VERBOSE) O=$(DPDK_SHARED_DIR) prefix=/usr libdir=$(LIBDIR) \
245                 DESTDIR=debian/dpdk-dev install-sdk
246         # remove workaround
247         rm -fr debian/dpdk-dev/usr/lib
248         cp $(DPDK_SHARED_DIR)/.config debian/dpdk-dev/usr/share/dpdk/config
249         sed -e 's/SDK_TARGET/$(RTE_TARGET)/' debian/dpdk-sdk-env.sh.in > \
250                 debian/dpdk-dev/usr/share/dpdk/dpdk-sdk-env.sh
251         # include the bundled autotest suite to be usable from the dpdk-dev package
252         mkdir -p debian/dpdk-dev/usr/share/dpdk/test
253         cp -a app/test/autotest* debian/dpdk-dev/usr/share/dpdk/test
254         cp $(DPDK_SHARED_DIR)/app/test debian/dpdk-dev/usr/share/dpdk/test/
255         # since we move libs to multiarch dirs update the non aware symlink
256         rm debian/dpdk-dev/usr/share/dpdk/$(RTE_TARGET)/lib
257         ln -rs debian/dpdk-dev/$(LIBDIR)/ \
258                 debian/dpdk-dev/usr/share/dpdk/$(RTE_TARGET)/lib
259         # Package: libdpdk-dev (bare headers, static devel libs and linker
260         # script)
261         mkdir -p debian/libdpdk-dev/$(LIBDIR)
262         # linker script
263         mv debian/dpdk/$(LIBDIR)/libdpdk.so debian/libdpdk-dev/$(LIBDIR)/
264         # includes
265         mkdir -p debian/libdpdk-dev/usr/include
266         mv debian/dpdk-dev/usr/include/dpdk debian/libdpdk-dev/usr/include/
267         # all static libs are in the dev package
268 ifeq (y,$(BUILD_STATIC_LIB))
269         mv debian/dpdk/$(LIBDIR)/lib*.a debian/libdpdk-dev/$(LIBDIR)/
270 endif
271         # symlinks to last .so's are in the non versioned libdpdk-dev as well
272         # this allows multiple libdpdk-<NAME><VER> at different VER concurrently
273         # libdpdk-dev depends on all sublibs so symlinks are never broken
274         mv debian/dpdk/$(LIBDIR)/*.so debian/libdpdk-dev/$(LIBDIR)/
275         # Package(s): libdpdk-<NAME><VER> (bare runtime libs)
276         for lib in $$(ls -1 debian/dpdk/$(LIBDIR)/*.so.*); do \
277           BN=$$(basename $${lib}); \
278           VER=$$(echo $${BN} | sed -e 's/^.*\.so\.//'); \
279           LN=$$(echo $${BN} | sed -e 's/\.so\.[0-9]*$$//' | tr '_' '-'); \
280           if echo $${LN} | grep -q ".*[0-9]$$"; then \
281             PKG=$${LN}-$${VER}; \
282           else \
283             PKG=$${LN}$${VER}; \
284           fi; \
285           LIBF="$$(basename $${lib})"; \
286           LIBD="debian/$${PKG}/$(LIBDIR)"; \
287           echo "moving $${lib} for library $${PKG}"; \
288           mkdir -p $${LIBD}; \
289           mv $${lib} $${LIBD}; \
290           if [ "$${LIBF#librte_pmd_}x" != "$${LIBF}x" ]; then \
291             mkdir -p $${LIBD}/dpdk-pmds; \
292             echo "PMD: linking $${LIBF} into RTE_EAL_PMD_PATH at $${LIBD}/dpdk-pmds/"; \
293             ln -s --relative --target-directory=$${LIBD}/dpdk-pmds/ $${LIBD}/$${LIBF}; \
294           fi; \
295           if [ "$${LIBF#librte_mempool_}x" != "$${LIBF}x" ]; then \
296             mkdir -p $${LIBD}/dpdk-pmds; \
297             echo "MEMPOOL: linking $${LIBF} into RTE_EAL_PMD_PATH at $${LIBD}/dpdk-pmds/"; \
298             ln -s --relative --target-directory=$${LIBD}/dpdk-pmds/ $${LIBD}/$${LIBF}; \
299           fi; \
300           if [ "$${LIBF#librte_eal}x" != "$${LIBF}x" ]; then \
301             mkdir -p $${LIBD}/dpdk-pmds; \
302           fi; \
303         done
304         # pkg-config
305         mkdir -p debian/libdpdk-dev/$(LIBDIR)/pkgconfig
306         LIBS=$$(sed -e 's/GROUP ( \(.*\) )/\1/' -e 's/lib/-l/g' -e 's/\.so//g' \
307                 $(CURDIR)/debian/libdpdk-dev/$(LIBDIR)/libdpdk.so); \
308         sed -e "s/@DPDK_LIBS@/$${LIBS}/" -e "s/@VERSION@/$(VERSION)/" \
309                 -e "s|@LIBDIR@|$(LIBDIR)|" \
310                 debian/libdpdk.pc.in > debian/libdpdk-dev/$(LIBDIR)/pkgconfig/libdpdk.pc
311         # Package: dpdk-igb-uio-dkms
312         mkdir -p debian/dpdk-igb-uio-dkms/usr/src/dpdk-igb-uio-$(VERSION)
313         cp lib/librte_eal/linuxapp/igb_uio/* \
314                 debian/dpdk-igb-uio-dkms/usr/src/dpdk-igb-uio-$(VERSION)
315         # Package: dpdk-rte-kni-dkms
316         mkdir -p debian/dpdk-rte-kni-dkms/usr/src/dpdk-rte-kni-$(VERSION)
317         cp -a lib/librte_eal/linuxapp/kni/* \
318                 debian/dpdk-rte-kni-dkms/usr/src/dpdk-rte-kni-$(VERSION)
319 ifneq (,$(KVERS))
320         # Package: dpdk-modules-<kernel version>
321         $(MAKE) V=$(DH_VERBOSE) O=$(DPDK_SHARED_DIR) \
322                 kerneldir=/lib/modules/$(KVERS)/extra/dpdk \
323                 DESTDIR=debian/dpdk-modules-$(KVERS) install-kmod
324 endif
325
326 override_dh_dkms:
327         dh_dkms -V $(VERSION)
328
329 override_dh_installinit:
330         dh_installinit --no-start --no-restart-on-upgrade
331
332 override_dh_systemd_start:
333         dh_systemd_start --no-start --no-restart-on-upgrade
334
335 override_dh_auto_test:
336