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