]> git.saurik.com Git - wxWidgets.git/blob - build/osx/makeprojects.applescript
Convert wxFSW_EVENT_{WARNING,ERROR} to string correctly.
[wxWidgets.git] / build / osx / makeprojects.applescript
1 global oldDelimiters
2 global variables
3 global variablesRef
4 global bakefilesXML
5 global bakefilesXMLRef
6 global projectFile
7
8 global osxBuildFolder
9
10 property test : false
11
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 " "
15 set allElements 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)
19 else
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))
23 end if
24 end if
25 end if
26 end repeat
27 set AppleScript's text item delimiters to oldDelimiters
28 copy {varname:theName, entries:allElements} to end of theVariables
29 end parseSources
30
31 on parseEntry(theElement, theVariables, theConditions)
32 set theName to var of XML attributes of theElement
33 parseSources(theName, theElement, theVariables, theConditions)
34 end parseEntry
35
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)
41 end if
42 end repeat
43 end parseLib
44
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)
49 else
50 if class of anElement is XML element and Â
51 XML tag of anElement is "lib" then
52 parseLib(anElement, theVariables, theConditions)
53 end if
54 end if
55 end parseNode
56
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
61 try
62 parseNode(anElement, theVariables, theConditions)
63 on error number -1728
64 -- ignore this error
65 end try
66 end repeat
67 else if class of theXML is list then
68 repeat with anElement in theXML
69 try
70 parseNode(anElement, theVariables, theConditions)
71 on error number -1728
72 -- ignore this error
73 end try
74 end repeat
75 end if
76 end parseFiles
77
78 -- gets the entries of the variable named theName
79 on getVar(theName)
80 repeat with anElement in variablesRef
81 if (varname of anElement is theName) then
82 return entries of anElement
83 end if
84 end repeat
85 end getVar
86
87 -- adds sources from fileList to a group named container
88 on addNode(theContainer, fileList)
89 tell application "Xcode"
90 tell project 1
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))
98 else
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
105 try
106 set theGroup to group theContainer
107 on error
108 tell root group
109 make new group with properties {name:theContainer}
110 end tell
111 end try
112 tell group theContainer
113 try
114 set theGroup to group named currGroup
115 on error
116 make new group with properties {name:currGroup}
117 end try
118 tell group 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)
122 end repeat
123 end tell
124 end tell
125 end if
126 end repeat
127 end tell
128 end tell
129 end addNode
130
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
135 close access fileRef
136 return theData
137 end readFile
138
139 on init()
140 tell application "Xcode"
141 quit
142 end tell
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)
148 end tell
149 end init
150
151 -- reads the files list and evaluates the conditions
152 on readFilesList(theFiles, theConditions)
153 set variables to {}
154 repeat with theFile in theFiles
155 set bakefilesXML to parse XML (readFile(osxBuildFolder & theFile))
156 parseFiles(bakefilesXMLRef, variablesRef, theConditions)
157 end repeat
158 end readFilesList
159
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")
169 try
170 tell me
171 do shell script "rm -f " & quoted form of projectContentFile
172 end tell
173 end try
174 try
175 tell me
176 do shell script "cp " & quoted form of templateContentFile & " " & quoted form of projectContentFile
177 end tell
178 end try
179 else
180 set duplicateProject to duplicate (template as POSIX file) with replace
181 set name of duplicateProject to (projectName & ".xcodeproj")
182 end if
183 end tell
184 end instantiateProject
185
186 -- adds the source files of the nodes of theProject to the xcode project
187 on populateProject(theProject)
188 tell application "Xcode"
189 open projectFile
190 end tell
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)
195 end repeat
196 tell application "Xcode"
197 quit
198 end tell
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"
202 open projectFile
203 end tell
204 tell application "Xcode"
205 quit
206 end tell
207 end populateProject
208
209 on makeProject(theProject)
210 instantiateProject(theProject)
211 readFilesList(bklfiles of theProject, conditions of theProject)
212 populateProject(theProject)
213 end makeProject
214
215 -- main
216
217 init()
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)"}} Â
242 }}
243 makeProject(theProject)
244
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)"}} Â
269 }}
270 makeProject(theProject)
271
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)"}} Â
296 }}
297 makeProject(theProject)
298
299