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

« back to all changes in this revision

Viewing changes to make/makeLibs.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 libs --
 
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
 
 
18
-- Which targets to build.
 
19
-- All of the targets are populated all the time. These affect what is compiled & built.
 
20
property pCreateMachOTargets : true
 
21
property pCreateCarbonTargets : false
 
22
property pCreateWinTargets : false
 
23
 
 
24
property pCreateOptimizedTargets : true
 
25
property pCreateDebugTargets : false
 
26
property pCreateProfiledTargets : false
 
27
 
 
28
-- Whether to have the projects use CVS or not.
 
29
property pProjectsCVSEnabled : true
 
30
 
 
31
-- Whether to compile anything.
 
32
property pShouldBuild : true
 
33
 
 
34
property pStationeryName : "LibraryStationery"
 
35
 
 
36
-- the handler GetTargetSpecs should change if these do.
 
37
property pTargetKeyWords : "Mach-O Carbon Win32 Debug Final Profile"
 
38
 
 
39
 
 
40
global gStartupDisk
 
41
global gHomeDir
 
42
global gDistribRoot
 
43
global gProjectsDir
 
44
global gSourceDir
 
45
global gIncludeDir
 
46
global gRsrcsDir
 
47
global gMakeDir
 
48
 
 
49
global gProjectData
 
50
 
 
51
on ProjectData(projName, features, aFileData)
 
52
        
 
53
        if (count characters of projName) > 25 then
 
54
                set projName to characters 1 through 25 of projName as string
 
55
        end if
 
56
        
 
57
        if features does not contain "C" and features does not contain "C++" then
 
58
                copy "C" to end of features
 
59
        end if
 
60
        set myFeatures to features
 
61
        
 
62
        return {name:projName, features:myFeatures, rsrcs:{}, settings:�
 
63
                {prefixFile:"", ppcProject:{}}, projLibs:{}, sysPaths:{}, fileData:�
 
64
                aFileData}
 
65
        
 
66
end ProjectData
 
67
 
 
68
on AddProject(projData)
 
69
        copy projData to end of gProjectData
 
70
end AddProject
 
71
 
 
72
on AddSimpleProject(projName, features, section)
 
73
        AddProject(ProjectData(projName, features, {mkFileData(section)}))
 
74
end AddSimpleProject
 
75
 
 
76
on AddSimpleProjectListFiles(projName, features, section, fileList)
 
77
        AddProject(ProjectData(projName, features, {mkFileDataListFiles(section, fileList)}))
 
78
end AddSimpleProjectListFiles
 
79
 
 
80
on AddSimpleProjectExceptFiles(projName, features, section, fileNotList)
 
81
        AddProject(ProjectData(projName, features, {mkFileDataExceptFiles(section, fileNotList)}))
 
82
end AddSimpleProjectExceptFiles
 
83
 
 
84
on mkFileData(section)
 
85
        if (section does not end with ":") then set section to section & ":"
 
86
        return {projPath:section, fileList:GetFileNames(section), fileNotList:{}}
 
87
end mkFileData
 
88
 
 
89
on mkFileDataListFiles(section, fileList)
 
90
        if (section does not end with ":") then set section to section & ":"
 
91
        set newFileList to {}
 
92
        repeat with i in fileList
 
93
                if i does not contain "." then set i to i & ".c"
 
94
                copy (contents of i) to end of newFileList
 
95
        end repeat
 
96
        return {projPath:section, fileList:newFileList, fileNotList:{}}
 
97
end mkFileDataListFiles
 
98
 
 
99
on mkFileDataExceptFiles(section, fileNotList)
 
100
        if (section does not end with ":") then set section to section & ":"
 
101
        set theFileList to GetFileNames(section)
 
102
        set theRealFileList to {}
 
103
        repeat with f in theFileList
 
104
                if fileNotList does not contain f then
 
105
                        copy f to the end of theRealFileList
 
106
                end if
 
107
        end repeat
 
108
        return {projPath:section, fileList:theRealFileList, fileNotList:fileNotList}
 
109
end mkFileDataExceptFiles
 
110
 
 
111
on DataPlusPrefixFile(dataRec, prefix)
 
112
        tell application "CodeWarrior IDE"
 
113
                
 
114
                set the prefixFile of dataRec's settings to prefix
 
115
                return dataRec
 
116
                
 
117
        end tell
 
118
end DataPlusPrefixFile
 
119
 
 
120
on GetFileNames(relPath)
 
121
        set theFiles to list folder (gSourceDir & relPath) without invisibles
 
122
        set theFiles to EndsWith(theFiles, ".c") -- Assume C projects not C++
 
123
        
 
124
        return theFiles
 
125
end GetFileNames
 
126
 
 
127
on EndsWith(aList, suffix)
 
128
        set newList to {}
 
129
        repeat with f in aList
 
130
                if (f ends with suffix) then
 
131
                        copy (f as string) to end of newList
 
132
                end if
 
133
        end repeat
 
134
        return newList
 
135
end EndsWith
 
136
 
 
137
on SetProjectData()
 
138
        
 
139
        -- Only needed for Carbon
 
140
        AddSimpleProject("mitsock", {}, "connect:mitsock")
 
141
        
 
142
        AddProject(ProjectData("ncbi", {"winprefix"}, {�
 
143
                mkFileDataExceptFiles("corelib:", {"drwnflpt.c", "drwnfspc.c", "drwnmfls.c", "ncbiargs.c", "ncbimain.c"}), �
 
144
                mkFileData("corelib:morefile:"), �
 
145
                mkFileDataListFiles("connect:", {"ncbibuf", "ncbisock", "urlquery"}), �
 
146
                mkFileData("ctools:"), �
 
147
                mkFileDataListFiles("util:tables:", {"raw_scoremat"}), �
 
148
                mkFileDataExceptFiles("asnlib:", {"asncode.c", "asntool.c"})}))
 
149
        
 
150
        AddProject(ProjectData("ncbiobj", {}, {�
 
151
                mkFileDataExceptFiles("object:", {"objmime.c"}), �
 
152
                mkFileDataExceptFiles("access:", {"strucapi.c"}), �
 
153
                mkFileData("api:"), �
 
154
                mkFileData("util:creaders:"), �
 
155
                mkFileDataExceptFiles("ddv:", {"ddvmain.c"})}))
 
156
        
 
157
        AddSimpleProject("vibrant", {"winprefix"}, "vibrant")
 
158
        
 
159
        AddSimpleProjectExceptFiles("ncbicdr", {}, "cdromlib", {"acccn3ds.c", "accentr.c", "accmmdbs.c", "accutils.c"})
 
160
        
 
161
        AddSimpleProjectExceptFiles("ncbidesk", {}, "desktop", {"sdisplay.c"})
 
162
        
 
163
        AddSimpleProject("ddvlib", {}, "ddv")
 
164
        
 
165
        AddProject(DataPlusPrefixFile(ProjectData("ncbimmdb", {}, {�
 
166
                mkFileDataListFiles("biostruc:", {�
 
167
                        "corematx", "dvncode", "objmmdb1", "objmmdb2", "objmmdb3", "mmdbapi", �
 
168
                        "mmdbapi1", "mmdbapi2", "mmdbapi3", "mmdbapi4", "mmdbentr", "vastsubs", �
 
169
                        "prunebsc"}), �
 
170
                mkFileDataListFiles("object:", {�
 
171
                        "objmime"}), �
 
172
                mkFileDataListFiles("access:", {�
 
173
                        "strucapi"}), �
 
174
                mkFileDataListFiles("biostruc:cn3d:", {�
 
175
                        "objcn3d"}), �
 
176
                mkFileDataListFiles("biostruc:cdd:", {�
 
177
                        "objcdd", "cddutil", "cddposutil", �
 
178
                        "thrdalgs", "thrdatd", "thrdbwfi", "thrdcpal", �
 
179
                        "thrdcpll", "thrdcprl", "thrdcxei", "thrddgri", "thrdrsmp", �
 
180
                        "thrdsal0", "thrdsalr", "thrdsalu", "thrdsgoi", "thrdslo0", �
 
181
                        "thrdslor", "thrdslou", "thrdspci", "thrdspea", "thrdspel", �
 
182
                        "thrdspni", "thrdttb0", "thrdttbi", "thrdzsc"})}), "gif.pfx"))
 
183
        
 
184
        AddSimpleProject("ncbiNacc", {}, "cdromlib")
 
185
        
 
186
        AddSimpleProject("vibnet", {}, "network:vibnet")
 
187
        
 
188
        AddSimpleProject("ncbitool", {}, "tools")
 
189
        
 
190
        AddSimpleProject("netentr", {}, "network:entrez:client")
 
191
        
 
192
        AddSimpleProjectExceptFiles("ncbibls3", {}, "network:blast3:client", {"blastcl3.c"})
 
193
        
 
194
        AddSimpleProjectExceptFiles("ncbiid1", {}, "network:id1arch", {"idfetch.c"})
 
195
        
 
196
        -- AddSimpleProject("ncbiid2", {}, "network:id2arch")
 
197
        
 
198
        AddSimpleProjectExceptFiles("ncbimla", {}, "network:medarch:client", {"sybmed.c"})
 
199
        
 
200
        AddProject(DataPlusPrefixFile(ProjectData("ncbitxc2", {}, {�
 
201
                mkFileDataExceptFiles("network:taxon1:taxon2:", {"txcproc.c"}), �
 
202
                mkFileDataExceptFiles("network:taxon1:common:", {"checkid.c"})}), "tax2.pfx"))
 
203
        
 
204
        AddSimpleProjectListFiles("ncbiconn", {"winprefix"}, "connect", �
 
205
                {"ncbi_buffer", "ncbi_socket", "ncbi_core", "ncbi_core_c", "ncbi_util", "ncbi_priv", �
 
206
                        "ncbi_ansi_ext", "ncbi_connection", "ncbi_connector", "ncbi_connutil", �
 
207
                        "ncbi_file_connector", "ncbi_host_info.c", "ncbi_http_connector", �
 
208
                        "ncbi_memory_connector", "ncbi_server_info", "ncbi_service", �
 
209
                        "ncbi_service_connector", "ncbi_dispd", "ncbi_lbsmd_stub", �
 
210
                        "ncbi_socket_connector", "ncbi_sendmail"})
 
211
        
 
212
        AddSimpleProjectExceptFiles("netcli", {}, "network:nsclilib", {"ni_encr.c", "ni_list.c", "ni_lib.c"})
 
213
        
 
214
        AddSimpleProject("ncbispell", {}, "network:spell:client")
 
215
        
 
216
        AddSimpleProject("ncbiblast", {}, "algo:blast:core")
 
217
        
 
218
        AddSimpleProject("ncbiblastapi", {}, "algo:blast:api")
 
219
        
 
220
end SetProjectData
 
221
 
 
222
--
 
223
--  Set Global variables
 
224
--
 
225
 
 
226
on IsOSX()
 
227
        tell application "Finder"
 
228
                set vers to the version as text
 
229
                if second character of vers is equal to "." then
 
230
                        set vers to "0" & vers
 
231
                end if
 
232
                return vers > 10 or vers = 10
 
233
        end tell
 
234
end IsOSX
 
235
 
 
236
on ResolveAlias(pathname)
 
237
        tell application "Finder"
 
238
                if exists folder pathname then
 
239
                        -- if pathname does not end with ":" then set pathname to pathname & ":"
 
240
                        return folder pathname as string
 
241
                end if
 
242
                if exists alias file pathname then return the original item of alias file pathname as string
 
243
        end tell
 
244
        return ""
 
245
end ResolveAlias
 
246
 
 
247
on stripVolName(macPath)
 
248
        set saveTID to get text item delimiters of AppleScript
 
249
        set text item delimiters of AppleScript to ":"
 
250
        set strippedPath to (rest of text items of macPath) as string
 
251
        set text item delimiters of AppleScript to saveTID
 
252
        return strippedPath
 
253
end stripVolName
 
254
 
 
255
on HomeDir()
 
256
        tell application "Finder"
 
257
                if my IsOSX() then
 
258
                        return the home as string
 
259
                else
 
260
                        return gStartupDisk
 
261
                end if
 
262
        end tell
 
263
end HomeDir
 
264
 
 
265
on ModuleRoot()
 
266
        set modRoot to ""
 
267
        try
 
268
                set modRoot to ResolveAlias(pRootFolderPath & pRootFolderName)
 
269
        end try
 
270
        if modRoot is "" then
 
271
                set modRoot to ResolveAlias(gHomeDir & pRootFolderName)
 
272
        end if
 
273
        return modRoot
 
274
end ModuleRoot
 
275
 
 
276
on GetMyPath()
 
277
        set myPath to path to me as string
 
278
        if myPath contains "Script Editor" or �
 
279
                myPath contains "osascript" or �
 
280
                myPath contains "Smile.app" then
 
281
                -- Oops! running under script editor. 'me' is Script Editor not this script.
 
282
                -- use the location this script is supposed to be in.
 
283
                return gDistribRoot & "make:"
 
284
        else
 
285
                tell application "Finder"
 
286
                        return container of myPath as string
 
287
                end tell
 
288
        end if
 
289
end GetMyPath
 
290
 
 
291
on SetGlobals()
 
292
        tell application "Finder"
 
293
                
 
294
                set gProjectData to {}
 
295
                
 
296
                set gStartupDisk to startup disk as string
 
297
                set gHomeDir to my HomeDir()
 
298
                set gDistribRoot to my ModuleRoot()
 
299
                
 
300
                set gIncludeDir to gDistribRoot & "include:"
 
301
                set gSourceDir to gDistribRoot
 
302
                set gProjectsDir to gDistribRoot & "lib:"
 
303
                set gRsrcsDir to gDistribRoot & "link:macmet:"
 
304
                set gMakeDir to my GetMyPath()
 
305
                
 
306
        end tell
 
307
end SetGlobals
 
308
 
 
309
on HeaderExists(header, headerDir)
 
310
        tell application "Finder"
 
311
                if headerDir is "" then set headerDir to folder gIncludeDir
 
312
                return exists file header of headerDir
 
313
        end tell
 
314
end HeaderExists
 
315
 
 
316
on IsOlderThan(fileA, fileB)
 
317
        tell application "Finder"
 
318
                return (the modification date of fileA < the modification date of fileB)
 
319
        end tell
 
320
end IsOlderThan
 
321
 
 
322
on UpdateRenameHeader(canonicalName, canonicalDir, dotHName, dotHDir)
 
323
        tell application "Finder"
 
324
                
 
325
                set needRename to (dotHName is not "")
 
326
                if not needRename then set dotHName to canonicalName
 
327
                if dotHDir is "" then set dotHDir to folder gIncludeDir
 
328
                
 
329
                -- This file is only present if the script was interrupted.
 
330
                if needRename and my HeaderExists(canonicalName, dotHDir) then
 
331
                        delete file canonicalName of dotHDir
 
332
                end if
 
333
                
 
334
                -- The native config file.
 
335
                -- If it's missing, assume this is a prepared distribution and the header is already up-to-date.
 
336
                if not my HeaderExists(canonicalName, canonicalDir) then return
 
337
                set canonicalFile to file canonicalName of canonicalDir
 
338
                
 
339
                set needCopy to true
 
340
                if my HeaderExists(dotHName, dotHDir) then
 
341
                        set dotHFile to file dotHName of dotHDir
 
342
                        if my IsOlderThan(dotHFile, canonicalFile) then
 
343
                                delete dotHFile
 
344
                        else
 
345
                                set needCopy to false
 
346
                        end if
 
347
                end if
 
348
                if needCopy then
 
349
                        duplicate canonicalFile to dotHDir
 
350
                        if needRename then set name of file canonicalName of dotHDir to dotHName
 
351
                end if
 
352
        end tell
 
353
end UpdateRenameHeader
 
354
 
 
355
on CopyHeaders()
 
356
        CreateFolder(gIncludeDir)
 
357
        tell application "Finder"
 
358
                set corelibFolder to folder (gDistribRoot & "corelib")
 
359
                my UpdateRenameHeader("ncbilcl.met", corelibFolder, "ncbilcl.h", "")
 
360
        end tell
 
361
end CopyHeaders
 
362
 
 
363
 
 
364
on AppendAccessPath(aPath, isRecursive, isUserPath)
 
365
        tell application "CodeWarrior IDE"
 
366
                if (aPath does not end with ":") then set aPath to aPath & ":"
 
367
                
 
368
                set aPath to POSIX path of aPath
 
369
                set pathsToAdd to {{name:aPath, recursive:isRecursive, origin:absolute, format:Unix Path}}
 
370
                if isUserPath then
 
371
                        Set Preferences of panel "Access Paths" to {User Paths:pathsToAdd}
 
372
                else
 
373
                        Set Preferences of panel "Access Paths" to {System Paths:pathsToAdd}
 
374
                end if
 
375
        end tell
 
376
end AppendAccessPath
 
377
 
 
378
 
 
379
on AppendPrefixFile(filename)
 
380
        tell application "CodeWarrior IDE"
 
381
                try -- CW ver. 8
 
382
                        Set Preferences of panel "C/C++ Compiler" to {Prefix File:prefixFile}
 
383
                end try
 
384
                try -- CW ver. 9
 
385
                        set oldtext to Get Preferences of {Prefix Text} from panel "C/C++ Preprocessor"
 
386
                        set oldtext to (Prefix Text of oldtext)
 
387
                        set prefixFileInclude to (oldtext & return & "#include \"" & filename & "\"")
 
388
                        Set Preferences of panel "C/C++ Preprocessor" to {Prefix Text:prefixFileInclude}
 
389
                end try
 
390
        end tell
 
391
end AppendPrefixFile
 
392
 
 
393
 
 
394
on SetupTarget(proj, targetIndex)
 
395
        tell application "CodeWarrior IDE"
 
396
                
 
397
                set targetName to name of target targetIndex of project document 1
 
398
                if targetName contains "Carbon" then
 
399
                        set targetAPI to "Carbon"
 
400
                else if targetName contains "Mach-O" then
 
401
                        if not my IsOSX() then return -- do not try to populate Mach-O targets on pre-OS X systems.
 
402
                        set targetAPI to "Mach-O"
 
403
                else if targetName contains "Win32" then
 
404
                        set targetAPI to "Win32"
 
405
                end if
 
406
                
 
407
                if targetName contains "Debug" then
 
408
                        set targetDebug to true
 
409
                        set targetProfile to false
 
410
                else if targetName contains "Profile" then
 
411
                        set targetDebug to false
 
412
                        set targetProfile to true
 
413
                else -- if targeName contains "Final" then
 
414
                        set targetDebug to false
 
415
                        set targetProfile to false
 
416
                end if
 
417
                
 
418
                -- NOTE: no Profile targets. if pCreateProfiledTargets, we make the debug targets also profile-able.
 
419
                
 
420
                set the current target of project document 1 to target targetIndex of project document 1
 
421
                
 
422
                -- initialize variables
 
423
                set projRsrcs to {}
 
424
                set projFeatures to {}
 
425
                set sysPaths to {}
 
426
                
 
427
                -- Grab the fields of our project record and store them in local variables.
 
428
                set projName to proj's name
 
429
                set projSettings to proj's settings
 
430
                try
 
431
                        set projFeatures to proj's features
 
432
                end try
 
433
                try
 
434
                        set sysPaths to proj's sysPaths
 
435
                end try
 
436
                try
 
437
                        set projRsrcs to proj's rsrcs
 
438
                end try
 
439
                set projLibs to proj's projLibs
 
440
                set projFileData to proj's fileData
 
441
                
 
442
                -- mitsock library isn't needed (and won't compile) as Mach-O
 
443
                if projName is "mitsock" and targetAPI is not "Carbon" then
 
444
                        return
 
445
                end if
 
446
                
 
447
                -- Figure out what our output file and input libraries will be named.
 
448
                set targetFilename to projName
 
449
                
 
450
                if targetAPI is "Carbon" then
 
451
                        set targetFilename to targetFilename & "_C"
 
452
                else if targetAPI is "Mach-O" then
 
453
                        set targetFilename to targetFilename & "_M"
 
454
                else if targetAPI is "Win32" then
 
455
                        set targetFilename to targetFilename & "_W"
 
456
                end if
 
457
                
 
458
                -- Debug or not.
 
459
                if targetDebug then
 
460
                        set targetFilename to targetFilename & "_D"
 
461
                else if targetProfile then
 
462
                        set targetFilename to targetFilename & "_P"
 
463
                else
 
464
                        set targetFilename to targetFilename & "_O" -- for Optimized.
 
465
                end if
 
466
                
 
467
                set targetFilename to targetFilename & ".lib"
 
468
                
 
469
                -- Get Preference Panel names.
 
470
                if targetAPI is "Mach-O" then
 
471
                        set targetPanelName to "PPC Mac OS X Project"
 
472
                        set codeGenPanelName to "PPC CodeGen Mach-O"
 
473
                else if targetAPI is "Win32" then
 
474
                        set targetPanelName to "x86 Project"
 
475
                        set codeGenPanelName to "x86 CodeGen"
 
476
                else
 
477
                        set targetPanelName to "PPC Project"
 
478
                        set codeGenPanelName to "PPC CodeGen"
 
479
                end if
 
480
                
 
481
                -- Set the name of the output file (the application)
 
482
                Set Preferences of panel targetPanelName to {File Name:targetFilename}
 
483
                
 
484
                -- If we have any per-project override settings, set them.
 
485
                if (count ppcProject of projSettings) > 0 then
 
486
                        Set Preferences of panel targetPanelName to ppcProject of projSettings
 
487
                end if
 
488
                
 
489
                
 
490
                if targetAPI is "Mach-O" then
 
491
                        my AppendAccessPath(gDistribRoot, true, false) -- end of system paths.
 
492
                else
 
493
                        my AppendAccessPath(gDistribRoot, true, true) -- end of user paths.
 
494
                end if
 
495
                
 
496
                -- Add per-project system paths.
 
497
                set pathsToAdd to {}
 
498
                repeat with i in sysPaths
 
499
                        copy {name:i, recursive:false, origin:absolute} to end of pathsToAdd
 
500
                end repeat
 
501
                if (count pathsToAdd) > 0 then �
 
502
                        Set Preferences of panel "Access Paths" to {System Paths:pathsToAdd}
 
503
                
 
504
                -- Set the appropriate prefix file.
 
505
                set prefixFile to prefixFile of projSettings
 
506
                if targetAPI is "Win32" and projFeatures contains "winprefix" then
 
507
                        set prefixFile to "Win32Headers.pch"
 
508
                else
 
509
                        if prefixFile is "" then
 
510
                                set prefixFile to "CarbonPrefix.h"
 
511
                        else
 
512
                                set prefixFile to "Carbon-" & prefixFile
 
513
                        end if
 
514
                end if
 
515
                if prefixFile is not "" then
 
516
                        my AppendPrefixFile(prefixFile)
 
517
                end if
 
518
                
 
519
        end tell
 
520
        
 
521
        -- Add source files.
 
522
        repeat with group in projFileData
 
523
                set projPath to projPath of group
 
524
                set fileList to group's fileList
 
525
                
 
526
                set filesToAdd to {}
 
527
                repeat with i in fileList
 
528
                        try -- ignore it if the file doesn't exist.
 
529
                                
 
530
                                -- NOTE: if the following line is within a tell "Codewarrior" block then
 
531
                                --  the following Add Files command will fail.
 
532
                                copy alias (gSourceDir & projPath & i) to end of filesToAdd
 
533
                        end try
 
534
                end repeat
 
535
                
 
536
                tell application "CodeWarrior IDE"
 
537
                        Add Files filesToAdd
 
538
                        
 
539
                        -- Take out source files that do not belong.
 
540
                        --set fileNotList to group's fileNotList
 
541
                        --Remove Files fileNotList
 
542
                end tell
 
543
        end repeat
 
544
        
 
545
        tell application "CodeWarrior IDE"
 
546
                
 
547
                -- take care of debugging and profiling settings
 
548
                if targetDebug or targetProfile then
 
549
                        set the debug of every target file of target targetIndex �
 
550
                                of project document 1 to true
 
551
                end if
 
552
                
 
553
                
 
554
                if targetAPI is "Carbon" then
 
555
                        if targetProfile then
 
556
                                (* ===== Panel PPC Processor ===== *)
 
557
                                Set Preferences of panel codeGenPanelName to �
 
558
                                        {Use Profiler:true}
 
559
                        else
 
560
                                (* ===== Panel PPC Processor ===== *)
 
561
                                Set Preferences of panel codeGenPanelName to �
 
562
                                        {Use Profiler:false}
 
563
                        end if
 
564
                end if
 
565
                
 
566
                
 
567
                -- Add resources.
 
568
                set filesToAdd to {}
 
569
                if targetAPI is not "Win32" then
 
570
                        repeat with i in projRsrcs
 
571
                                copy gRsrcsDir & i to end of filesToAdd
 
572
                        end repeat
 
573
                        
 
574
                        Add Files filesToAdd
 
575
                end if
 
576
                
 
577
        end tell
 
578
end SetupTarget
 
579
 
 
580
 
 
581
on GetTargetFiles(i)
 
582
        tell application "CodeWarrior IDE"
 
583
                -- get the target
 
584
                if (i > (count of targets of project document 1)) then
 
585
                        return {}
 
586
                end if
 
587
                -- get references to all the targets files
 
588
                set atarget to get target i of project document 1
 
589
                set trefs to (target files of atarget whose linked is true)
 
590
        end tell
 
591
        set tfiles to {}
 
592
        if ((count of trefs) � 0) then
 
593
                repeat with tf in trefs
 
594
                        -- get locations of the targets files (as file objects)
 
595
                        tell application "CodeWarrior IDE"
 
596
                                set f to (location of tf)
 
597
                        end tell
 
598
                        tell application "Finder"
 
599
                                -- convert the file's to strings (colon style paths)
 
600
                                try
 
601
                                        copy f as string to end of tfiles
 
602
                                on error errmsg number errnum
 
603
                                        -- file in target but does not exist.
 
604
                                        if errnum � -2753 then -- variable not defined.
 
605
                                                error errmsg number errnum
 
606
                                        end if
 
607
                                end try
 
608
                        end tell
 
609
                end repeat
 
610
        end if
 
611
        return tfiles
 
612
end GetTargetFiles
 
613
 
 
614
on UpdateTarget(proj, targetIndex)
 
615
        
 
616
        tell application "CodeWarrior IDE"
 
617
                
 
618
                set targetName to name of target targetIndex of project document 1
 
619
                if targetName contains "Carbon" then
 
620
                        set targetAPI to "Carbon"
 
621
                else if targetName contains "Mach-O" then
 
622
                        if not my IsOSX() then return -- do not try to populate Mach-O targets on pre-OS X systems.
 
623
                        set targetAPI to "Mach-O"
 
624
                else if targetName contains "Win32" then
 
625
                        set targetAPI to "Win32"
 
626
                end if
 
627
                
 
628
                -- Grab the fields of our project record and store them in local variables.
 
629
                set projName to proj's name
 
630
                
 
631
                -- mitsock library isn't needed (and won't compile) except under Carbon.
 
632
                if projName is "mitsock" and targetAPI is not "Carbon" then
 
633
                        return
 
634
                end if
 
635
                
 
636
                set targetName to name of target targetIndex of project document 1
 
637
                
 
638
                set the current target of project document 1 to target targetIndex of project document 1
 
639
                
 
640
                -- initialize variables
 
641
                set projFeatures to {}
 
642
                
 
643
                -- Grab the fields of our project record and store them in local variables.
 
644
                try
 
645
                        set projFeatures to proj's features
 
646
                end try
 
647
                set projFileData to proj's fileData
 
648
                
 
649
        end tell
 
650
        
 
651
        -- Update source files
 
652
        set targetFileList to my GetTargetFiles(targetIndex)
 
653
        repeat with group in projFileData
 
654
                set projPath to projPath of group -- projPath is relative.
 
655
                
 
656
                set fileList to group's fileList
 
657
                
 
658
                set filesToAdd to {}
 
659
                
 
660
                repeat with i in fileList
 
661
                        set fileFullPath to gSourceDir & projPath & i
 
662
                        set found to targetFileList contains fileFullPath
 
663
                        if (not found) then
 
664
                                try -- ignore it if the file doesn't exist.
 
665
                                        
 
666
                                        -- NOTE: if the following line is within a tell "Codewarrior" block then
 
667
                                        --  the following Add Files command will fail.
 
668
                                        
 
669
                                        copy alias (fileFullPath) to end of filesToAdd
 
670
                                end try
 
671
                        end if
 
672
                end repeat
 
673
                
 
674
                tell application "CodeWarrior IDE"
 
675
                        if ((count of filesToAdd) is not 0) then
 
676
                                Add Files filesToAdd
 
677
                                set targetFileList to my GetTargetFiles(targetIndex)
 
678
                        end if
 
679
                        
 
680
                        -- Take out source files that do not belong.
 
681
                        --set fileNotList to group's fileNotList
 
682
                        --Remove Files fileNotList
 
683
                end tell
 
684
        end repeat
 
685
        
 
686
end UpdateTarget
 
687
 
 
688
on CreateFolder(folderPath)
 
689
        set text item delimiters of AppleScript to ":"
 
690
        -- strip off disk name.
 
691
        tell application "Finder"
 
692
                set pathSoFar to ""
 
693
                if (exists disk (first text item of folderPath)) then
 
694
                        set pathSoFar to first text item of folderPath
 
695
                        set folderPath to (rest of text items of folderPath) as string
 
696
                end if
 
697
                repeat with f in (text items of folderPath)
 
698
                        set longerPath to pathSoFar & ":" & f
 
699
                        if not (exists folder (longerPath)) then
 
700
                                make new folder at folder (pathSoFar) with properties {name:f}
 
701
                        end if
 
702
                        set pathSoFar to longerPath
 
703
                end repeat
 
704
        end tell
 
705
        set text item delimiters of AppleScript to ""
 
706
end CreateFolder
 
707
 
 
708
on GetStationeryName(proj)
 
709
        set stationeryDir to gProjectsDir & pStationeryName & ":"
 
710
        set stationeryName to pStationeryName & pProjectFileExt
 
711
        
 
712
        CreateFolder(stationeryDir)
 
713
        tell application "Finder"
 
714
                -- does the Library Stationery already exist?
 
715
                if not (exists file (stationeryDir & stationeryName)) then
 
716
                        -- copy it.
 
717
                        duplicate file (stationeryName) of folder gRsrcsDir to folder stationeryDir
 
718
                end if
 
719
        end tell
 
720
        return (stationeryDir & stationeryName)
 
721
end GetStationeryName
 
722
 
 
723
on CreateProject(proj)
 
724
        tell application "CodeWarrior IDE"
 
725
                try
 
726
                        get proj's name
 
727
                on error
 
728
                        return
 
729
                end try
 
730
                
 
731
                set projFilename to proj's name & pProjectFileExt
 
732
                set projPathname to gProjectsDir & projFilename
 
733
                if pAlwaysCreateProjects or not (exists file projPathname of application "Finder") then
 
734
                        
 
735
                        try
 
736
                                close (the first project document whose name is projFilename)
 
737
                        end try
 
738
                        
 
739
                        set stationeryName to my GetStationeryName(proj)
 
740
                        
 
741
                        Create Project projPathname from stationery alias stationeryName
 
742
                        if the name of window 1 is "Project Messages" then
 
743
                                close first window -- "close window 1" becomes "Close Window 1" (different event)
 
744
                        end if
 
745
                        
 
746
                        repeat with i from 1 to (count targets of project document 1)
 
747
                                my SetupTarget(proj, i)
 
748
                        end repeat
 
749
                else
 
750
                        -- project already exists. Make sure it has all right files.
 
751
                        open (projPathname)
 
752
                        if the name of window 1 is "Project Messages" then
 
753
                                close first window -- "close window 1" becomes "Close Window 1" (different event)
 
754
                        end if
 
755
                        repeat with i from 1 to (count targets of project document 1)
 
756
                                my UpdateTarget(proj, i)
 
757
                        end repeat
 
758
                end if
 
759
                if pProjectsCVSEnabled then
 
760
                        --try
 
761
                        Set Preferences of panel "VCS Setup" to {VCS Active:true, Connection Method:"mwCVS"}
 
762
                        --end try
 
763
                end if
 
764
                set the current target of project document 1 to target 1 of project document 1
 
765
                Close Project
 
766
                
 
767
        end tell
 
768
end CreateProject
 
769
 
 
770
on CreateAllProjects()
 
771
        CreateFolder(gProjectsDir)
 
772
        CleanupFiles(gProjectsDir)
 
773
        
 
774
        repeat with proj in gProjectData
 
775
                CreateProject(proj)
 
776
        end repeat
 
777
        
 
778
end CreateAllProjects
 
779
 
 
780
(*
 
781
        a target spec is a string of words "MSL Debug", all of which appear on our list of keywords.
 
782
        Convert a Build file name to a target spec by filtering out non-keywords.
 
783
        Each Build file creates another target spec.
 
784
        A project target must match one of the target specs to compile.
 
785
        To match, a target's name must contain each of the words in the target spec.
 
786
        An empty target spec matches everything.
 
787
        An empty list of target specs (no Build files) matches nothing, 
 
788
        But if there are no Build files we make target specs based on
 
789
        the script parameters.
 
790
*)
 
791
 
 
792
on GetTargetSpecs()
 
793
        set theFiles to (list folder gMakeDir without invisibles)
 
794
        set targetSpecs to {}
 
795
        repeat with f in theFiles
 
796
                if (f begins with "Build ") then
 
797
                        set targetSpecs to targetSpecs & MakeTargetSpec(f)
 
798
                end if
 
799
        end repeat
 
800
        -- no Build files? match what the script parameters say to match.
 
801
        -- NOTE: This is dependent on pTargetKeyWords and the target names in the stationery.
 
802
        if (count items of targetSpecs) is 0 then
 
803
                set debugspec to ""
 
804
                if pCreateDebugTargets then
 
805
                        if pCreateMachOTargets then copy ("Mach-O Debug") to end of targetSpecs
 
806
                        if pCreateCarbonTargets then copy ("Carbon Debug") to end of targetSpecs
 
807
                        if pCreateWinTargets then copy ("Win32 Debug") to end of targetSpecs
 
808
                end if
 
809
                if pCreateProfiledTargets then
 
810
                        if pCreateMachOTargets then copy ("Mach-O Profile") to end of targetSpecs
 
811
                        if pCreateCarbonTargets then copy ("Carbon Profile") to end of targetSpecs
 
812
                        if pCreateWinTargets then copy ("Win32 Profile") to end of targetSpecs
 
813
                end if
 
814
                if pCreateOptimizedTargets then
 
815
                        if pCreateMachOTargets then copy ("Mach-O Final") to end of targetSpecs
 
816
                        if pCreateCarbonTargets then copy ("Carbon Final") to end of targetSpecs
 
817
                        if pCreateWinTargets then copy ("Win32 Final") to end of targetSpecs
 
818
                end if
 
819
        end if
 
820
        return targetSpecs
 
821
end GetTargetSpecs
 
822
 
 
823
on MakeTargetSpec(f)
 
824
        set tspec to ""
 
825
        repeat with w in (words of f)
 
826
                if pTargetKeyWords contains w then
 
827
                        set tspec to tspec & w & " "
 
828
                end if
 
829
        end repeat
 
830
        return tspec
 
831
end MakeTargetSpec
 
832
 
 
833
on OkaytoBuild(targetName, targetSpecs)
 
834
        --This target name must match at least one of the target specs.
 
835
        repeat with ts in targetSpecs
 
836
                if MatchSpec2Target(ts, targetName) then return true
 
837
        end repeat
 
838
        return false
 
839
end OkaytoBuild
 
840
 
 
841
on MatchSpec2Target(targSpec, targName)
 
842
        -- the targetname must contain all of the words in the target spec.
 
843
        repeat with w in (words of targSpec)
 
844
                if w is not in targName then return false
 
845
        end repeat
 
846
        return true
 
847
end MatchSpec2Target
 
848
 
 
849
on BuildProject(projName, targetSpecs)
 
850
        tell application "CodeWarrior IDE"
 
851
                open (gProjectsDir & projName & pProjectFileExt)
 
852
                if the name of window 1 is "Project Messages" then
 
853
                        close first window -- "close window 1" becomes "Close Window 1" (different event)
 
854
                end if
 
855
                repeat with i from 1 to (count targets of project document 1)
 
856
                        -- do we want to build this target?
 
857
                        set thisTarget to name of target i of project document 1
 
858
                        if my OkaytoBuild(thisTarget, targetSpecs) then
 
859
                                
 
860
                                set the current target of project document 1 to target i of project document 1
 
861
                                if pSaveContinueOnErrors then
 
862
                                        try
 
863
                                                Make Project
 
864
                                        on error errmsg number errnum
 
865
                                                if (errnum = 5) then
 
866
                                                        set errFileName to (gProjectsDir & projName & "-" & i & ".errs")
 
867
                                                        Save Error Window As (file errFileName)
 
868
                                                        close first window
 
869
                                                else
 
870
                                                        error errmsg number errnum
 
871
                                                end if
 
872
                                        end try
 
873
                                else -- stop on any error.
 
874
                                        Make Project
 
875
                                end if
 
876
                                -- If there were compiler warnings, then a compiler window will be in front.
 
877
                                -- For whatever reason, this causes the next "set the current target..." to fail.
 
878
                                -- So check for the window and close it.
 
879
                                if the name of window 1 is "Errors & Warnings" then
 
880
                                        close first window -- "close window 1" becomes "Close Window 1" (different event)
 
881
                                end if
 
882
                        end if
 
883
                end repeat
 
884
                set the current target of project document 1 to target 1 of project document 1
 
885
                Close Project
 
886
        end tell
 
887
end BuildProject
 
888
 
 
889
on BuildAllProjects()
 
890
        set targetSpecs to GetTargetSpecs()
 
891
        repeat with proj in gProjectData
 
892
                try
 
893
                        set projName to proj's name
 
894
                on error
 
895
                        set projName to ""
 
896
                end try
 
897
                if projName is not "" then
 
898
                        BuildProject(projName, targetSpecs)
 
899
                end if
 
900
        end repeat
 
901
        
 
902
end BuildAllProjects
 
903
 
 
904
on CleanupFiles(thePath)
 
905
        -- get rid of all the files and folders starting with xxxx in thePath
 
906
        repeat with f in list folder (thePath) without invisibles
 
907
                if ((f as string) begins with "xxxx") then
 
908
                        try
 
909
                                tell application "Finder" to delete folder (thePath & f)
 
910
                        end try
 
911
                        try
 
912
                                tell application "Finder" to delete file (thePath & f)
 
913
                        end try
 
914
                end if
 
915
        end repeat
 
916
        -- delete the stationery folder.
 
917
        try
 
918
                tell application "Finder" to delete folder (thePath & pStationeryName)
 
919
        end try
 
920
end CleanupFiles
 
921
 
 
922
on SignalCompletion()
 
923
        beep
 
924
end SignalCompletion
 
925
 
 
926
with timeout of 60000 seconds
 
927
        
 
928
        SetGlobals()
 
929
        SetProjectData()
 
930
        CopyHeaders()
 
931
        
 
932
        tell application "CodeWarrior IDE" to activate
 
933
        
 
934
        CreateAllProjects()
 
935
        
 
936
        if pShouldBuild then
 
937
                BuildAllProjects()
 
938
        end if
 
939
        
 
940
        CleanupFiles(gProjectsDir)
 
941
        
 
942
        SignalCompletion()
 
943
        
 
944
end timeout
 
945