[6deab5a] | 1 | #!/usr/bin/env python3
|
---|
| 2 |
|
---|
[616f5dd3] | 3 | #
|
---|
[6deab5a] | 4 | # Copyright (c) 2024 Vojtech Horky
|
---|
[616f5dd3] | 5 | # All rights reserved.
|
---|
| 6 | #
|
---|
| 7 | # Redistribution and use in source and binary forms, with or without
|
---|
| 8 | # modification, are permitted provided that the following conditions
|
---|
| 9 | # are met:
|
---|
| 10 | #
|
---|
| 11 | # - Redistributions of source code must retain the above copyright
|
---|
| 12 | # notice, this list of conditions and the following disclaimer.
|
---|
| 13 | # - Redistributions in binary form must reproduce the above copyright
|
---|
| 14 | # notice, this list of conditions and the following disclaimer in the
|
---|
| 15 | # documentation and/or other materials provided with the distribution.
|
---|
| 16 | # - The name of the author may not be used to endorse or promote products
|
---|
| 17 | # derived from this software without specific prior written permission.
|
---|
| 18 | #
|
---|
| 19 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 20 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 21 | # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 22 | # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 23 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 24 | # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 25 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 26 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 27 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 28 | # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 29 | #
|
---|
| 30 | # pkg-config-like tool for HelenOS libraries
|
---|
| 31 | # HelenOS Cross Compiler Wrapper (XCW)
|
---|
| 32 | # Facilitate cross-compiling external software to HelenOS
|
---|
| 33 | #
|
---|
| 34 |
|
---|
| 35 |
|
---|
[6deab5a] | 36 | import argparse
|
---|
| 37 | import os
|
---|
| 38 | import sys
|
---|
| 39 |
|
---|
| 40 | # Package dependencies: always list only immediate dependencies so that
|
---|
| 41 | # we can get proper ordering for static libraries
|
---|
| 42 | CONFIG_DEPENDENCIES = {
|
---|
| 43 | 'libui': ['libdisplay', 'libcongfx', 'libgfxfont', 'libriff', 'libmemgfx', 'libconsole'],
|
---|
| 44 | 'libdisplay': ['libgfx', 'libipcgfx', 'libinput'],
|
---|
| 45 | 'libconsole': ['libinput', 'liboutput'],
|
---|
| 46 | 'libipcfgfx': ['libgfx'],
|
---|
| 47 | 'libgfximage': ['libpixconv'],
|
---|
| 48 | }
|
---|
| 49 |
|
---|
| 50 | CONFIG_CFLAGS = {
|
---|
| 51 | }
|
---|
| 52 |
|
---|
| 53 | CONFIG_LIBS = {
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | def get_with_dependencies(package, dependencies_first=True):
|
---|
| 57 | deps = CONFIG_DEPENDENCIES.get(package, [])
|
---|
| 58 | all_deps = [
|
---|
| 59 | i
|
---|
| 60 | for d in deps
|
---|
| 61 | for i in get_with_dependencies(d, dependencies_first)
|
---|
| 62 | ]
|
---|
| 63 | result = (all_deps if dependencies_first else []) + [package] + ([] if dependencies_first else all_deps)
|
---|
| 64 | seen = set()
|
---|
| 65 | return [
|
---|
| 66 | i
|
---|
| 67 | for i in result
|
---|
| 68 | if not (i in seen or seen.add(i))
|
---|
| 69 | ]
|
---|
| 70 |
|
---|
| 71 | def get_build_root():
|
---|
| 72 | dn = lambda x : os.path.dirname(x)
|
---|
| 73 | return dn(dn(dn(dn(os.path.abspath(sys.argv[0])))))
|
---|
| 74 |
|
---|
| 75 | def main():
|
---|
| 76 | args = argparse.ArgumentParser(description='pkg-config-like tool for HelenOS')
|
---|
| 77 | args.add_argument(
|
---|
| 78 | '--cflags',
|
---|
| 79 | dest='cflags',
|
---|
| 80 | action='store_true',
|
---|
| 81 | default=False,
|
---|
| 82 | help='Print required C compiler flags to stdout.'
|
---|
| 83 | )
|
---|
| 84 | args.add_argument(
|
---|
| 85 | '--libs',
|
---|
| 86 | dest='libs',
|
---|
| 87 | action='store_true',
|
---|
| 88 | default=False,
|
---|
| 89 | help='Print required linker flags to stdout.'
|
---|
| 90 | )
|
---|
| 91 | args.add_argument('packages', metavar='PACKAGE', nargs='+')
|
---|
| 92 |
|
---|
| 93 | config = args.parse_args()
|
---|
| 94 |
|
---|
| 95 | export_dir = os.getenv('EXPORT_DIR', get_build_root())
|
---|
| 96 |
|
---|
| 97 | result = []
|
---|
| 98 | for package in config.packages:
|
---|
| 99 | if config.cflags:
|
---|
| 100 | for i in get_with_dependencies(package, False):
|
---|
| 101 | if i in CONFIG_CFLAGS:
|
---|
| 102 | result.extend(CONFIG_CFLAGS[i])
|
---|
| 103 | else:
|
---|
| 104 | result.append(f'-I{export_dir}/include/{i}')
|
---|
| 105 | if config.libs:
|
---|
| 106 | for i in get_with_dependencies(package, False):
|
---|
| 107 | if i in CONFIG_LIBS:
|
---|
| 108 | result.extend(CONFIG_LIBS[i])
|
---|
| 109 | else:
|
---|
| 110 | result.append(f'{export_dir}/lib/{i}.a')
|
---|
| 111 |
|
---|
| 112 | print(' '.join(result))
|
---|
| 113 |
|
---|
| 114 |
|
---|
| 115 | if __name__ == '__main__':
|
---|
| 116 | main()
|
---|