source: examples-v2/rtems_waf/pkgconfig.py @ ace2e32

4.11
Last change on this file since ace2e32 was ace2e32, checked in by Gedare Bloom <gedare@…>, on Nov 21, 2013 at 9:58:11 PM

Waf: Add top-level wscript and rtems_waf module to support waf builds.

  • Property mode set to 100644
File size: 3.6 KB
Line 
1# Copyright 2013 Chris Johns (chrisj@rtems.org)
2#
3# Redistribution and use in source and binary forms, with or without
4# modification, are permitted provided that the following conditions are met:
5#
6# 1. Redistributions of source code must retain the above copyright notice,
7# this list of conditions and the following disclaimer.
8#
9# 2. Redistributions in binary form must reproduce the above copyright notice,
10# this list of conditions and the following disclaimer in the documentation
11# and/or other materials provided with the distribution.
12#
13# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
14# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
17# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
23# POSSIBILITY OF SUCH DAMAGE.
24
25#
26# Pkg-config in python. Pkg-config as a tool is a good idea how-ever the
27# implementation is really Linux (or Unix) based and requires a couple of
28# packages that it should not. If it was implemented with all parts included it
29# would be portable and I suspect useful to others on platforms other than
30# Linux or Unix equivs that contain the required packages.
31#
32import re
33
34class error(Exception):
35    def __init__(self, msg):
36        self.msg = msg
37
38    def __str__(self):
39        return self.msg
40
41class package:
42    def __init__(self, file = None):
43        self.defines = {}
44        self.fields = {}
45        if file:
46            self.load(file)
47
48    def load(self, file):
49        f = open(file)
50        tm = False
51        for l in f.readlines():
52            l = l[:-1]
53            hash = l.find('#')
54            if hash >= 0:
55                l = l[:hash]
56            if len(l):
57                d = 0
58                define = False
59                eq = l.find('=')
60                dd = l.find(':')
61                if eq > 0 and dd > 0:
62                    if eq < dd:
63                        define = True
64                        d = eq
65                    else:
66                        define = False
67                        d = dd
68                elif eq >= 0:
69                    define = True
70                    d = eq
71                elif dd >= 0:
72                    define = False
73                    d = dd
74                if d > 0:
75                    lhs = l[:d].lower()
76                    rhs = l[d + 1:]
77
78                    if tm:
79                        print('define: ' + str(define) + ', lhs: ' + lhs + ', ' + rhs)
80
81                    if define:
82                        self.defines[lhs] = rhs
83                    else:
84                        self.fields[lhs] = rhs
85
86    def get(self, label):
87        if label.lower()  not in self.fields:
88            raise error('Label not found: ' + label)
89        mre = re.compile('\$\{[^\}]+\}')
90        s = self.fields[label.lower()]
91        expanded = True
92        tm = False
93        while expanded:
94            expanded = False
95            if tm:
96                print 'pc:get: "' + s + '"'
97            ms = mre.findall(s)
98            for m in ms:
99                mn = m[2:-1]
100                if mn.lower() in self.defines:
101                    s = s.replace(m, self.defines[mn.lower()])
102                    expanded = True
103        return s
Note: See TracBrowser for help on using the repository browser.