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