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