Add option to disable static libraries build
[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 ifneq (,$(findstring nodocs,$(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 override_dh_gencontrol:
117         dh_gencontrol
118         dh_gencontrol -p dpdk-modules-$(KVERS) -- \
119                 -v`cat debian/VERSION` \
120                 -V'built:using:kernel=$(call get_built_using,linux-headers-$(KVERS))'
121
122 build:
123         @if [ x"$(KVERS)" = x ] ; then \
124             echo 'No version in $(KSRC)/include/linux/version.h' >&2; \
125             exit 1; \
126         fi
127         sh debian/prep-modules $(KSRC)
128         cat debian/control.modules >> debian/control
129         dh $@ --with python2,dkms
130 endif
131
132 %:
133         dh $@ --with python2,dkms
134
135 override_dh_auto_clean:
136         rm -rf debian/build debian/tmp debian/dpdk-modules-* \
137                 debian/control.modules debian/VERSION
138         sed -i '/Package: dpdk-modules-/,/`tail -n1 debian/control.modules.in`/d' debian/control
139         test -L config/defconfig_$(DPDK_CONFIG) && rm -f config/defconfig_$(DPDK_CONFIG) || true
140
141 override_dh_clean:
142         dh_clean
143         rm -f debian/libethdev4.links
144         rm -f debian/librte-cryptodev1.links
145         rm -f debian/librte-eal2.links
146
147 override_dh_auto_configure:
148         # Add support for a custom defconfig file in the debian directory.
149 ifneq (,$(filter dpdk_config=%,$(DEB_BUILD_OPTIONS)))
150         test -e config/defconfig_$(DPDK_CONFIG) || ln -fs ../debian/defconfig_$(DPDK_CONFIG) config/defconfig_$(DPDK_CONFIG)
151 endif
152         # report dpkg-buildflags status to build log
153         dpkg-buildflags --status
154         echo EXTRA_CFLAGS $$EXTRA_CFLAGS
155         echo EXTRA_LDFLAGS: $$EXTRA_LDFLAGS
156         $(MAKE) V=$(DH_VERBOSE) O=$(DPDK_STATIC_DIR) T=$(DPDK_CONFIG) config
157 ifeq (,$(filter dpdk_config=%,$(DEB_BUILD_OPTIONS)))
158         sed -ri -e 's,(RTE_MACHINE=).*,\1$(RTE_MACHINE),' \
159                 -e 's,(RTE_NEXT_ABI=).*,\1n,' \
160                 -e 's,(CONFIG_RTE_EAL_IGB_UIO=).*,\1$(DPDK_CONFIG_BUILD_KMOD),' \
161                 -e 's,(CONFIG_RTE_KNI_KMOD=).*,\1$(DPDK_CONFIG_BUILD_KMOD),' \
162                 -e 's,(LIBRTE_PMD_PCAP=).*,\1y,' \
163                 -e 's,(LIBRTE_PMD_XENVIRT=).*,\1y,' \
164                 -e 's,(CONFIG_RTE_EAL_PMD_PATH=).*,\1"/usr/lib/$(shell dpkg-architecture -qDEB_HOST_MULTIARCH)/dpdk-pmds/",' \
165                 $(DPDK_STATIC_DIR)/.config
166         # xen not available on ppc64el
167 ifneq (,$(filter $(DEB_HOST_ARCH), ppc64el))
168         sed -ri -e 's,(LIBRTE_PMD_XENVIRT=).*,\1n,' $(DPDK_STATIC_DIR)/.config
169 endif
170 endif
171         dh_auto_configure
172
173 override_dh_auto_build-indep:
174 ifeq (y,$(BUILD_DOCS))
175         $(MAKE) -j $(PAR) V=$(DH_VERBOSE) O=$(DPDK_STATIC_DIR) doc-api-html doc-guides-html \
176                 doc-guides-man
177 endif
178
179 override_dh_auto_install-indep:
180         # Package: dpdk-doc
181         # All files based on the install-doc rule (includes examples)
182 ifeq (y,$(BUILD_DOCS))
183         $(MAKE) V=$(DH_VERBOSE) O=$(DPDK_STATIC_DIR) prefix=/usr \
184                 DESTDIR=debian/dpdk-doc install-doc
185 endif
186
187 override_dh_auto_build-arch:
188 ifeq (y,$(BUILD_STATIC_LIB))
189         $(MAKE) -j $(PAR) V=$(DH_VERBOSE) O=$(DPDK_STATIC_DIR) RTE_KERNELDIR=$(KSRC) build
190 endif
191         # Unfortunately the decision about having static or shared libraries is
192         # made for the whole build, which then produces only .a or .so files
193         # (but not both).
194         # And the target layout for target selection has no field for the
195         # type of library.
196         # Right now I hack this by doing a second build which only differs in
197         # the selection of shared libs.
198         # Shared libs should be default, so the previous static build is only
199         # used to get static libraries.
200         cp -a $(DPDK_STATIC_DIR) $(DPDK_SHARED_DIR)
201         sed -ri 's,(RTE_BUILD_SHARED_LIB=).*,\1y,' \
202                 $(DPDK_SHARED_DIR)/.config
203         $(MAKE) -j $(PAR) V=$(DH_VERBOSE) O=$(DPDK_SHARED_DIR) RTE_KERNELDIR=$(KSRC) build
204
205 override_dh_auto_install-arch: LIBDIR=/usr/lib/$(shell dpkg-architecture -qDEB_HOST_MULTIARCH)
206 override_dh_auto_install-arch:
207         # Package: dpdk (runtime)
208 ifeq (y,$(BUILD_STATIC_LIB))
209         $(MAKE) V=$(DH_VERBOSE) O=$(DPDK_STATIC_DIR) prefix=/usr libdir=$(LIBDIR) \
210                 DESTDIR=debian/dpdk install-runtime
211 endif
212         $(MAKE) V=$(DH_VERBOSE) O=$(DPDK_SHARED_DIR) prefix=/usr libdir=$(LIBDIR) \
213                 DESTDIR=debian/dpdk install-runtime
214         mkdir -p debian/dpdk/etc/dpdk
215         cp debian/dpdk.interfaces debian/dpdk/etc/dpdk/interfaces
216         rm debian/dpdk/usr/sbin/dpdk-devbind
217         mkdir -p debian/dpdk/sbin
218         ln -s /usr/share/dpdk/tools/dpdk-devbind.py \
219                 debian/dpdk/sbin/dpdk-devbind
220         # Package: dpdk-dev (build environment)
221         # workaround to fix symbolic link creation
222         mkdir -p debian/dpdk-dev/$(LIBDIR)
223         $(MAKE) V=$(DH_VERBOSE) O=$(DPDK_SHARED_DIR) prefix=/usr libdir=$(LIBDIR) \
224                 DESTDIR=debian/dpdk-dev install-sdk
225         # remove workaround
226         rm -fr debian/dpdk-dev/usr/lib
227         cp $(DPDK_SHARED_DIR)/.config debian/dpdk-dev/usr/share/dpdk/config
228         sed -e 's/SDK_TARGET/$(RTE_TARGET)/' debian/dpdk-sdk-env.sh.in > \
229                 debian/dpdk-dev/usr/share/dpdk/dpdk-sdk-env.sh
230         # include the bundled autotest suite to be usable from the dpdk-dev package
231         mkdir -p debian/dpdk-dev/usr/share/dpdk/test
232         cp -a app/test/autotest* debian/dpdk-dev/usr/share/dpdk/test
233         cp $(DPDK_SHARED_DIR)/app/test debian/dpdk-dev/usr/share/dpdk/test/
234         # since we move libs to multiarch dirs update the non aware symlink
235         rm debian/dpdk-dev/usr/share/dpdk/$(RTE_TARGET)/lib
236         ln -rs debian/dpdk-dev/$(LIBDIR)/ \
237                 debian/dpdk-dev/usr/share/dpdk/$(RTE_TARGET)/lib
238         # Package: libdpdk-dev (bare headers, static devel libs and linker
239         # script)
240         mkdir -p debian/libdpdk-dev/$(LIBDIR)
241         # linker script
242         mv debian/dpdk/$(LIBDIR)/libdpdk.so debian/libdpdk-dev/$(LIBDIR)/
243         # includes
244         mkdir -p debian/libdpdk-dev/usr/include
245         mv debian/dpdk-dev/usr/include/dpdk debian/libdpdk-dev/usr/include/
246         # all static libs are in the dev package
247 ifeq (y,$(BUILD_STATIC_LIB))
248         mv debian/dpdk/$(LIBDIR)/lib*.a debian/libdpdk-dev/$(LIBDIR)/
249 endif
250         # symlinks to last .so's are in the non versioned libdpdk-dev as well
251         # this allows multiple libdpdk-<NAME><VER> at different VER concurrently
252         # libdpdk-dev depends on all sublibs so symlinks are never broken
253         mv debian/dpdk/$(LIBDIR)/*.so debian/libdpdk-dev/$(LIBDIR)/
254         # Package(s): libdpdk-<NAME><VER> (bare runtime libs)
255         for lib in $$(ls -1 debian/dpdk/$(LIBDIR)/*.so.*); do \
256           BN=$$(basename $${lib}); \
257           VER=$$(echo $${BN} | sed -e 's/^.*\.so\.//'); \
258           LN=$$(echo $${BN} | sed -e 's/\.so\.[0-9]*$$//' | tr '_' '-'); \
259           if echo $${LN} | grep -q ".*[0-9]$$"; then \
260             PKG=$${LN}-$${VER}; \
261           else \
262             PKG=$${LN}$${VER}; \
263           fi; \
264           LIBF="$$(basename $${lib})"; \
265           LIBD="debian/$${PKG}/$(LIBDIR)"; \
266           echo "moving $${lib} for library $${PKG}"; \
267           mkdir -p $${LIBD}; \
268           mv $${lib} $${LIBD}; \
269           if [ "$${LIBF#librte_pmd_}x" != "$${LIBF}x" ]; then \
270             mkdir -p $${LIBD}/dpdk-pmds; \
271             echo "PMD: linking $${LIBF} into RTE_EAL_PMD_PATH at $${LIBD}/dpdk-pmds/"; \
272             ln -s --relative --target-directory=$${LIBD}/dpdk-pmds/ $${LIBD}/$${LIBF}; \
273           fi; \
274           if [ "$${LIBF#librte_eal}x" != "$${LIBF}x" ]; then \
275             mkdir -p $${LIBD}/dpdk-pmds; \
276           fi; \
277         done
278         # pkg-config
279         mkdir -p debian/libdpdk-dev/$(LIBDIR)/pkgconfig
280         LIBS=$$(sed -e 's/GROUP ( \(.*\) )/\1/' -e 's/lib/-l/g' -e 's/\.so//g' \
281                 $(CURDIR)/debian/libdpdk-dev/$(LIBDIR)/libdpdk.so); \
282         sed -e "s/@DPDK_LIBS@/$${LIBS}/" -e "s/@VERSION@/$(VERSION)/" \
283                 -e "s|@LIBDIR@|$(LIBDIR)|" \
284                 debian/libdpdk.pc.in > debian/libdpdk-dev/$(LIBDIR)/pkgconfig/libdpdk.pc
285         # Package: dpdk-igb-uio-dkms
286         mkdir -p debian/dpdk-igb-uio-dkms/usr/src/dpdk-igb-uio-$(VERSION)
287         cp lib/librte_eal/linuxapp/igb_uio/* \
288                 debian/dpdk-igb-uio-dkms/usr/src/dpdk-igb-uio-$(VERSION)
289         # Package: dpdk-rte-kni-dkms
290         mkdir -p debian/dpdk-rte-kni-dkms/usr/src/dpdk-rte-kni-$(VERSION)
291         cp -a lib/librte_eal/linuxapp/kni/* \
292                 debian/dpdk-rte-kni-dkms/usr/src/dpdk-rte-kni-$(VERSION)
293 ifneq (,$(KVERS))
294         # Package: dpdk-modules-<kernel version>
295         $(MAKE) V=$(DH_VERBOSE) O=$(DPDK_SHARED_DIR) \
296                 kerneldir=/lib/modules/$(KVERS)/extra/dpdk \
297                 DESTDIR=debian/dpdk-modules-$(KVERS) install-kmod
298 endif
299
300 debian/libethdev4.links: debian/libethdev4.links.in
301         sed -e 's/@DEB_HOST_MULTIARCH@/$(DEB_HOST_MULTIARCH)/g' < $< > $@
302 debian/librte-cryptodev1.links: debian/librte-cryptodev1.links.in
303         sed -e 's/@DEB_HOST_MULTIARCH@/$(DEB_HOST_MULTIARCH)/g' < $< > $@
304 debian/librte-eal2.links: debian/librte-eal2.links.in
305         sed -e 's/@DEB_HOST_MULTIARCH@/$(DEB_HOST_MULTIARCH)/g' < $< > $@
306 override_dh_link: debian/libethdev4.links debian/librte-cryptodev1.links debian/librte-eal2.links
307         dh_link
308
309 override_dh_dkms:
310         dh_dkms -V $(VERSION)
311
312 override_dh_installinit:
313         dh_installinit --no-start --no-restart-on-upgrade
314
315 override_dh_systemd_start:
316         dh_systemd_start --no-start --no-restart-on-upgrade
317
318 override_dh_auto_test:
319