home *** CD-ROM | disk | FTP | other *** search
/ BMUG PD-ROM 1995 Fall / PD-ROM F95.toast / Programming / Programming Utilities / ThreadLibrary 1.0 ƒ / Scripts / Build.as
Encoding:
Text File  |  1995-06-08  |  10.7 KB  |  349 lines  |  [TEXT/ToyS]

  1.  
  2. -- Compiles and builds all the components of Thread Library using CodeWarrior. Before running, 
  3. -- you need to set the strings returned by mpwhomeFolder, cwhomeFolder, and tlhomeFolder. You
  4. -- can also set gMakeProject to true to compile anything that needs compiling, and
  5. -- gRemoveBinaries to strip the binaries after compiling. Still waiting on a scriptable Find
  6. -- File and proper script compiler to make this script independent of application locations...
  7.  
  8. -- Note: should use Finder's Find File to locate MPW, CW, and Thread Library,
  9. -- but can't since Find File isn't scriptable and ScriptEditor's AppleScript
  10. -- compiler won't accept application aliases in variables as targets of
  11. -- tell statements. This means you need to set the strings
  12. -- returned by compiler68k() and compilerPPC(). You also
  13. -- need to set the names of the applications in the tell
  14. -- statements to whatever version of CodeWarrior you now
  15. -- have (for instance, CW6 uses version number "1.2.2"
  16. -- in the application names).
  17.  
  18. -- Globals
  19.  
  20. global gMakeProject
  21. global gRemoveBinaries
  22.  
  23. -- CodeWarrior
  24.  
  25. on cwhomeFolder()
  26.     return alias "Flicker:Development:Environments:CodeWarrior:"
  27. end cwhomeFolder
  28.  
  29. on compiler68k()
  30.     return ((cwhomeFolder() as string) & "Metrowerks C/C++ ƒ:MW C/C++ 68K 1.2.2")
  31. end compiler68k
  32.  
  33. on compilerPPC()
  34.     return ((cwhomeFolder() as string) & "Metrowerks C/C++ ƒ:MW C/C++ PPC 1.2.2")
  35. end compilerPPC
  36.  
  37. -- MPW
  38.  
  39. on mpwhomeFolder()
  40.     return alias ((cwhomeFolder() as string) & "Fully Configured MPW")
  41. end mpwhomeFolder
  42.  
  43. on mpwApplication()
  44.     return application ((mpwhomeFolder() as string) & "MPW Shell")
  45. end mpwApplication
  46.  
  47. -- Thread Library
  48.  
  49. on tlhomeFolder()
  50.     return alias "Flicker:WinterShell:Shared:Libraries:ThreadLibrary-1.0:"
  51. end tlhomeFolder
  52.  
  53. on tlexecFolder()
  54.     return alias ((tlhomeFolder() as string) & "Executables")
  55. end tlexecFolder
  56.  
  57. on tllibFolder()
  58.     return alias ((tlhomeFolder() as string) & "Libraries")
  59. end tllibFolder
  60.  
  61. on libhomeFolder()
  62.     return alias ((tlhomeFolder() as string) & "Source:Libraries")
  63. end libhomeFolder
  64.  
  65. -- remove suffix from string
  66. on stripSuffix(s)
  67.     set n to length of s
  68.     set a to 1
  69.     set b to n + 1
  70.     repeat with i from 1 to n
  71.         if character i of s = "." then
  72.             set b to i
  73.         end if
  74.     end repeat
  75.     set b to (b - 1)
  76.     if b = 0 then
  77.         return ""
  78.     end if
  79.     return characters a thru b of s as string
  80. end stripSuffix
  81.  
  82. -- place quotation marks around string
  83. on stringQuote(s)
  84.     return "\"" & s & "\""
  85. end stringQuote
  86.  
  87. -- merge resource fork with destination's resource fork
  88. on mergeResources(src, dst)
  89.     set src to ("∂\"" & src as string) & "∂\""
  90.     set dst to stringQuote(dst as string)
  91.     tell application "MPW Shell"
  92.         DoScript ("echo \"include " & src & ";\" | rez -a -o " & dst)
  93.     end tell
  94. end mergeResources
  95.  
  96. -- copy data fork to destination
  97. on copyDataFork(src, dst)
  98.     set src to stringQuote(src as string)
  99.     set dst to stringQuote(dst as string)
  100.     tell application "MPW Shell"
  101.         DoScript ("duplicate -d -y " & src & " " & dst)
  102.     end tell
  103. end copyDataFork
  104.  
  105. -- copy resource fork to destination
  106. on copyResourceFork(src, dst)
  107.     set src to stringQuote(src as string)
  108.     set dst to stringQuote(dst as string)
  109.     tell application "MPW Shell"
  110.         DoScript ("duplicate -r -y " & src & " " & dst)
  111.     end tell
  112. end copyResourceFork
  113.  
  114. -- copy file to destination
  115. on copyFile(src, dst)
  116.     set src to stringQuote(src as string)
  117.     set dst to stringQuote(dst as string)
  118.     tell application "MPW Shell"
  119.         DoScript ("duplicate -y " & src & " " & dst)
  120.     end tell
  121. end copyFile
  122.  
  123. -- move file to destination
  124. on replaceFile(src, dst)
  125.     tell application "Finder"
  126.         move src to dst replacing conflicts
  127.     end tell
  128. end replaceFile
  129.  
  130. -- move file to destination
  131. on replaceFileIfExists(src, dst)
  132.     set src to (src as string)
  133.     tell application "Finder"
  134.         if file src exists then
  135.             move file src to dst replacing conflicts
  136.         else if file ((dst as string) & src) exists then
  137.             delete file ((dst as string) & src)
  138.         end if
  139.     end tell
  140. end replaceFileIfExists
  141.  
  142. -- delete file
  143. on deleteFile(path)
  144.     tell application "Finder"
  145.         if file path exists then
  146.             delete file path
  147.         end if
  148.     end tell
  149. end deleteFile
  150.  
  151. -- bring a project up to date
  152. on makeProject(projectspec, compiler)
  153.     tell application "Finder"
  154.         open projectspec
  155.     end tell
  156.     with timeout of 60000 seconds
  157.         if compiler = compiler68k() then
  158.             tell application "MW C/C++ 68K 1.2.2"
  159.                 -- activate
  160.                 Make Project
  161.             end tell
  162.         else if compiler = compilerPPC() then
  163.             tell application "MW C/C++ PPC 1.2.2"
  164.                 -- activate
  165.                 Make Project
  166.             end tell
  167.         else
  168.             error "Unknown compiler."
  169.         end if
  170.     end timeout
  171. end makeProject
  172.  
  173. -- bring a 68K project up to date
  174. on makeProject68K(Project)
  175.     makeProject(Project, compiler68k())
  176. end makeProject68K
  177.  
  178. -- bring a PPC project up to date
  179. on makeProjectPPC(Project)
  180.     makeProject(Project, compilerPPC())
  181. end makeProjectPPC
  182.  
  183. -- remove binaries from project
  184. on removeBinaries(projectspec, output, compiler)
  185.     if gRemoveBinaries then
  186.         tell application "Finder"
  187.             open projectspec
  188.         end tell
  189.         with timeout of 60000 seconds
  190.             if compiler = compiler68k() then
  191.                 -- remove binaries from project file
  192.                 tell application "MW C/C++ 68K 1.2.2"
  193.                     Remove Binaries
  194.                 end tell
  195.                 -- remove debug and symbol files
  196.                 deleteFile(stripSuffix(projectspec as string) & ".dbg")
  197.                 deleteFile(stripSuffix(projectspec as string) & ".SYM")
  198.             else if compiler = compilerPPC() then
  199.                 -- remove binaries from project file
  200.                 tell application "MW C/C++ PPC 1.2.2"
  201.                     Remove Binaries
  202.                 end tell
  203.                 deleteFile(stripSuffix(projectspec as string) & ".xdbg")
  204.                 deleteFile(stripSuffix(projectspec as string) & ".xSYM")
  205.             else
  206.                 error "Unknown compiler."
  207.             end if
  208.         end timeout
  209.         -- remove output file
  210.         deleteFile(output)
  211.     end if
  212. end removeBinaries
  213.  
  214. -- remove binaries from 68k project
  215. on removeBinaries68k(Project, output)
  216.     removeBinaries(Project, output, compiler68k())
  217. end removeBinaries68k
  218.  
  219. -- remove binaries from PPC project
  220. on removeBinariesPPC(Project, output)
  221.     removeBinaries(Project, output, compilerPPC())
  222. end removeBinariesPPC
  223.  
  224. -- make a fat application
  225. on makeProjectFat(project68k, output68k, projectPPC, outputPPC, outputFat, outputFolder)
  226.     if gMakeProject then
  227.         makeProject68K(project68k)
  228.         makeProjectPPC(projectPPC)
  229.         copyFile(outputPPC, outputFat)
  230.         mergeResources(output68k, outputFat)
  231.         replaceFile(alias output68k, outputFolder)
  232.         replaceFile(alias outputPPC, outputFolder)
  233.     end if
  234.     removeBinaries68k(project68k, output68k)
  235.     removeBinariesPPC(projectPPC, outputPPC)
  236. end makeProjectFat
  237.  
  238. -- build project using specified compiler
  239. on makeProjectTarget(Project, output, destination, compiler)
  240.     if gMakeProject then
  241.         makeProject(Project, compiler)
  242.         replaceFile(output as alias, destination as alias)
  243.         replaceFileIfExists(((output as string) & ".SYM"), destination as alias)
  244.         replaceFileIfExists(((output as string) & ".xSYM"), destination as alias)
  245.     end if
  246.     removeBinaries(Project, output, compiler)
  247. end makeProjectTarget
  248.  
  249. -- build 68k project
  250. on makeProjectTarget68K(Project, output, destination)
  251.     makeProjectTarget(Project, output, destination, compiler68k())
  252. end makeProjectTarget68K
  253.  
  254. -- build PPC project
  255. on makeProjectTargetPPC(Project, output, destination)
  256.     makeProjectTarget(Project, output, destination, compilerPPC())
  257. end makeProjectTargetPPC
  258.  
  259. -- return name of output file of project
  260. on projectOutput(projectspec, compiler)
  261.     tell application "Finder"
  262.         open projectspec
  263.     end tell
  264.     if compiler = compiler68k() then
  265.         tell application "MW C/C++ 68K 1.2.2"
  266.             set output to (File Name of (Get Preferences Of {File Name}))
  267.         end tell
  268.     else if compiler = compilerPPC() then
  269.         tell application "MW C/C++ PPC 1.2.2"
  270.             set output to (File Name of (Get Preferences Of {File Name}))
  271.         end tell
  272.     else
  273.         error "Unknown compiler."
  274.     end if
  275.     return output
  276. end projectOutput
  277.  
  278. -- return name of output file of 68k project
  279. on projectOutput68k(Project)
  280.     return projectOutput(Project, compiler68k())
  281. end projectOutput68k
  282.  
  283. -- return name of output file of PPC project
  284. on projectOutputPPC(Project)
  285.     return projectOutput(Project, compilerPPC())
  286. end projectOutputPPC
  287.  
  288. on build68kLibraries()
  289.     set project68k to alias ((libhomeFolder() as string) & "ThreadLibrary-68K.π")
  290.     set output68k to ((libhomeFolder() as string) & projectOutput68k(project68k))
  291.     makeProjectTarget68K(project68k, output68k, tllibFolder())
  292.     set project68k to alias ((libhomeFolder() as string) & "ThreadLibrary-68K-Debug.π")
  293.     set output68k to ((libhomeFolder() as string) & projectOutput68k(project68k))
  294.     makeProjectTarget68K(project68k, output68k, tllibFolder())
  295. end build68kLibraries
  296.  
  297. on buildPPCLibraries()
  298.     set projectPPC to alias ((libhomeFolder() as string) & "ThreadLibrary-PPC.π")
  299.     set outputPPC to ((libhomeFolder() as string) & projectOutputPPC(projectPPC))
  300.     makeProjectTargetPPC(projectPPC, outputPPC, tllibFolder())
  301.     set projectPPC to alias ((libhomeFolder() as string) & "ThreadLibrary-PPC-Debug.π")
  302.     set outputPPC to ((libhomeFolder() as string) & projectOutputPPC(projectPPC))
  303.     makeProjectTargetPPC(projectPPC, outputPPC, tllibFolder())
  304. end buildPPCLibraries
  305.  
  306. on buildPPCSharedLibaries()
  307.     set projectPPC to alias ((libhomeFolder() as string) & "ThreadLibrary-PPC.lib.π")
  308.     set outputPPC to ((libhomeFolder() as string) & projectOutputPPC(projectPPC))
  309.     makeProjectTargetPPC(projectPPC, outputPPC, tllibFolder())
  310.     set projectPPC to alias ((libhomeFolder() as string) & "ThreadLibrary-PPC-Debug.lib.π")
  311.     set outputPPC to ((libhomeFolder() as string) & projectOutputPPC(projectPPC))
  312.     makeProjectTargetPPC(projectPPC, outputPPC, tllibFolder())
  313. end buildPPCSharedLibaries
  314.  
  315. on buildTestApplication()
  316.     set testhomeFolder to alias ((tlhomeFolder() as string) & "Source:Demos:ThreadsTest")
  317.     set project68k to alias ((testhomeFolder as string) & "ThreadsTest-68K.π")
  318.     set output68k to ((testhomeFolder as string) & projectOutput68k(project68k))
  319.     set projectPPC to alias ((testhomeFolder as string) & "ThreadsTest-PPC.π")
  320.     set outputPPC to ((testhomeFolder as string) & projectOutputPPC(projectPPC))
  321.     set outputFat to ((tlexecFolder() as string) & "ThreadsTest-FAT")
  322.     makeProjectFat(project68k, output68k, projectPPC, outputPPC, outputFat, tlexecFolder())
  323. end buildTestApplication
  324.  
  325. on buildSpeedTestApplication()
  326.     set timedhomeFolder to alias ((tlhomeFolder() as string) & "Source:Demos:ThreadsTimed")
  327.     set project68k to alias ((timedhomeFolder as string) & "ThreadsTimed-68K.π")
  328.     set output68k to ((timedhomeFolder as string) & projectOutput68k(project68k))
  329.     set projectPPC to alias ((timedhomeFolder as string) & "ThreadsTimed-PPC.π")
  330.     set outputPPC to ((timedhomeFolder as string) & projectOutputPPC(projectPPC))
  331.     set outputFat to ((tlexecFolder() as string) & "ThreadsTimed-FAT")
  332.     makeProjectFat(project68k, output68k, projectPPC, outputPPC, outputFat, tlexecFolder())
  333. end buildSpeedTestApplication
  334.  
  335. on run
  336.     
  337.     -- set globals
  338.     set gMakeProject to true
  339.     set gRemoveBinaries to true
  340.     
  341.     -- build everything
  342.     build68kLibraries()
  343.     buildPPCLibraries()
  344.     buildPPCSharedLibaries()
  345.     buildTestApplication()
  346.     buildSpeedTestApplication()
  347.     
  348. end run
  349.