]>
Commit | Line | Data |
---|---|---|
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 | |
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 | ||
24 | lines = [] | |
25 | all = {} | |
26 | all['autoconf'] = ['../../configure'] | |
27 | ||
28 | def addMakefile(bake, makedirs, deps=[], args={}): | |
29 | """Adds rules to regenerate native makefile in directory 'makedir' from | |
30 | bakefiles 'bake'. 'deps' contains additional dependencies (bakefiles | |
31 | other than 'bake'.""" | |
32 | print 'adding %s...' % bake | |
33 | lines.append('') | |
34 | ||
35 | def add(bake, makedirs, make, dep, format, args={}): | |
36 | a = '' | |
37 | if 'all' in args: a += ' %s' % args['all'] | |
38 | if format in args: a += ' %s' % args[format] | |
39 | if format != 'autoconf' and 'not_autoconf' in args: | |
40 | a += ' %s' % args['not_autoconf'] | |
41 | if format in makedirs: | |
42 | makedir = makedirs[format] | |
43 | else: | |
44 | makedir = makedirs['all'] | |
45 | tfile = '%s/%s' % (makedir, make) | |
46 | lines.append('%s: %s' % (tfile, dep)) | |
47 | lines.append('\t$(BAKEFILE) -f%s -o$@ %s %s' % (format, a, bake)) | |
48 | lines.append('\ttouch $@') | |
49 | if format not in all: all[format] = [] | |
50 | all[format].append(tfile) | |
51 | ||
52 | dep = string.join(deps + [bake], ' ') | |
53 | ||
54 | add(bake, makedirs, 'Makefile.in', dep, 'autoconf', args) | |
55 | add(bake, makedirs, 'makefile.bcc', dep, 'borland', args) | |
56 | add(bake, makedirs, 'makefile.vc', dep, 'msvc', args) | |
57 | add(bake, makedirs, 'makefile.gcc', dep, 'mingw', args) | |
58 | add(bake, makedirs, 'makefile.wat', dep, 'watcom', args) | |
59 | ||
60 | ||
61 | ||
62 | # ----------------------------------------------- | |
63 | # Add the makefiles: | |
64 | # ----------------------------------------------- | |
65 | ||
66 | # main makefile: | |
67 | addMakefile('wx.bkl', {'all':'..','autoconf':'../..'}, [ '$(MDEPS)' ]) | |
68 | ||
69 | # samples main makefile: | |
70 | addMakefile('../../samples/samples.bkl', {'all':'../../samples'}, | |
71 | args={'autoconf':'-DAUTOCONF_MACROS_FILE=../../autoconf_inc.m4'}) | |
72 | ||
73 | ||
74 | CONTRIB_DIR = 1 | |
75 | SAMPLES_DIR = 2 | |
76 | ||
77 | def onSubmakefile(type, dirname, names): | |
78 | bakes = [x for x in names if x.endswith('.bkl')] | |
79 | if len(bakes) == 0: return | |
80 | dirname = dirname.replace(os.sep, '/') | |
81 | depth = dirname.count('/') - 2 | |
82 | if depth <= 0: return | |
83 | ||
84 | if type==SAMPLES_DIR: | |
85 | prefix = ''.join(['../' for i in range(0,depth)]) | |
86 | dirflags = '-DWXTOPDIR=%s../' % prefix | |
87 | elif type==CONTRIB_DIR: | |
88 | dirflags = '-DSRCDIR=../../src/%s' % dirname.split('/')[-1] | |
89 | dirflags += ' -DWXTOPDIR=../../../' | |
90 | ||
91 | args = { | |
92 | 'not_autoconf':dirflags, | |
93 | 'autoconf':'-DAUTOCONF_MACROS_FILE=../../autoconf_inc.m4', | |
94 | } | |
95 | ||
96 | for bake in bakes: | |
97 | if type==CONTRIB_DIR: | |
98 | acdir = '../../contrib/src/%s' % dirname.split('/')[-1] | |
99 | ruledep = '$(CDEPS)' | |
100 | else: | |
101 | acdir = dirname | |
102 | ruledep = '$(SDEPS)' | |
103 | addMakefile('%s/%s' % (dirname, bake), | |
104 | {'all':dirname,'autoconf':acdir}, deps=[ruledep], | |
105 | args=args) | |
106 | ||
107 | os.path.walk(os.path.join('..','..','samples'), | |
108 | onSubmakefile, SAMPLES_DIR) | |
109 | os.path.walk(os.path.join('..','..','contrib','build'), | |
110 | onSubmakefile, CONTRIB_DIR) | |
111 | os.path.walk(os.path.join('..','..','contrib','samples'), | |
112 | onSubmakefile, SAMPLES_DIR) | |
113 | ||
114 | ||
115 | cleanCmds = '' | |
116 | for f in all: | |
117 | for i in all[f]: | |
118 | cleanCmds += '\trm -f %s\n' % i | |
119 | ||
120 | for f in all: | |
121 | var = '%s_ALL' % f.upper() | |
122 | file.write('%s = %s\n' % (var,' '.join(all[f]))) | |
123 | ||
124 | file.write('all:') | |
125 | for f in all: | |
126 | file.write(' %s' % f) | |
127 | file.write('\n\n') | |
128 | for f in all: | |
129 | file.write('%s: $(%s_ALL)\n' % (f, f.upper())) | |
130 | ||
131 | file.write(""" | |
132 | clean: | |
133 | \trm -f ../../autoconf_inc.m4 | |
134 | %s | |
135 | ||
136 | ../../autoconf_inc.m4: ../../Makefile.in | |
137 | ../../configure: ../../autoconf_inc.m4 | |
138 | \t(cd ../.. ; aclocal && autoconf) | |
139 | ||
140 | Makefile: regenMakefile.py | |
141 | \t./regenMakefile.py | |
142 | \t@echo | |
143 | \t@echo ------------------------------------------- | |
144 | \t@echo Please rerun make, Makefile was regenerated | |
145 | \t@echo ------------------------------------------- | |
146 | \t@echo | |
147 | \t@exit 1 | |
148 | """ % cleanCmds) | |
149 | for l in lines: | |
150 | file.write('%s\n' % l) | |
151 | file.close() |