Merge "debian/changelog: move post-first-debian-release changes to a new changelog...
[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 # kernel_modules can be passed via DEB_BUILD_OPTIONS to enable building the
79 # optional binary kernel modules package. By default it will be built against
80 # the current kernel, or ksrc can be passed with a path to the target kernel
81 # sources instead.
82 ifeq (,$(findstring kernel_modules,$(DEB_BUILD_OPTIONS)))
83 DPDK_CONFIG_BUILD_KMOD=n
84 KSRC=""
85 else
86 ifneq (,$(filter ksrc=%,$(DEB_BUILD_OPTIONS)))
87     KSRC := $(patsubst ksrc=%,%,$(filter ksrc=%,$(DEB_BUILD_OPTIONS)))
88 else
89     KSRC := /lib/modules/$(shell uname -r)/build
90 endif
91
92 KVERS := $(shell perl debian/kernel-version $(KSRC))
93 export KVERS
94
95 DPDK_CONFIG_BUILD_KMOD=y
96
97 # Since the binary module package is generated at build time depending on the
98 # local kernel version, we have to append the new package in d/control.
99 # We cannot use a separate control file since that wouldn't work with
100 # dpkg-genchanges, and also would require a lot of overrides for debhelpers.
101 get_built_using ?= $(filter-out (=),$(shell dpkg-query -f='$${source:Package} (=$${source:Version})' -W $1))
102
103 override_dh_gencontrol:
104         dh_gencontrol
105         dh_gencontrol -p dpdk-modules-$(KVERS) -- \
106                 -v`cat debian/VERSION` \
107                 -V'built:using:kernel=$(call get_built_using,linux-headers-$(KVERS))'
108
109 build:
110         @if [ x"$(KVERS)" = x ] ; then \
111             echo 'No version in $(KSRC)/include/linux/version.h' >&2; \
112             exit 1; \
113         fi
114         sh debian/prep-modules $(KSRC)
115         cat debian/control.modules >> debian/control
116         dh $@ --with python2,dkms
117 endif
118
119 %:
120         dh $@ --with python2,dkms
121
122 override_dh_auto_clean:
123         rm -rf debian/build debian/tmp debian/dpdk-modules-* \
124                 debian/control.modules debian/VERSION
125         sed -i '/Package: dpdk-modules-/,/`tail -n1 debian/control.modules.in`/d' debian/control
126         test -L config/defconfig_$(DPDK_CONFIG) && rm -f config/defconfig_$(DPDK_CONFIG) || true
127
128 override_dh_auto_configure:
129         # Add support for a custom defconfig file in the debian directory.
130 ifneq (,$(filter dpdk_config=%,$(DEB_BUILD_OPTIONS)))
131         test -e config/defconfig_$(DPDK_CONFIG) || ln -fs ../debian/defconfig_$(DPDK_CONFIG) config/defconfig_$(DPDK_CONFIG)
132 endif
133         # report dpkg-buildflags status to build log
134         dpkg-buildflags --status
135         echo EXTRA_CFLAGS $$EXTRA_CFLAGS
136         echo EXTRA_LDFLAGS: $$EXTRA_LDFLAGS
137         $(MAKE) V=$(DH_VERBOSE) O=$(DPDK_STATIC_DIR) T=$(DPDK_CONFIG) config
138 ifeq (,$(filter dpdk_config=%,$(DEB_BUILD_OPTIONS)))
139         sed -ri -e 's,(RTE_MACHINE=).*,\1$(RTE_MACHINE),' \
140                 -e 's,(RTE_NEXT_ABI=).*,\1n,' \
141                 -e 's,(CONFIG_RTE_EAL_IGB_UIO=).*,\1$(DPDK_CONFIG_BUILD_KMOD),' \
142                 -e 's,(CONFIG_RTE_KNI_KMOD=).*,\1$(DPDK_CONFIG_BUILD_KMOD),' \
143                 -e 's,(LIBRTE_PMD_PCAP=).*,\1y,' \
144                 -e 's,(LIBRTE_PMD_XENVIRT=).*,\1y,' \
145                 -e 's,(CONFIG_RTE_EAL_PMD_PATH=).*,\1"/usr/lib/$(shell dpkg-architecture -qDEB_HOST_MULTIARCH)/dpdk-pmds/",' \
146                 $(DPDK_STATIC_DIR)/.config
147         # xen not available on ppc64el
148 ifneq (,$(filter $(DEB_HOST_ARCH), ppc64el))
149         sed -ri -e 's,(LIBRTE_PMD_XENVIRT=).*,\1n,' $(DPDK_STATIC_DIR)/.config
150 endif
151 endif
152         dh_auto_configure
153
154 override_dh_auto_build-indep:
155         $(MAKE) -j $(PAR) V=$(DH_VERBOSE) O=$(DPDK_STATIC_DIR) doc-api-html doc-guides-html \
156                 doc-guides-man
157
158 override_dh_auto_install-indep:
159         # Package: dpdk-doc
160         # All files based on the install-doc rule (includes examples)
161         $(MAKE) V=$(DH_VERBOSE) O=$(DPDK_STATIC_DIR) prefix=/usr \
162                 DESTDIR=debian/dpdk-doc install-doc
163
164 override_dh_auto_build-arch:
165         $(MAKE) -j $(PAR) V=$(DH_VERBOSE) O=$(DPDK_STATIC_DIR) RTE_KERNELDIR=$(KSRC) build
166         # Unfortunately the decision about having static or shared libraries is
167         # made for the whole build, which then produces only .a or .so files
168         # (but not both).
169         # And the target layout for target selection has no field for the
170         # type of library.
171         # Right now I hack this by doing a second build which only differs in
172         # the selection of shared libs.
173         # Shared libs should be default, so the previous static build is only
174         # used to get static libraries.
175         cp -a $(DPDK_STATIC_DIR) $(DPDK_SHARED_DIR)
176         sed -ri 's,(RTE_BUILD_SHARED_LIB=).*,\1y,' \
177                 $(DPDK_SHARED_DIR)/.config
178         $(MAKE) -j $(PAR) V=$(DH_VERBOSE) O=$(DPDK_SHARED_DIR) RTE_KERNELDIR=$(KSRC) build
179
180 override_dh_auto_install-arch: LIBDIR=usr/lib/$(shell dpkg-architecture -qDEB_HOST_MULTIARCH)
181 override_dh_auto_install-arch:
182         # Package: dpdk (runtime)
183         $(MAKE) V=$(DH_VERBOSE) O=$(DPDK_STATIC_DIR) prefix=/usr \
184                 DESTDIR=debian/dpdk install-runtime
185         $(MAKE) V=$(DH_VERBOSE) O=$(DPDK_SHARED_DIR) prefix=/usr \
186                 DESTDIR=debian/dpdk install-runtime
187         mkdir -p debian/dpdk/etc/dpdk
188         cp debian/dpdk.interfaces debian/dpdk/etc/dpdk/interfaces
189         rm debian/dpdk/usr/sbin/dpdk-devbind
190         mkdir -p debian/dpdk/sbin
191         ln -s /usr/share/dpdk/tools/dpdk-devbind.py \
192                 debian/dpdk/sbin/dpdk-devbind
193         # Package: dpdk-dev (build environment)
194         $(MAKE) V=$(DH_VERBOSE) O=$(DPDK_SHARED_DIR) prefix=/usr \
195                 DESTDIR=debian/dpdk-dev install-sdk
196         cp $(DPDK_SHARED_DIR)/.config debian/dpdk-dev/usr/share/dpdk/config
197         sed -e 's/SDK_TARGET/$(RTE_TARGET)/' debian/dpdk-sdk-env.sh.in > \
198                 debian/dpdk-dev/usr/share/dpdk/dpdk-sdk-env.sh
199         # include the bundled autotest suite to be usable from the dpdk-dev package
200         mkdir -p debian/dpdk-dev/usr/share/dpdk/test
201         cp -a app/test/autotest* debian/dpdk-dev/usr/share/dpdk/test
202         cp $(DPDK_SHARED_DIR)/app/test debian/dpdk-dev/usr/share/dpdk/test/
203         # Package: libdpdk-dev (bare headers, static devel libs and linker
204         # script)
205         mkdir -p debian/libdpdk-dev/$(LIBDIR)
206         # linker script
207         mv debian/dpdk/usr/lib/libdpdk.so debian/libdpdk-dev/$(LIBDIR)/
208         # includes
209         mkdir -p debian/libdpdk-dev/usr/include
210         mv debian/dpdk-dev/usr/include/dpdk debian/libdpdk-dev/usr/include/
211         # all static libs are in the dev package
212         mv debian/dpdk/usr/lib/lib*.a debian/libdpdk-dev/$(LIBDIR)/
213         # symlinks to last .so's are in the non versioned libdpdk-dev as well
214         # this allows multiple libdpdk-<NAME><VER> at different VER concurrently
215         # libdpdk-dev depends on all sublibs so symlinks are never broken
216         mv debian/dpdk/usr/lib/*.so debian/libdpdk-dev/$(LIBDIR)/
217         # Package(s): libdpdk-<NAME><VER> (bare runtime libs)
218         for lib in $$(ls -1 debian/dpdk/usr/lib/*.so.*); do \
219           BN=$$(basename $${lib}); \
220           VER=$$(echo $${BN} | sed -e 's/^.*\.so\.//'); \
221           LN=$$(echo $${BN} | sed -e 's/\.so\.[0-9]*$$//' | tr '_' '-'); \
222           if echo $${LN} | grep -q ".*[0-9]$$"; then \
223             PKG=$${LN}-$${VER}; \
224           else \
225             PKG=$${LN}$${VER}; \
226           fi; \
227           LIBF="$$(basename $${lib})"; \
228           LIBD="debian/$${PKG}/$(LIBDIR)"; \
229           echo "moving $${lib} for library $${PKG}"; \
230           mkdir -p $${LIBD}; \
231           mv $${lib} $${LIBD}; \
232           if [ "$${LIBF#librte_pmd_}x" != "$${LIBF}x" ]; then \
233             mkdir -p $${LIBD}/dpdk-pmds; \
234             echo "PMD: linking $${LIBF} into RTE_EAL_PMD_PATH at $${LIBD}/dpdk-pmds/"; \
235             ln -s --relative --target-directory=$${LIBD}/dpdk-pmds/ $${LIBD}/$${LIBF}; \
236           fi; \
237           if [ "$${LIBF#librte_eal}x" != "$${LIBF}x" ]; then \
238             mkdir -p $${LIBD}/dpdk-pmds; \
239           fi; \
240         done
241         # pkg-config
242         mkdir -p debian/libdpdk-dev/$(LIBDIR)/pkgconfig
243         LIBS=$$(sed -e 's/GROUP ( \(.*\) )/\1/' -e 's/lib/-l/g' -e 's/\.so//g' \
244                 $(CURDIR)/debian/libdpdk-dev/$(LIBDIR)/libdpdk.so); \
245         sed -e "s/@DPDK_LIBS@/$${LIBS}/" -e "s/@VERSION@/$(VERSION)/" \
246                 debian/libdpdk.pc.in > debian/libdpdk-dev/$(LIBDIR)/pkgconfig/libdpdk.pc
247         # Package: dpdk-igb-uio-dkms
248         mkdir -p debian/dpdk-igb-uio-dkms/usr/src/dpdk-igb-uio-$(VERSION)
249         cp lib/librte_eal/linuxapp/igb_uio/* \
250                 debian/dpdk-igb-uio-dkms/usr/src/dpdk-igb-uio-$(VERSION)
251         # Package: dpdk-rte-kni-dkms
252         mkdir -p debian/dpdk-rte-kni-dkms/usr/src/dpdk-rte-kni-$(VERSION)
253         cp -a lib/librte_eal/linuxapp/kni/* \
254                 debian/dpdk-rte-kni-dkms/usr/src/dpdk-rte-kni-$(VERSION)
255 ifneq (,$(KVERS))
256         # Package: dpdk-modules-<kernel version>
257         mkdir -p debian/dpdk-modules-$(KVERS)/lib/modules/$(KVERS)/kernel/drivers/net
258         cp -a debian/build/shared-root/kmod/* \
259                 debian/dpdk-modules-$(KVERS)/lib/modules/$(KVERS)/kernel/drivers/net
260 endif
261
262 override_dh_dkms:
263         dh_dkms -V $(VERSION)
264
265 override_dh_installinit:
266         dh_installinit --no-start --no-restart-on-upgrade
267
268 override_dh_systemd_start:
269         dh_systemd_start --no-start --no-restart-on-upgrade
270
271 override_dh_auto_test:
272