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