1-- C apps -- 2 3-- 4-- Properties 5-- 6 7property pUsingCPlusPlus : false 8property pProjectFileExtension : ".mcp" 9 10-- Whether to recreate existing project files. 11property pAlwaysCreateProjects : false 12-- Which targets to build. 13-- All of the targets are populated all the time. These affect what is compiled & built. 14property pCreateCarbonTargets : true 15property pCreateMachOTargets : true 16property pCreateWinTargets : true 17 18property pCreateDebugTargets : true 19property pCreateOptimizedTargets : true 20 21property pCreateProfiledTargets : false 22 23property pCreateBlastTargets : false 24 25-- Whether to compile anything. 26property pShouldBuild : true 27 28property pMakeStationeryScript : "makeStat.met" 29property pStationeryName : "ApplicationStationery" 30 31property pDirsToCreate : {� 32 {relPath:"", name:"build"}, � 33 {relPath:"build", name:pStationeryName}} 34 35 36global gProjectData 37 38on SimpleProjectData(projName, features) 39 40 if (count characters of projName) > 18 then 41 set projName to characters 1 through 18 of projName as string 42 end if 43 44 tell application "CodeWarrior IDE" 45 46 if features does not contain "C" and features does not contain "C++" then 47 --error "Project " & projName & "'s default language (a feature) must be C or C++." 48 copy "C" to end of features 49 end if 50 set myFeatures to features 51 return {name:projName, features:myFeatures, rsrcs:{"ncbilogo.r", "Info.plc"}, settings:� 52 {Prefix File:"", ppcProject:{}}, projLibs:� 53 {"ncbi", "ncbiconn", "ncbiobj", "vibrant", "ncbimmdb", "ncbitool"}, fileData:� 54 {{projPath:"demo:", fileList:{projName}}}} 55 56 end tell 57end SimpleProjectData 58 59on AddSimpleProject(projName, features) 60 61 AddProject(SimpleProjectData(projName, features)) 62 63end AddSimpleProject 64 65on AddProject(projData) 66 67 copy projData to end of gProjectData 68 69end AddProject 70 71on SetProjectData() 72 tell application "CodeWarrior IDE" 73 74 -- Sequin 75 set myName to "Sequin" 76 set myFeatures to {"sockets"} 77 set mySettings to � 78 {Prefix File:"", creator:"SEQN", ppcProject:{Preferred Heap Size:32000, Min Heap Size:6000}} � 79 80 set myRsrcs to {"sequin.r", "InfoSequin.plc"} 81 set myLibs to {"ncbi", "ncbiconn", "ncbiobj", "ncbicdr", "vibrant", "ncbidesk", � 82 "ncbimmdb", "ncbitool", "netcli", "netentr", "ncbibls3", "ncbimla", � 83 "ncbitxc2", "ncbiid1", "vibnet"} 84 set myFiles to � 85 {{projPath:"cdromlib:", fileList:{"accentr", "accutils"}}, � 86 {projPath:"sequin:", fileList:{"sequin1", "sequin2", "sequin3", "sequin4", "sequin5", � 87 "sequin6", "sequin7", "sequin8", "sequin9", "sequin10", "sequinx"}}} 88 set sequinData to � 89 {name:myName, features:myFeatures, settings:mySettings, rsrcs:myRsrcs, projLibs:� 90 myLibs, fileData:myFiles} 91 92 -- Entrez 93 set myName to "Entrez" 94 set myFeatures to {"sockets"} 95 set mySettings to {Prefix File:"", creator:"ENTZ", ppcProject:{}} 96 set myRsrcs to {"entrez.r", "Info.plc"} 97 set myLibs to {"ncbi", "ncbiconn", "ncbiobj", "ncbicdr", "vibrant", "ncbidesk", "ncbimmdb", � 98 "ncbitool", "netcli", "netentr", "ncbibls3", "ncbiid1", "vibnet"} 99 set myFiles to � 100 {{projPath:"cdromlib:", fileList:{"accentr", "accutils"}}, � 101 {projPath:"demo:", fileList:{"entrez"}}} 102 set entrezData to � 103 {name:myName, features:myFeatures, settings:mySettings, rsrcs:myRsrcs, projLibs:� 104 myLibs, fileData:myFiles} 105 106 -- Entrez2 107 set myName to "Entrez2" 108 set myFeatures to {"sockets"} 109 set mySettings to {Prefix File:"", creator:"ENTZ", ppcProject:{}} 110 set myRsrcs to {"entrez.r", "Info.plc"} 111 set myLibs to {"ncbi", "ncbiconn", "ncbiobj", "ncbimmdb", "ncbitool", "vibrant", "ncbidesk"} 112 set myFiles to � 113 {{projPath:"demo:", fileList:{"entrez2"}}} 114 set entrez2Data to � 115 {name:myName, features:myFeatures, settings:mySettings, rsrcs:myRsrcs, projLibs:� 116 myLibs, fileData:myFiles} 117 118 -- BlastCL3 119 set myName to "blastcl3" 120 set myFeatures to {"sockets"} 121 set mySettings to {Prefix File:"blastcl3.pfx", ppcProject:{}} 122 set myRsrcs to {"ncbilogo.r", "Info.plc"} 123 set myLibs to {"ncbi", "ncbiconn", "ncbiobj", "vibrant", "ncbitool", "netcli", "ncbibls3"} 124 set myFiles to � 125 {{projPath:"demo:", fileList:{"blastall"}}} 126 set blastcl3Data to � 127 {name:myName, features:myFeatures, settings:mySettings, rsrcs:myRsrcs, projLibs:� 128 myLibs, fileData:myFiles} 129 130 -- Bl2seq 131 set myName to "bl2seq" 132 set myFeatures to {"sockets"} 133 set mySettings to {Prefix File:"", ppcProject:{}} 134 set myRsrcs to {"ncbilogo.r", "Info.plc"} 135 set myLibs to {"ncbi", "ncbiconn", "ncbiobj", "vibrant", "ncbitool", "netcli", "ncbibls3", "ncbiid1"} 136 set myFiles to � 137 {{projPath:"demo:", fileList:{"bl2seq"}}} 138 set bl2seqData to � 139 {name:myName, features:myFeatures, settings:mySettings, rsrcs:myRsrcs, projLibs:� 140 myLibs, fileData:myFiles} 141 142 -- Impala 143 set impalaData to my SimpleProjectData("impala", {}) 144 set item 1 of fileList of item 1 of fileData of impalaData to "profiles" 145 146 -- Spidey 147 set myName to "spidey" 148 set myFeatures to {"sockets"} 149 set mySettings to {Prefix File:"", ppcProject:{}} 150 set myRsrcs to {"ncbilogo.r", "Info.plc"} 151 set myLibs to {"ncbi", "ncbiconn", "ncbiobj", "vibrant", "ncbitool", "netcli", "ncbiid1"} 152 set myFiles to � 153 {{projPath:"demo:", fileList:{"spideymain"}}} 154 set spideyData to � 155 {name:myName, features:myFeatures, settings:mySettings, rsrcs:myRsrcs, projLibs:� 156 myLibs, fileData:myFiles} 157 158 end tell 159 160 161 AddProject(sequinData) 162 AddProject(entrez2Data) 163 AddSimpleProject("tbl2asn", {}) 164 AddSimpleProject("asn2gb", {"sockets"}) 165 AddProject(spideyData) 166 167 -- AddProject(entrezData) 168 169 if pCreateBlastTargets then 170 AddSimpleProject("formatdb", {}) 171 AddSimpleProject("fastacmd", {}) 172 173 AddProject(bl2seqData) 174 175 AddSimpleProject("blastall", {}) 176 AddSimpleProject("blastpgp", {}) 177 178 AddProject(blastcl3Data) 179 AddSimpleProject("megablast", {}) 180 AddSimpleProject("blastclust", {}) 181 AddSimpleProject("rpsblast", {}) 182 AddSimpleProject("seedtop", {}) 183 AddSimpleProject("copymat", {}) 184 AddSimpleProject("makemat", {}) 185 186 AddProject(impalaData) 187 end if 188 189end SetProjectData 190 191-- 192-- Global variables 193-- 194 195global gStartupDisk 196global gHomeDir 197global gMWroot 198global gMWCWfolder 199 200global gDistribRoot 201global gAccessRoot 202 203global gProjectsDir 204global gSourceDir 205global gIncludeDir 206global gLibsDir 207global gRsrcsDir 208global gMakeDir 209global gStationeryDir 210 211on GetFileNames(relPath) 212 set theFiles to list folder (gSourceDir & relPath) without invisibles 213 set theFiles to EndsWith(theFiles, ".c") -- Assume C projects not C++ 214 215 return theFiles 216end GetFileNames 217 218on EndsWith(aList, suffix) 219 set newList to {} 220 repeat with f in aList 221 if (f ends with suffix) then 222 set newList to newList & (f as string) 223 end if 224 end repeat 225 226 return newList 227end EndsWith 228 229 230on ResolveAlias(pathname) 231 tell application "Finder" 232 --if the last character of pathname is ":" then error "Don't use a trailing colon with ResolveAlias." 233 if exists folder pathname then return pathname & ":" 234 if exists alias file pathname then return the original item of alias file pathname as string 235 error "The folder (or alias) '" & pathname & "' doesn't exist." 236 end tell 237end ResolveAlias 238 239on IsOSX() 240 tell application "Finder" 241 242 set vers to the version as text 243 244 if second character of vers is equal to "." then 245 set vers to "0" & vers 246 end if 247 248 return vers > 10 or vers = 10 249 250 end tell 251end IsOSX 252 253on stripVolName(macPath) 254 set saveTID to get text item delimiters of AppleScript 255 set text item delimiters of AppleScript to ":" 256 set strippedPath to (rest of text items of macPath) as string 257 set text item delimiters of AppleScript to saveTID 258 return strippedPath 259end stripVolName 260 261on HomeDir() 262 tell application "Finder" 263 264 if my IsOSX() then 265 return the home as string 266 -- return my stripVolName(home as string) 267 else 268 return gStartupDisk 269 end if 270 271 end tell 272end HomeDir 273 274on ModuleRoot() 275 276 if pUsingCPlusPlus then 277 set subFolder to "cxx" 278 else 279 set subFolder to "ncbi" 280 end if 281 282 set modRoot to "" 283 try 284 set modRoot to ResolveAlias(gMWroot & subFolder) 285 on error 286 try 287 set modRoot to ResolveAlias(gHomeDir & subFolder) 288 end try 289 end try 290 291 return modRoot 292end ModuleRoot 293 294on AccessRoot() 295 if my IsOSX() then 296 -- strip off the volume name at the front. 297 return my stripVolName(gDistribRoot) 298 else 299 return gDistribRoot 300 end if 301end AccessRoot 302 303on MWRootDir() 304 305 set mwRoot to "" 306 set mwLocations to {gStartupDisk, gStartupDisk & "Applications:", gStartupDisk & "Applications (Mac OS 9):", � 307 gStartupDisk & "AppsLocal:", gHomeDir, gHomeDir & "Applications:", gHomeDir & "Applications (Mac OS 9):", � 308 gHomeDir & "AppsLocal:"} 309 repeat with mwVersion from 8 to 9 310 set dirName to "Metrowerks CodeWarrior " & mwVersion & ".0" 311 repeat with mwLoc in mwLocations 312 try 313 set mwRoot to ResolveAlias(mwLoc & dirName) 314 return mwRoot 315 end try 316 end repeat 317 end repeat 318 319 error "Can't find the Metrowerks CodeWarrior folder." 320 321end MWRootDir 322 323on GetMyPath() 324 set myPath to path to me as string 325 if myPath contains "Script Editor" then 326 -- Oops! running under script editor. 'me' is Script Editor not this script. 327 -- use the location this script is supposed to be in. 328 if pUsingCPlusPlus then 329 return gDistribRoot & "compilers:mac_prj" 330 else 331 return gDistribRoot & "make:" 332 end if 333 else 334 tell application "Finder" 335 return container of myPath 336 end tell 337 end if 338end GetMyPath 339 340on SetGlobals() 341 tell application "Finder" 342 343 set gProjectData to {} 344 345 set gStartupDisk to startup disk as string 346 set gHomeDir to my HomeDir() 347 set gMWroot to my MWRootDir() 348 set gMWCWfolder to gMWroot & "Metrowerks CodeWarrior:" 349 350 set gDistribRoot to my ModuleRoot() 351 set gAccessRoot to my AccessRoot() 352 353 set gIncludeDir to gDistribRoot & "include:" 354 if pUsingCPlusPlus then 355 set gSourceDir to gDistribRoot & "src:" 356 set gLibsDir to gDistribRoot & "compilers:mac_prj:lib:" 357 set gProjectsDir to gDistribRoot & "compilers:mac_prj:bin:" 358 set gRsrcsDir to gDistribRoot & "compilers:mac_prj:" 359 else 360 set gSourceDir to gDistribRoot 361 set gLibsDir to gDistribRoot & "lib:" 362 set gProjectsDir to gDistribRoot & "build:" 363 set gRsrcsDir to gDistribRoot & "link:macmet:" 364 end if 365 set gStationeryDir to gProjectsDir & pStationeryName & ":" 366 set gMakeDir to my GetMyPath() 367 368 end tell 369end SetGlobals 370 371 372on SetUserPaths() 373 tell application "CodeWarrior IDE" 374 375 set pathsToAdd to {} 376 -- Put the ncbi root, recursively at the end of the user paths. 377 -- we did not do this in makeStationery because we did not want to drag over there the mess 378 -- of the distinction between file paths names (which include volume name) 379 -- and access paths (which do not). 380 copy {name:gAccessRoot, recursive:true, origin:absolute} to end of pathsToAdd 381 Set Preferences of panel "Access Paths" to {User Paths:pathsToAdd} 382 383 end tell 384end SetUserPaths 385 386on SetSysPaths() 387 -- This was all done in the Stationery project. 388end SetSysPaths 389 390 391on SetupTarget(proj, targetIndex) 392 tell application "CodeWarrior IDE" 393 394 set targetName to name of target targetIndex of project document 1 395 if targetName contains "Carbon" then 396 set targetAPI to "Carbon" 397 else if targetName contains "Mach-O" then 398 if not my IsOSX() then return -- do not try to populate Mach-O targets on pre-OS X systems. 399 set targetAPI to "Mach-O" 400 else if targetName contains "Win32" then 401 set targetAPI to "Win32" 402 end if 403 404 if targetName contains "Debug" then 405 set targetDebug to true 406 if pCreateProfiledTargets then 407 set targetProfile to true 408 else 409 set targetProfile to false 410 end if 411 else -- if targeName contains "Final" then 412 set targetDebug to false 413 set targetProfile to false 414 end if 415 416 -- NOTE: no Profile targets. if pCreateProfiledTargets, we make the debug targets also profile-able. 417 418 set the current target of project document 1 to target targetIndex of project document 1 419 420 -- initialize variables 421 set projRsrcs to {} 422 set projFeatures to {} 423 set sysPaths to {} 424 425 -- Grab the fields of our project record and store them in local variables. 426 set projName to proj's name 427 set projSettings to proj's settings 428 try 429 set projFeatures to proj's features 430 end try 431 try 432 set sysPaths to proj's sysPaths 433 end try 434 try 435 set projRsrcs to proj's rsrcs 436 end try 437 set projLibs to proj's projLibs 438 set projFileData to proj's fileData 439 440 -- Figure out what our output file and input libraries will be named. 441 set fileNameSuffix to "" 442 443 if targetAPI is "Carbon" then 444 set fileNameSuffix to "_C" 445 else if targetAPI is "Mach-O" then 446 set fileNameSuffix to "_M" 447 else if targetAPI is "Win32" then 448 set fileNameSuffix to "_W" 449 end if 450 451 -- Debug or not. 452 if not targetDebug then 453 set fileNameSuffix to fileNameSuffix & "_O" -- for Optimized. 454 else 455 set fileNameSuffix to fileNameSuffix & "_D" 456 end if 457 458 -- non debug targets get different output names. 459 if not targetDebug then 460 if targetAPI is "Mach-O" then 461 set targetFilename to projName & "OSX" -- Mach adds OSX on the end. 462 else 463 set targetFilename to projName -- Carbon & Windows have same name as project. 464 end if 465 else 466 set targetFilename to projName & fileNameSuffix 467 end if 468 469 -- make sure Mach bundles have .app on the end. 470 if targetAPI is "Mach-O" then 471 set targetFilename to targetFilename & ".app" 472 else if targetAPI is "Win32" then 473 -- and Windows executables have .exe 474 set targetFilename to targetFilename & ".exe" 475 end if 476 477 -- Get Preference Panel names. 478 if targetAPI is "Mach-O" then 479 set targetPanelName to "PPC Mac OS X Project" 480 set codeGenPanelName to "PPC CodeGen Mach-O" 481 else if targetAPI is "Win32" then 482 set targetPanelName to "x86 Project" 483 set codeGenPanelName to "x86 CodeGen" 484 else 485 set targetPanelName to "PPC Project" 486 set codeGenPanelName to "PPC CodeGen" 487 end if 488 489 -- Set the name of the output file (the application) 490 Set Preferences of panel targetPanelName to {File Name:targetFilename} 491 492 -- If specified, set the File Creator. 493 try 494 set creatorName to creator of projSettings 495 Set Preferences of panel targetPanelName to {File Creator:creatorName} 496 end try 497 498 -- If we have any per-project override settings, set them. 499 -- ignore errors since ppcProject might not be appropriate for all targets. 500 try 501 if (count ppcProject of projSettings) > 0 then 502 Set Preferences of panel targetPanelName to ppcProject of projSettings 503 end if 504 end try 505 506 my SetUserPaths() 507 -- my SetSysPaths() -- done in the stationery project. 508 509 -- Add per-project system paths. 510 set pathsToAdd to {} 511 repeat with i in sysPaths 512 copy {name:i, recursive:false, origin:absolute} to end of pathsToAdd 513 end repeat 514 if (count pathsToAdd) > 0 then � 515 Set Preferences of panel "Access Paths" to {System Paths:pathsToAdd} 516 517 -- Set the appropriate prefix file. 518 set prefixFile to Prefix File of projSettings 519 if targetAPI is "Win32" and projFeatures contains "winprefix" then 520 set prefixFile to "Win32Headers.pch" 521 else 522 if prefixFile is "" then 523 set prefixFile to "CarbonPrefix.h" 524 else 525 set prefixFile to "Carbon-" & prefixFile 526 end if 527 end if 528 if prefixFile is not "" then 529 Set Preferences of panel "C/C++ Compiler" to {Prefix File:prefixFile} 530 end if 531 532 533 -- Are we assuming a .c or a .cpp extension? 534 if projFeatures contains "C++" then 535 set fileExtension to pCPlusPlusExtension 536 else 537 set fileExtension to ".c" 538 end if 539 540 end tell 541 542 -- Add source files. 543 repeat with group in projFileData 544 set projPath to projPath of group 545 set fileList to group's fileList 546 547 set filesToAdd to {} 548 repeat with i in fileList 549 if i does not contain "." then set i to i & fileExtension 550 try -- ignore it if the file doesn't exist. 551 552 -- NOTE: if the following line is within a tell "Codewarrior" block then 553 -- the following Add Files command will fail. 554 copy alias (gSourceDir & projPath & i) to end of filesToAdd 555 end try 556 end repeat 557 558 tell application "CodeWarrior IDE" 559 Add Files filesToAdd 560 561 -- Take out source files that do not belong. 562 --set fileNotList to group's fileNotList 563 --Remove Files fileNotList 564 end tell 565 end repeat 566 567 tell application "CodeWarrior IDE" 568 569 -- take care of debugging and profiling settings 570 if targetDebug then 571 set the debug of every target file of target targetIndex � 572 of project document 1 to true 573 end if 574 575 576 if targetAPI is "Carbon" then 577 if targetProfile then 578 (* ===== Panel PPC Processor ===== *) 579 Set Preferences of panel codeGenPanelName to � 580 {Use Profiler:true} 581 else 582 (* ===== Panel PPC Processor ===== *) 583 Set Preferences of panel codeGenPanelName to � 584 {Use Profiler:false} 585 end if 586 (* 587 else if targetAPI is "Mach-O" 588 In the following lines we should see Mach-O Profiling instead of �property B617� 589 But a hyphen is illegal in a name in Applescript (MW's fault). When compiling, the 590 property B617 will get replaced with Mach-O Profiling, which is okay. 591 But if the script gets changed and recompiled this will give an error. 592 So ... replace 'Mach-O Profiling' below with '�property B617�' (minus the quotes). 593 You can copy and paste from this comment. 594 Or comment all of this out and forget Mach-O profiling till MW fixes this. 595 -- *) 596 if targetProfile then 597 (* ===== Panel PPC Processor ===== *) 598 Set Preferences of panel codeGenPanelName to � 599 {�property B617�:metrowerks} 600 else 601 (* ===== Panel PPC Processor ===== *) 602 Set Preferences of panel codeGenPanelName to � 603 {�property B617�:off} 604 end if 605 *) 606 end if 607 608 -- Add user libraries. 609 set filesToAdd to {} 610 if projFeatures contains "sockets" and targetAPI is "Carbon" then 611 if projLibs does not contain "mitsock" then 612 copy "mitsock" to beginning of projLibs 613 end if 614 end if 615 repeat with i in projLibs 616 copy gLibsDir & i & fileNameSuffix & ".lib" to end of filesToAdd 617 end repeat 618 619 -- No profiling library for MW on Mach-O yet. 620 if targetProfile and targetAPI is "Carbon" then 621 copy gMWCWfolder & "MacOS Support:Profiler:Profiler PPC:Profiler Carbon.Lib" to end of filesToAdd 622 end if 623 624 try 625 Add Files filesToAdd 626 end try 627 628 -- Add resources. 629 set filesToAdd to {} 630 if targetAPI is not "Win32" then 631 repeat with i in projRsrcs 632 if targetAPI is "Carbon" then 633 if i ends with ".plc" then 634 copy gRsrcsDir & "Carbon-" & i to end of filesToAdd 635 else 636 copy gRsrcsDir & i to end of filesToAdd 637 end if 638 else 639 -- Mach-O does not need the .r files, only the .plc files. 640 if i does not end with ".r" then 641 copy gRsrcsDir & i to end of filesToAdd 642 end if 643 end if 644 end repeat 645 646 Add Files filesToAdd 647 end if 648 649 Reset File Paths 650 651 end tell 652end SetupTarget 653 654on CreateFolders() 655 tell application "Finder" 656 657 repeat with i in pDirsToCreate 658 set pth to relPath of i 659 if pth is not "" then set pth to pth & ":" 660 661 -- display dialog "Folder? " & (gDistribRoot & pth & i's name) buttons {"OK"} default button 1 662 663 if not (exists folder (gDistribRoot & pth & i's name)) then 664 -- display dialog "make Folder: " & i's name & " at: " & (gDistribRoot & pth) buttons {"OK"} default button 1 665 666 make new folder at folder (gDistribRoot & pth) with properties {name:i's name} 667 end if 668 end repeat 669 670 end tell 671end CreateFolders 672 673on CreateProject(proj) 674 tell application "CodeWarrior IDE" 675 676 -- This statement doesn't work, because AppleScript is broken. 677 if proj is {} then return 678 679 try 680 get proj's name 681 on error 682 return 683 end try 684 685 set projFilename to proj's name & pProjectFileExtension 686 set projPathname to gProjectsDir & projFilename 687 if pAlwaysCreateProjects or not (exists file projPathname of application "Finder") then 688 689 try 690 close (the first project document whose name is projFilename) 691 end try 692 693 set stationeryName to (gStationeryDir & pStationeryName & pProjectFileExtension) 694 (* display dialog "creating project: " & projPathname & return & "from: " & stationeryName � 695 buttons {"OK"} default button 1 696 *) 697 Create Project {projPathname} from stationery alias stationeryName 698 if the name of window 1 is "Project Messages" then 699 close first window -- "close window 1" becomes "Close Window 1" (different event) 700 end if 701 702 -- display dialog "created project: " & projPathname buttons {"OK"} default button 1 703 704 repeat with i from 1 to (count targets of project document 1) 705 my SetupTarget(proj, i) 706 end repeat 707 708 set the current target of project document 1 to target 1 of project document 1 709 710 Close Project 711 712 end if 713 714 end tell 715end CreateProject 716 717on CreateAllProjects() 718 719 repeat with proj in gProjectData 720 CreateProject(proj) 721 end repeat 722 723end CreateAllProjects 724 725global gTargets2Build 726 727-- get names of files in thePath that start with "Build" 728on GetMakeFileNames(thePath) 729 set theFiles to list folder (thePath) without invisibles 730 set newList to {} 731 repeat with f in theFiles 732 if (f begins with "Build") then 733 set newList to newList & (f as string) 734 end if 735 end repeat 736 737 return newList 738end GetMakeFileNames 739 740on AddtoList(aList, anItem) 741 if (aList does not contain anItem) then 742 copy anItem to end of aList 743 end if 744end AddtoList 745 746on FindTargets2Build() 747 set gTargets to {} 748 if pCreateCarbonTargets then 749 set gTargets to gTargets & "Carbon" 750 end if 751 if pCreateMachOTargets then 752 set gTargets to gTargets & "Mach-O" 753 end if 754 if pCreateWinTargets then 755 set gTargets to gTargets & "Win32" 756 end if 757 758 set gBuildTypes to {} 759 if pCreateDebugTargets or pCreateProfileTargets then 760 set gBuildTypes to gBuildTypes & "Debug" 761 end if 762 if pCreateOptimizedTargets then 763 set gBuildTypes to gBuildTypes & "Final" 764 end if 765 766 -- set gTargets to {"Carbon", "Mach-O"} 767 -- set gBuildTypes to {"Final", "Debug", "Profile"} 768 769 set makeFiles to my GetMakeFileNames(gMakeDir) 770 if (count items of makeFiles) is 0 then 771 set makeFiles to gTargets -- if nothing, make everything. 772 end if 773 774 set gTargets2Build to {} 775 776 repeat with f in makeFiles 777 set thisTarget to "" 778 set targetSet to false 779 repeat with t in gTargets 780 if f contains t then 781 set thisTarget to contents of t 782 set targetSet to true 783 exit repeat 784 end if 785 end repeat 786 787 set typeSet to false 788 repeat with t in gBuildTypes 789 if f contains t then 790 set thisTarget to thisTarget & " " & t 791 set typeSet to true 792 exit repeat 793 end if 794 end repeat 795 796 if targetSet and typeSet then 797 my AddtoList(gTargets2Build, thisTarget) 798 else if (targetSet or typeSet) then 799 if not typeSet then 800 repeat with t in {"Final", "Debug"} 801 AddtoList(gTargets2Build, (thisTarget & " " & t)) 802 end repeat 803 end if 804 if not targetSet then 805 repeat with t in gTargets 806 AddtoList(gTargets2Build, (t & thisTarget)) 807 end repeat 808 end if 809 end if 810 end repeat 811end FindTargets2Build 812 813on OkaytoBuild(targetName) 814 repeat with t in gTargets2Build 815 if (targetName contains t) then 816 return true 817 end if 818 end repeat 819 return false 820end OkaytoBuild 821 822on BuildProject(projName) 823 tell application "CodeWarrior IDE" 824 open (gProjectsDir & projName & pProjectFileExtension) 825 if the name of window 1 is "Project Messages" then 826 close first window -- "close window 1" becomes "Close Window 1" (different event) 827 end if 828 829 repeat with i from 1 to (count targets of project document 1) 830 -- do we want to build this target? 831 if my OkaytoBuild(name of target i of project document 1) then 832 833 set the current target of project document 1 to target i of project document 1 834 Make Project 835 -- If there were compiler warnings, then a compiler window will be in front. 836 -- For whatever reason, this causes the next "set the current target..." to fail. 837 -- So check for the window and close it. 838 if the name of window 1 is "Errors & Warnings" then 839 close first window -- "close window 1" becomes "Close Window 1" (different event) 840 end if 841 end if 842 end repeat 843 set the current target of project document 1 to target 1 of project document 1 844 Close Project 845 end tell 846end BuildProject 847 848on BuildAllProjects() 849 FindTargets2Build() 850 repeat with proj in gProjectData 851 try 852 set projName to proj's name 853 on error 854 set projName to "" 855 end try 856 -- This statement doesn't work, because AppleScript is broken. 857 if proj is not {} then 858 if projName is not "" then 859 BuildProject(projName) 860 end if 861 end if 862 end repeat 863 864end BuildAllProjects 865 866on GuaranteeStationery() 867 tell application "Finder" 868 -- get rid of any old copy. 869 try 870 delete file (gStationeryDir & pStationeryName & pProjectFileExtension) 871 end try 872 -- copy it. 873 my DuplicateFile(file (gRsrcsDir & pStationeryName & pProjectFileExtension), folder gStationeryDir) 874 -- make sure there is nothing else in the folder. 875 my CleanupFolder(gStationeryDir, pStationeryName & pProjectFileExtension) 876 end tell 877end GuaranteeStationery 878 879on DuplicateFile(fileToCopy, destFolder) 880 tell application "Finder" 881 try 882 duplicate fileToCopy to destFolder 883 on error msg number errnum 884 if errnum is -43 then 885 (* if the file was just newly created (e.g. a clean install or cvs update) 886 the finder gets this error trying to copy a file from it. 887 Opening its folder with the finder fixes this. 888 We do this in a try block so we aren't always flashing the window open 889 for this somewhat rare occurrence. 890 *) 891 open (container of fileToCopy) 892 close first Finder window 893 duplicate fileToCopy to destFolder 894 else 895 error msg number errnum 896 end if 897 end try 898 end tell 899end DuplicateFile 900 901-- Delete everything in the folder 'thePath' except the saveFile. 902on CleanupFolder(thePath, saveFile) 903 repeat with f in list folder (thePath) with invisibles 904 if (f as string is not saveFile) then 905 try 906 tell application "Finder" to delete folder (thePath & f) 907 end try 908 try 909 tell application "Finder" to delete file (thePath & f) 910 end try 911 end if 912 end repeat 913end CleanupFolder 914 915on CleanupFiles(thePath) 916 -- get rid of all the files and folders starting with xxxx in thePath 917 repeat with f in list folder (thePath) without invisibles 918 if ((f as string) begins with "xxxx") then 919 try 920 tell application "Finder" to delete folder (thePath & f) 921 end try 922 try 923 tell application "Finder" to delete file (thePath & f) 924 end try 925 end if 926 end repeat 927 -- delete the stationery folder. 928 try 929 tell application "Finder" to delete folder gStationeryDir 930 end try 931end CleanupFiles 932 933on SignalCompletion() 934 935 beep 936 937end SignalCompletion 938 939with timeout of 60000 seconds 940 941 SetGlobals() 942 SetProjectData() 943 944 CreateFolders() 945 946 tell application "CodeWarrior IDE" to activate 947 948 GuaranteeStationery() 949 CreateAllProjects() 950 951 if pShouldBuild then 952 BuildAllProjects() 953 end if 954 955 CleanupFiles(gProjectsDir) 956 957 SignalCompletion() 958 959end timeout 960 961