Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 416 lines (350 sloc) 11.737 kb
7e5aed5 @jacius - Rakefile:
jacius authored
1 require 'rubygems'
2 Gem::manage_gems
3
4 require 'rake'
5 require 'rake/gempackagetask'
6 require 'rake/rdoctask'
7
828cb08 @jacius Merge changes from newbuild branch -r186:194 into trunk.
jacius authored
8 require "rbconfig"
9 include Config
9d2e5d4 @jacius Check ENV for CFLAGS, etc. in addition to CONFIG (helps win32 compile).
jacius authored
10
83288e9 @jacius Rakefile will complain loudly and exit with error if compile fails.
jacius authored
11 require 'English'
12
13 class ShellCommandError < RuntimeError
14 end
15
16 # Execute the block (which is supposed to perform a shell command),
17 # then raise ShellCommandError if the command failed.
18 def try_shell( &block )
19 result = yield
20
21 unless $CHILD_STATUS.exitstatus == 0
22 raise ShellCommandError, "Command failed. Aborting."
23 end
24
25 return result
26 end
27
28 def try_sdl_config( flag )
29 begin
30 if $options[:"sdl-config"]
31 return try_shell { `sdl-config #{flag}`.chomp }
32 else
33 return String.new
34 end
35 rescue ShellCommandError
36 warn "WARNING: 'sdl-config' failed."
37 warn "Continuing anyway, but compile may fail."
38 return String.new
39 end
40 end
41
9d2e5d4 @jacius Check ENV for CFLAGS, etc. in addition to CONFIG (helps win32 compile).
jacius authored
42 # Get a variable from ENV or CONFIG, with ENV having precedence.
43 # Returns "" if the variable didn't exist at all.
44 def from_env_or_config(string)
45 ([ENV[string], CONFIG[string]] - ["", nil])[0] or ""
46 end
47
48 OBJEXT = from_env_or_config("OBJEXT")
49 DLEXT = from_env_or_config("DLEXT")
828cb08 @jacius Merge changes from newbuild branch -r186:194 into trunk.
jacius authored
50
028b39a @jacius Bumped version to 2.1.0.
jacius authored
51 RUBYGAME_VERSION = "2.1.0"
d8085c2 @jacius Remove constants.o dependency, add rubygem compatibility code, RDoc t…
jacius authored
52
7e5aed5 @jacius - Rakefile:
jacius authored
53 spec = Gem::Specification.new do |s|
bc12ecf @jacius - Rakefile:
jacius authored
54 s.name = "rubygame"
d8085c2 @jacius Remove constants.o dependency, add rubygem compatibility code, RDoc t…
jacius authored
55 s.version = RUBYGAME_VERSION
bc12ecf @jacius - Rakefile:
jacius authored
56 s.author = "John Croisant"
828cb08 @jacius Merge changes from newbuild branch -r186:194 into trunk.
jacius authored
57 s.email = "jacius@users.sourceforge.net"
58 s.homepage = "http://rubygame.sourceforge.net/"
59 s.summary = "Clean and powerful library for game programming"
bc12ecf @jacius - Rakefile:
jacius authored
60 s.has_rdoc = true
61
30f5eaf @jacius Improved how Rakefile finds files to package and/or rdoc.
jacius authored
62 s.files = FileList.new do |fl|
63 fl.include("{lib,ext,samples,doc}/**/*")
64 fl.exclude(/svn/)
65 fl.exclude(/\.#{OBJEXT}/)
bc12ecf @jacius - Rakefile:
jacius authored
66 end
67
d8085c2 @jacius Remove constants.o dependency, add rubygem compatibility code, RDoc t…
jacius authored
68 s.require_paths = ["lib", "lib/rubygame/", "ext/rubygame/"]
bc12ecf @jacius - Rakefile:
jacius authored
69 s.autorequire = "rubygame.rb"
d8085c2 @jacius Remove constants.o dependency, add rubygem compatibility code, RDoc t…
jacius authored
70 s.extensions = ["Rakefile"]
bc12ecf @jacius - Rakefile:
jacius authored
71
30f5eaf @jacius Improved how Rakefile finds files to package and/or rdoc.
jacius authored
72 s.extra_rdoc_files = FileList.new do |fl|
73 fl.include "doc/*.rdoc"
74 fl.include "README", "LICENSE", "CREDITS", "TODO", "Changelog"
75 end
53a7221 @jacius Merged changes in branches/prerelease-2.0.1 (r376:414, excepting r409…
jacius authored
76 end
77
78 task :linux do
79 spec.platform = Gem::Platform::LINUX_586
80 end
81
82 task :macosx do
83 spec.platform = Gem::Platform::DARWIN
84 end
85
86 task :win32 do
87 spec.platform = Gem::Platform::WIN32
7e5aed5 @jacius - Rakefile:
jacius authored
88 end
89
90 Rake::GemPackageTask.new(spec) do |pkg|
91 pkg.need_tar_bz2 = true
92 end
93
94 Rake::RDocTask.new do |rd|
098089d @jacius Tweak RDoc settings
jacius authored
95 rd.main = "README"
96 rd.title = "Rubygame #{RUBYGAME_VERSION} Docs"
99e041e @jacius Give better info/feedback to the user
jacius authored
97 rd.rdoc_files.include("ext/rubygame/*.c",
30f5eaf @jacius Improved how Rakefile finds files to package and/or rdoc.
jacius authored
98 "lib/rubygame/**/*.rb",
99e041e @jacius Give better info/feedback to the user
jacius authored
99 "doc/*.rdoc",
53a7221 @jacius Merged changes in branches/prerelease-2.0.1 (r376:414, excepting r409…
jacius authored
100 "README",
101 "LICENSE",
102 "CREDITS",
103 "TODO",
104 "Changelog")
7e5aed5 @jacius - Rakefile:
jacius authored
105 end
106
828cb08 @jacius Merge changes from newbuild branch -r186:194 into trunk.
jacius authored
107 task :default => [:build]
99e041e @jacius Give better info/feedback to the user
jacius authored
108 desc "Compile all of the extensions"
828cb08 @jacius Merge changes from newbuild branch -r186:194 into trunk.
jacius authored
109 task :build
110
111 require 'rake/clean'
99e041e @jacius Give better info/feedback to the user
jacius authored
112 task(:clean) { puts "Cleaning out temporary generated files" }
113 task(:clobber) { puts "Cleaning out final generated files" }
114
1c902e0 @jacius Replacing Rakefile option handling (2 of 2)
jacius authored
115 ##############################
116 ## BUILD OPTIONS ##
117 ##############################
118
119 $options = {
6e37567 @jacius Changed sdl_config to sdl-config.
jacius authored
120 :"sdl-gfx" => true,
121 :"sdl-image" => true,
122 :"sdl-ttf" => true,
123 :"sdl-mixer" => true,
124 :opengl => true,
125 :"sdl-config" => true,
126 :debug => false,
127 :verbose => false,
128 :sitearchdir => CONFIG["sitearchdir"],
129 :sitelibdir => CONFIG["sitelibdir"]
1c902e0 @jacius Replacing Rakefile option handling (2 of 2)
jacius authored
130 }
131
132 # Default behavior for win32 is to skip sdl_config,
133 # since it's usually not available. It can still be
134 # enabled through the options, though.
135 if PLATFORM =~ /win32/
6e37567 @jacius Changed sdl_config to sdl-config.
jacius authored
136 $options[:"sdl-config"] = false
1c902e0 @jacius Replacing Rakefile option handling (2 of 2)
jacius authored
137 end
138
139 # Define tasks to enable and disable bool options.
140 #
141 # rake option
142 # rake no-option
143 #
144 # task_name:: the task name to use
145 # option_name:: the option name (if different from
146 # the task name)
147 # desc:: a longer description, to fill
148 # "Enable ________.", if different
149 # from the task name.
150 #
151 def bool_option( task_name, option_name=nil, desc=nil )
152 option_name = task_name unless option_name
7d4f756 @jacius Fix string_option using rake's envvar capabilities.
jacius authored
153 option_name = option_name.intern if option_name.kind_of? String
154
155 desc = task_name.to_s unless desc
156
1c902e0 @jacius Replacing Rakefile option handling (2 of 2)
jacius authored
157 notask_name = "no-#{task_name.to_s}".intern
158
159 is_true = $options[option_name]
160
161 desc "Enable #{desc} #{'(default)' if is_true}"
162 task(task_name) { $options[option_name] = true }
163
164 desc "Disable #{desc} #{'(default)' unless is_true}"
165 task(notask_name) { $options[option_name] = false }
166 end
167
7d4f756 @jacius Fix string_option using rake's envvar capabilities.
jacius authored
168 # Gather a string option from an environment variable:
1c902e0 @jacius Replacing Rakefile option handling (2 of 2)
jacius authored
169 #
170 # rake option="the value of the option"
171 #
172 # task_name:: the task name to use
173 # option_name:: the option name (if different from
174 # the task name)
175 #
176 def string_option( task_name, option_name=nil )
7d4f756 @jacius Fix string_option using rake's envvar capabilities.
jacius authored
177 option_name = task_name unless option_name
178 option_name = option_name.intern if option_name.kind_of? String
1c902e0 @jacius Replacing Rakefile option handling (2 of 2)
jacius authored
179
544360f @jacius Only overwrite options from envvar if the envvar is defined.
jacius authored
180 $options[option_name] = ENV["#{task_name}"] if ENV["#{task_name}"]
1c902e0 @jacius Replacing Rakefile option handling (2 of 2)
jacius authored
181 end
182
6e37567 @jacius Changed sdl_config to sdl-config.
jacius authored
183 bool_option :"sdl-gfx", nil, "SDL_gfx support"
184 bool_option :"sdl-image", nil, "SDL_image support"
185 bool_option :"sdl-mixer", nil, "SDL_mixer support"
186 bool_option :"sdl-ttf", nil, "SDL_ttf support"
187 bool_option :"sdl-config", nil, "guess compiler flags for SDL"
188 bool_option :opengl, nil, "OpenGL support"
189 bool_option :debug, nil, "compil with debug symbols"
190 bool_option :verbose, nil, "show compiler commands"
1c902e0 @jacius Replacing Rakefile option handling (2 of 2)
jacius authored
191
7d4f756 @jacius Fix string_option using rake's envvar capabilities.
jacius authored
192 string_option "RUBYARCHDIR", :sitearchdir
1c902e0 @jacius Replacing Rakefile option handling (2 of 2)
jacius authored
193 string_option :sitearchdir
194
7d4f756 @jacius Fix string_option using rake's envvar capabilities.
jacius authored
195 string_option "RUBYLIBDIR", :sitelibdir
1c902e0 @jacius Replacing Rakefile option handling (2 of 2)
jacius authored
196 string_option :sitelibdir
197
198
9d2e5d4 @jacius Check ENV for CFLAGS, etc. in addition to CONFIG (helps win32 compile).
jacius authored
199 CFLAGS = [from_env_or_config("CFLAGS"),
53a7221 @jacius Merged changes in branches/prerelease-2.0.1 (r376:414, excepting r409…
jacius authored
200 try_sdl_config("--cflags"),
98169f9 @smashwilson Use options.sdl_config properly, make 'rubygame' subdirectory
smashwilson authored
201 "-I. -I#{CONFIG['topdir']}",
9f70ce0 @jacius Cleaning up after replacing options system.
jacius authored
202 ("-g" if $options[:debug]) ].join(" ")
7e5aed5 @jacius - Rakefile:
jacius authored
203
9d2e5d4 @jacius Check ENV for CFLAGS, etc. in addition to CONFIG (helps win32 compile).
jacius authored
204 LINK_FLAGS = [from_env_or_config("LIBRUBYARG_SHARED"),
0bb2a6b @jacius Removed --cflags and --lflags config options; use CFLAGS and LDFLAGS …
jacius authored
205 from_env_or_config("LDFLAGS"),
53a7221 @jacius Merged changes in branches/prerelease-2.0.1 (r376:414, excepting r409…
jacius authored
206 try_sdl_config("--libs")].join(" ")
7e5aed5 @jacius - Rakefile:
jacius authored
207
993f5a4 @jacius Minor typo in Rakefile.
jacius authored
208 DEFAULT_EXTDIR = File.join('ext','rubygame','')
65169e5 @jacius More flexible system; extensions don't link to unneeded libs now
jacius authored
209
210 class ExtensionModule
211 @@libflag = " -l%s " # compiler flag for giving linked libraries
e367b5f @jacius Modularize build directories (don't assume ext/rubygame/).
jacius authored
212 attr_accessor :dynlib, :objs, :libs, :cflags, :lflags, :directory
65169e5 @jacius More flexible system; extensions don't link to unneeded libs now
jacius authored
213 def initialize(&block)
993f5a4 @jacius Minor typo in Rakefile.
jacius authored
214 @directory = DEFAULT_EXTDIR
65169e5 @jacius More flexible system; extensions don't link to unneeded libs now
jacius authored
215 @dynlib = ""
216 @objs = []
217 @libs = []
218 @lflags = ""
219 yield self if block_given?
220 end
221
222 def add_lib( lib )
223 @lflags << @@libflag%lib
224 end
225
226 def add_header( header )
227 #CFLAGS << " -DHAVE_#{header.upcase.gsub('.','_')} "
228 end
229
e367b5f @jacius Modularize build directories (don't assume ext/rubygame/).
jacius authored
230 def create_all_tasks()
231 create_obj_task
232 create_dl_task
233 CLEAN.include("#{@directory}/*.#{OBJEXT}")
234 CLOBBER.include("#{@directory}/*.#{DLEXT}")
235 end
236
65169e5 @jacius More flexible system; extensions don't link to unneeded libs now
jacius authored
237 # Create a file task for each dynamic library (.so) we want to generate.
53a7221 @jacius Merged changes in branches/prerelease-2.0.1 (r376:414, excepting r409…
jacius authored
238 #
239 # The file task invokes another task which does the actual compiling, and
240 # has the true prerequisites.
241 #
242 # This is done so that the prerequisites don't have to be compiled when
243 # the final product already exists (such as in the precompiled win32 gem).
244 #
65169e5 @jacius More flexible system; extensions don't link to unneeded libs now
jacius authored
245 def create_dl_task
53a7221 @jacius Merged changes in branches/prerelease-2.0.1 (r376:414, excepting r409…
jacius authored
246 dynlib_full = File.join( @directory, "#{dynlib}.#{DLEXT}" )
247 objs_full = @objs.collect { |obj|
248 File.join( @directory, "#{obj}.#{OBJEXT}" )
249 }
250
251 taskname = @dynlib.gsub('rubygame_','')
65169e5 @jacius More flexible system; extensions don't link to unneeded libs now
jacius authored
252
53a7221 @jacius Merged changes in branches/prerelease-2.0.1 (r376:414, excepting r409…
jacius authored
253 file dynlib_full do
254 Rake::Task[taskname].invoke
255 end
256
257 desc "Compile the #{@dynlib} extension"
258 task taskname => objs_full do |task|
259 link_command = "#{from_env_or_config('LDSHARED')} #{LINK_FLAGS} #{@lflags} -o #{dynlib_full} #{task.prerequisites.join(' ')}"
9f70ce0 @jacius Cleaning up after replacing options system.
jacius authored
260 if( $options[:verbose] )
83288e9 @jacius Rakefile will complain loudly and exit with error if compile fails.
jacius authored
261 try_shell { sh link_command }
65169e5 @jacius More flexible system; extensions don't link to unneeded libs now
jacius authored
262 else
53a7221 @jacius Merged changes in branches/prerelease-2.0.1 (r376:414, excepting r409…
jacius authored
263 puts "Linking compiled files to create #{File.basename(@directory)}/#{File.basename(dynlib_full)}"
83288e9 @jacius Rakefile will complain loudly and exit with error if compile fails.
jacius authored
264 try_shell { `#{link_command}` }
65169e5 @jacius More flexible system; extensions don't link to unneeded libs now
jacius authored
265 end
266 end
53a7221 @jacius Merged changes in branches/prerelease-2.0.1 (r376:414, excepting r409…
jacius authored
267
268 task :build => [dynlib_full] # Add this as a prereq of the build
65169e5 @jacius More flexible system; extensions don't link to unneeded libs now
jacius authored
269 task :install_ext => [dynlib_full] # ...and install_ext tasks
270 end
e367b5f @jacius Modularize build directories (don't assume ext/rubygame/).
jacius authored
271
272 def create_obj_task
273 # A rule for object files (".o" on linux).
274 # This won't work for rake < 0.7.2, because the proc returns an Array.
275 # If it raises an exception, we'll try a more compatible way.
276 rule(/#{@directory}.+\.#{OBJEXT}$/ =>
277 [
278 # Generate dependencies for this .o file
279 proc do |objfile|
280 source = objfile.sub(".#{OBJEXT}", ".c") # the .c file
281 [source] + depends_headers( source ) # Array of .c + .h dependencies
282 end
283 ])\
284 do |t|
285 compile_command = "#{from_env_or_config('CC')} -c #{CFLAGS} #{t.source} -o #{t.name}"
9f70ce0 @jacius Cleaning up after replacing options system.
jacius authored
286 if( $options[:verbose] )
83288e9 @jacius Rakefile will complain loudly and exit with error if compile fails.
jacius authored
287 try_shell { sh compile_command }
e367b5f @jacius Modularize build directories (don't assume ext/rubygame/).
jacius authored
288 else
289 puts "Compiling #{File.basename(@directory)}/#{File.basename(t.source)}"
83288e9 @jacius Rakefile will complain loudly and exit with error if compile fails.
jacius authored
290 try_shell { `#{compile_command}` }
e367b5f @jacius Modularize build directories (don't assume ext/rubygame/).
jacius authored
291 end
292 end
293 rescue
294 # Generate a .o rule for each .c file in the directory.
295 FileList.new("#{@directory}*.c").each do |source|
296 object = source.sub(".c", ".#{OBJEXT}")
297 file object => ([source] + depends_headers( source )) do |t|
298 compile_command = "#{CONFIG['CC']} -c #{CFLAGS} #{source} -o #{t.name}"
9f70ce0 @jacius Cleaning up after replacing options system.
jacius authored
299 if( $options[:verbose] )
83288e9 @jacius Rakefile will complain loudly and exit with error if compile fails.
jacius authored
300 try_shell { sh compile_command }
e367b5f @jacius Modularize build directories (don't assume ext/rubygame/).
jacius authored
301 else
302 puts "Compiling #{File.basename(@directory)}/#{File.basename(source)}"
83288e9 @jacius Rakefile will complain loudly and exit with error if compile fails.
jacius authored
303 try_shell { `#{compile_command}` }
e367b5f @jacius Modularize build directories (don't assume ext/rubygame/).
jacius authored
304 end
305 end
306 end
307 end
308
309 # Extracts the names of all the headers that the C file depends on.
310 def depends_headers( filename )
311 return [] # workaround for a bug
312 depends = []
313 File.open(filename, "r") do |file|
314 file.each_line do |line|
315 if /#include\s+"(\w+\.h)"/ =~ line
316 depends << @directory+$1
317 end
318 end
319 end
320 return depends
321 end
65169e5 @jacius More flexible system; extensions don't link to unneeded libs now
jacius authored
322 end
323
324 rubygame_core = ExtensionModule.new do |core|
325 core.dynlib = 'rubygame_core'
326 core.objs = ['rubygame_main',
327 'rubygame_shared',
328 'rubygame_event',
329 'rubygame_gl',
330 'rubygame_joystick',
331 'rubygame_screen',
332 'rubygame_surface',
333 'rubygame_time',
334 ]
e367b5f @jacius Modularize build directories (don't assume ext/rubygame/).
jacius authored
335 core.create_all_tasks()
7e5aed5 @jacius - Rakefile:
jacius authored
336 end
337
828cb08 @jacius Merge changes from newbuild branch -r186:194 into trunk.
jacius authored
338 # TODO: We should check if the libraries exist?
339
65169e5 @jacius More flexible system; extensions don't link to unneeded libs now
jacius authored
340 rubygame_gfx = ExtensionModule.new do |gfx|
341 gfx.dynlib = 'rubygame_gfx'
342 gfx.objs = ['rubygame_shared', 'rubygame_gfx']
343 gfx.add_lib( 'SDL_gfx' )
344 gfx.add_header( 'SDL_gfxPrimitives.h')
345 gfx.add_header( 'SDL_rotozoom.h' )
03059f5 @jacius More cleaning up.
jacius authored
346 gfx.create_all_tasks() if $options[:"sdl-gfx"]
65169e5 @jacius More flexible system; extensions don't link to unneeded libs now
jacius authored
347 end
348
349 rubygame_image = ExtensionModule.new do |image|
350 image.dynlib = 'rubygame_image'
351 image.objs = ['rubygame_shared', 'rubygame_image']
352 image.add_lib('SDL_image')
353 image.add_header('SDL_image.h')
03059f5 @jacius More cleaning up.
jacius authored
354 image.create_all_tasks() if $options[:"sdl-image"]
65169e5 @jacius More flexible system; extensions don't link to unneeded libs now
jacius authored
355 end
356
357 rubygame_mixer = ExtensionModule.new do |mixer|
358 mixer.dynlib = 'rubygame_mixer'
359 mixer.objs = ['rubygame_shared', 'rubygame_mixer']
360 mixer.add_lib('SDL_mixer')
361 mixer.add_header('SDL_mixer.h')
03059f5 @jacius More cleaning up.
jacius authored
362 mixer.create_all_tasks() if $options[:"sdl-mixer"]
65169e5 @jacius More flexible system; extensions don't link to unneeded libs now
jacius authored
363 end
364
365 rubygame_ttf = ExtensionModule.new do |ttf|
366 ttf.dynlib = 'rubygame_ttf'
367 ttf.add_lib('SDL_ttf')
368 ttf.objs = ['rubygame_shared', 'rubygame_ttf']
369 ttf.add_header('SDL_ttf.h')
03059f5 @jacius More cleaning up.
jacius authored
370 ttf.create_all_tasks() if $options[:"sdl-ttf"]
65169e5 @jacius More flexible system; extensions don't link to unneeded libs now
jacius authored
371 end
372
9f70ce0 @jacius Cleaning up after replacing options system.
jacius authored
373 if $options[:opengl]
65169e5 @jacius More flexible system; extensions don't link to unneeded libs now
jacius authored
374 CFLAGS << " -DHAVE_OPENGL "
375 end
828cb08 @jacius Merge changes from newbuild branch -r186:194 into trunk.
jacius authored
376
53a7221 @jacius Merged changes in branches/prerelease-2.0.1 (r376:414, excepting r409…
jacius authored
377 desc "(Called when installing via Rubygems)"
378 task :extension => [:fix_filenames, :build]
379
380 task :fix_filenames do
381 unless DLEXT == 'so'
382 Rake::Task[:install_ext].prerequisites.each do |prereq|
383 prereq = prereq.ext('so')
384 if File.exist? prereq
385 mv prereq, prereq.ext(DLEXT)
386 end
387 end
388 end
389 end
390
0a04fbc @jacius Improved how the library is installed.
jacius authored
391 desc "Install just the extensions"
828cb08 @jacius Merge changes from newbuild branch -r186:194 into trunk.
jacius authored
392 task :install_ext do |task|
9f70ce0 @jacius Cleaning up after replacing options system.
jacius authored
393 puts "Installing extensions to #{$options[:sitearchdir]}"
394 mkdir_p $options[:sitearchdir]
395 cp task.prerequisites.to_a, $options[:sitearchdir]
828cb08 @jacius Merge changes from newbuild branch -r186:194 into trunk.
jacius authored
396 end
7e5aed5 @jacius - Rakefile:
jacius authored
397
0a04fbc @jacius Improved how the library is installed.
jacius authored
398 desc "Install just the library"
828cb08 @jacius Merge changes from newbuild branch -r186:194 into trunk.
jacius authored
399 task :install_lib do |task|
9f70ce0 @jacius Cleaning up after replacing options system.
jacius authored
400 puts "Installing library to #{$options[:sitelibdir]}"
ddc058c @jacius Smarter installing of library files.
jacius authored
401
402 files = FileList.new do |fl|
403 fl.include("lib/**/*.rb")
404 fl.exclude(/svn/)
405 end
406
407 files.each do |f|
408 dir = File.join($options[:sitelibdir], File.dirname(f).sub('lib',''), "")
409 mkdir_p dir
410 cp f, dir
411 end
828cb08 @jacius Merge changes from newbuild branch -r186:194 into trunk.
jacius authored
412 end
7e5aed5 @jacius - Rakefile:
jacius authored
413
99e041e @jacius Give better info/feedback to the user
jacius authored
414 desc "Install both the extensions and the library"
828cb08 @jacius Merge changes from newbuild branch -r186:194 into trunk.
jacius authored
415 task :install => [:install_ext, :install_lib]
Something went wrong with that request. Please try again.