~jazzva/fakenes/ubuntu

« back to all changes in this revision

Viewing changes to build/mac/macsupport.rb

  • Committer: Sasa Bodiroza
  • Date: 2007-08-15 05:37:49 UTC
  • Revision ID: jazzva@gmail.com-20070815053749-76l0xj66tzgt290p
Upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
require 'rake/loaders/makefile'
 
2
 
 
3
@cc = 'cc'
 
4
@linker = 'cc'
 
5
@makedepend = 'makedepend'
 
6
@frameworkPaths = %w(~/Library/Frameworks /Library/Frameworks /System/Library/Frameworks)
 
7
 
 
8
@commonflags = ''
 
9
@cflags = ''
 
10
@cxxflags = ''
 
11
@objcflags = ''
 
12
 
 
13
@includes = ''
 
14
@defines = ''
 
15
@ldflags = ''
 
16
@frameworkFlags = ''
 
17
@libs = ''
 
18
@systemFrameworks = []
 
19
@frameworks = []
 
20
@cleanfiles = []
 
21
 
 
22
begin
 
23
        unless NOT_UNIVERSAL
 
24
                @commonflags += ' -arch ppc -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk '
 
25
                @ldflags += ' -arch ppc -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk '
 
26
        end
 
27
rescue NameError
 
28
        NOT_UNIVERSAL = false
 
29
        retry
 
30
end
 
31
 
 
32
begin
 
33
        if BUILDDIR
 
34
                @includes += " -I#{BUILDDIR} "
 
35
        end
 
36
rescue NameError
 
37
        BUILDDIR = ''
 
38
end
 
39
 
 
40
###########
 
41
# Cleanup #
 
42
###########
 
43
 
 
44
task(:clean) do |task|
 
45
        rm_rf(BUILDDIR)
 
46
        rm_rf(@cleanfiles)
 
47
        rm_rf(BUNDLEDIR)
 
48
end
 
49
 
 
50
################
 
51
# Installation #
 
52
################
 
53
 
 
54
def installRule(dir, file)
 
55
        target = File::join(dir, File::basename(file))
 
56
        file(target => [dir, file]) do |t|
 
57
                cp(file, target)
 
58
        end
 
59
end
 
60
 
 
61
def installTask(taskName, dir, files)
 
62
        if files.is_a?(String)
 
63
                files = [files]
 
64
        end
 
65
 
 
66
        array = []
 
67
        for f in files do
 
68
                array << File::join(dir, File::basename(f))
 
69
                installRule(dir, f)
 
70
        end
 
71
        task(taskName => array)
 
72
end
 
73
 
 
74
def installTaskRecursive(taskName, dest, src)
 
75
        target = File::join(dest, File::basename(src))
 
76
        file(target => [dest, src]) do |t|
 
77
                rm_rf(t.name)
 
78
                cp_r(t.prerequisites[1], t.prerequisites[0])
 
79
        end
 
80
        task(taskName => target)
 
81
end
 
82
 
 
83
def bundleDir(dir)
 
84
        file(dir) do |t|
 
85
                sh("/Developer/Tools/SetFile -a B #{dir}")
 
86
        end
 
87
end
 
88
 
 
89
def setCurrentVersion(taskName)
 
90
        task(taskName => "#{VERSIONSDIR}/#{FRAMEWORKVERSION}") do |t|
 
91
                for file in Dir::glob("#{t.prerequisites[0]}/*") do
 
92
                        filename = File::basename(file)
 
93
                        ln_s("Contents/Versions/#{FRAMEWORKVERSION}/#{filename}", "#{BUNDLEDIR}/#{filename}", :force => true)
 
94
                end
 
95
        end
 
96
end
 
97
 
 
98
begin
 
99
        if FRAMEWORK
 
100
                directory(BUNDLEDIR = "#{BUILDDIR}#{NAME}.framework")
 
101
                directory(CONTENTSDIR = "#{BUNDLEDIR}/Contents")
 
102
                directory(VERSIONSDIR = "#{CONTENTSDIR}/Versions")
 
103
                directory(VERSIONDIR = "#{VERSIONSDIR}/#{FRAMEWORKVERSION}")
 
104
                directory(RESOURCEDIR = "#{VERSIONDIR}/Resources")
 
105
                directory(HEADERDIR = "#{VERSIONDIR}/Headers")
 
106
 
 
107
                @ldflags += " -dynamiclib -install_name @executable_path/../Frameworks/#{VERSIONDIR}/#{NAME}"
 
108
        else
 
109
                directory(BUNDLEDIR = "#{BUILDDIR}#{NAME}.app")
 
110
                directory(CONTENTSDIR = "#{BUNDLEDIR}/Contents")
 
111
                directory(RESOURCEDIR = "#{CONTENTSDIR}/Resources")
 
112
                directory(BINDIR = "#{CONTENTSDIR}/MacOS")
 
113
                directory(FRAMEWORKDIR = "#{CONTENTSDIR}/Frameworks")
 
114
        end
 
115
rescue NameError => e
 
116
        if e.name == :FRAMEWORK
 
117
                FRAMEWORK = false
 
118
                retry
 
119
        else
 
120
                raise e
 
121
        end
 
122
end
 
123
 
 
124
bundleDir(BUNDLEDIR)
 
125
task(:bundle => BUNDLEDIR)
 
126
 
 
127
##############
 
128
# Frameworks #
 
129
##############
 
130
 
 
131
def installFrameworks(task)
 
132
        for name in [@frameworks, @systemFrameworks].flatten
 
133
                framework = nil
 
134
                for path in @frameworkPaths
 
135
                        try = "#{File::expand_path(path)}/#{name}.framework"
 
136
                        if File::directory?(try)
 
137
                                framework = try
 
138
                                break
 
139
                        end
 
140
                end
 
141
 
 
142
                if not framework
 
143
                        puts "Framework #{name} missing!"
 
144
                        exit(1)
 
145
                end
 
146
 
 
147
                @frameworkFlags += " -framework #{name} "
 
148
                @includes += " -I#{framework}/Headers "
 
149
 
 
150
                if @frameworks.include?(name)
 
151
                        installTaskRecursive(task, FRAMEWORKDIR, framework)
 
152
                        bundleDir("#{FRAMEWORKDIR}/#{name}.framework")
 
153
                end
 
154
        end
 
155
 
 
156
        for dir in @frameworkPaths
 
157
                @cflags += " -F#{File::expand_path(dir)} "
 
158
                @ldflags += " -F#{File::expand_path(dir)} "
 
159
        end
 
160
end
 
161
 
 
162
###############
 
163
# Compilation #
 
164
###############
 
165
 
 
166
def cTask(object, source)
 
167
        file(object => source) do |task|
 
168
                sh("#{@cc} #{@commonflags} #{@cflags} #{@includes} #{@defines} -o \"#{task.name}\" -c #{task.prerequisites[0]}")
 
169
        end
 
170
end
 
171
 
 
172
def objcTask(object, source)
 
173
        file(object => source) do |task|
 
174
                sh("#{@cc} #{@commonflags} #{@objcflags} #{@includes} #{@defines} -o \"#{task.name}\" -c #{task.prerequisites[0]}")
 
175
        end
 
176
end
 
177
 
 
178
def objcxxTask(object, source)
 
179
        file(object => source) do |task|
 
180
                sh("#{@cc} #{@commonflags} #{@cxxflags} #{@objcflags} #{@includes} #{@defines} -o \"#{task.name}\" -c #{task.prerequisites[0]}")
 
181
        end
 
182
end
 
183
 
 
184
def cxxTask(object, source)
 
185
        file(object => source) do |task|
 
186
                sh("#{@cc} #{@commonflags} #{@cxxflags} #{@includes} #{@defines} -o \"#{task.name}\" -c #{task.prerequisites[0]}")
 
187
        end
 
188
end
 
189
 
 
190
def buildBinary(task, path, file, sources)
 
191
        objects = []
 
192
        target = "#{path}/#{file}"
 
193
        for source in sources
 
194
                object = "#{BUILDDIR}#{File::dirname(source)}/#{File::basename(source, '.*')}.o"
 
195
                if ['.m'].include?(File::extname(source))
 
196
                        objcTask(object, source)
 
197
                elsif ['.M', '.mm'].include?(File::extname(source))
 
198
                        objcxxTask(object, source)
 
199
                elsif ['.cxx', '.cc', '.cpp', '.C'].include?(File::extname(source))
 
200
                        cxxTask(object, source)
 
201
                else
 
202
                        cTask(object, source)
 
203
                end
 
204
                objects.push(object)
 
205
                @cleanfiles.push(object)
 
206
 
 
207
                deps = [source]
 
208
                if BUILDDIR != ''
 
209
                        dir = "#{BUILDDIR}#{File::dirname(source)}"
 
210
                        directory(dir)
 
211
                        deps.push(dir)
 
212
                end
 
213
                depfile = "#{BUILDDIR}#{File::dirname(source)}/.#{File::basename(source, '.*')}.dep.mf"
 
214
                file(depfile => deps) do |task|
 
215
                        prefix = File::join(File::dirname(task.prerequisites[0]), '')
 
216
                        sh("#{@makedepend} -p#{BUILDDIR}#{prefix} -f- -- #{@includes} #{@defines} -- #{task.prerequisites[0]} > #{task.name} 2> /dev/null")
 
217
                end
 
218
                import depfile
 
219
                @cleanfiles.push(depfile)
 
220
        end
 
221
 
 
222
        file(target => [path, *objects]) do |task|
 
223
                sh("#{@linker} #{@frameworkFlags} #{@ldflags} #{@libs} -o \"#{task.name}\" #{task.prerequisites[1..-1].join(' ')}")
 
224
        end
 
225
 
 
226
        task(task => target)
 
227
end