~ubuntu-branches/ubuntu/precise/ncbi-tools6/precise

« back to all changes in this revision

Viewing changes to make/makeApps.met

  • Committer: Bazaar Package Importer
  • Author(s): Aaron M. Ucko
  • Date: 2005-03-27 12:00:15 UTC
  • mfrom: (2.1.2 hoary)
  • Revision ID: james.westby@ubuntu.com-20050327120015-embhesp32nj73p9r
Tags: 6.1.20041020-3
* Fix FTBFS under GCC 4.0 caused by inconsistent use of "static" on
  functions.  (Closes: #295110.)
* Add a watch file, now that we can.  (Upstream's layout needs version=3.)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
-- C apps --
 
2
 
 
3
--
 
4
-- Properties
 
5
--
 
6
property pRootFolderName : "ncbi" -- name of the toolkit directory
 
7
property pRootFolderPath : "" -- full path of the parent of the toolkit directory. Optional
 
8
 
 
9
property pProjectFileExt : ".mcp"
 
10
 
 
11
property pSaveContinueOnErrors : false
 
12
-- true if we want to save compilation errors in a file and continue.
 
13
-- false if we want to stop on an error.
 
14
 
 
15
-- Whether to recreate existing project files.
 
16
property pAlwaysCreateProjects : false
 
17
-- Which targets to build.
 
18
-- All of the targets are populated all the time. These affect what is compiled & built.
 
19
property pCreateMachOTargets : true
 
20
property pCreateCarbonTargets : false
 
21
property pCreateWinTargets : false
 
22
 
 
23
property pCreateOptimizedTargets : true
 
24
property pCreateDebugTargets : false
 
25
property pCreateProfiledTargets : false
 
26
 
 
27
-- Whether to have the projects use CVS or not.
 
28
property pProjectsCVSEnabled : true
 
29
 
 
30
property pCreateBlastTargets : false
 
31
 
 
32
-- Whether to compile anything.
 
33
property pShouldBuild : true
 
34
 
 
35
property pStationeryName : "ApplicationStationery"
 
36
 
 
37
-- the handler GetTargetSpecs should change if these do.
 
38
property pTargetKeyWords : "Mach-O Carbon Win32 Debug Final Profile"
 
39
 
 
40
 
 
41
global gProjectData
 
42
 
 
43
on SimpleProjectData(projName, features)
 
44
        
 
45
        if (count characters of projName) > 25 then
 
46
                set projName to characters 1 through 25 of projName as string
 
47
        end if
 
48
        
 
49
        if features does not contain "C" and features does not contain "C++" then
 
50
                --error "Project " & projName & "'s default language (a feature) must be C or C++."
 
51
                copy "C" to end of features
 
52
        end if
 
53
        set myFeatures to features
 
54
        return {name:projName, features:myFeatures, rsrcs:{"ncbilogo.r", "Info.plc"}, settings:�
 
55
                {prefixFile:"", ppcProject:{}}, projLibs:�
 
56
                {"ncbi", "ncbiconn", "ncbiobj", "vibrant", "ncbimmdb", "ncbitool"}, fileData:�
 
57
                {{projPath:"demo:", fileList:{projName & ".c"}}}}
 
58
        
 
59
end SimpleProjectData
 
60
 
 
61
on AddProject(projData)
 
62
        copy projData to end of gProjectData
 
63
end AddProject
 
64
 
 
65
on AddSimpleProject(projName, features)
 
66
        AddProject(SimpleProjectData(projName, features))
 
67
end AddSimpleProject
 
68
 
 
69
on SetProjectData()
 
70
        tell application "CodeWarrior IDE"
 
71
                
 
72
                -- Sequin
 
73
                set myName to "Sequin"
 
74
                set myFeatures to {"sockets"}
 
75
                set mySettings to �
 
76
                        {prefixFile:"", creator:"SEQN", ppcProject:{Preferred Heap Size:32000, Min Heap Size:6000}} �
 
77
                                
 
78
                set myRsrcs to {"sequin.r", "InfoSequin.plc"}
 
79
                set myLibs to {"ncbi", "ncbiconn", "ncbiobj", "ncbicdr", "vibrant", "ncbidesk", �
 
80
                        "ncbimmdb", "ncbitool", "netcli", "netentr", "ncbibls3", "ncbimla", �
 
81
                        "ncbitxc2", "ncbiid1", "ncbispell", "vibnet", "ncbiblast", "ncbiblastapi"}
 
82
                set myFiles to �
 
83
                        {{projPath:"cdromlib:", fileList:{"accentr.c", "accutils.c"}}, �
 
84
                                {projPath:"sequin:", fileList:{"sequin1.c", "sequin2.c", "sequin3.c", "sequin4.c", "sequin5.c", �
 
85
                                        "sequin6.c", "sequin7.c", "sequin8.c", "sequin9.c", "sequin10.c", "sequinx.c"}}}
 
86
                set sequinData to �
 
87
                        {name:myName, features:myFeatures, settings:mySettings, rsrcs:myRsrcs, projLibs:�
 
88
                                myLibs, fileData:myFiles}
 
89
                
 
90
                -- Entrez
 
91
                set myName to "Entrez"
 
92
                set myFeatures to {"sockets"}
 
93
                set mySettings to {prefixFile:"", creator:"ENTZ", ppcProject:{}}
 
94
                set myRsrcs to {"entrez.r", "Info.plc"}
 
95
                set myLibs to {"ncbi", "ncbiconn", "ncbiobj", "ncbicdr", "vibrant", "ncbidesk", "ncbimmdb", �
 
96
                        "ncbitool", "netcli", "netentr", "ncbibls3", "ncbiid1", "vibnet"}
 
97
                set myFiles to �
 
98
                        {{projPath:"cdromlib:", fileList:{"accentr.c", "accutils.c"}}, �
 
99
                                {projPath:"demo:", fileList:{"entrez.c"}}}
 
100
                set entrezData to �
 
101
                        {name:myName, features:myFeatures, settings:mySettings, rsrcs:myRsrcs, projLibs:�
 
102
                                myLibs, fileData:myFiles}
 
103
                
 
104
                -- Entrez2
 
105
                set myName to "Entrez2"
 
106
                set myFeatures to {"sockets"}
 
107
                set mySettings to {prefixFile:"", creator:"ENTZ", ppcProject:{}}
 
108
                set myRsrcs to {"entrez.r", "Info.plc"}
 
109
                set myLibs to {"ncbi", "ncbiconn", "ncbiobj", "ncbimmdb", "ncbitool", "vibrant", "ncbidesk", �
 
110
                        "ncbiblast", "ncbiblastapi"}
 
111
                set myFiles to �
 
112
                        {{projPath:"demo:", fileList:{"entrez2.c"}}}
 
113
                set entrez2Data to �
 
114
                        {name:myName, features:myFeatures, settings:mySettings, rsrcs:myRsrcs, projLibs:�
 
115
                                myLibs, fileData:myFiles}
 
116
                
 
117
                -- BlastCL3
 
118
                set myName to "blastcl3"
 
119
                set myFeatures to {"sockets"}
 
120
                set mySettings to {prefixFile:"blastcl3.pfx", ppcProject:{}}
 
121
                set myRsrcs to {"ncbilogo.r", "Info.plc"}
 
122
                set myLibs to {"ncbi", "ncbiconn", "ncbiobj", "vibrant", "ncbitool", "netcli", "ncbibls3"}
 
123
                set myFiles to �
 
124
                        {{projPath:"demo:", fileList:{"blastall.c"}}}
 
125
                set blastcl3Data to �
 
126
                        {name:myName, features:myFeatures, settings:mySettings, rsrcs:myRsrcs, projLibs:�
 
127
                                myLibs, fileData:myFiles}
 
128
                
 
129
                -- Bl2seq
 
130
                set myName to "bl2seq"
 
131
                set myFeatures to {"sockets"}
 
132
                set mySettings to {prefixFile:"", ppcProject:{}}
 
133
                set myRsrcs to {"ncbilogo.r", "Info.plc"}
 
134
                set myLibs to {"ncbi", "ncbiconn", "ncbiobj", "vibrant", "ncbitool", "netcli", "ncbibls3", "ncbiid1"}
 
135
                set myFiles to �
 
136
                        {{projPath:"demo:", fileList:{"bl2seq.c"}}}
 
137
                set bl2seqData to �
 
138
                        {name:myName, features:myFeatures, settings:mySettings, rsrcs:myRsrcs, projLibs:�
 
139
                                myLibs, fileData:myFiles}
 
140
                
 
141
                -- Megablast
 
142
                set myName to "megablast"
 
143
                set myFeatures to {"sockets"}
 
144
                set mySettings to {prefixFile:"", ppcProject:{}}
 
145
                set myRsrcs to {"ncbilogo.r", "Info.plc"}
 
146
                set myLibs to {"ncbi", "ncbiconn", "ncbiobj", "vibrant", "ncbitool", "ncbiblast", "ncbiblastapi"}
 
147
                set myFiles to �
 
148
                        {{projPath:"demo:", fileList:{"megablast.c"}}}
 
149
                set megablastData to �
 
150
                        {name:myName, features:myFeatures, settings:mySettings, rsrcs:myRsrcs, projLibs:�
 
151
                                myLibs, fileData:myFiles}
 
152
                
 
153
                -- Copymat
 
154
                set myName to "copymat"
 
155
                set myFeatures to {"sockets"}
 
156
                set mySettings to {prefixFile:"", ppcProject:{}}
 
157
                set myRsrcs to {"ncbilogo.r", "Info.plc"}
 
158
                set myLibs to {"ncbi", "ncbiconn", "ncbiobj", "vibrant", "ncbitool", "ncbiblast", "ncbiblastapi"}
 
159
                set myFiles to �
 
160
                        {{projPath:"demo:", fileList:{"copymat.c"}}}
 
161
                set copymatData to �
 
162
                        {name:myName, features:myFeatures, settings:mySettings, rsrcs:myRsrcs, projLibs:�
 
163
                                myLibs, fileData:myFiles}
 
164
                
 
165
                -- Impala
 
166
                set impalaData to my SimpleProjectData("impala", {})
 
167
                set item 1 of fileList of item 1 of fileData of impalaData to "profiles.c"
 
168
                
 
169
                -- asn2fsa
 
170
                set myName to "asn2fsa"
 
171
                set myFeatures to {"sockets"}
 
172
                set mySettings to {prefixFile:"", ppcProject:{}}
 
173
                set myRsrcs to {"ncbilogo.r", "Info.plc"}
 
174
                set myLibs to {"ncbi", "ncbiconn", "ncbiobj", "vibrant", "ncbitool", "netcli", "ncbiid1"}
 
175
                set myFiles to �
 
176
                        {{projPath:"demo:", fileList:{"asn2fsa.c"}}}
 
177
                set asn2fsaData to �
 
178
                        {name:myName, features:myFeatures, settings:mySettings, rsrcs:myRsrcs, projLibs:�
 
179
                                myLibs, fileData:myFiles}
 
180
                
 
181
                -- asn2all
 
182
                set myName to "asn2all"
 
183
                set myFeatures to {"sockets"}
 
184
                set mySettings to {prefixFile:"", ppcProject:{}}
 
185
                set myRsrcs to {"ncbilogo.r", "Info.plc"}
 
186
                set myLibs to {"ncbi", "ncbiconn", "ncbiobj", "vibrant", "ncbitool", "netcli", "ncbiid1"}
 
187
                set myFiles to �
 
188
                        {{projPath:"demo:", fileList:{"asn2all.c"}}}
 
189
                set asn2allData to �
 
190
                        {name:myName, features:myFeatures, settings:mySettings, rsrcs:myRsrcs, projLibs:�
 
191
                                myLibs, fileData:myFiles}
 
192
                
 
193
                -- Spidey
 
194
                set myName to "spidey"
 
195
                set myFeatures to {"sockets"}
 
196
                set mySettings to {prefixFile:"", ppcProject:{}}
 
197
                set myRsrcs to {"ncbilogo.r", "Info.plc"}
 
198
                set myLibs to {"ncbi", "ncbiconn", "ncbiobj", "vibrant", "ncbitool", "netcli", "ncbiid1", �
 
199
                        "ncbiblast", "ncbiblastapi"}
 
200
                set myFiles to �
 
201
                        {{projPath:"demo:", fileList:{"spideymain.c"}}}
 
202
                set spideyData to �
 
203
                        {name:myName, features:myFeatures, settings:mySettings, rsrcs:myRsrcs, projLibs:�
 
204
                                myLibs, fileData:myFiles}
 
205
                
 
206
        end tell
 
207
        
 
208
        
 
209
        AddProject(sequinData)
 
210
        AddProject(entrez2Data)
 
211
        AddSimpleProject("tbl2asn", {"sockets"})
 
212
        AddSimpleProject("asn2gb", {"sockets"})
 
213
        AddProject(asn2fsaData)
 
214
        AddProject(asn2allData)
 
215
        AddProject(spideyData)
 
216
        
 
217
        -- AddProject(entrezData)
 
218
        
 
219
        if pCreateBlastTargets then
 
220
                AddSimpleProject("formatdb", {})
 
221
                AddSimpleProject("fastacmd", {})
 
222
                
 
223
                AddProject(bl2seqData)
 
224
                
 
225
                AddSimpleProject("blastall", {})
 
226
                AddSimpleProject("blastpgp", {})
 
227
                
 
228
                AddProject(blastcl3Data)
 
229
                AddProject(megablastData)
 
230
                AddSimpleProject("blastclust", {})
 
231
                AddSimpleProject("rpsblast", {})
 
232
                AddSimpleProject("seedtop", {})
 
233
                AddProject(copymatData)
 
234
                AddSimpleProject("makemat", {})
 
235
                
 
236
                AddProject(impalaData)
 
237
        end if
 
238
        
 
239
end SetProjectData
 
240
 
 
241
--
 
242
-- Global variables
 
243
--
 
244
 
 
245
global gStartupDisk
 
246
global gHomeDir
 
247
 
 
248
global gDistribRoot
 
249
global gAccessRoot
 
250
 
 
251
global gProjectsDir
 
252
global gSourceDir
 
253
global gIncludeDir
 
254
global gLibsDir
 
255
global gRsrcsDir
 
256
global gMakeDir
 
257
global gStationeryDir
 
258
 
 
259
on GetFileNames(relPath)
 
260
        set theFiles to list folder (gSourceDir & relPath) without invisibles
 
261
        set theFiles to EndsWith(theFiles, ".c") -- Assume C projects not C++
 
262
        
 
263
        return theFiles
 
264
end GetFileNames
 
265
 
 
266
on EndsWith(aList, suffix)
 
267
        set newList to {}
 
268
        repeat with f in aList
 
269
                if (f ends with suffix) then
 
270
                        set newList to newList & (f as string)
 
271
                end if
 
272
        end repeat
 
273
        
 
274
        return newList
 
275
end EndsWith
 
276
 
 
277
 
 
278
on CopyHeaders()
 
279
        CreateFolder(gIncludeDir)
 
280
        tell application "Finder"
 
281
                
 
282
                set corelibFolder to folder (gDistribRoot & "corelib")
 
283
                
 
284
                my UpdateRenameHeader("ncbilcl.met", corelibFolder, "ncbilcl.h", "")
 
285
                
 
286
        end tell
 
287
end CopyHeaders
 
288
 
 
289
on ResolveAlias(pathname)
 
290
        tell application "Finder"
 
291
                if exists folder pathname then
 
292
                        -- if pathname does not end with ":" then set pathname to pathname & ":"
 
293
                        return folder pathname as string
 
294
                end if
 
295
                if exists alias file pathname then return the original item of alias file pathname as string
 
296
        end tell
 
297
        return ""
 
298
end ResolveAlias
 
299
 
 
300
on IsOSX()
 
301
        tell application "Finder"
 
302
                
 
303
                set vers to the version as text
 
304
                
 
305
                if second character of vers is equal to "." then
 
306
                        set vers to "0" & vers
 
307
                end if
 
308
                
 
309
                return vers > 10 or vers = 10
 
310
                
 
311
        end tell
 
312
end IsOSX
 
313
 
 
314
on stripVolName(macPath)
 
315
        set saveTID to get text item delimiters of AppleScript
 
316
        set text item delimiters of AppleScript to ":"
 
317
        set strippedPath to (rest of text items of macPath) as string
 
318
        set text item delimiters of AppleScript to saveTID
 
319
        return strippedPath
 
320
end stripVolName
 
321
 
 
322
on HomeDir()
 
323
        tell application "Finder"
 
324
                if my IsOSX() then
 
325
                        return the home as string
 
326
                else
 
327
                        return gStartupDisk
 
328
                end if
 
329
        end tell
 
330
end HomeDir
 
331
 
 
332
on ModuleRoot()
 
333
        set modRoot to ""
 
334
        try
 
335
                set modRoot to ResolveAlias(pRootFolderPath & pRootFolderName)
 
336
        end try
 
337
        if modRoot is "" then
 
338
                set modRoot to ResolveAlias(gHomeDir & pRootFolderName)
 
339
        end if
 
340
        return modRoot
 
341
end ModuleRoot
 
342
 
 
343
on GetMyPath()
 
344
        set myPath to path to me as string
 
345
        if myPath contains "Script Editor" or �
 
346
                myPath contains "osascript" or �
 
347
                myPath contains "Smile.app" then
 
348
                -- Oops! running under script editor. 'me' is Script Editor not this script.
 
349
                -- use the location this script is supposed to be in.
 
350
                return gDistribRoot & "make:"
 
351
        else
 
352
                tell application "Finder"
 
353
                        return container of myPath as string
 
354
                end tell
 
355
        end if
 
356
end GetMyPath
 
357
 
 
358
on SetGlobals()
 
359
        tell application "Finder"
 
360
                
 
361
                set gProjectData to {}
 
362
                
 
363
                set gStartupDisk to startup disk as string
 
364
                set gHomeDir to my HomeDir()
 
365
                set gDistribRoot to my ModuleRoot()
 
366
                
 
367
                set gIncludeDir to gDistribRoot & "include:"
 
368
                set gSourceDir to gDistribRoot
 
369
                set gLibsDir to gDistribRoot & "lib:"
 
370
                set gProjectsDir to gDistribRoot & "build:"
 
371
                set gRsrcsDir to gDistribRoot & "link:macmet:"
 
372
                set gStationeryDir to gProjectsDir & pStationeryName & ":"
 
373
                set gMakeDir to my GetMyPath()
 
374
                
 
375
        end tell
 
376
end SetGlobals
 
377
 
 
378
on HeaderExists(header, headerDir)
 
379
        tell application "Finder"
 
380
                if headerDir is "" then set headerDir to folder gIncludeDir
 
381
                return exists file header of headerDir
 
382
        end tell
 
383
end HeaderExists
 
384
 
 
385
on IsOlderThan(fileA, fileB)
 
386
        tell application "Finder"
 
387
                return (the modification date of fileA < the modification date of fileB)
 
388
        end tell
 
389
end IsOlderThan
 
390
 
 
391
on UpdateRenameHeader(canonicalName, canonicalDir, dotHName, dotHDir)
 
392
        tell application "Finder"
 
393
                
 
394
                set needRename to (dotHName is not "")
 
395
                if not needRename then set dotHName to canonicalName
 
396
                if dotHDir is "" then set dotHDir to folder gIncludeDir
 
397
                
 
398
                -- This file is only present if the script was interrupted.
 
399
                if needRename and my HeaderExists(canonicalName, dotHDir) then
 
400
                        delete file canonicalName of dotHDir
 
401
                end if
 
402
                
 
403
                -- The native config file.
 
404
                -- If it's missing, assume this is a prepared distribution and the header is already up-to-date.
 
405
                if not my HeaderExists(canonicalName, canonicalDir) then return
 
406
                set canonicalFile to file canonicalName of canonicalDir
 
407
                
 
408
                set needCopy to true
 
409
                if my HeaderExists(dotHName, dotHDir) then
 
410
                        set dotHFile to file dotHName of dotHDir
 
411
                        if my IsOlderThan(dotHFile, canonicalFile) then
 
412
                                delete dotHFile
 
413
                        else
 
414
                                set needCopy to false
 
415
                        end if
 
416
                end if
 
417
                
 
418
                if needCopy then
 
419
                        duplicate canonicalFile to dotHDir
 
420
                        if needRename then set name of file canonicalName of dotHDir to dotHName
 
421
                end if
 
422
                
 
423
        end tell
 
424
end UpdateRenameHeader
 
425
 
 
426
 
 
427
on AppendAccessPath(aPath, isRecursive, isUserPath)
 
428
        tell application "CodeWarrior IDE"
 
429
                if (aPath does not end with ":") then set aPath to aPath & ":"
 
430
                
 
431
                set aPath to POSIX path of aPath
 
432
                set pathsToAdd to {{name:aPath, recursive:isRecursive, origin:absolute, format:Unix Path}}
 
433
                if isUserPath then
 
434
                        Set Preferences of panel "Access Paths" to {User Paths:pathsToAdd}
 
435
                else
 
436
                        Set Preferences of panel "Access Paths" to {System Paths:pathsToAdd}
 
437
                end if
 
438
        end tell
 
439
end AppendAccessPath
 
440
 
 
441
 
 
442
on AppendPrefixFile(filename)
 
443
        tell application "CodeWarrior IDE"
 
444
                try -- CW ver. 8
 
445
                        Set Preferences of panel "C/C++ Compiler" to {Prefix File:prefixFile}
 
446
                end try
 
447
                try -- CW ver. 9
 
448
                        set oldtext to Get Preferences of {Prefix Text} from panel "C/C++ Preprocessor"
 
449
                        set oldtext to (Prefix Text of oldtext)
 
450
                        set prefixFileInclude to (oldtext & return & "#include \"" & filename & "\"")
 
451
                        Set Preferences of panel "C/C++ Preprocessor" to {Prefix Text:prefixFileInclude}
 
452
                end try
 
453
        end tell
 
454
end AppendPrefixFile
 
455
 
 
456
 
 
457
on SetupTarget(proj, targetIndex)
 
458
        tell application "CodeWarrior IDE"
 
459
                
 
460
                set targetName to name of target targetIndex of project document 1
 
461
                if targetName contains "Carbon" then
 
462
                        set targetAPI to "Carbon"
 
463
                else if targetName contains "Mach-O" then
 
464
                        if not my IsOSX() then return -- do not try to populate Mach-O targets on pre-OS X systems.
 
465
                        set targetAPI to "Mach-O"
 
466
                else if targetName contains "Win32" then
 
467
                        set targetAPI to "Win32"
 
468
                end if
 
469
                
 
470
                if targetName contains "Debug" then
 
471
                        set targetDebug to true
 
472
                        set targetProfile to false
 
473
                else if targetName contains "Profile" then
 
474
                        set targetDebug to false
 
475
                        set targetProfile to true
 
476
                else -- if targeName contains "Final" then
 
477
                        set targetDebug to false
 
478
                        set targetProfile to false
 
479
                end if
 
480
                
 
481
                -- NOTE: no Profile targets. if pCreateProfiledTargets, we make the debug targets also profile-able.
 
482
                
 
483
                set the current target of project document 1 to target targetIndex of project document 1
 
484
                
 
485
                -- initialize variables
 
486
                set projRsrcs to {}
 
487
                set projFeatures to {}
 
488
                set sysPaths to {}
 
489
                
 
490
                -- Grab the fields of our project record and store them in local variables.
 
491
                set projName to proj's name
 
492
                set projSettings to proj's settings
 
493
                try
 
494
                        set projFeatures to proj's features
 
495
                end try
 
496
                try
 
497
                        set sysPaths to proj's sysPaths
 
498
                end try
 
499
                try
 
500
                        set projRsrcs to proj's rsrcs
 
501
                end try
 
502
                set projLibs to proj's projLibs
 
503
                set projFileData to proj's fileData
 
504
                
 
505
                -- Figure out what our output file and input libraries will be named.
 
506
                set fileNameSuffix to ""
 
507
                
 
508
                if targetAPI is "Carbon" then
 
509
                        set fileNameSuffix to "_C"
 
510
                else if targetAPI is "Mach-O" then
 
511
                        set fileNameSuffix to "_M"
 
512
                else if targetAPI is "Win32" then
 
513
                        set fileNameSuffix to "_W"
 
514
                end if
 
515
                
 
516
                -- Debug or not.
 
517
                if targetDebug then
 
518
                        set fileNameSuffix to fileNameSuffix & "_D"
 
519
                else if targetProfile then
 
520
                        set fileNameSuffix to fileNameSuffix & "_P"
 
521
                else
 
522
                        set fileNameSuffix to fileNameSuffix & "_O" -- for Optimized.
 
523
                end if
 
524
                
 
525
                -- non debug targets get different output names.
 
526
                if not targetDebug and not targetProfile then
 
527
                        if targetAPI is "Mach-O" then
 
528
                                set targetFilename to projName & "OSX" -- Mach adds OSX on the end.
 
529
                        else if targetAPI is "Carbon" then
 
530
                                set targetFilename to projName & "OS9" -- Carbon adds OS9 on the end.
 
531
                        else
 
532
                                set targetFilename to projName -- Windows have same name as project.
 
533
                        end if
 
534
                else
 
535
                        set targetFilename to projName & fileNameSuffix
 
536
                end if
 
537
                
 
538
                -- make sure Mach bundles have .app on the end.
 
539
                if targetAPI is "Mach-O" then
 
540
                        set targetFilename to targetFilename & ".app"
 
541
                else if targetAPI is "Win32" then
 
542
                        -- and Windows executables have .exe
 
543
                        set targetFilename to targetFilename & ".exe"
 
544
                end if
 
545
                
 
546
                -- Get Preference Panel names.
 
547
                if targetAPI is "Mach-O" then
 
548
                        set targetPanelName to "PPC Mac OS X Project"
 
549
                        set codeGenPanelName to "PPC CodeGen Mach-O"
 
550
                else if targetAPI is "Win32" then
 
551
                        set targetPanelName to "x86 Project"
 
552
                        set codeGenPanelName to "x86 CodeGen"
 
553
                else
 
554
                        set targetPanelName to "PPC Project"
 
555
                        set codeGenPanelName to "PPC CodeGen"
 
556
                end if
 
557
                
 
558
                -- Set the name of the output file (the application)
 
559
                Set Preferences of panel targetPanelName to {File Name:targetFilename}
 
560
                
 
561
                -- If specified, set the File Creator.
 
562
                try
 
563
                        set creatorName to creator of projSettings
 
564
                        Set Preferences of panel targetPanelName to {File Creator:creatorName}
 
565
                end try
 
566
                
 
567
                -- If we have any per-project override settings, set them.
 
568
                if (count ppcProject of projSettings) > 0 then
 
569
                        try
 
570
                                Set Preferences of panel targetPanelName to ppcProject of projSettings
 
571
                        end try
 
572
                end if
 
573
                
 
574
                
 
575
                if targetAPI is "Mach-O" then
 
576
                        my AppendAccessPath(gDistribRoot, true, false) -- end of system paths.
 
577
                else
 
578
                        my AppendAccessPath(gDistribRoot, true, true) -- end of user paths.
 
579
                end if
 
580
                
 
581
                -- Add per-project system paths.
 
582
                set pathsToAdd to {}
 
583
                repeat with i in sysPaths
 
584
                        copy {name:i, recursive:false, origin:absolute} to end of pathsToAdd
 
585
                end repeat
 
586
                if (count pathsToAdd) > 0 then �
 
587
                        Set Preferences of panel "Access Paths" to {System Paths:pathsToAdd}
 
588
                
 
589
                -- Set the appropriate prefix file.
 
590
                set prefixFile to prefixFile of projSettings
 
591
                if targetAPI is "Win32" and projFeatures contains "winprefix" then
 
592
                        set prefixFile to "Win32Headers.pch"
 
593
                else
 
594
                        if prefixFile is "" then
 
595
                                set prefixFile to "CarbonPrefix.h"
 
596
                        else
 
597
                                set prefixFile to "Carbon-" & prefixFile
 
598
                        end if
 
599
                end if
 
600
                if prefixFile is not "" then
 
601
                        my AppendPrefixFile(prefixFile)
 
602
                end if
 
603
                
 
604
        end tell
 
605
        
 
606
        -- Add source files.
 
607
        repeat with group in projFileData
 
608
                set projPath to projPath of group
 
609
                set fileList to group's fileList
 
610
                
 
611
                set filesToAdd to {}
 
612
                repeat with i in fileList
 
613
                        --try -- ignore it if the file doesn't exist.
 
614
                        
 
615
                        -- NOTE: if the following line is within a tell "Codewarrior" block then
 
616
                        --  the following Add Files command will fail.
 
617
                        copy alias (gSourceDir & projPath & i) to end of filesToAdd
 
618
                        --end try
 
619
                end repeat
 
620
                
 
621
                tell application "CodeWarrior IDE"
 
622
                        Add Files filesToAdd
 
623
                        
 
624
                        -- Take out source files that do not belong.
 
625
                        --set fileNotList to group's fileNotList
 
626
                        --Remove Files fileNotList
 
627
                end tell
 
628
        end repeat
 
629
        
 
630
        tell application "CodeWarrior IDE"
 
631
                
 
632
                -- take care of debugging and profiling settings
 
633
                if targetDebug or targetProfile then
 
634
                        set the debug of every target file of target targetIndex �
 
635
                                of project document 1 to true
 
636
                end if
 
637
                
 
638
                
 
639
                if targetAPI is "Carbon" then
 
640
                        if targetProfile then
 
641
                                (* ===== Panel PPC Processor ===== *)
 
642
                                Set Preferences of panel codeGenPanelName to �
 
643
                                        {Use Profiler:true}
 
644
                        else
 
645
                                (* ===== Panel PPC Processor ===== *)
 
646
                                Set Preferences of panel codeGenPanelName to �
 
647
                                        {Use Profiler:false}
 
648
                        end if
 
649
                end if
 
650
                
 
651
                -- Add user libraries.
 
652
                set filesToAdd to {}
 
653
                if projFeatures contains "sockets" and targetAPI is "Carbon" then
 
654
                        if projLibs does not contain "mitsock" then
 
655
                                copy "mitsock" to beginning of projLibs
 
656
                        end if
 
657
                end if
 
658
                repeat with i in projLibs
 
659
                        if exists file (gLibsDir & i & fileNameSuffix & ".lib") of application "Finder" then
 
660
                                copy gLibsDir & i & fileNameSuffix & ".lib" to end of filesToAdd
 
661
                        end if
 
662
                end repeat
 
663
                
 
664
                try
 
665
                        Add Files filesToAdd
 
666
                end try
 
667
                
 
668
                -- Add resources.
 
669
                set filesToAdd to {}
 
670
                if targetAPI is not "Win32" then
 
671
                        repeat with i in projRsrcs
 
672
                                if targetAPI is "Carbon" then
 
673
                                        if i ends with ".plc" then
 
674
                                                copy gRsrcsDir & "Carbon-" & i to end of filesToAdd
 
675
                                        else
 
676
                                                copy gRsrcsDir & i to end of filesToAdd
 
677
                                        end if
 
678
                                else
 
679
                                        -- Mach-O does not need the .r files, only the .plc files.
 
680
                                        if i does not end with ".r" then
 
681
                                                copy gRsrcsDir & i to end of filesToAdd
 
682
                                        end if
 
683
                                end if
 
684
                        end repeat
 
685
                        
 
686
                        Add Files filesToAdd
 
687
                end if
 
688
                
 
689
        end tell
 
690
end SetupTarget
 
691
 
 
692
 
 
693
on GetTargetFiles(i)
 
694
        tell application "CodeWarrior IDE"
 
695
                -- get the target
 
696
                if (i > (count of targets of project document 1)) then
 
697
                        return {}
 
698
                end if
 
699
                -- get references to all the targets files
 
700
                set atarget to get target i of project document 1
 
701
                set trefs to (target files of atarget whose linked is true)
 
702
        end tell
 
703
        set tfiles to {}
 
704
        if ((count of trefs) � 0) then
 
705
                repeat with tf in trefs
 
706
                        -- get locations of the targets files (as file objects)
 
707
                        tell application "CodeWarrior IDE"
 
708
                                set f to (location of tf)
 
709
                        end tell
 
710
                        tell application "Finder"
 
711
                                -- convert the file's to strings (colon style paths)
 
712
                                try
 
713
                                        copy f as string to end of tfiles
 
714
                                on error errmsg number errnum
 
715
                                        -- file in target but does not exist.
 
716
                                        if errnum � -2753 then -- variable not defined.
 
717
                                                error errmsg number errnum
 
718
                                        end if
 
719
                                end try
 
720
                        end tell
 
721
                end repeat
 
722
        end if
 
723
        return tfiles
 
724
end GetTargetFiles
 
725
 
 
726
on UpdateTarget(proj, targetIndex)
 
727
        
 
728
        tell application "CodeWarrior IDE"
 
729
                
 
730
                set targetName to name of target targetIndex of project document 1
 
731
                if targetName contains "Carbon" then
 
732
                        set targetAPI to "Carbon"
 
733
                else if targetName contains "Mach-O" then
 
734
                        if not my IsOSX() then return -- do not try to populate Mach-O targets on pre-OS X systems.
 
735
                        set targetAPI to "Mach-O"
 
736
                else if targetName contains "Win32" then
 
737
                        set targetAPI to "Win32"
 
738
                end if
 
739
                
 
740
                -- Grab the fields of our project record and store them in local variables.
 
741
                set projName to proj's name
 
742
                
 
743
                set targetName to name of target targetIndex of project document 1
 
744
                
 
745
                set the current target of project document 1 to target targetIndex of project document 1
 
746
                
 
747
                -- initialize variables
 
748
                set projFeatures to {}
 
749
                
 
750
                -- Grab the fields of our project record and store them in local variables.
 
751
                try
 
752
                        set projFeatures to proj's features
 
753
                end try
 
754
                set projFileData to proj's fileData
 
755
                
 
756
        end tell
 
757
        
 
758
        -- Update source files
 
759
        set targetFileList to my GetTargetFiles(targetIndex)
 
760
        repeat with group in projFileData
 
761
                set projPath to projPath of group -- projPath is relative.
 
762
                
 
763
                set fileList to group's fileList
 
764
                
 
765
                set filesToAdd to {}
 
766
                
 
767
                repeat with i in fileList
 
768
                        set fileFullPath to gSourceDir & projPath & i
 
769
                        set found to targetFileList contains fileFullPath
 
770
                        if (not found) then
 
771
                                try -- ignore it if the file doesn't exist.
 
772
                                        
 
773
                                        -- NOTE: if the following line is within a tell "Codewarrior" block then
 
774
                                        --  the following Add Files command will fail.
 
775
                                        
 
776
                                        copy alias (fileFullPath) to end of filesToAdd
 
777
                                end try
 
778
                        end if
 
779
                end repeat
 
780
                
 
781
                tell application "CodeWarrior IDE"
 
782
                        if ((count of filesToAdd) is not 0) then
 
783
                                Add Files filesToAdd
 
784
                                set targetFileList to my GetTargetFiles(targetIndex)
 
785
                        end if
 
786
                        
 
787
                        -- Take out source files that do not belong.
 
788
                        --set fileNotList to group's fileNotList
 
789
                        --Remove Files fileNotList
 
790
                end tell
 
791
        end repeat
 
792
        
 
793
end UpdateTarget
 
794
 
 
795
on CreateFolder(folderPath)
 
796
        set text item delimiters of AppleScript to ":"
 
797
        -- strip off disk name.
 
798
        tell application "Finder"
 
799
                set pathSoFar to ""
 
800
                if (exists disk (first text item of folderPath)) then
 
801
                        set pathSoFar to first text item of folderPath
 
802
                        set folderPath to (rest of text items of folderPath) as string
 
803
                end if
 
804
                repeat with f in (text items of folderPath)
 
805
                        set longerPath to pathSoFar & ":" & f
 
806
                        if not (exists folder (longerPath)) then
 
807
                                make new folder at folder (pathSoFar) with properties {name:f}
 
808
                        end if
 
809
                        set pathSoFar to longerPath
 
810
                end repeat
 
811
        end tell
 
812
        set text item delimiters of AppleScript to ""
 
813
end CreateFolder
 
814
 
 
815
on GetStationeryName(proj)
 
816
        set stationeryDir to gProjectsDir & pStationeryName & ":"
 
817
        set stationeryName to pStationeryName & pProjectFileExt
 
818
        
 
819
        CreateFolder(stationeryDir)
 
820
        tell application "Finder"
 
821
                -- does the Library Stationery already exist?
 
822
                if not (exists file (stationeryDir & stationeryName)) then
 
823
                        -- copy it.
 
824
                        duplicate file (stationeryName) of folder gRsrcsDir to folder stationeryDir
 
825
                end if
 
826
        end tell
 
827
        return (stationeryDir & stationeryName)
 
828
end GetStationeryName
 
829
 
 
830
on CreateProject(proj)
 
831
        tell application "CodeWarrior IDE"
 
832
                try
 
833
                        get proj's name
 
834
                on error
 
835
                        return
 
836
                end try
 
837
                
 
838
                set projFilename to proj's name & pProjectFileExt
 
839
                set projPathname to gProjectsDir & projFilename
 
840
                if pAlwaysCreateProjects or not (exists file projPathname of application "Finder") then
 
841
                        
 
842
                        try
 
843
                                close (the first project document whose name is projFilename)
 
844
                        end try
 
845
                        
 
846
                        set stationeryName to my GetStationeryName(proj)
 
847
                        
 
848
                        Create Project projPathname from stationery alias stationeryName
 
849
                        if the name of window 1 is "Project Messages" then
 
850
                                close first window -- "close window 1" becomes "Close Window 1" (different event)
 
851
                        end if
 
852
                        
 
853
                        repeat with i from 1 to (count targets of project document 1)
 
854
                                my SetupTarget(proj, i)
 
855
                        end repeat
 
856
                else
 
857
                        -- project already exists. Make sure it has all right files.
 
858
                        open (projPathname)
 
859
                        if the name of window 1 is "Project Messages" then
 
860
                                close first window -- "close window 1" becomes "Close Window 1" (different event)
 
861
                        end if
 
862
                        repeat with i from 1 to (count targets of project document 1)
 
863
                                my UpdateTarget(proj, i)
 
864
                        end repeat
 
865
                end if
 
866
                if pProjectsCVSEnabled then
 
867
                        --try
 
868
                        Set Preferences of panel "VCS Setup" to {VCS Active:true, Connection Method:"mwCVS"}
 
869
                        --end try
 
870
                end if
 
871
                set the current target of project document 1 to target 1 of project document 1
 
872
                Close Project
 
873
                
 
874
        end tell
 
875
end CreateProject
 
876
 
 
877
on CreateAllProjects()
 
878
        CreateFolder(gProjectsDir)
 
879
        CleanupFiles(gProjectsDir)
 
880
        
 
881
        repeat with proj in gProjectData
 
882
                CreateProject(proj)
 
883
        end repeat
 
884
        
 
885
end CreateAllProjects
 
886
 
 
887
(*
 
888
        a target spec is a string of words "MSL Debug", all of which appear on our list of keywords.
 
889
        Convert a Build file name to a target spec by filtering out non-keywords.
 
890
        Each Build file creates another target spec.
 
891
        A project target must match one of the target specs to compile.
 
892
        To match, a target's name must contain each of the words in the target spec.
 
893
        An empty target spec matches everything.
 
894
        An empty list of target specs (no Build files) matches nothing, 
 
895
        But if there are no Build files we make target specs based on
 
896
        the script parameters.
 
897
*)
 
898
 
 
899
on GetTargetSpecs()
 
900
        set theFiles to (list folder gMakeDir without invisibles)
 
901
        set targetSpecs to {}
 
902
        repeat with f in theFiles
 
903
                if (f begins with "Build ") then
 
904
                        set targetSpecs to targetSpecs & MakeTargetSpec(f)
 
905
                end if
 
906
        end repeat
 
907
        -- no Build files? match what the script parameters say to match.
 
908
        -- NOTE: This is dependent on pTargetKeyWords and the target names in the stationery.
 
909
        if (count items of targetSpecs) is 0 then
 
910
                set debugspec to ""
 
911
                if pCreateDebugTargets then
 
912
                        if pCreateMachOTargets then copy ("Mach-O Debug") to end of targetSpecs
 
913
                        if pCreateCarbonTargets then copy ("Carbon Debug") to end of targetSpecs
 
914
                        if pCreateWinTargets then copy ("Win32 Debug") to end of targetSpecs
 
915
                end if
 
916
                if pCreateProfiledTargets then
 
917
                        if pCreateMachOTargets then copy ("Mach-O Profile") to end of targetSpecs
 
918
                        if pCreateCarbonTargets then copy ("Carbon Profile") to end of targetSpecs
 
919
                        if pCreateWinTargets then copy ("Win32 Profile") to end of targetSpecs
 
920
                end if
 
921
                if pCreateOptimizedTargets then
 
922
                        if pCreateMachOTargets then copy ("Mach-O Final") to end of targetSpecs
 
923
                        if pCreateCarbonTargets then copy ("Carbon Final") to end of targetSpecs
 
924
                        if pCreateWinTargets then copy ("Win32 Final") to end of targetSpecs
 
925
                end if
 
926
        end if
 
927
        return targetSpecs
 
928
end GetTargetSpecs
 
929
 
 
930
on MakeTargetSpec(f)
 
931
        set tspec to ""
 
932
        repeat with w in (words of f)
 
933
                if pTargetKeyWords contains w then
 
934
                        set tspec to tspec & w & " "
 
935
                end if
 
936
        end repeat
 
937
        return tspec
 
938
end MakeTargetSpec
 
939
 
 
940
on OkaytoBuild(targetName, targetSpecs)
 
941
        --This target name must match at least one of the target specs.
 
942
        repeat with ts in targetSpecs
 
943
                if MatchSpec2Target(ts, targetName) then return true
 
944
        end repeat
 
945
        return false
 
946
end OkaytoBuild
 
947
 
 
948
on MatchSpec2Target(targSpec, targName)
 
949
        -- the targetname must contain all of the words in the target spec.
 
950
        repeat with w in (words of targSpec)
 
951
                if w is not in targName then return false
 
952
        end repeat
 
953
        return true
 
954
end MatchSpec2Target
 
955
 
 
956
on BuildProject(projName, targetSpecs)
 
957
        tell application "CodeWarrior IDE"
 
958
                open (gProjectsDir & projName & pProjectFileExt)
 
959
                if the name of window 1 is "Project Messages" then
 
960
                        close first window -- "close window 1" becomes "Close Window 1" (different event)
 
961
                end if
 
962
                repeat with i from 1 to (count targets of project document 1)
 
963
                        -- do we want to build this target?
 
964
                        set thisTarget to name of target i of project document 1
 
965
                        if my OkaytoBuild(thisTarget, targetSpecs) then
 
966
                                
 
967
                                set the current target of project document 1 to target i of project document 1
 
968
                                if pSaveContinueOnErrors then
 
969
                                        try
 
970
                                                Make Project
 
971
                                        on error errmsg number errnum
 
972
                                                if (errnum = 5) then
 
973
                                                        set errFileName to (gProjectsDir & projName & "-" & i & ".errs")
 
974
                                                        Save Error Window As (file errFileName)
 
975
                                                        close first window
 
976
                                                else
 
977
                                                        error errmsg number errnum
 
978
                                                end if
 
979
                                        end try
 
980
                                else -- stop on any error.
 
981
                                        Make Project
 
982
                                end if
 
983
                                -- If there were compiler warnings, then a compiler window will be in front.
 
984
                                -- For whatever reason, this causes the next "set the current target..." to fail.
 
985
                                -- So check for the window and close it.
 
986
                                if the name of window 1 is "Errors & Warnings" then
 
987
                                        close first window -- "close window 1" becomes "Close Window 1" (different event)
 
988
                                end if
 
989
                        end if
 
990
                end repeat
 
991
                set the current target of project document 1 to target 1 of project document 1
 
992
                Close Project
 
993
        end tell
 
994
end BuildProject
 
995
 
 
996
on BuildAllProjects()
 
997
        set targetSpecs to GetTargetSpecs()
 
998
        repeat with proj in gProjectData
 
999
                try
 
1000
                        set projName to proj's name
 
1001
                on error
 
1002
                        set projName to ""
 
1003
                end try
 
1004
                if projName is not "" then
 
1005
                        BuildProject(projName, targetSpecs)
 
1006
                end if
 
1007
        end repeat
 
1008
        
 
1009
end BuildAllProjects
 
1010
 
 
1011
-- Delete everything in the folder 'thePath' except the saveFile.
 
1012
on CleanupFolder(thePath, saveFile)
 
1013
        repeat with f in list folder (thePath) with invisibles
 
1014
                if (f as string is not saveFile) then
 
1015
                        try
 
1016
                                tell application "Finder" to delete folder (thePath & f)
 
1017
                        end try
 
1018
                        try
 
1019
                                tell application "Finder" to delete file (thePath & f)
 
1020
                        end try
 
1021
                end if
 
1022
        end repeat
 
1023
end CleanupFolder
 
1024
 
 
1025
on CleanupFiles(thePath)
 
1026
        -- get rid of all the files and folders starting with xxxx in thePath
 
1027
        repeat with f in list folder (thePath) without invisibles
 
1028
                if ((f as string) begins with "xxxx") then
 
1029
                        try
 
1030
                                tell application "Finder" to delete folder (thePath & f)
 
1031
                        end try
 
1032
                        try
 
1033
                                tell application "Finder" to delete file (thePath & f)
 
1034
                        end try
 
1035
                end if
 
1036
        end repeat
 
1037
        -- delete the stationery folder.
 
1038
        try
 
1039
                tell application "Finder" to delete folder (thePath & pStationeryName)
 
1040
        end try
 
1041
end CleanupFiles
 
1042
 
 
1043
on SignalCompletion()
 
1044
        beep
 
1045
end SignalCompletion
 
1046
 
 
1047
with timeout of 60000 seconds
 
1048
        
 
1049
        SetGlobals()
 
1050
        SetProjectData()
 
1051
        CopyHeaders()
 
1052
        
 
1053
        tell application "CodeWarrior IDE" to activate
 
1054
        
 
1055
        CreateAllProjects()
 
1056
        
 
1057
        if pShouldBuild then
 
1058
                BuildAllProjects()
 
1059
        end if
 
1060
        
 
1061
        CleanupFiles(gProjectsDir)
 
1062
        
 
1063
        SignalCompletion()
 
1064
        
 
1065
end timeout
 
1066