install_megadrivers.py revision 993e1d59
101e04c3fSmrg# encoding=utf-8
201e04c3fSmrg# Copyright © 2017-2018 Intel Corporation
301e04c3fSmrg
401e04c3fSmrg# Permission is hereby granted, free of charge, to any person obtaining a copy
501e04c3fSmrg# of this software and associated documentation files (the "Software"), to deal
601e04c3fSmrg# in the Software without restriction, including without limitation the rights
701e04c3fSmrg# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
801e04c3fSmrg# copies of the Software, and to permit persons to whom the Software is
901e04c3fSmrg# furnished to do so, subject to the following conditions:
1001e04c3fSmrg
1101e04c3fSmrg# The above copyright notice and this permission notice shall be included in
1201e04c3fSmrg# all copies or substantial portions of the Software.
1301e04c3fSmrg
1401e04c3fSmrg# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1501e04c3fSmrg# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1601e04c3fSmrg# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1701e04c3fSmrg# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1801e04c3fSmrg# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1901e04c3fSmrg# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2001e04c3fSmrg# SOFTWARE.
2101e04c3fSmrg
2201e04c3fSmrg"""Script to install megadriver symlinks for meson."""
2301e04c3fSmrg
2401e04c3fSmrgfrom __future__ import print_function
2501e04c3fSmrgimport argparse
2601e04c3fSmrgimport os
2701e04c3fSmrgimport shutil
2801e04c3fSmrg
2901e04c3fSmrg
3001e04c3fSmrgdef main():
3101e04c3fSmrg    parser = argparse.ArgumentParser()
3201e04c3fSmrg    parser.add_argument('megadriver')
3301e04c3fSmrg    parser.add_argument('libdir')
3401e04c3fSmrg    parser.add_argument('drivers', nargs='+')
3501e04c3fSmrg    args = parser.parse_args()
3601e04c3fSmrg
3701e04c3fSmrg    if os.path.isabs(args.libdir):
38993e1d59Smrg        destdir = os.environ.get('DESTDIR')
39993e1d59Smrg        if destdir:
40993e1d59Smrg            to = os.path.join(destdir, args.libdir[1:])
41993e1d59Smrg        else:
42993e1d59Smrg            to = args.libdir
4301e04c3fSmrg    else:
4401e04c3fSmrg        to = os.path.join(os.environ['MESON_INSTALL_DESTDIR_PREFIX'], args.libdir)
4501e04c3fSmrg
4601e04c3fSmrg    master = os.path.join(to, os.path.basename(args.megadriver))
4701e04c3fSmrg
4801e04c3fSmrg    if not os.path.exists(to):
4901e04c3fSmrg        if os.path.lexists(to):
5001e04c3fSmrg            os.unlink(to)
5101e04c3fSmrg        os.makedirs(to)
5201e04c3fSmrg
5301e04c3fSmrg    for driver in args.drivers:
5401e04c3fSmrg        abs_driver = os.path.join(to, driver)
5501e04c3fSmrg
5601e04c3fSmrg        if os.path.lexists(abs_driver):
5701e04c3fSmrg            os.unlink(abs_driver)
5801e04c3fSmrg        print('installing {} to {}'.format(args.megadriver, abs_driver))
5901e04c3fSmrg        os.link(master, abs_driver)
6001e04c3fSmrg
6101e04c3fSmrg        try:
6201e04c3fSmrg            ret = os.getcwd()
6301e04c3fSmrg            os.chdir(to)
6401e04c3fSmrg
6501e04c3fSmrg            name, ext = os.path.splitext(driver)
6601e04c3fSmrg            while ext != '.so':
6701e04c3fSmrg                if os.path.lexists(name):
6801e04c3fSmrg                    os.unlink(name)
6901e04c3fSmrg                os.symlink(driver, name)
7001e04c3fSmrg                name, ext = os.path.splitext(name)
7101e04c3fSmrg        finally:
7201e04c3fSmrg            os.chdir(ret)
7301e04c3fSmrg    os.unlink(master)
7401e04c3fSmrg
7501e04c3fSmrg
7601e04c3fSmrgif __name__ == '__main__':
7701e04c3fSmrg    main()
78