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