Skip to content

Commit

Permalink
Make the Rakefile properly parallelizable.
Browse files Browse the repository at this point in the history
  • Loading branch information
FooBarWidget committed Apr 20, 2009
1 parent 6189c05 commit 83761fa
Showing 1 changed file with 65 additions and 79 deletions.
144 changes: 65 additions & 79 deletions Rakefile
Expand Up @@ -73,73 +73,70 @@ task :clobber

##### Ruby C extension

subdir 'ext/phusion_passenger' do
task :native_support => ["native_support.#{LIBEXT}"]

file 'Makefile' => 'extconf.rb' do
sh "#{RUBY} extconf.rb"
end

file "native_support.#{LIBEXT}" => ['Makefile', 'native_support.c'] do
sh "make"
end

task :clean do
sh "make clean" if File.exist?('Makefile')
sh "rm -f Makefile"
end
task :native_support => "ext/phusion_passenger/native_support.#{LIBEXT}"

file 'ext/phusion_passenger/Makefile' => 'ext/phusion_passenger/extconf.rb' do
sh "cd ext/phusion_passenger && #{RUBY} extconf.rb"
end

file "ext/phusion_passenger/native_support.#{LIBEXT}" => [
'ext/phusion_passenger/Makefile',
'ext/phusion_passenger/native_support.c'
] do
sh "cd ext/phusion_passenger && make"
end

task :clean do
sh "cd ext/phusion_passenger && make clean" if File.exist?('ext/phusion_passenger/Makefile')
sh "rm -f ext/phusion_passenger/Makefile"
end


##### Boost and OXT static library

def define_libboost_oxt_task(output_dir, extra_compiler_flags = nil)
output_file = "#{output_dir}/libboost_oxt.a"
objects_output_dir = "#{output_dir}/libboost_oxt"
objects_output_path = Pathname.new(objects_output_dir).expand_path
ext_path = Pathname.new("ext").expand_path

file(output_file =>
Dir['ext/boost/src/*.cpp'] +
Dir['ext/boost/src/pthread/*.cpp'] +
Dir['ext/oxt/*.cpp'] +
Dir['ext/oxt/*.hpp'] +
Dir['ext/oxt/detail/*.hpp']
) do
sh "mkdir -p #{objects_output_dir}/boost #{objects_output_dir}/oxt"
output_dir_base = "#{output_dir}/libboost_oxt"
flags = "-Iext #{extra_compiler_flags} #{PlatformInfo.portability_cflags} #{EXTRA_CXXFLAGS}"

# Define compilation targets for .cpp files in ext/boost/src/pthread.
boost_object_files = []
Dir['ext/boost/src/pthread/*.cpp'].each do |source_file|
object_name = File.basename(source_file.sub(/\.cpp$/, '.o'))
boost_output_dir = "#{output_dir_base}/boost"
object_file = "#{boost_output_dir}/#{object_name}"
boost_object_files << object_file

Dir.chdir("#{objects_output_dir}/boost") do
puts "### In #{objects_output_dir}/boost:"
current_dir = Pathname.new(".").expand_path
ext_dir = ext_path.relative_path_from(current_dir)
flags = "-I#{ext_dir} #{extra_compiler_flags} #{PlatformInfo.portability_cflags} #{EXTRA_CXXFLAGS}"

# Compling "pthread/*.cpp" doesn't work on some systems,
# so we compile each cpp file invidually instead.
Dir["#{ext_dir}/boost/src/pthread/*.cpp"].each do |file|
compile_cxx(file, flags)
end
puts
file object_file => source_file do
sh "mkdir -p #{boost_output_dir}" if !File.directory?(boost_output_dir)
compile_cxx(source_file, "#{flags} -o #{object_file}")
end
end

# Define compilation targets for .cpp files in ext/oxt.
oxt_object_files = []
oxt_dependency_files = Dir["ext/oxt/*.hpp"] + Dir["ext/oxt/detail/*.hpp"]
Dir['ext/oxt/*.cpp'].each do |source_file|
object_name = File.basename(source_file.sub(/\.cpp$/, '.o'))
oxt_output_dir = "#{output_dir_base}/oxt"
object_file = "#{oxt_output_dir}/#{object_name}"
oxt_object_files << object_file

Dir.chdir("#{objects_output_dir}/oxt") do
puts "### In #{objects_output_dir}/oxt:"
current_dir = Pathname.new(".").expand_path
ext_dir = ext_path.relative_path_from(current_dir)
flags = "-I#{ext_dir} #{extra_compiler_flags} #{PlatformInfo.portability_cflags} #{EXTRA_CXXFLAGS}"
Dir["#{ext_dir}/oxt/*.cpp"].each do |file|
compile_cxx(file, flags)
end
puts
file object_file => [source_file, *oxt_dependency_files] do
sh "mkdir -p #{oxt_output_dir}" if !File.directory?(oxt_output_dir)
compile_cxx(source_file, "#{flags} -o #{object_file}")
end

end

file(output_file => boost_object_files + oxt_object_files) do
sh "mkdir -p #{output_dir_base}/boost #{output_dir_base}/oxt"
create_static_library(output_file,
"#{objects_output_dir}/boost/*.o " <<
"#{objects_output_dir}/oxt/*.o")
"#{output_dir_base}/boost/*.o " <<
"#{output_dir_base}/oxt/*.o")
end

task :clean do
sh "rm -rf #{output_file} #{objects_output_dir}"
sh "rm -rf #{output_file} #{output_dir_base}"
end

return output_file
Expand All @@ -156,37 +153,26 @@ def define_common_library_task(output_dir, extra_compiler_flags = nil,
extra_linker_flags = nil)
static_library = "#{output_dir}/libpassenger_common.a"
objects_output_dir = "#{output_dir}/libpassenger_common"
objects_output_path = Pathname.new(objects_output_dir).expand_path
ext_path = Pathname.new("ext").expand_path
targets = [static_library]

file(static_library => [
'ext/common/Utils.h',
'ext/common/Utils.cpp',
'ext/common/Logging.h',
'ext/common/Logging.cpp',
'ext/common/SystemTime.h',
'ext/common/SystemTime.cpp',
'ext/common/CachedFileStat.h',
'ext/common/CachedFileStat.cpp'
]) do
sh "mkdir -p #{objects_output_dir}"
# Define compilation targets for the object files in libpassenger_common.
flags = "-Iext -Iext/common #{extra_compiler_flags} "
flags << "#{PlatformInfo.portability_cflags} #{EXTRA_CXXFLAGS}"
common_object_files = []
['Utils.cpp', 'Logging.cpp', 'SystemTime.cpp', 'CachedFileStat.cpp'].each do |source_file|
object_name = source_file.sub(/\.cpp$/, '.o')
object_file = "#{objects_output_dir}/#{object_name}"
header_file = source_file.sub(/\.cpp$/, '.h')
common_object_files << object_file

Dir.chdir(objects_output_dir) do
puts "### In #{objects_output_dir}:"
current_dir = Pathname.new(".").expand_path
ext_dir = ext_path.relative_path_from(current_dir)
flags = "-I#{ext_dir} -I#{ext_dir}/common #{extra_compiler_flags} "
flags << "#{PlatformInfo.portability_cflags} #{EXTRA_CXXFLAGS}"

compile_cxx("#{ext_dir}/common/Utils.cpp", flags)
compile_cxx("#{ext_dir}/common/Logging.cpp", flags)
compile_cxx("#{ext_dir}/common/SystemTime.cpp", flags)
compile_cxx("#{ext_dir}/common/CachedFileStat.cpp", flags)

puts
file object_file => ["ext/common/#{source_file}", "ext/common/#{header_file}"] do
sh "mkdir -p #{objects_output_dir}" if !File.directory?(objects_output_dir)
compile_cxx("ext/common/#{source_file}", "#{flags} -o #{object_file}")
end

end

file(static_library => common_object_files) do
sh "mkdir -p #{objects_output_dir}"
create_static_library(static_library, "#{objects_output_dir}/*.o")
end

Expand Down

0 comments on commit 83761fa

Please sign in to comment.