12 -- retrieves the files from the xml node including optional conditions
 
  13 on parseSources(theName, theElement, theVariables, theConditions)
 
  14         set AppleScript's text item delimiters to " "
 
  16         repeat with currElement in XML contents of theElement
 
  17                 if class of currElement is text then
 
  18                         set allElements to allElements & (every text item of currElement)
 
  20                         if class of currElement is XML element and XML tag of currElement is "if" then
 
  21                                 if (cond of XML attributes of currElement is in theConditions) then
 
  22                                         set allElements to allElements & (every text item of (item 1 of XML contents of currElement))
 
  27         set AppleScript's text item delimiters to oldDelimiters
 
  28         copy {varname:theName, entries:allElements} to end of theVariables
 
  31 on parseEntry(theElement, theVariables, theConditions)
 
  32         set theName to var of XML attributes of theElement
 
  33         parseSources(theName, theElement, theVariables, theConditions)
 
  36 on parseLib(theElement, theVariables, theConditions)
 
  37         set theName to |id| of XML attributes of theElement
 
  38         repeat with currElement in XML contents of theElement
 
  39                 if class of currElement is XML element and XML tag of currElement is "sources" then
 
  40                         parseSources(theName, currElement, theVariables, theConditions)
 
  45 on parseNode(anElement, theVariables, theConditions)
 
  46         if class of anElement is XML element and Â
 
  47                 XML tag of anElement is "set" then
 
  48                 parseEntry(anElement, theVariables, theConditions)
 
  50                 if class of anElement is XML element and Â
 
  51                         XML tag of anElement is "lib" then
 
  52                         parseLib(anElement, theVariables, theConditions)
 
  57 -- iterates through the entire xml tree and populates the variables
 
  58 on parseFiles(theXML, theVariables, theConditions)
 
  59         if class of theXML is XML element or class of theXML is XML document then
 
  60                 repeat with anElement in XML contents of theXML
 
  62                                 parseNode(anElement, theVariables, theConditions)
 
  67         else if class of theXML is list then
 
  68                 repeat with anElement in theXML
 
  70                                 parseNode(anElement, theVariables, theConditions)
 
  78 -- gets the entries of the variable named theName
 
  80         repeat with anElement in variablesRef
 
  81                 if (varname of anElement is theName) then
 
  82                         return entries of anElement
 
  87 -- adds sources from fileList to a group named container
 
  88 on addNode(theContainer, fileList)
 
  89         tell application "Xcode"
 
  91                         set theTargets to targets
 
  92                         repeat with listItem in fileList
 
  93                                 if (listItem starts with "$(") then
 
  94                                         set AppleScript's text item delimiters to ""
 
  95                                         set variableName to (characters 3 through ((length of listItem) - 1) of listItem) as text
 
  96                                         set AppleScript's text item delimiters to oldDelimiters
 
  97                                         my addNode(theContainer, my getVar(variableName))
 
  99                                         set AppleScript's text item delimiters to "/"
 
 100                                         set currPath to every text item in listItem
 
 101                                         set currFile to "../../" & listItem
 
 102                                         set currFileName to (item -1 in currPath)
 
 103                                         set currGroup to (items 1 through -2 in currPath as text)
 
 104                                         set AppleScript's text item delimiters to oldDelimiters
 
 106                                                 set theGroup to group theContainer
 
 109                                                         make new group with properties {name:theContainer}
 
 112                                         tell group theContainer
 
 114                                                         set theGroup to group named currGroup
 
 116                                                         make new group with properties {name:currGroup}
 
 119                                                         set newFile to make new file reference with properties {name:currFileName, path:currFile, path type:project relative}
 
 120                                                         repeat with theTarget in theTargets
 
 121                                                                 add newFile to (get compile sources phase of theTarget)
 
 131 -- retrieves contents of file at posixFilePath
 
 132 on readFile(posixFilePath)
 
 133         set fileRef to open for access POSIX file posixFilePath
 
 134         set theData to read fileRef
 
 140         tell application "Xcode"
 
 143         set variablesRef to a reference to variables
 
 144         set bakefilesXMLRef to a reference to bakefilesXML
 
 145         set oldDelimiters to AppleScript's text item delimiters
 
 146         tell application "Finder"
 
 147                 set osxBuildFolder to POSIX path of ((folder of (path to me)) as Unicode text)
 
 151 -- reads the files list and evaluates the conditions
 
 152 on readFilesList(theFiles, theConditions)
 
 154         repeat with theFile in theFiles
 
 155                 set bakefilesXML to parse XML (readFile(osxBuildFolder & theFile))
 
 156                 parseFiles(bakefilesXMLRef, variablesRef, theConditions)
 
 160 -- creates a new project file from the respective template
 
 161 on instantiateProject(theProject)
 
 162         set projectName to projectName of theProject
 
 163         set template to (osxBuildFolder & projectName & "_in.xcodeproj")
 
 164         set projectFile to (osxBuildFolder & projectName & ".xcodeproj")
 
 165         tell application "Finder"
 
 166                 if exists projectFile as POSIX file then
 
 167                         set templateContentFile to (osxBuildFolder & projectName & "_in.xcodeproj/project.pbxproj")
 
 168                         set projectContentFile to (osxBuildFolder & projectName & ".xcodeproj/project.pbxproj")
 
 171                                         do shell script "rm -f " & quoted form of projectContentFile
 
 176                                         do shell script "cp " & quoted form of templateContentFile & " " & quoted form of projectContentFile
 
 180                         set duplicateProject to duplicate (template as POSIX file) with replace
 
 181                         set name of duplicateProject to (projectName & ".xcodeproj")
 
 184 end instantiateProject
 
 186 -- adds the source files of the nodes of theProject to the xcode project
 
 187 on populateProject(theProject)
 
 188         tell application "Xcode"
 
 191         repeat with theNode in nodes of theProject
 
 192                 -- reopen xcode for each pass, as otherwise the undomanager
 
 193                 -- happens to crash quite frequently
 
 194                 addNode(label of theNode, entries of theNode)
 
 196         tell application "Xcode"
 
 199         do shell script (osxBuildFolder as text) & "fix_xcode_ids.py \"" & (POSIX path of projectFile as Unicode text) & "\""
 
 200         -- reopen again to let Xcode sort identifiers
 
 201         tell application "Xcode"
 
 204         tell application "Xcode"
 
 209 on makeProject(theProject)
 
 210         instantiateProject(theProject)
 
 211         readFilesList(bklfiles of theProject, conditions of theProject)
 
 212         populateProject(theProject)
 
 218 set theProject to {conditions:{"PLATFORM_MACOSX=='1'", "TOOLKIT=='OSX_CARBON'", "WXUNIV=='0'", "USE_GUI=='1' and WXUNIV=='0'"}, projectName:Â
 
 219         "wxcarbon", bklfiles:{Â
 
 220         "../bakefiles/files.bkl", "../bakefiles/regex.bkl", "../bakefiles/tiff.bkl", "../bakefiles/png.bkl", "../bakefiles/jpeg.bkl", "../bakefiles/scintilla.bkl", "../bakefiles/expat.bkl"}, nodes:{Â
 
 221         {label:"base", entries:{"$(BASE_SRC)"}}, Â
 
 222         {label:"base", entries:{"$(BASE_AND_GUI_SRC)"}}, Â
 
 223         {label:"core", entries:{"$(CORE_SRC)"}}, Â
 
 224         {label:"net", entries:{"$(NET_SRC)"}}, Â
 
 225         {label:"adv", entries:{"$(ADVANCED_SRC)"}}, Â
 
 226         {label:"media", entries:{"$(MEDIA_SRC)"}}, Â
 
 227         {label:"html", entries:{"$(HTML_SRC)"}}, Â
 
 228         {label:"xrc", entries:{"$(XRC_SRC)"}}, Â
 
 229         {label:"xml", entries:{"$(XML_SRC)"}}, Â
 
 230         {label:"opengl", entries:{"$(OPENGL_SRC)"}}, Â
 
 231         {label:"aui", entries:{"$(AUI_SRC)"}}, Â
 
 232         {label:"ribbon", entries:{"$(RIBBON_SRC)"}}, Â
 
 233         {label:"propgrid", entries:{"$(PROPGRID_SRC)"}}, Â
 
 234         {label:"richtext", entries:{"$(RICHTEXT_SRC)"}}, Â
 
 235         {label:"stc", entries:{"$(STC_SRC)"}}, Â
 
 236         {label:"libtiff", entries:{"$(wxtiff)"}}, Â
 
 237         {label:"libjpeg", entries:{"$(wxjpeg)"}}, Â
 
 238         {label:"libpng", entries:{"$(wxpng)"}}, Â
 
 239         {label:"libregex", entries:{"$(wxregex)"}}, Â
 
 240         {label:"libscintilla", entries:{"$(wxscintilla)"}}, Â
 
 241         {label:"libexpat", entries:{"$(wxexpat)"}} Â
 
 243 makeProject(theProject)
 
 245 set theProject to {conditions:{"PLATFORM_MACOSX=='1'", "TOOLKIT=='OSX_COCOA'", "WXUNIV=='0'", "USE_GUI=='1' and WXUNIV=='0'"}, projectName:Â
 
 246         "wxcocoa", bklfiles:{Â
 
 247         "../bakefiles/files.bkl", "../bakefiles/regex.bkl", "../bakefiles/tiff.bkl", "../bakefiles/png.bkl", "../bakefiles/jpeg.bkl", "../bakefiles/scintilla.bkl", "../bakefiles/expat.bkl"}, nodes:{Â
 
 248         {label:"base", entries:{"$(BASE_SRC)"}}, Â
 
 249         {label:"base", entries:{"$(BASE_AND_GUI_SRC)"}}, Â
 
 250         {label:"core", entries:{"$(CORE_SRC)"}}, Â
 
 251         {label:"net", entries:{"$(NET_SRC)"}}, Â
 
 252         {label:"adv", entries:{"$(ADVANCED_SRC)"}}, Â
 
 253         {label:"media", entries:{"$(MEDIA_SRC)"}}, Â
 
 254         {label:"html", entries:{"$(HTML_SRC)"}}, Â
 
 255         {label:"xrc", entries:{"$(XRC_SRC)"}}, Â
 
 256         {label:"xml", entries:{"$(XML_SRC)"}}, Â
 
 257         {label:"opengl", entries:{"$(OPENGL_SRC)"}}, Â
 
 258         {label:"aui", entries:{"$(AUI_SRC)"}}, Â
 
 259         {label:"ribbon", entries:{"$(RIBBON_SRC)"}}, Â
 
 260         {label:"propgrid", entries:{"$(PROPGRID_SRC)"}}, Â
 
 261         {label:"richtext", entries:{"$(RICHTEXT_SRC)"}}, Â
 
 262         {label:"stc", entries:{"$(STC_SRC)"}}, Â
 
 263         {label:"libtiff", entries:{"$(wxtiff)"}}, Â
 
 264         {label:"libjpeg", entries:{"$(wxjpeg)"}}, Â
 
 265         {label:"libpng", entries:{"$(wxpng)"}}, Â
 
 266         {label:"libregex", entries:{"$(wxregex)"}}, Â
 
 267         {label:"libscintilla", entries:{"$(wxscintilla)"}}, Â
 
 268         {label:"libexpat", entries:{"$(wxexpat)"}} Â
 
 270 makeProject(theProject)
 
 272 set theProject to {conditions:{"PLATFORM_MACOSX=='1'", "TOOLKIT=='OSX_IPHONE'", "WXUNIV=='0'", "USE_GUI=='1' and WXUNIV=='0'"}, projectName:Â
 
 273         "wxiphone", bklfiles:{Â
 
 274         "../bakefiles/files.bkl", "../bakefiles/regex.bkl", "../bakefiles/tiff.bkl", "../bakefiles/png.bkl", "../bakefiles/jpeg.bkl", "../bakefiles/scintilla.bkl", "../bakefiles/expat.bkl"}, nodes:{Â
 
 275         {label:"base", entries:{"$(BASE_SRC)"}}, Â
 
 276         {label:"base", entries:{"$(BASE_AND_GUI_SRC)"}}, Â
 
 277         {label:"core", entries:{"$(CORE_SRC)"}}, Â
 
 278         {label:"net", entries:{"$(NET_SRC)"}}, Â
 
 279         {label:"adv", entries:{"$(ADVANCED_SRC)"}}, Â
 
 280         {label:"media", entries:{"$(MEDIA_SRC)"}}, Â
 
 281         {label:"html", entries:{"$(HTML_SRC)"}}, Â
 
 282         {label:"xrc", entries:{"$(XRC_SRC)"}}, Â
 
 283         {label:"xml", entries:{"$(XML_SRC)"}}, Â
 
 284         {label:"opengl", entries:{"$(OPENGL_SRC)"}}, Â
 
 285         {label:"aui", entries:{"$(AUI_SRC)"}}, Â
 
 286         {label:"ribbon", entries:{"$(RIBBON_SRC)"}}, Â
 
 287         {label:"propgrid", entries:{"$(PROPGRID_SRC)"}}, Â
 
 288         {label:"richtext", entries:{"$(RICHTEXT_SRC)"}}, Â
 
 289         {label:"stc", entries:{"$(STC_SRC)"}}, Â
 
 290         {label:"libtiff", entries:{"$(wxtiff)"}}, Â
 
 291         {label:"libjpeg", entries:{"$(wxjpeg)"}}, Â
 
 292         {label:"libpng", entries:{"$(wxpng)"}}, Â
 
 293         {label:"libregex", entries:{"$(wxregex)"}}, Â
 
 294         {label:"libscintilla", entries:{"$(wxscintilla)"}}, Â
 
 295         {label:"libexpat", entries:{"$(wxexpat)"}} Â
 
 297 makeProject(theProject)