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