]> git.saurik.com Git - wxWidgets.git/blame - build/bakefiles/regenMakefile.py
define __GNUWIN32__ if __MINGW32__ is defined, so that it doesn't have to be defined...
[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
16BAKEFILE = bakefile
17BAKEARGS = -v
18
19
20""")
21
22lines = []
23all = {}
481290e2 24all['autoconf'] = ['../../configure']
ddf98968
VS
25
26def addMakefile(bake, makedirs, deps=[], args={}):
27 """Adds rules to regenerate native makefile in directory 'makedir' from
28 bakefiles 'bake'. 'deps' contains additional dependencies (bakefiles
29 other than 'bake'."""
30 print 'adding %s...' % bake
31 lines.append('')
32 lines.append('# from %s' % bake)
33
34 def add(bake, makedirs, make, dep, format, args={}):
35 a = ''
36 if 'all' in args: a += ' %s' % args['all']
37 if format in args: a += ' %s' % args[format]
2e1a466f
VS
38 if format != 'autoconf' and 'not_autoconf' in args:
39 a += ' %s' % args['not_autoconf']
ddf98968
VS
40 if format in makedirs:
41 makedir = makedirs[format]
42 else:
43 makedir = makedirs['all']
44 tfile = '%s/%s' % (makedir, make)
a0034878 45 lines.append('%s: %s' % (tfile, dep))
ddf98968
VS
46 lines.append('\t$(BAKEFILE) $(BAKEARGS) -f%s -o%s%s %s' % \
47 (format, tfile, a, bake))
48 lines.append('\ttouch %s' % tfile)
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)
ddf98968
VS
58
59
60
61# -----------------------------------------------
62# Add the makefiles:
63# -----------------------------------------------
64
65# main makefile:
66addMakefile('wx.bkl', {'all':'..','autoconf':'../..'},
67 ['common.bkl', 'config.bkl', 'files.bkl', 'monolithic.bkl',
e86e1522 68 'multilib.bkl', 'wxwin.py'])
ddf98968
VS
69
70# samples main makefile:
fd3880a7
VS
71addMakefile('../../samples/samples.bkl', {'all':'../../samples'},
72 args={'autoconf':'-DAUTOCONF_MACROS_FILE=../../autoconf_inc.m4'})
ddf98968
VS
73
74
a90f1b0b 75CONTRIB_DIR = 1
2e1a466f 76SAMPLES_DIR = 2
a90f1b0b
VS
77
78def onSubmakefile(type, dirname, names):
ddf98968
VS
79 bakes = [x for x in names if x.endswith('.bkl')]
80 if len(bakes) == 0: return
2e1a466f 81 dirname = dirname.replace(os.sep, '/')
ddf98968
VS
82 depth = dirname.count('/') - 2
83 if depth <= 0: return
2e1a466f
VS
84
85 if type==SAMPLES_DIR:
86 prefix = ''.join(['../' for i in range(0,depth)])
87 dirflags = '-DWXTOPDIR=%s../' % prefix
88 elif type==CONTRIB_DIR:
89 dirflags = '-DSRCDIR=../../src/%s' % dirname.split('/')[-1]
90 dirflags += ' -DWXTOPDIR=../../../'
ddf98968
VS
91
92 args = {
2e1a466f 93 'not_autoconf':dirflags,
481290e2 94 'autoconf':'-DAUTOCONF_MACROS_FILE=../../autoconf_inc.m4',
ddf98968
VS
95 }
96
97 for bake in bakes:
a90f1b0b
VS
98 if type==CONTRIB_DIR:
99 acdir = '../../contrib/src/%s' % dirname.split('/')[-1]
e86e1522 100 ruledep = 'common_contrib.bkl'
a90f1b0b
VS
101 else:
102 acdir = dirname
e86e1522 103 ruledep = 'common_samples.bkl'
c0608865 104 addMakefile('%s/%s' % (dirname, bake),
a90f1b0b 105 {'all':dirname,'autoconf':acdir},
e86e1522 106 deps=['common.bkl',ruledep,'config.bkl'],
ddf98968
VS
107 args=args)
108
2e1a466f
VS
109os.path.walk(os.path.join('..','..','samples'),
110 onSubmakefile, SAMPLES_DIR)
111os.path.walk(os.path.join('..','..','contrib','build'),
112 onSubmakefile, CONTRIB_DIR)
ddf98968
VS
113
114
115cleanCmds = ''
116for f in all:
117 for i in all[f]:
118 cleanCmds += '\trm -f %s\n' % i
119
120for f in all:
121 var = '%s_ALL' % f.upper()
122 file.write('%s = %s\n' % (var,' '.join(all[f])))
123
124file.write('all:')
125for f in all:
126 file.write(' %s' % f)
127file.write('\n\n')
128for f in all:
129 file.write('%s: $(%s_ALL)\n' % (f, f.upper()))
130
131file.write("""
132clean:
133\trm -f ../../autoconf_inc.m4
ddf98968
VS
134%s
135
6bd5dab5 136../../autoconf_inc.m4: ../../Makefile.in
ddf98968
VS
137../../configure: ../../autoconf_inc.m4
138\t(cd ../.. ; aclocal && autoconf)
139
ddf98968
VS
140Makefile: 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)
149for l in lines:
150 file.write('%s\n' % l)
151file.close()