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