xref: /dpdk/buildtools/symlink-drivers-solibs.py (revision cd27047dbee1eda0e8ed12300bc035636d89607b)
1#!/usr/bin/env python3
2# SPDX-License-Identifier: BSD-3-Clause
3# Copyright(c) 2021 Intel Corporation
4
5import os
6import sys
7import glob
8import shutil
9
10# post-install script for meson/ninja builds to symlink the PMDs stored in
11# $libdir/dpdk/pmds-*/ to $libdir. This is needed as some PMDs depend on
12# others, e.g. PCI device PMDs depending on the PCI bus driver.
13
14# parameters to script are paths relative to install prefix:
15# 1. directory for installed regular libs e.g. lib64
16# 2. subdirectory of libdir where the PMDs are
17# 3. directory for installed regular binaries e.g. bin
18
19os.chdir(os.environ['MESON_INSTALL_DESTDIR_PREFIX'])
20
21lib_dir = sys.argv[1]
22pmd_subdir = sys.argv[2]
23bin_dir = sys.argv[3]
24pmd_dir = os.path.join(lib_dir, pmd_subdir)
25
26# copy Windows PMDs to avoid any issues with symlinks since the
27# build could be a cross-compilation under WSL, Msys or Cygnus.
28# the filenames are dependent upon the specific toolchain in use.
29
30def copy_pmd_files(pattern, to_dir):
31	for file in glob.glob(os.path.join(pmd_dir, pattern)):
32		to = os.path.join(to_dir, os.path.basename(file))
33		shutil.copy2(file, to)
34		print(to + ' -> ' + file)
35
36copy_pmd_files('*rte_*.dll', bin_dir)
37copy_pmd_files('*rte_*.pdb', bin_dir)
38copy_pmd_files('*rte_*.lib', lib_dir)
39copy_pmd_files('*rte_*.dll.a', lib_dir)
40
41# symlink shared objects
42
43os.chdir(lib_dir)
44for file in glob.glob(os.path.join(pmd_subdir, 'librte_*.so*')):
45	to = os.path.basename(file)
46	if os.path.exists(to):
47		os.remove(to)
48	os.symlink(file, to)
49	print(to + ' -> ' + file)
50