1 | n/a | # Check for a module in a set of extension directories. |
---|
2 | n/a | # An extension directory should contain a Setup file |
---|
3 | n/a | # and one or more .o files or a lib.a file. |
---|
4 | n/a | |
---|
5 | n/a | import os |
---|
6 | n/a | import parsesetup |
---|
7 | n/a | |
---|
8 | n/a | def checkextensions(unknown, extensions): |
---|
9 | n/a | files = [] |
---|
10 | n/a | modules = [] |
---|
11 | n/a | edict = {} |
---|
12 | n/a | for e in extensions: |
---|
13 | n/a | setup = os.path.join(e, 'Setup') |
---|
14 | n/a | liba = os.path.join(e, 'lib.a') |
---|
15 | n/a | if not os.path.isfile(liba): |
---|
16 | n/a | liba = None |
---|
17 | n/a | edict[e] = parsesetup.getsetupinfo(setup), liba |
---|
18 | n/a | for mod in unknown: |
---|
19 | n/a | for e in extensions: |
---|
20 | n/a | (mods, vars), liba = edict[e] |
---|
21 | n/a | if mod not in mods: |
---|
22 | n/a | continue |
---|
23 | n/a | modules.append(mod) |
---|
24 | n/a | if liba: |
---|
25 | n/a | # If we find a lib.a, use it, ignore the |
---|
26 | n/a | # .o files, and use *all* libraries for |
---|
27 | n/a | # *all* modules in the Setup file |
---|
28 | n/a | if liba in files: |
---|
29 | n/a | break |
---|
30 | n/a | files.append(liba) |
---|
31 | n/a | for m in list(mods.keys()): |
---|
32 | n/a | files = files + select(e, mods, vars, |
---|
33 | n/a | m, 1) |
---|
34 | n/a | break |
---|
35 | n/a | files = files + select(e, mods, vars, mod, 0) |
---|
36 | n/a | break |
---|
37 | n/a | return files, modules |
---|
38 | n/a | |
---|
39 | n/a | def select(e, mods, vars, mod, skipofiles): |
---|
40 | n/a | files = [] |
---|
41 | n/a | for w in mods[mod]: |
---|
42 | n/a | w = treatword(w) |
---|
43 | n/a | if not w: |
---|
44 | n/a | continue |
---|
45 | n/a | w = expandvars(w, vars) |
---|
46 | n/a | for w in w.split(): |
---|
47 | n/a | if skipofiles and w[-2:] == '.o': |
---|
48 | n/a | continue |
---|
49 | n/a | # Assume $var expands to absolute pathname |
---|
50 | n/a | if w[0] not in ('-', '$') and w[-2:] in ('.o', '.a'): |
---|
51 | n/a | w = os.path.join(e, w) |
---|
52 | n/a | if w[:2] in ('-L', '-R') and w[2:3] != '$': |
---|
53 | n/a | w = w[:2] + os.path.join(e, w[2:]) |
---|
54 | n/a | files.append(w) |
---|
55 | n/a | return files |
---|
56 | n/a | |
---|
57 | n/a | cc_flags = ['-I', '-D', '-U'] |
---|
58 | n/a | cc_exts = ['.c', '.C', '.cc', '.c++'] |
---|
59 | n/a | |
---|
60 | n/a | def treatword(w): |
---|
61 | n/a | if w[:2] in cc_flags: |
---|
62 | n/a | return None |
---|
63 | n/a | if w[:1] == '-': |
---|
64 | n/a | return w # Assume loader flag |
---|
65 | n/a | head, tail = os.path.split(w) |
---|
66 | n/a | base, ext = os.path.splitext(tail) |
---|
67 | n/a | if ext in cc_exts: |
---|
68 | n/a | tail = base + '.o' |
---|
69 | n/a | w = os.path.join(head, tail) |
---|
70 | n/a | return w |
---|
71 | n/a | |
---|
72 | n/a | def expandvars(str, vars): |
---|
73 | n/a | i = 0 |
---|
74 | n/a | while i < len(str): |
---|
75 | n/a | i = k = str.find('$', i) |
---|
76 | n/a | if i < 0: |
---|
77 | n/a | break |
---|
78 | n/a | i = i+1 |
---|
79 | n/a | var = str[i:i+1] |
---|
80 | n/a | i = i+1 |
---|
81 | n/a | if var == '(': |
---|
82 | n/a | j = str.find(')', i) |
---|
83 | n/a | if j < 0: |
---|
84 | n/a | break |
---|
85 | n/a | var = str[i:j] |
---|
86 | n/a | i = j+1 |
---|
87 | n/a | if var in vars: |
---|
88 | n/a | str = str[:k] + vars[var] + str[i:] |
---|
89 | n/a | i = k |
---|
90 | n/a | return str |
---|