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