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