Skip to content

Commit

Permalink
refactored build to support any number of Classes/*.m into single bun…
Browse files Browse the repository at this point in the history
…dle; rather than multiple bundles
  • Loading branch information
drnic committed Sep 6, 2008
1 parent c30c9b0 commit e463bb5
Showing 1 changed file with 19 additions and 27 deletions.
46 changes: 19 additions & 27 deletions Rakefile
Expand Up @@ -10,44 +10,36 @@ end

task :compile => "objc:compile"

fmdb_dir = File.dirname(__FILE__) + "/fmdb"
fmdb_dir = File.dirname(__FILE__) + "/fmdb"
src_files = FileList['fmdb/FM*.m', 'Classes/*.m']

# compile fmdb/*.m files into build/*.o files
FileList['fmdb/FM*.m'].each do |fmdb_file|
src_files.each do |file|
FileUtils.mkdir_p "build"
base = fmdb_file.gsub(/\.m$/,'')
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}"
sh "gcc -c #{base}.m -o #{dot_o} -I#{fmdb_dir} -IClasses"
end
end

fmdb_o_files = FileList['fmdb/FM*.m'].map { |fmdb_file| File.join("build", File.basename(fmdb_file).gsub(/m$/,'o')) }
dot_o_files = src_files.map { |file| "build/" + File.basename(file).gsub(/\.m$/,'') + ".o" }

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 => "build/bundles/#{model_name}.bundle" do
if Dir.glob("**/#{model_name}.bundle").length == 0
STDERR.puts "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
STDERR.puts "Bundle actually failed to build."
STDERR.puts "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
exit(1)
end
end

file "build/bundles/#{model_name}.bundle" => fmdb_o_files + ["Classes/#{model_name}.m", "Classes/#{model_name}.h"] do |t|
FileUtils.mkdir_p "build/bundles"
FileUtils.rm Dir["build/bundles/#{model_name}.bundle"]
fmdb_files = FileList['build/FM*.o'].join(" ")
sh "gcc -o build/bundles/#{model_name}.bundle #{fmdb_files} -bundle -framework Foundation -lsqlite3 -I#{fmdb_dir} Classes/#{model_name}.m"
bundle_name = 'FmdbMigrationManager'

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 -framework Foundation -lsqlite3 -I#{fmdb_dir} -IClasses"
end
end

0 comments on commit e463bb5

Please sign in to comment.