NCBI C Toolkit Cross Reference

C/make/makeApps.met


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

source navigation ]   [ diff markup ]   [ identifier search ]   [ freetext search ]   [ file search ]  

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.