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