File: makeStat.met

package info (click to toggle)
ncbi-tools6 6.1.20120620-8
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 241,628 kB
  • ctags: 101,236
  • sloc: ansic: 1,431,713; cpp: 6,248; pascal: 3,949; xml: 3,390; sh: 3,090; perl: 1,077; csh: 488; makefile: 449; ruby: 93; lisp: 81
file content (491 lines) | stat: -rwxr-xr-x 15,216 bytes parent folder | download | duplicates (12)
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
(*
	Make our stationery project from scratch that will 
	be used to make all other libraries. This allows us to get all of these common 
	settings out of the makeall script.
*)

-- create library or application stationery?
property pCreateLibrary : false

property pProjectFileExtension : ".mcp"

property pTargetList : {"Carbon Debug", "Carbon Final", "Mach-O Debug", "Mach-O Final"}
global gAccessRoot
global gMWCWfolder

(* ======  Stand alone. When run by itself, make the appropriate stationery. ====== *)

set my pCreateLibrary to true
SetGlobals()
CreateFolders()
CreateStationeryProject(gStationeryName, gRsrcsDir, gMWCWfolder)
set my pCreateLibrary to false
SetGlobals()
CreateFolders()
CreateStationeryProject(gStationeryName, gRsrcsDir, gMWCWfolder)



on CreateStationeryProject(projName, projDir, cwDir)
	
	-- make sure the Metrowerks folder spec is global.
	if gMWCWfolder is not cwDir then
		set gMWCWfolder to cwDir
	end if
	
	set projFilename to projName & pProjectFileExtension
	set projPathname to projDir & projFilename
	
	tell application "CodeWarrior IDE"
		
		try
			close (the first project document whose name is projFilename)
		end try
		
		-- try
		
		-- display dialog "creating project: " & projPathname buttons {"OK"} default button 1
		
		Create Project {projPathname}
		
		-- end try
		
		repeat with t in pTargetList
			my SetupTarget(t, projName)
		end repeat
		
		-- finish up.
		if my IsOSX() and not pCreateLibrary then
			display dialog "To finish add the following files into " & projFilename & "'s Mach-O targets:" & return & 
				"  /System/Library/Frameworks/Carbon.framework" & return & 
				"  /System/Library/Frameworks/System.framework" & return & 
				"  /usr/lib/crt1.o" & return & return & 
				"Sorry, but Codewarrior's Applescript won't do these." buttons {"OK"} default button 1
		else
			Close Project
		end if
		
	end tell
	
	CleanupFolder(projDir, projName)
	
end CreateStationeryProject

-- Delete files and folders created during this process we do not  need.
-- particularly the project's Data directory and output files and directories.
on CleanupFolder(thePath, projName)
	repeat with f in list folder (thePath) without invisibles
		if ((f as string) begins with "xxxx_" or (f as string) is projName & " Data") 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 SetupTarget(targetName, projName)
	tell application "CodeWarrior IDE"
		
		-- display dialog "Setup target: " & targetName & return & "project: " & projName
		
		-- Figure out what our output file will be (tentatively) named.
		
		set targetFilename to "xxxx" -- The real target's output name will get set later.
		set targetAPI to ""
		set debugFlag to ""
		
		-- Linker & Output type.
		
		if targetName contains "Carbon" then
			set targetFilename to targetFilename & "_C"
			set targetAPI to "Carbon"
		else if targetName contains "Mach-O" and my IsOSX() then
			set targetFilename to targetFilename & "_M"
			set targetAPI to "Mach-O"
		else
			-- I do not know what kind of target you are talking about.
			-- or we are on a OS 9 machine and I don't know what Mach-O is.
			-- ignore this argument.
			return
		end if
		
		-- Debug or not.
		if targetName contains "Final" or targetName contains "Release" then
			set debugFlag to "Final"
			set targetFilename to targetFilename & "_O" -- for Optimized.
		else
			-- Assume Debug if nothing else.
			set debugFlag to "Debug"
			set targetFilename to targetFilename & "_D"
		end if
		
		if pCreateLibrary then
			set targetFilename to targetFilename & ".lib"
			set targetName to "Library " & targetName
		else
			set targetFilename to targetFilename & ".app"
			set targetName to "Application " & targetName
		end if
		
		-- Make the new target, and set the current target to be it.
		
		if (count targets of project document 1) is 1 and 
			(name of target 1 of project document 1) is projName then
			-- brand new project comes with one default target, same name as the project.
			-- rename that one.
			set (name of target 1 of project document 1) to targetName
			set the current target of project document 1 to the target 1 of project document 1
		else
			-- make all the subsequent targets.
			make new target at project document 1 with properties {name:targetName}
			set the current target of project document 1 to the result
		end if
		
		-- set all the preference panels
		-- display dialog " API: " & targetAPI & return & " filename: " & targetFilename & return & debugFlag
		my SetPreferences(targetAPI, targetFilename, debugFlag is "Debug")
		
	end tell
end SetupTarget

------ All Preference Panel settings in here.  ----- 

on SetPreferences(targetAPI, targetFilename, shouldDebug)
	set weAreMach to (targetAPI is "Mach-O")
	
	tell application "CodeWarrior IDE"
		
		if weAreMach then
			set linkerName to "MacOS X PPC Linker"
			set targetPanelName to "PPC Mac OS X Project"
			set codeGenPanelName to "PPC CodeGen Mach-O"
			set linkerPanelName to "PPC Mac OS X Linker"
		else
			set linkerName to "MacOS PPC Linker"
			set targetPanelName to "PPC Project"
			set codeGenPanelName to "PPC CodeGen"
			set linkerPanelName to "PPC Linker"
		end if
		
		(* ===== Section "Target" ===== *)
		
		Set Preferences of panel "Target Settings" to {Linker:linkerName}
		
		-- Panel "PPC or Mac OS X Target"
		if pCreateLibrary then
			Set Preferences of panel targetPanelName to {Project Type:library, File Name:targetFilename}
		else
			if weAreMach then
				Set Preferences of panel targetPanelName to 
					{Project Type:application package, File Name:targetFilename, File Creator:"NCBI", File Type:"APPL"}
			else
				Set Preferences of panel targetPanelName to 
					{Project Type:standard application, File Name:targetFilename, File Creator:"NCBI", File Type:"APPL", SIZE Flags:22720, Preferred Heap Size:8000, Min Heap Size:5000, Stack Size:64} 
						
				-- the following only needed on pre-OS X systems when we turn on the Output Flags post-linker, 
				-- but it is harmless in other cases.
				Set Preferences of panel "Output Flags" to {Has Bundle:true}
			end if
		end if
		
		(* ===== Section "Language Settings" ===== *)
		
		-- Panel "C/C++ Language"
		Set Preferences of panel "C/C++ Compiler" to 
			{Activate CPlusPlus:false 
				, ARM Conformance:false 
				, Exception Handling:true 
				, RTTI:true 
				, Pool Strings:true 
				, Dont Reuse Strings:false 
				, Require Function Prototypes:true 
				, Enable bool Support:true 
				, Enable wchar_t:true 
				, C99:false 
				, ANSI Strict:false 
				, ANSI Keywords Only:false 
				, Expand Trigraph Sequences:false 
				, MPW Newlines:false 
				, MPW Pointer Type Rules:false 
				, Enums Always Ints:false 
				, Prefix File:""}
		
		-- Panel "C/C++ Warnings"
		Set Preferences of panel "C/C++ Warnings" to 
			{Treat Warnings As Errors:false 
				, Illegal Pragmas:true 
				, Empty Declarations:true 
				, Possible Errors:true 
				, Unused Variables:true 
				, Unused Arguments:false 
				, Extra Commas:true 
				, Extended Error Checking:true 
				, Hidden Virtual Functions:true 
				, Implicit Arithmetic Conversions:false 
				, NonInlined Functions:false 
				, Inconsistent Class Struct:true}
		
		(* ===== Section "Code Generation" ===== *)
		
		-- Panel "PPC CodeGen Mach-O"
		Set Preferences of panel codeGenPanelName to 
			{Struct Alignment:Align_PPC 
				, Make Strings ReadOnly:true 
				, Use FMADD Instructions:false 
				, Schedule:false 
				, Peephole Optimizer:true}
		
		if not weAreMach then
			-- preferences that are only on non-Mach targets.
			Set Preferences of panel codeGenPanelName to 
				{Store Data in TOC:true 
					, Traceback Tables:TB_Inline}
		end if
		
		(* ===== Section "Debugger" ===== *)
		
		if shouldDebug then
			(* ==== Debug settings ==== *)
			(* ===== Panel PPC Global Optimizer =====  *)
			Set Preferences of panel "PPC Global Optimizer" to 
				{Optimize For:code_Speed, Level:0}
			
			(* ===== Panel PPC Linker ===== *)
			Set Preferences of panel linkerPanelName to 
				{Generate SYM File:true 
					, Full Path In SYM:true 
					, Generate Link Map:false 
					, Link Mode:fast}
			
			(* ===== Panel C/C++ Language =====  *)
			Set Preferences of panel "C/C++ Compiler" to 
				{Inlining:inline_none, AutoInlining:false}
		else
			(* ==== optimized/release settings ==== *)
			(* ===== Panel PPC Global Optimizer =====  *)
			Set Preferences of panel "PPC Global Optimizer" to 
				{Optimize For:code_Speed, Level:4}
			(* ===== Panel PPC Linker ===== *)
			
			Set Preferences of panel linkerPanelName to 
				{Generate SYM File:false 
					, Generate Link Map:false 
					, Link Mode:fast}
			
			(* ===== Panel C/C++ Language =====  *)
			Set Preferences of panel "C/C++ Compiler" to 
				{Inlining:inline_smart, AutoInlining:true}
		end if
		
		-- Panel "Debugger Settings"
		Set Preferences of panel "Debugger Target" to 
			{Log System Messages:false}
		
		(* ===== Panel Access Paths ===== *)
		-- when building projects add the other paths at the end of User Paths.
		-- since 'Always Full Search' is true they will get searched before the default System Paths.
		-- But MachO needs to move the /usr/.. directories to User Paths.
		
		Set Preferences of panel "Access Paths" to {Always Full Search:true, Convert Paths:true, Require Framework Includes:false}
		my SetPaths(weAreMach)
		
		-- add libraries to this target
		
		if not pCreateLibrary then
			if not weAreMach then
				if shouldDebug then
					set libsToAdd to {gMWCWfolder & "MacOS Support:Libraries:Runtime:Libs:MSL_All_Carbon_D.lib"}
				else
					set libsToAdd to {gMWCWfolder & "MacOS Support:Libraries:Runtime:Libs:MSL_All_Carbon.lib"}
				end if
				copy (gMWCWfolder & "MacOS Support:Universal:Libraries:StubLibraries:CarbonLib") to end of libsToAdd
			else
				if shouldDebug then
					set libsToAdd to {gMWCWfolder & "MacOS X Support:Libraries:Runtime:Libs:MSL_All_Mach-O_D.lib"}
				else
					set libsToAdd to {gMWCWfolder & "MacOS X Support:Libraries:Runtime:Libs:MSL_All_Mach-O.lib"}
				end if
				copy (gMWCWfolder & "MSL:MSL_C:MSL_MacOS:Src:console_OS_X.c") to end of libsToAdd
				copy ("/usr/lib/crt1.o") to end of libsToAdd
				copy "abc:System:Library:Frameworks:Carbon.framework" to end of libsToAdd
				copy "abc:System:Library:Frameworks:System.framework" to end of libsToAdd
			end if
			
			Add Files libsToAdd
		end if
		
	end tell
end SetPreferences

on SetPaths(weAreMach)
	tell application "CodeWarrior IDE"
		
		(* ===== Panel Access Paths ===== *)
		
		-- This removes the compiler default folders because otherwise setting the paths only adds on to the end. Never deletes anything.
		Set Preferences of panel "Access Paths" to {User Paths:{}, System Paths:{}}
		
		-- set up User Paths
		set userPaths to {{name:":", format:MacOS Path, origin:project relative, recursive:true}}
		if weAreMach then
			copy {name:":usr:include:", format:MacOS Path, origin:root relative, root:"OS X Volume", recursive:false} 
				to end of userPaths
			if not pCreateLibrary then
				copy {name:":usr:lib:", format:MacOS Path, origin:root relative, root:"OS X Volume", recursive:false} 
					to end of userPaths
			end if
		end if
		
		-- set up System Paths
		if weAreMach then
			set sysPaths to {
				{name:":MSL:MSL_C:", format:MacOS Path, origin:shell relative, recursive:true}, 
				{name:":MacOS Support:", format:MacOS Path, origin:shell relative, recursive:true}, 
				{name:":MacOS X Support:", format:MacOS Path, origin:shell relative, recursive:true}}
		else
			set sysPaths to {
				{name:":MSL:", format:MacOS Path, origin:shell relative, recursive:true}, 
				{name:":MacOS Support:", format:MacOS Path, origin:shell relative, recursive:true}}
		end if
		
		-- put everything back.
		Set Preferences of panel "Access Paths" to {User Paths:userPaths, System Paths:sysPaths}
		
	end tell
end SetPaths


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 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


-- the following will build the stationery project in the lib directory.
-- CreateStationeryProject(gStationeryName, gDistribRoot & gBuildDir & ":" & gStationeryName & ":", gMWCWfolder)


-- the following are needed to run this script by itself,
-- they are not needed when it is called by another script.

--
-- Global variables
--

global gStartupDisk
global gHomeDir
global gMWroot
global gDistribRoot
global gBuildDir
global gRsrcsDir
global gStationeryName
global gDirsToCreate

on ResolveAlias(pathname)
	tell application "Finder"
		if exists folder pathname then return pathname & ":"
		if exists alias file pathname then return the original item of alias file pathname as string
		error "The folder (or alias) '" & pathname & "' doesn't exist."
	end tell
end ResolveAlias

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(gMWroot & "ncbi")
	on error
		try
			set modRoot to ResolveAlias(gHomeDir & "ncbi")
		end try
	end try
	
	return modRoot
end ModuleRoot

on MWRootDir()
	
	set mwRoot to ""
	set mwLocations to {gStartupDisk, gStartupDisk & "Applications:", gStartupDisk & "Applications (Mac OS 9):", 
		gHomeDir, gHomeDir & "Applications:", gHomeDir & "Applications (Mac OS 9):"}
	repeat with mwVersion from 8 to 9
		set dirName to "Metrowerks CodeWarrior " & mwVersion & ".0"
		repeat with mwLoc in mwLocations
			try
				set mwRoot to ResolveAlias(mwLoc & dirName)
				return mwRoot
			end try
		end repeat
	end repeat
	
	error "Can't find the Metrowerks CodeWarrior folder."
	
end MWRootDir

on SetGlobals()
	tell application "Finder"
		
		set gStartupDisk to startup disk as string
		set gHomeDir to my HomeDir()
		set gMWroot to my MWRootDir()
		set gMWCWfolder to gMWroot & "Metrowerks CodeWarrior:"
		set gDistribRoot to my ModuleRoot()
		set gRsrcsDir to gDistribRoot & "link:macmet:"
		
		if pCreateLibrary then
			set gStationeryName to "LibraryStationery"
			set gBuildDir to "lib"
		else
			set gStationeryName to "ApplicationStationery"
			set gBuildDir to "build"
		end if
		
		set gDirsToCreate to {
			{relPath:"", name:gBuildDir}, 
			{relPath:gBuildDir, name:gStationeryName}}
		
	end tell
end SetGlobals

on CreateFolders()
	tell application "Finder"
		
		repeat with i in gDirsToCreate
			set pth to relPath of i
			if pth is not "" then set pth to pth & ":"
			
			if not (exists folder (gDistribRoot & pth & i's name)) then
				make new folder at folder (gDistribRoot & pth) with properties {name:i's name}
			end if
		end repeat
		
	end tell
end CreateFolders