]>
Commit | Line | Data |
---|---|---|
1 | #!/usr/bin/env python | |
2 | ||
3 | # | |
4 | # Generates Makefile that is used to regenerate native makefiles from | |
5 | # bakefiles. | |
6 | # | |
7 | # $Id$ | |
8 | # | |
9 | ||
10 | import string, os.path, copy | |
11 | ||
12 | # list of files that should _not_ be generated even thought we could do it: | |
13 | DONT_GENERATE = [ | |
14 | '../../samples/Makefile.in', | |
15 | '../../samples/samples.dsw', | |
16 | '../../demos/demos.dsw', | |
17 | '../../samples/html/html_samples.dsw', | |
18 | '../../samples/opengl/opengl_samples.dsw', | |
19 | '../../samples/mobile/mobile_samples.dsw', | |
20 | '../../utils/utils.dsw', | |
21 | ] | |
22 | ||
23 | file = open('Makefile', 'wt') | |
24 | file.write(""" | |
25 | # Generated by regenMakefile.py | |
26 | ||
27 | BAKEFILE = bakefile -v | |
28 | ||
29 | ||
30 | CDEPS = config.bkl common.bkl common_contrib.bkl | |
31 | SDEPS = config.bkl common.bkl common_samples.bkl | |
32 | MDEPS = common.bkl config.bkl files.bkl monolithic.bkl multilib.bkl opengl.bkl wxwin.py | |
33 | ||
34 | DSWFLAGS = -DRUNTIME_LIBS=dynamic -DOFFICIAL_BUILD=0 -DUSE_HTML=1 \\ | |
35 | -DUSE_OPENGL=1 -DUSE_ODBC=1 -DMONOLITHIC=0 -DUSE_GUI=1 \\ | |
36 | -DDEBUG_INFO=default -DDEBUG_FLAG=default -DMSLU=0 | |
37 | ||
38 | COMPAT_TARGETS = ../../src/wxWindows.dsp | |
39 | ||
40 | """) | |
41 | ||
42 | lines = {} | |
43 | all = {} | |
44 | all['autoconf'] = [] | |
45 | ||
46 | linesCur = None | |
47 | ||
48 | def addMakefile(bake, makedirs, deps=[], args={}): | |
49 | """Adds rules to regenerate native makefile in directory 'makedir' from | |
50 | bakefiles 'bake'. 'deps' contains additional dependencies (bakefiles | |
51 | other than 'bake'.""" | |
52 | print 'adding %s...' % bake | |
53 | global linesCur | |
54 | linesCur = ['\n'] | |
55 | ||
56 | def add(bake, makedirs, make, dep, format, args={}): | |
57 | global linesCur | |
58 | a = '' | |
59 | if 'all' in args: a += ' %s' % args['all'] | |
60 | if format in args: a += ' %s' % args[format] | |
61 | if format != 'autoconf' and 'not_autoconf' in args: | |
62 | a += ' %s' % args['not_autoconf'] | |
63 | if format in makedirs: | |
64 | makedir = makedirs[format] | |
65 | else: | |
66 | makedir = makedirs['all'] | |
67 | tfile = '%s/%s' % (makedir, make) | |
68 | ||
69 | if tfile in DONT_GENERATE: return | |
70 | ||
71 | linesCur.append('%s: %s' % (tfile, dep)) | |
72 | linesCur.append('\t$(BAKEFILE) -f%s -o$@ %s %s' % (format, a, bake)) | |
73 | linesCur.append('\ttouch $@') | |
74 | if format not in all: all[format] = [] | |
75 | all[format].append(tfile) | |
76 | ||
77 | dep = string.join(deps + [bake], ' ') | |
78 | ||
79 | add(bake, makedirs, 'Makefile.in', dep, 'autoconf', args) | |
80 | add(bake, makedirs, 'makefile.bcc', dep, 'borland', args) | |
81 | add(bake, makedirs, 'makefile.vc', dep, 'msvc', args) | |
82 | add(bake, makedirs, 'makefile.gcc', dep, 'mingw', args) | |
83 | add(bake, makedirs, 'makefile.wat', dep, 'watcom', args) | |
84 | add(bake, makedirs, | |
85 | (bake[1+bake.rfind('/'):]).replace('.bkl','.dsw'), | |
86 | dep, 'msvc6prj', args) | |
87 | ||
88 | lines[bake] = linesCur | |
89 | ||
90 | ||
91 | ||
92 | # ----------------------------------------------- | |
93 | # Add the makefiles: | |
94 | # ----------------------------------------------- | |
95 | ||
96 | # main makefile: | |
97 | addMakefile('wx.bkl', {'all':'../msw','autoconf':'../..'}, [ '$(MDEPS)' ], | |
98 | args={ | |
99 | 'borland':'-DOPTIONS_FILE=config.bcc', | |
100 | 'msvc':'-DOPTIONS_FILE=config.vc', | |
101 | 'mingw':'-DOPTIONS_FILE=config.gcc', | |
102 | 'watcom':'-DOPTIONS_FILE=config.wat', | |
103 | 'msvc6prj':'$(DSWFLAGS)', | |
104 | }) | |
105 | ||
106 | # samples main makefile: | |
107 | addMakefile('../../samples/samples.bkl', {'all':'../../samples'}, | |
108 | args={ | |
109 | 'autoconf':'-DAUTOCONF_MACROS_FILE=../../autoconf_inc.m4', | |
110 | 'borland':'-DOPTIONS_FILE=../build/msw/config.bcc -DWRITE_OPTIONS_FILE=0', | |
111 | 'msvc':'-DOPTIONS_FILE=../build/msw/config.vc -DWRITE_OPTIONS_FILE=0', | |
112 | 'mingw':'-DOPTIONS_FILE=../build/msw/config.gcc -DWRITE_OPTIONS_FILE=0', | |
113 | 'watcom':'-DOPTIONS_FILE=../build/msw/config.wat -DWRITE_OPTIONS_FILE=0', | |
114 | }) | |
115 | addMakefile('../../demos/demos.bkl', {'all':'../../demos'}, | |
116 | args={ | |
117 | 'autoconf':'-DAUTOCONF_MACROS_FILE=../../autoconf_inc.m4', | |
118 | 'borland':'-DOPTIONS_FILE=../build/msw/config.bcc -DWRITE_OPTIONS_FILE=0', | |
119 | 'msvc':'-DOPTIONS_FILE=../build/msw/config.vc -DWRITE_OPTIONS_FILE=0', | |
120 | 'mingw':'-DOPTIONS_FILE=../build/msw/config.gcc -DWRITE_OPTIONS_FILE=0', | |
121 | 'watcom':'-DOPTIONS_FILE=../build/msw/config.wat -DWRITE_OPTIONS_FILE=0', | |
122 | }) | |
123 | addMakefile('../../utils/utils.bkl', {'all':'../../utils'}, | |
124 | args={ | |
125 | 'autoconf':'-DAUTOCONF_MACROS_FILE=../../autoconf_inc.m4', | |
126 | 'borland':'-DOPTIONS_FILE=../build/msw/config.bcc -DWRITE_OPTIONS_FILE=0', | |
127 | 'msvc':'-DOPTIONS_FILE=../build/msw/config.vc -DWRITE_OPTIONS_FILE=0', | |
128 | 'mingw':'-DOPTIONS_FILE=../build/msw/config.gcc -DWRITE_OPTIONS_FILE=0', | |
129 | 'watcom':'-DOPTIONS_FILE=../build/msw/config.wat -DWRITE_OPTIONS_FILE=0', | |
130 | }) | |
131 | ||
132 | ||
133 | CONTRIB_DIR = 1 | |
134 | SAMPLES_DIR = 2 | |
135 | ||
136 | def onSubmakefile(type, dirname, names): | |
137 | bakes = [x for x in names if x.endswith('.bkl')] | |
138 | if len(bakes) == 0: return | |
139 | bakes.sort() | |
140 | dirname = dirname.replace(os.sep, '/') | |
141 | depth = dirname.count('/') - 2 | |
142 | if depth <= 0: return | |
143 | ||
144 | if type==SAMPLES_DIR: | |
145 | prefix = ''.join(['../' for i in range(0,depth)]) | |
146 | topdirflags = '-DWXTOPDIR=%s../' % prefix | |
147 | srcdirflags = '' | |
148 | cfgbase = '%s../build/msw/config.' % prefix | |
149 | elif type==CONTRIB_DIR: | |
150 | srcdirflags = '-DSRCDIR=../../src/%s' % dirname.split('/')[-1] | |
151 | topdirflags = ' -DWXTOPDIR=../../../' | |
152 | cfgbase = '../../../build/msw/config.' | |
153 | ||
154 | args = { | |
155 | 'all':topdirflags, | |
156 | 'not_autoconf':srcdirflags, | |
157 | 'autoconf':'-DAUTOCONF_MACROS_FILE=../../autoconf_inc.m4', | |
158 | 'msvc':'-DOPTIONS_FILE='+cfgbase+'vc -DWRITE_OPTIONS_FILE=0', | |
159 | 'mingw':'-DOPTIONS_FILE='+cfgbase+'gcc -DWRITE_OPTIONS_FILE=0', | |
160 | 'borland':'-DOPTIONS_FILE='+cfgbase+'bcc -DWRITE_OPTIONS_FILE=0', | |
161 | 'watcom':'-DOPTIONS_FILE='+cfgbase+'wat -DWRITE_OPTIONS_FILE=0', | |
162 | 'msvc6prj':'$(DSWFLAGS)', | |
163 | } | |
164 | ||
165 | for bake in bakes: | |
166 | if type==CONTRIB_DIR: | |
167 | acdir = '../../contrib/src/%s' % dirname.split('/')[-1] | |
168 | ruledep = '$(CDEPS)' | |
169 | else: | |
170 | acdir = dirname | |
171 | ruledep = '$(SDEPS)' | |
172 | addMakefile('%s/%s' % (dirname, bake), | |
173 | {'all':dirname,'autoconf':acdir}, deps=[ruledep], | |
174 | args=args) | |
175 | ||
176 | os.path.walk(os.path.join('..','..','samples'), | |
177 | onSubmakefile, SAMPLES_DIR) | |
178 | os.path.walk(os.path.join('..','..','demos'), | |
179 | onSubmakefile, SAMPLES_DIR) | |
180 | os.path.walk(os.path.join('..','..','utils'), | |
181 | onSubmakefile, SAMPLES_DIR) | |
182 | os.path.walk(os.path.join('..','..','contrib','build'), | |
183 | onSubmakefile, CONTRIB_DIR) | |
184 | os.path.walk(os.path.join('..','..','contrib','samples'), | |
185 | onSubmakefile, SAMPLES_DIR) | |
186 | os.path.walk(os.path.join('..','..','contrib','utils'), | |
187 | onSubmakefile, SAMPLES_DIR) | |
188 | ||
189 | ||
190 | cleanCmds = '' | |
191 | allK = all.keys() | |
192 | allK.sort() | |
193 | cleanList = [] | |
194 | ||
195 | for f in allK: | |
196 | all[f].sort() | |
197 | ||
198 | for f in allK: | |
199 | for i in all[f]: | |
200 | cleanList.append('\trm -f %s\n' % i) | |
201 | cleanCmds = ''.join(cleanList) | |
202 | ||
203 | for f in allK: | |
204 | var = '%s_ALL' % f.upper() | |
205 | file.write('%s = \\\n\t%s\n' % (var,' \\\n\t'.join(all[f]))) | |
206 | ||
207 | file.write('\nall: $(COMPAT_TARGETS)') | |
208 | for f in allK: | |
209 | file.write(' %s' % f) | |
210 | file.write('\n\n') | |
211 | for f in allK: | |
212 | file.write('%s: $(%s_ALL)\n' % (f, f.upper())) | |
213 | ||
214 | file.write(""" | |
215 | clean: | |
216 | \trm -f ../../autoconf_inc.m4 | |
217 | \trm -f $(COMPAT_TARGETS) | |
218 | %s | |
219 | ||
220 | library: ../../Makefile.in\\ | |
221 | ../msw/makefile.bcc\\ | |
222 | ../msw/makefile.vc\\ | |
223 | ../msw/makefile.wat\\ | |
224 | ../msw/makefile.gcc\\ | |
225 | ../msw/wx.dsw\\ | |
226 | ../../src/wxWindows.dsp | |
227 | ||
228 | ../../autoconf_inc.m4: ../../Makefile.in | |
229 | ||
230 | ../../src/wxWindows.dsp: monolithic.bkl files.bkl | |
231 | \t$(BAKEFILE) -Icompat -fwx24dsp -DUSE_GUI=1 -DWXUNIV=0 -o$@ wx.bkl | |
232 | \ttouch $@ | |
233 | ||
234 | Makefile: regenMakefile.py | |
235 | \t./regenMakefile.py | |
236 | \t@echo | |
237 | \t@echo ------------------------------------------- | |
238 | \t@echo Please rerun make, Makefile was regenerated | |
239 | \t@echo ------------------------------------------- | |
240 | \t@echo | |
241 | \t@exit 1 | |
242 | """ % cleanCmds) | |
243 | linesK = lines.keys() | |
244 | linesK.sort() | |
245 | for lk in linesK: | |
246 | for l in lines[lk]: | |
247 | file.write('%s\n' % l) | |
248 | file.close() |