Skip to content

Commit

Permalink
first attempt at refactoring Rakefile into generic one-bundle for all…
Browse files Browse the repository at this point in the history
… src
  • Loading branch information
drnic committed Sep 10, 2008
1 parent 26e00a9 commit 185fb94
Showing 1 changed file with 37 additions and 21 deletions.
58 changes: 37 additions & 21 deletions app_generators/rbiphonetest/templates/Rakefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
require "rubygems"
require "rake"

src_paths = %w[Classes] # any included projects, add folders here
src_files = FileList['Classes/**/*.m'] # any included projects, add files here
req_frameworks = %w[Foundation] # use only frameworks available to both Cocoa + iPhone SDKs
req_libraries = %w[] # e.g. add sqlite3 for libsqlite3 to be used by linking step

Dir['tasks/**/*.rake'].each { |rake| load rake }

namespace :objc do
Expand All @@ -10,31 +15,42 @@ end

task :compile => "objc:compile"

namespace :objc do
# look for Classes/*.m files containing a line "void Init_ClassName"
# These are the primary classes for bundles; make a bundle for each
model_file_paths = `find Classes/*.m -exec grep -l "^void Init_" {} \\;`.split("\n")
model_file_paths.each do |path|
path =~ /Classes\/(.*)\.m/
model_name = $1

task :compile => model_name do
if Dir.glob("**/#{model_name}.bundle").length == 0
STDERR.puts "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
STDERR.puts "Bundle actually failed to build."
STDERR.puts "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
exit(1)
end
end
# Converts ('-I', ['foo', 'bar'])
# Into: -Ifoo -Ibar
def make_options(flag, items)
items.map { |item| "#{flag}#{item}" }.join(" ")
end

task model_name.to_sym => "build/bundles/#{model_name}.bundle"
src_files.each do |file|
FileUtils.mkdir_p "build"
base = file.gsub(/\.m$/,'')
dot_o = "build/#{File.basename base}.o"
file dot_o => ["#{base}.m", "#{base}.h"] do
sh "gcc -c #{base}.m -o #{dot_o} #{make_options '-I', src_paths}"
end
end

dot_o_files = src_files.map { |file| "build/" + File.basename(file).gsub(/\.m$/,'') + ".o" }

file "build/bundles/#{model_name}.bundle" => ["Classes/#{model_name}.m", "Classes/#{model_name}.h"] do |t|
FileUtils.mkdir_p "build/bundles"
FileUtils.rm Dir["build/bundles/#{model_name}.bundle"]
sh "gcc -o build/bundles/#{model_name}.bundle -bundle -framework Foundation Classes/#{model_name}.m"
namespace :objc do
bundle_name = File.basename File.dirname(__FILE__)

task :compile => "build/bundles/#{bundle_name}.bundle" do
if Dir.glob("**/#{bundle_name}.bundle").length == 0
STDERR.puts "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
STDERR.puts "Bundle actually failed to build."
STDERR.puts "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
exit(1)
end
end

file "build/bundles/#{bundle_name}.bundle" => dot_o_files do |t|
FileUtils.mkdir_p "build/bundles"
FileUtils.rm Dir["build/bundles/#{bundle_name}.bundle"]
sh "gcc -o build/bundles/#{bundle_name}.bundle #{dot_o_files.join(" ")} -bundle " +
"#{make_options '-framework', req_frameworks} " +
"#{make_options '-l', req_libraries} " +
"#{make_options '-I', src_paths}"
end
end

0 comments on commit 185fb94

Please sign in to comment.