Path: blob/21.2-virgl/bin/install_megadrivers.py
4545 views
#!/usr/bin/env python31# encoding=utf-82# Copyright 2017-2018 Intel Corporation34# Permission is hereby granted, free of charge, to any person obtaining a copy5# of this software and associated documentation files (the "Software"), to deal6# in the Software without restriction, including without limitation the rights7# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell8# copies of the Software, and to permit persons to whom the Software is9# furnished to do so, subject to the following conditions:1011# The above copyright notice and this permission notice shall be included in12# all copies or substantial portions of the Software.1314# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE17# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,19# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE20# SOFTWARE.2122"""Script to install megadriver symlinks for meson."""2324from __future__ import print_function25import argparse26import os272829def main():30parser = argparse.ArgumentParser()31parser.add_argument('megadriver')32parser.add_argument('libdir')33parser.add_argument('drivers', nargs='+')34args = parser.parse_args()3536if os.path.isabs(args.libdir):37destdir = os.environ.get('DESTDIR')38if destdir:39to = os.path.join(destdir, args.libdir[1:])40else:41to = args.libdir42else:43to = os.path.join(os.environ['MESON_INSTALL_DESTDIR_PREFIX'], args.libdir)4445master = os.path.join(to, os.path.basename(args.megadriver))4647if not os.path.exists(to):48if os.path.lexists(to):49os.unlink(to)50os.makedirs(to)5152for driver in args.drivers:53abs_driver = os.path.join(to, driver)5455if os.path.lexists(abs_driver):56os.unlink(abs_driver)57print('installing {} to {}'.format(args.megadriver, abs_driver))58os.link(master, abs_driver)5960try:61ret = os.getcwd()62os.chdir(to)6364name, ext = os.path.splitext(driver)65while ext != '.so':66if os.path.lexists(name):67os.unlink(name)68os.symlink(driver, name)69name, ext = os.path.splitext(name)70finally:71os.chdir(ret)7273# Remove meson-created master .so and symlinks74os.unlink(master)75name, ext = os.path.splitext(master)76while ext != '.so':77if os.path.lexists(name):78os.unlink(name)79name, ext = os.path.splitext(name)808182if __name__ == '__main__':83main()848586