bd6c4448b18fe42ac9420da0e108d26807e59c2e
[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 clean:
43         dh_testdir
44         rm -rf debian/build debian/tmp
45         dh_clean
46
47 build-config:
48         dh_testdir
49         # report dpkg-buildflags status to build log
50         dpkg-buildflags --status
51         echo EXTRA_CFLAGS $$EXTRA_CFLAGS
52         echo EXTRA_LDFLAGS: $$EXTRA_LDFLAGS
53         $(MAKE) V=$(DH_VERBOSE) O=$(DPDK_STATIC_DIR) T=$(DPDK_CONFIG) config
54         sed -ri -e 's,(RTE_MACHINE=).*,\1$(RTE_MACHINE),' \
55                 -e 's,(RTE_NEXT_ABI=).*,\1n,' \
56                 -e 's,(CONFIG_RTE_EAL_IGB_UIO=).*,\1n,' \
57                 -e 's,(CONFIG_RTE_KNI_KMOD=).*,\1n,' \
58                 -e 's,(LIBRTE_PMD_PCAP=).*,\1y,' \
59                 -e 's,(LIBRTE_PMD_XENVIRT=).*,\1y,' \
60                 $(DPDK_STATIC_DIR)/.config
61
62 build-indep: build-config
63         dh_testdir
64         $(MAKE) V=$(DH_VERBOSE) O=$(DPDK_STATIC_DIR) doc-api-html doc-guides-html
65
66 build-arch: build-config
67         dh_testdir
68         $(MAKE) V=$(DH_VERBOSE) O=$(DPDK_STATIC_DIR) build
69         # Unfortunately the decision about having static or shared libraries is
70         # made for the whole build, which then produces only .a or .so files
71         # (but not both).
72         # And the target layout for target selection has no field for the
73         # type of library.
74         # Right now I hack this by doing a second build which only differs in
75         # the selection of shared libs.
76         # Shared libs should be default, so the previous static build is only
77         # used to get static libraries.
78         cp -a $(DPDK_STATIC_DIR) $(DPDK_SHARED_DIR)
79         sed -ri 's,(RTE_BUILD_SHARED_LIB=).*,\1y,' \
80                 $(DPDK_SHARED_DIR)/.config
81         $(MAKE) V=$(DH_VERBOSE) O=$(DPDK_SHARED_DIR) build
82
83 build: build-arch build-indep
84
85 binary-indep: PACKAGE_NAME=dpdk-doc
86 binary-indep: DOCDIR=usr/share/doc/dpdk
87 binary-indep: export DH_OPTIONS=--indep
88 binary-indep:
89         dh_testroot
90         dh_prep
91         dh_testdir
92         dh_installdirs
93         dh_install
94         dh_installdocs
95         dh_installchangelogs
96         dh_lintian
97         # Package: dpdk-doc
98         # All files based on the install-doc rule (includes examples)
99         $(MAKE) V=$(DH_VERBOSE) O=$(DPDK_STATIC_DIR) prefix=/usr \
100                 DESTDIR=debian/dpdk-doc install-doc
101         dh_link
102         dh_compress
103         dh_fixperms
104         dh_installdeb
105         dh_gencontrol
106         dh_md5sums
107         dh_builddeb
108
109 binary-arch: LIBDIR=usr/lib/$(shell dpkg-architecture -qDEB_HOST_MULTIARCH)
110 binary-arch: export DH_OPTIONS=--arch
111 binary-arch:
112         dh_testroot
113         dh_prep
114         dh_testdir
115         dh_installdirs
116         dh_install
117         dh_installdocs
118         dh_installchangelogs
119         dh_lintian
120         dh_systemd_enable
121         dh_installinit --no-start --no-restart-on-upgrade
122         dh_systemd_start --no-start --no-restart-on-upgrade
123         # Package: dpdk (runtime)
124         $(MAKE) V=$(DH_VERBOSE) O=$(DPDK_STATIC_DIR) prefix=/usr \
125                 DESTDIR=debian/dpdk install-runtime
126         $(MAKE) V=$(DH_VERBOSE) O=$(DPDK_SHARED_DIR) prefix=/usr \
127                 DESTDIR=debian/dpdk install-runtime
128         cp debian/dpdk.interfaces debian/dpdk/etc/dpdk/interfaces
129         rm debian/dpdk/usr/sbin/dpdk-devbind
130         mkdir -p debian/dpdk/sbin
131         ln -s /usr/share/dpdk/tools/dpdk-devbind.py \
132                 debian/dpdk/sbin/dpdk-devbind
133         # Package: dpdk-dev (build environment)
134         $(MAKE) V=$(DH_VERBOSE) O=$(DPDK_SHARED_DIR) prefix=/usr \
135                 DESTDIR=debian/dpdk-dev install-sdk
136         cp $(DPDK_SHARED_DIR)/.config debian/dpdk-dev/usr/share/dpdk/config
137         sed -e 's/SDK_TARGET/$(RTE_TARGET)/' debian/dpdk-sdk-env.sh.in > \
138                 debian/dpdk-dev/usr/share/dpdk/dpdk-sdk-env.sh
139         # Package: libdpdk-dev (bare headers, static devel libs and linker
140         # script)
141         mkdir -p debian/libdpdk-dev/$(LIBDIR)
142         # linker script
143         mv debian/dpdk/usr/lib/libdpdk.so debian/libdpdk-dev/$(LIBDIR)/
144         # includes
145         mkdir -p debian/libdpdk-dev/usr/include
146         mv debian/dpdk-dev/usr/include/dpdk debian/libdpdk-dev/usr/include/
147         # all static libs are in the dev package
148         mv debian/dpdk/usr/lib/lib*.a debian/libdpdk-dev/$(LIBDIR)/
149         # symlinks to last .so's are in the non versioned libdpdk-dev as well
150         # this allows multiple libdpdk-<NAME><VER> at different VER concurrently
151         # libdpdk-dev depends on all sublibs so symlinks are never broken
152         mv debian/dpdk/usr/lib/*.so debian/libdpdk-dev/$(LIBDIR)/
153         # Package(s): libdpdk-<NAME><VER> (bare runtime libs)
154         for lib in $$(ls -1 debian/dpdk/usr/lib/*.so.*); do \
155           BN=$$(basename $${lib}); \
156           VER=$$(echo $${BN} | sed -e 's/^.*\.so\.//'); \
157           LN=$$(echo $${BN} | sed -e 's/\.so\.[0-9]*$$//' | tr '_' '-'); \
158           if echo $${LN} | grep -q ".*[0-9]$$"; then \
159             PKG=$${LN}-$${VER}; \
160           else \
161             PKG=$${LN}$${VER}; \
162           fi; \
163           echo "moving $${lib} for library $${PKG}"; \
164           mkdir -p debian/$${PKG}/$(LIBDIR); \
165           mv $${lib} debian/$${PKG}/$(LIBDIR); \
166         done
167         # pkg-config
168         mkdir -p debian/libdpdk-dev/$(LIBDIR)/pkgconfig
169         LIBS=$$(sed -e 's/GROUP ( \(.*\) )/\1/' -e 's/lib/-l/g' -e 's/\.so//g' \
170                 $(CURDIR)/debian/libdpdk-dev/$(LIBDIR)/libdpdk.so); \
171         sed -e "s/@DPDK_LIBS@/$${LIBS}/" -e "s/@VERSION@/$(VERSION)/" \
172                 debian/libdpdk.pc.in > debian/libdpdk-dev/$(LIBDIR)/pkgconfig/libdpdk.pc
173         # Package: dpdk-igb-uio-dkms
174         mkdir -p debian/dpdk-igb-uio-dkms/usr/src/dpdk-igb-uio-$(VERSION)
175         cp lib/librte_eal/linuxapp/igb_uio/* \
176                 debian/dpdk-igb-uio-dkms/usr/src/dpdk-igb-uio-$(VERSION)
177         # Package: dpdk-rte-kni-dkms
178         mkdir -p debian/dpdk-rte-kni-dkms/usr/src/dpdk-rte-kni-$(VERSION)
179         cp -a lib/librte_eal/linuxapp/kni/* \
180                 debian/dpdk-rte-kni-dkms/usr/src/dpdk-rte-kni-$(VERSION)
181         dh_dkms -V $(VERSION)
182         dh_python2
183         dh_perl
184         dh_link
185         dh_compress
186         dh_fixperms
187         dh_strip
188         dh_makeshlibs
189         dh_shlibdeps
190         dh_installdeb
191         dh_gencontrol
192         dh_md5sums
193         dh_builddeb
194
195 binary: binary-arch binary-indep