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