build/pkg-config: improve static linking flags
[dpdk.git] / buildtools / pkg-config / meson.build
1 # SPDX-License-Identifier: BSD-3-Clause
2 # Copyright(c) 2020 Intel Corporation
3
4 pkg = import('pkgconfig')
5 pkg_extra_cflags = ['-include', 'rte_config.h'] + machine_args
6 if is_freebsd
7         pkg_extra_cflags += ['-D__BSD_VISIBLE']
8 endif
9
10 # When calling pkg-config --static --libs, pkg-config will always output the
11 # regular libs first, and then the extra libs from Libs.private field,
12 # since the assumption is that those are additional dependencies for building
13 # statically that the .a files depend upon. The output order of .pc fields is:
14 #   Libs   Libs.private   Requires   Requires.private
15 # The fields Requires* are for package names.
16 # The flags of the DPDK libraries must be defined in Libs* fields.
17 # However, the DPDK drivers are linked only in static builds (Libs.private),
18 # and those need to come *before* the regular libraries (Libs field).
19 # This requirement is satisfied by moving the regular libs in a separate file
20 # included in the field Requires (after Libs.private).
21 # Another requirement is to allow linking dependencies as shared libraries,
22 # while linking static DPDK libraries and drivers. It is satisfied by
23 # listing the static files in Libs.private with the explicit syntax -l:libfoo.a.
24
25 pkg.generate(name: 'dpdk-libs',
26         filebase: 'libdpdk-libs',
27         description: '''Internal-only DPDK pkgconfig file. Not for direct use.
28 Use libdpdk.pc instead of this file to query DPDK compile/link arguments''',
29         version: meson.project_version(),
30         subdirs: [get_option('include_subdir_arch'), '.'],
31         extra_cflags: pkg_extra_cflags,
32         libraries: dpdk_libraries,
33         libraries_private: dpdk_extra_ldflags)
34
35 pkg.generate(name: 'DPDK', # main DPDK pkgconfig file
36         filebase: 'libdpdk',
37         version: meson.project_version(),
38         description: '''The Data Plane Development Kit (DPDK).
39 Note that CFLAGS might contain an -march flag higher than typical baseline.
40 This is required for a number of static inline functions in the public headers.''',
41         requires: ['libdpdk-libs', libbsd], # may need libbsd for string funcs
42                           # if libbsd is not enabled, then this is blank
43         libraries_private: ['-Wl,--whole-archive'] +
44                         dpdk_drivers + dpdk_static_libraries +
45                         ['-Wl,--no-whole-archive']
46 )
47
48 # For static linking with dependencies as shared libraries,
49 # the internal static libraries must be flagged explicitly.
50 run_command(py3, 'set-static-linker-flags.py', check: true)