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