]> git.saurik.com Git - wxWidgets.git/blame - build/bakefiles/regenMakefile.py
split win32 makefiles into shared config files and the rest
[wxWidgets.git] / build / bakefiles / regenMakefile.py
CommitLineData
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
10import string, os.path
11
12file = open('Makefile', 'wt')
13file.write("""
14# Generated by regenMakefile.py
15
31009f33 16BAKEFILE = bakefile -v
ddf98968
VS
17
18
31009f33
VS
19CDEPS = config.bkl common.bkl common_contrib.bkl
20SDEPS = config.bkl common.bkl common_samples.bkl
50da51ee 21MDEPS = common.bkl config.bkl files.bkl monolithic.bkl multilib.bkl opengl.bkl wxwin.py
ddf98968
VS
22""")
23
24lines = []
25all = {}
481290e2 26all['autoconf'] = ['../../configure']
ddf98968
VS
27
28def 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('')
ddf98968
VS
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]
2e1a466f
VS
39 if format != 'autoconf' and 'not_autoconf' in args:
40 a += ' %s' % args['not_autoconf']
ddf98968
VS
41 if format in makedirs:
42 makedir = makedirs[format]
43 else:
44 makedir = makedirs['all']
45 tfile = '%s/%s' % (makedir, make)
a0034878 46 lines.append('%s: %s' % (tfile, dep))
5646c3f8 47 lines.append('\t$(BAKEFILE) -f%s -o$@ %s %s' % (format, a, bake))
31009f33 48 lines.append('\ttouch $@')
ddf98968
VS
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)
f5f530fd 55 add(bake, makedirs, 'makefile.bcc', dep, 'borland', args)
e234d4c9 56 add(bake, makedirs, 'makefile.vc', dep, 'msvc', args)
2e1a466f 57 add(bake, makedirs, 'makefile.gcc', dep, 'mingw', args)
31009f33 58 add(bake, makedirs, 'makefile.wat', dep, 'watcom', args)
ddf98968
VS
59
60
61
62# -----------------------------------------------
63# Add the makefiles:
64# -----------------------------------------------
65
66# main makefile:
73d01310
VS
67addMakefile('wx.bkl', {'all':'..','autoconf':'../..'}, [ '$(MDEPS)' ],
68 args={
69 'borland':'-DOPTIONS_FILE=config.bcc',
70 'msvc':'-DOPTIONS_FILE=config.vc',
71 'mingw':'-DOPTIONS_FILE=config.gcc',
72 'watcom':'-DOPTIONS_FILE=config.wat',
73 })
ddf98968
VS
74
75# samples main makefile:
fd3880a7 76addMakefile('../../samples/samples.bkl', {'all':'../../samples'},
73d01310
VS
77 args={
78 'autoconf':'-DAUTOCONF_MACROS_FILE=../../autoconf_inc.m4',
79 'borland':'-DOPTIONS_FILE=../build/config.bcc -DWRITE_OPTIONS_FILE=0',
80 'msvc':'-DOPTIONS_FILE=../build/config.vc -DWRITE_OPTIONS_FILE=0',
81 'mingw':'-DOPTIONS_FILE=../build/config.gcc -DWRITE_OPTIONS_FILE=0',
82 'watcom':'-DOPTIONS_FILE=../build/config.wat -DWRITE_OPTIONS_FILE=0',
83 })
ddf98968
VS
84
85
a90f1b0b 86CONTRIB_DIR = 1
2e1a466f 87SAMPLES_DIR = 2
a90f1b0b
VS
88
89def onSubmakefile(type, dirname, names):
ddf98968
VS
90 bakes = [x for x in names if x.endswith('.bkl')]
91 if len(bakes) == 0: return
2e1a466f 92 dirname = dirname.replace(os.sep, '/')
ddf98968
VS
93 depth = dirname.count('/') - 2
94 if depth <= 0: return
2e1a466f
VS
95
96 if type==SAMPLES_DIR:
97 prefix = ''.join(['../' for i in range(0,depth)])
98 dirflags = '-DWXTOPDIR=%s../' % prefix
73d01310 99 cfgbase = '%s../build/config.' % prefix
2e1a466f
VS
100 elif type==CONTRIB_DIR:
101 dirflags = '-DSRCDIR=../../src/%s' % dirname.split('/')[-1]
102 dirflags += ' -DWXTOPDIR=../../../'
73d01310 103 cfgbase = '../../../build/config.'
ddf98968
VS
104
105 args = {
2e1a466f 106 'not_autoconf':dirflags,
481290e2 107 'autoconf':'-DAUTOCONF_MACROS_FILE=../../autoconf_inc.m4',
73d01310
VS
108 'msvc':'-DOPTIONS_FILE='+cfgbase+'vc -DWRITE_OPTIONS_FILE=0',
109 'mingw':'-DOPTIONS_FILE='+cfgbase+'gcc -DWRITE_OPTIONS_FILE=0',
110 'borland':'-DOPTIONS_FILE='+cfgbase+'bcc -DWRITE_OPTIONS_FILE=0',
111 'watcom':'-DOPTIONS_FILE='+cfgbase+'wat -DWRITE_OPTIONS_FILE=0',
ddf98968
VS
112 }
113
114 for bake in bakes:
a90f1b0b
VS
115 if type==CONTRIB_DIR:
116 acdir = '../../contrib/src/%s' % dirname.split('/')[-1]
31009f33 117 ruledep = '$(CDEPS)'
a90f1b0b
VS
118 else:
119 acdir = dirname
31009f33 120 ruledep = '$(SDEPS)'
c0608865 121 addMakefile('%s/%s' % (dirname, bake),
31009f33 122 {'all':dirname,'autoconf':acdir}, deps=[ruledep],
ddf98968
VS
123 args=args)
124
2e1a466f
VS
125os.path.walk(os.path.join('..','..','samples'),
126 onSubmakefile, SAMPLES_DIR)
127os.path.walk(os.path.join('..','..','contrib','build'),
128 onSubmakefile, CONTRIB_DIR)
3560dc76
VS
129os.path.walk(os.path.join('..','..','contrib','samples'),
130 onSubmakefile, SAMPLES_DIR)
ddf98968
VS
131
132
133cleanCmds = ''
134for f in all:
135 for i in all[f]:
136 cleanCmds += '\trm -f %s\n' % i
137
138for f in all:
139 var = '%s_ALL' % f.upper()
140 file.write('%s = %s\n' % (var,' '.join(all[f])))
141
142file.write('all:')
143for f in all:
144 file.write(' %s' % f)
145file.write('\n\n')
146for f in all:
147 file.write('%s: $(%s_ALL)\n' % (f, f.upper()))
148
149file.write("""
150clean:
151\trm -f ../../autoconf_inc.m4
ddf98968
VS
152%s
153
6bd5dab5 154../../autoconf_inc.m4: ../../Makefile.in
ddf98968
VS
155../../configure: ../../autoconf_inc.m4
156\t(cd ../.. ; aclocal && autoconf)
157
ddf98968
VS
158Makefile: regenMakefile.py
159\t./regenMakefile.py
160\t@echo
161\t@echo -------------------------------------------
162\t@echo Please rerun make, Makefile was regenerated
163\t@echo -------------------------------------------
164\t@echo
165\t@exit 1
166""" % cleanCmds)
167for l in lines:
168 file.write('%s\n' % l)
169file.close()