1-- update C libs --
2
3--
4-- Properties
5--
6
7property pProjectFileExtension : ".mcp"
8
9--
10-- Global variables
11--
12
13global gStartupDisk
14global gHomeDir
15global gMWroot
16
17global gDistribRoot
18
19global gProjectsDir
20global gLibsDir
21
22global gProjectData
23
24on ResolveAlias(pathname)
25	tell application "Finder"
26		--if the last character of pathname is ":" then error "Don't use a trailing colon with ResolveAlias."
27		if exists folder pathname then return pathname & ":"
28		if exists alias file pathname then return the original item of alias file pathname as string
29		error "The folder (or alias) '" & pathname & "' doesn't exist."
30	end tell
31end ResolveAlias
32
33on IsOSX()
34	tell application "Finder"
35
36		set vers to the version as text
37
38		if second character of vers is equal to "." then
39			set vers to "0" & vers
40		end if
41
42		return vers > 10 or vers = 10
43
44	end tell
45end IsOSX
46
47on HomeDir()
48	tell application "Finder"
49
50		if my IsOSX() then
51			-- return the home as string
52			set hm to home as string
53			set wd to words of hm
54			set rs to rest of wd
55			set text item delimiters of AppleScript to ":"
56			set nw to (rs as string) & ":"
57			set text item delimiters of AppleScript to ""
58			return nw
59		else
60			return gStartupDisk
61		end if
62
63	end tell
64end HomeDir
65
66on CToolkitRoot()
67
68	try
69		set modRoot to ResolveAlias(gMWroot & "ncbi")
70	on error
71		try
72			set modRoot to ResolveAlias(gStartupDisk & gHomeDir & "ncbi")
73		end try
74	end try
75
76	return modRoot
77
78end CToolkitRoot
79
80on ModuleRoot()
81
82	return CToolkitRoot()
83
84end ModuleRoot
85
86on MWRootDir()
87
88	set mwRoot to ""
89	set mwLocations to {gStartupDisk, gStartupDisk & "Applications:", gStartupDisk & "Applications (Mac OS 9):", �
90		gStartupDisk & gHomeDir, gStartupDisk & gHomeDir & "Applications:", gStartupDisk & gHomeDir & "Applications (Mac OS 9):"}
91	repeat with mwVersion from 8 to 9
92		set dirName to "Metrowerks CodeWarrior " & mwVersion & ".0"
93		repeat with mwLoc in mwLocations
94			try
95				set mwRoot to ResolveAlias(mwLoc & dirName)
96				return mwRoot
97			end try
98		end repeat
99	end repeat
100
101	error "Can't find the Metrowerks CodeWarrior folder."
102
103end MWRootDir
104
105on SetGlobals()
106	tell application "Finder"
107
108		set gProjectData to {}
109
110		set gStartupDisk to startup disk as string
111		set gHomeDir to my HomeDir()
112		set gMWroot to my MWRootDir()
113
114		set gDistribRoot to my ModuleRoot()
115
116		set gLibsDir to gDistribRoot & "lib:"
117
118		set gProjectsDir to gLibsDir
119
120	end tell
121end SetGlobals
122
123on BuildLibraries(proj)
124	tell application "CodeWarrior IDE"
125		open (gProjectsDir & proj & pProjectFileExtension)
126		repeat with i from 2 to (count targets of project document 1)
127			set the current target of project document 1 to target i of project document 1
128			Make Project
129			-- If there were compiler warnings, then a compiler window will be in front.
130			-- For whatever reason, this causes the next "set the current target..." to fail.
131			-- An easy way to make the window go away without having to know if it's there or not
132			-- is to build again, which, because everything is already compiled, finishes instantly
133			-- and produces no warnings.
134			--Make Project
135			-- An even better way is to check for the window and close it.
136			if the name of window 1 is "Errors & Warnings" then
137				close first window -- "close window 1" becomes "Close Window 1" (different event)
138			end if
139		end repeat
140		set the current target of project document 1 to target 1 of project document 1
141		Close Project
142	end tell
143end BuildLibraries
144
145on BuildAllLibraries()
146	set myLibs to {"mitsock", "ncbi", "ncbiconn", "ncbiobj", "ncbicdr", "vibrant", �
147		"ncbidesk", "ddvlib", "ncbitool", "ncbimmdb", "ncbiNacc", �
148		"netentr", "netcli", "ncbibls3", "ncbiid1", "ncbimla", "ncbitxc2", "vibnet"}
149
150	repeat with proj in myLibs
151		BuildLibraries(proj)
152	end repeat
153end BuildAllLibraries
154
155(* ==== This section builds the libraries ==== *)
156
157with timeout of 60000 seconds
158
159	SetGlobals()
160
161	tell application "CodeWarrior IDE" to activate
162
163	BuildAllLibraries()
164
165	beep
166
167end timeout
168