blob: a6ec2638993277eea260af17f96da26a56c45e74 [file] [log] [blame]
Jack Jansen6655c4e1995-09-01 12:03:32 +00001#
2# fullbuild creates everything that needs to be created before a
3# distribution can be made, and puts it all in the right place.
4#
5# It expects the projects to be in the places where Jack likes them:
Jack Jansenfaad9951997-09-01 15:37:07 +00006# in directories named like 'build.mac'. That is fixable,
Jack Jansen6655c4e1995-09-01 12:03:32 +00007# however.
8#
9# NOTE: You should proably make a copy of python with which to execute this
10# script, rebuilding running programs does not work...
11
Jack Jansenfaad9951997-09-01 15:37:07 +000012MACBUILDNO=":Mac:Include:macbuildno.h"
13
Jack Jansen6655c4e1995-09-01 12:03:32 +000014import os
15import sys
16import macfs
Jack Jansen1023dff1996-02-21 15:28:49 +000017import MacOS
Jack Jansenf04fa721996-04-10 14:51:14 +000018import EasyDialogs
Jack Jansenfaad9951997-09-01 15:37:07 +000019import regex
20import string
Jack Jansen6655c4e1995-09-01 12:03:32 +000021
Jack Jansen6655c4e1995-09-01 12:03:32 +000022import aetools
Jack Jansen1023dff1996-02-21 15:28:49 +000023import AppleEvents
Jack Jansen6655c4e1995-09-01 12:03:32 +000024from Metrowerks_Shell_Suite import Metrowerks_Shell_Suite
Jack Jansen82bfde91997-08-27 14:10:29 +000025from CodeWarrior_Standard_Suite import CodeWarrior_Standard_Suite
Jack Jansen0f00c5e1997-05-06 16:15:32 +000026from Required_Suite import Required_Suite
27
28import Res
29import Dlg
Jack Jansen6655c4e1995-09-01 12:03:32 +000030
Jack Jansen490ec9c1998-07-31 09:45:27 +000031import buildtools
Jack Jansen0f00c5e1997-05-06 16:15:32 +000032import cfmfile
33
34# Dialog resource. Note that the item numbers should correspond
35# to those in the DITL resource. Also note that the order is important:
36# things are built in this order, so there should be no forward dependencies.
37DIALOG_ID = 512
38
39I_OK=1
40I_CANCEL=2
Jack Jansen675cda01997-09-09 13:57:15 +000041I_INC_BUILDNO=19
Jack Jansen0f00c5e1997-05-06 16:15:32 +000042
Jack Jansen82bfde91997-08-27 14:10:29 +000043I_CORE=3
Jack Jansen0f00c5e1997-05-06 16:15:32 +000044I_PPC_PLUGINS=4
45I_PPC_EXTENSIONS=5
Jack Jansen82bfde91997-08-27 14:10:29 +000046I_68K_PLUGINS=6
47I_68K_EXTENSIONS=7
48I_PPC_FULL=8
49I_PPC_SMALL=9
50I_68K_FULL=10
51I_68K_SMALL=11
52I_APPLETS=12
Jack Jansen0f00c5e1997-05-06 16:15:32 +000053
Jack Jansen82bfde91997-08-27 14:10:29 +000054N_BUTTONS=13
Jack Jansen6655c4e1995-09-01 12:03:32 +000055
Jack Jansen82bfde91997-08-27 14:10:29 +000056class MwShell(Metrowerks_Shell_Suite, CodeWarrior_Standard_Suite,
57 Required_Suite, aetools.TalkTo):
Jack Jansen6655c4e1995-09-01 12:03:32 +000058 pass
59
Jack Jansenf04fa721996-04-10 14:51:14 +000060RUNNING=[]
Jack Jansen6655c4e1995-09-01 12:03:32 +000061
62def buildmwproject(top, creator, projects):
63 """Build projects with an MW compiler"""
Jack Jansenb9e5e141996-09-20 15:30:52 +000064 mgr = MwShell(creator, start=1)
Jack Jansen1023dff1996-02-21 15:28:49 +000065 mgr.send_timeout = AppleEvents.kNoTimeOut
66
Jack Jansen6655c4e1995-09-01 12:03:32 +000067 for file in projects:
Jack Jansen82bfde91997-08-27 14:10:29 +000068 if type(file) == type(()):
69 file, target = file
70 else:
71 target = ''
Jack Jansen6655c4e1995-09-01 12:03:32 +000072 file = os.path.join(top, file)
Just van Rossum2607a441999-01-30 18:27:12 +000073 try:
74 fss = macfs.FSSpec(file)
75 except ValueError:
76 print '** file not found:', file
77 continue
Jack Jansen82bfde91997-08-27 14:10:29 +000078 print 'Building', file, target
Just van Rossum2607a441999-01-30 18:27:12 +000079 try:
80 mgr.open(fss)
81 except aetools.Error, detail:
82 print '**', detail, file
83 continue
Jack Jansen82bfde91997-08-27 14:10:29 +000084 if target:
85 try:
86 mgr.Set_Current_Target(target)
87 except aetools.Error, arg:
88 print '**', file, target, 'Cannot select:', arg
Jack Jansen1023dff1996-02-21 15:28:49 +000089 try:
90 mgr.Make_Project()
Jack Jansenb9e5e141996-09-20 15:30:52 +000091 except aetools.Error, arg:
Jack Jansen82bfde91997-08-27 14:10:29 +000092 print '**', file, target, 'Failed:', arg
Jack Jansen6655c4e1995-09-01 12:03:32 +000093 mgr.Close_Project()
Jack Jansenf04fa721996-04-10 14:51:14 +000094## mgr.quit()
Jack Jansen6655c4e1995-09-01 12:03:32 +000095
96def buildapplet(top, dummy, list):
Jack Jansen0f00c5e1997-05-06 16:15:32 +000097 """Create python applets"""
Jack Jansen490ec9c1998-07-31 09:45:27 +000098 template = buildtools.findtemplate()
Just van Rossum9d609b41999-02-01 01:21:18 +000099 for src, dst in list:
Jack Jansen6655c4e1995-09-01 12:03:32 +0000100 if src[-3:] != '.py':
101 raise 'Should end in .py', src
102 base = os.path.basename(src)
Jack Jansen6655c4e1995-09-01 12:03:32 +0000103 src = os.path.join(top, src)
Just van Rossum9d609b41999-02-01 01:21:18 +0000104 dst = os.path.join(top, dst)
Jack Jansen6655c4e1995-09-01 12:03:32 +0000105 try:
106 os.unlink(dst)
107 except os.error:
108 pass
109 print 'Building applet', dst
Jack Jansen490ec9c1998-07-31 09:45:27 +0000110 buildtools.process(template, src, dst, 1)
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000111
112def buildfat(top, dummy, list):
113 """Build fat binaries"""
114 for dst, src1, src2 in list:
115 dst = os.path.join(top, dst)
116 src1 = os.path.join(top, src1)
117 src2 = os.path.join(top, src2)
118 print 'Building fat binary', dst
119 cfmfile.mergecfmfiles((src1, src2), dst)
120
Jack Jansen675cda01997-09-09 13:57:15 +0000121def handle_dialog(filename):
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000122 """Handle selection dialog, return list of selected items"""
123 d = Dlg.GetNewDialog(DIALOG_ID, -1)
124 d.SetDialogDefaultItem(I_OK)
125 d.SetDialogCancelItem(I_CANCEL)
126 results = [0]*N_BUTTONS
127 while 1:
128 n = Dlg.ModalDialog(None)
129 if n == I_OK:
130 break
131 if n == I_CANCEL:
132 return []
Jack Jansen675cda01997-09-09 13:57:15 +0000133 if n == I_INC_BUILDNO:
134 incbuildno(filename)
135 continue
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000136 if n < len(results):
137 results[n] = (not results[n])
Jack Jansenc9b1e901999-12-24 13:39:23 +0000138 ctl = d.GetDialogItemAsControl(n)
139 ctl.SetControlValue(results[n])
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000140 rv = []
141 for i in range(len(results)):
142 if results[i]:
143 rv.append(i)
144 return rv
Jack Jansen6655c4e1995-09-01 12:03:32 +0000145
146#
147# The build instructions. Entries are (routine, arg, list-of-files)
148# XXXX We could also include the builds for stdwin and such here...
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000149BUILD_DICT = {
Jack Jansen82bfde91997-08-27 14:10:29 +0000150I_CORE : (buildmwproject, "CWIE", [
Jack Jansenc9bda411999-01-28 17:46:50 +0000151 (":Mac:Build:PythonCore.prj", "PythonCore"),
Jack Jansen3b805261999-02-14 23:12:06 +0000152 (":Mac:Build:PythonInterpreter.prj", "PythonInterpreter"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000153 ]),
154
155I_PPC_PLUGINS : (buildmwproject, "CWIE", [
Jack Jansen87352f81999-02-12 10:29:06 +0000156 (":Mac:Build:calldll.ppc.prj", "calldll.ppc"),
157 (":Mac:Build:ctb.prj", "ctb.ppc"),
158 (":Mac:Build:gdbm.prj", "gdbm.ppc"),
159 (":Mac:Build:icglue.prj", "icglue.ppc"),
160 (":Mac:Build:macspeech.prj", "macspeech.ppc"),
161 (":Mac:Build:waste.prj", "waste.ppc"),
162 (":Mac:Build:zlib.prj", "zlib.ppc"),
163 (":Mac:Build:_tkinter.prj", "_tkinter.ppc"),
164 (":Mac:Build:ColorPicker.prj", "ColorPicker.ppc"),
165 (":Mac:Build:Printing.prj", "Printing.ppc"),
166 (":Mac:Build:AE.prj", "AE.ppc"),
Jack Jansen57ed1391999-03-04 23:00:11 +0000167 (":Mac:Build:App.prj", "App.ppc"),
Jack Jansen87352f81999-02-12 10:29:06 +0000168 (":Mac:Build:Cm.prj", "Cm.ppc"),
169 (":Mac:Build:Evt.prj", "Evt.ppc"),
170 (":Mac:Build:Fm.prj", "Fm.ppc"),
171 (":Mac:Build:Help.prj", "Help.ppc"),
172 (":Mac:Build:Icn.prj", "Icn.ppc"),
173 (":Mac:Build:List.prj", "List.ppc"),
Jack Jansen6a51b371999-03-07 23:10:32 +0000174 (":Mac:Build:Qdoffs.prj", "Qdoffs.ppc"),
Jack Jansen87352f81999-02-12 10:29:06 +0000175 (":Mac:Build:Qt.prj", "Qt.ppc"),
176 (":Mac:Build:Scrap.prj", "Scrap.ppc"),
177 (":Mac:Build:Snd.prj", "Snd.ppc"),
178 (":Mac:Build:Sndihooks.prj", "Sndihooks.ppc"),
179 (":Mac:Build:TE.prj", "TE.ppc"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000180 ]),
181
182I_68K_PLUGINS : (buildmwproject, "CWIE", [
Jack Jansen87352f81999-02-12 10:29:06 +0000183 (":Mac:Build:ctb.prj", "ctb.CFM68K"),
184 (":Mac:Build:gdbm.prj", "gdbm.CFM68K"),
185 (":Mac:Build:icglue.prj", "icglue.CFM68K"),
186 (":Mac:Build:waste.prj", "waste.CFM68K"),
187 (":Mac:Build:zlib.prj", "zlib.CFM68K"),
188 (":Mac:Build:_tkinter.prj", "_tkinter.CFM68K"),
189 (":Mac:Build:ColorPicker.prj", "ColorPicker.CFM68K"),
190 (":Mac:Build:Printing.prj", "Printing.CFM68K"),
191 (":Mac:Build:AE.prj", "AE.CFM68K"),
Jack Jansen57ed1391999-03-04 23:00:11 +0000192 (":Mac:Build:App.prj", "App.CFM68K"),
Jack Jansen87352f81999-02-12 10:29:06 +0000193 (":Mac:Build:Cm.prj", "Cm.CFM68K"),
194 (":Mac:Build:Evt.prj", "Evt.CFM68K"),
195 (":Mac:Build:Fm.prj", "Fm.CFM68K"),
196 (":Mac:Build:Help.prj", "Help.CFM68K"),
197 (":Mac:Build:Icn.prj", "Icn.CFM68K"),
198 (":Mac:Build:List.prj", "List.CFM68K"),
Jack Jansen6a51b371999-03-07 23:10:32 +0000199 (":Mac:Build:Qdoffs.prj", "Qdoffs.CFM68K"),
Jack Jansen87352f81999-02-12 10:29:06 +0000200 (":Mac:Build:Qt.prj", "Qt.CFM68K"),
201 (":Mac:Build:Scrap.prj", "Scrap.CFM68K"),
202 (":Mac:Build:Snd.prj", "Snd.CFM68K"),
203 (":Mac:Build:Sndihooks.prj", "Sndihooks.CFM68K"),
204 (":Mac:Build:TE.prj", "TE.CFM68K"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000205 ]),
206
207I_68K_FULL : (buildmwproject, "CWIE", [
Jack Jansenc9bda411999-01-28 17:46:50 +0000208 (":Mac:Build:PythonStandalone.prj", "Python68K"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000209 ]),
210
211I_68K_SMALL : (buildmwproject, "CWIE", [
Jack Jansenc9bda411999-01-28 17:46:50 +0000212 (":Mac:Build:PythonStandSmall.prj", "PythonSmall68K"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000213 ]),
214
215I_PPC_FULL : (buildmwproject, "CWIE", [
Jack Jansenc9bda411999-01-28 17:46:50 +0000216 (":Mac:Build:PythonStandalone.prj", "PythonStandalone"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000217 ]),
218
219I_PPC_SMALL : (buildmwproject, "CWIE", [
Jack Jansenc9bda411999-01-28 17:46:50 +0000220 (":Mac:Build:PythonStandSmall.prj", "PythonStandSmall"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000221 ]),
222
223I_PPC_EXTENSIONS : (buildmwproject, "CWIE", [
Jack Jansen82bfde91997-08-27 14:10:29 +0000224 (":Extensions:Imaging:_imaging.prj", "_imaging.ppc"),
225 (":Extensions:Imaging:_tkinter.prj", "_tkinter.ppc"),
Jack Jansen8eea5ba1999-02-06 17:44:28 +0000226 (":Extensions:img:Mac:imgmodules.prj", "imgmodules PPC"),
Just van Rossum7bcd84d1999-02-02 23:58:50 +0000227 (":Extensions:Numerical:Mac:numpymodules.prj", "multiarraymodule"),
228 (":Extensions:Numerical:Mac:numpymodules.prj", "_numpy"),
229 (":Extensions:Numerical:Mac:numpymodules.prj", "umathmodule"),
230 (":Extensions:Numerical:Mac:numpymodules.prj", "fast_umathmodule"),
231 (":Extensions:Numerical:Mac:numpymodules.prj", "fftpackmodule"),
232 (":Extensions:Numerical:Mac:numpymodules.prj", "lapack_litemodule"),
233 (":Extensions:Numerical:Mac:numpymodules.prj", "ranlibmodule"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000234 ]),
235
236I_68K_EXTENSIONS : (buildmwproject, "CWIE", [
Jack Jansen82bfde91997-08-27 14:10:29 +0000237 (":Extensions:Imaging:_imaging.prj", "_imaging.CFM68K"),
238 (":Extensions:Imaging:_tkinter.prj", "_tkinter.CFM68K"),
Jack Jansen8eea5ba1999-02-06 17:44:28 +0000239 (":Extensions:img:Mac:imgmodules.prj", "imgmodules CFM68K"),
Just van Rossum7bcd84d1999-02-02 23:58:50 +0000240## (":Extensions:NumPy:numpymodules.prj", "numpymodules.CFM68K"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000241 ]),
242
243I_APPLETS : (buildapplet, None, [
Just van Rossum9d609b41999-02-01 01:21:18 +0000244 (":Mac:scripts:EditPythonPrefs.py", "EditPythonPrefs"),
245 (":Mac:scripts:BuildApplet.py", "BuildApplet"),
246 (":Mac:scripts:BuildApplication.py", "BuildApplication"),
247 (":Mac:scripts:ConfigurePython.py", "ConfigurePython"),
248 (":Mac:Tools:IDE:PythonIDE.py", "Python IDE"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000249 ]),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000250}
Jack Jansenfaad9951997-09-01 15:37:07 +0000251
252def incbuildno(filename):
253 fp = open(filename)
254 line = fp.readline()
255 fp.close()
256
257 pat = regex.compile('#define BUILD \([0-9][0-9]*\)')
258 pat.match(line)
259 buildno = pat.group(1)
260 if not buildno:
261 raise 'Incorrect macbuildno.h line', line
262 new = string.atoi(buildno) + 1
263 fp = open(filename, 'w')
264 fp.write('#define BUILD %d\n'%new)
265 fp.close()
Jack Jansen6655c4e1995-09-01 12:03:32 +0000266
267def main():
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000268 try:
269 h = Res.OpenResFile('fullbuild.rsrc')
270 except Res.Error:
271 pass # Assume we already have acces to our own resource
272
Jack Jansen6655c4e1995-09-01 12:03:32 +0000273 dir, ok = macfs.GetDirectory('Python source folder:')
274 if not ok:
275 sys.exit(0)
276 dir = dir.as_pathname()
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000277
Jack Jansen675cda01997-09-09 13:57:15 +0000278 todo = handle_dialog(os.path.join(dir, MACBUILDNO))
279
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000280 instructions = []
281 for i in todo:
282 instructions.append(BUILD_DICT[i])
283
284 for routine, arg, list in instructions:
Jack Jansen8b4c9871997-05-07 15:52:12 +0000285 routine(dir, arg, list)
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000286
Jack Jansen6655c4e1995-09-01 12:03:32 +0000287 print "All done!"
288 sys.exit(1)
289
290if __name__ == '__main__':
291 main()
292