summaryrefslogtreecommitdiff
path: root/mkspecs/pyfix.py
Unidiff
Diffstat (limited to 'mkspecs/pyfix.py') (more/less context) (ignore whitespace changes)
-rw-r--r--mkspecs/pyfix.py82
1 files changed, 82 insertions, 0 deletions
diff --git a/mkspecs/pyfix.py b/mkspecs/pyfix.py
new file mode 100644
index 0000000..7b86f42
--- a/dev/null
+++ b/mkspecs/pyfix.py
@@ -0,0 +1,82 @@
1import os
2
3# patch the following
4# QMAKE_CFLAGS add $(CFLAGS_EXTRA)
5# QMAKE_CXXFLAGS add $(CXXFLAGS_EXTRA)
6# QMAKE_LFLAGS add $(LFLAGS_EXTRA)
7# QMAKE_LIBS add $(LIBS_EXTRA)
8
9# QMAKE_CFLAGS_RELEASE include old argument
10#
11
12add_map = { "QMAKE_CFLAGS" : "$(CFLAGS_EXTRA)",
13 "QMAKE_CXXFLAGS" : "$(CXXFLAGS_EXTRA)",
14 "QMAKE_LFLAGS" : "$(LFLAGS_EXTRA)",
15 "QMAKE_LIBS" : "$(LIBS_EXTRA)" }
16
17rep_map = { "QMAKE_CFLAGS_RELEASE" : ["$(if $(CFLAGS_RELEASE),$(CFLAGS_RELEASE),", ")"] }
18
19
20def split_text(line):
21 """
22 SPlits the text in the form of "key = value"
23 and returns a two tuple-tuple
24 """
25 ## disabled strip and split tab stuff
26 left = line.find('=')
27 if left == -1:
28 raise Exception, "No src line"
29 key = line[0:left].strip()
30 val = line[left+1:].strip()
31 return (key,val)
32
33def apply_line(line):
34 """
35 Apply changes to a line. This will not handle the exception
36 thrown by split_text
37 """
38 key,val = split_text(line)
39
40 tabs = '\t'
41 if len(key) <= 14:
42 tabs = tabs + '\t'
43 spac = ''
44 if len(val) != 0:
45 spac = ' '
46
47 # for minimal changes on the file we've three returns
48 if add_map.has_key(key):
49 val = val + spac + add_map[key]
50 return key + tabs + '= ' + val + '\n'
51 elif rep_map.has_key(key):
52 val = rep_map[key][0] + ' ' + val + rep_map[key][1]
53 return key + tabs + '= ' + val + '\n'
54 return line
55
56
57
58def apply_on_file(fi):
59 """
60 Apply the maps on files
61 """
62 lines = []
63 for line in file(fi):
64 try:
65 line = apply_line(line)
66 except:
67 pass
68 lines.append(line)
69
70 f = file(fi,'w')
71 for line in lines:
72 f.write(line)
73
74def fix_it():
75 for root, dirs, files in os.walk('./mkspecs'):
76 for fil in files:
77 print root + '/' + fil
78 apply_on_file(root+'/'+fil)
79
80
81if __name__ == '__main__':
82 fix_it()