Rearranged the project to have src/ and build/ directories

This simplifies keeping everything clean.
This commit is contained in:
Alex Young
2012-05-30 09:51:20 +01:00
parent 21ccd17ea5
commit 7832958522
19 changed files with 48 additions and 31 deletions

View File

@@ -1,3 +1,5 @@
.o$
~$
^flexnbd$
^build/
^pkg/

View File

@@ -1,7 +1,8 @@
DEBUG = true
SOURCES = %w( flexnbd ioutil readwrite serve util parse control remote )
OBJECTS = SOURCES.map { |s| "#{s}.o" }
SOURCES = FileList['src/*.c']
OBJECTS = SOURCES.pathmap( "%{^src,build}X.o" )
LIBS = %w( pthread )
CCFLAGS = %w( -Wall )
LDFLAGS = []
@@ -15,20 +16,20 @@ if DEBUG
end
desc "Build flexnbd binary"
rule 'default' => 'flexnbd'
task :flexnbd => 'build/flexnbd'
namespace "test" do
desc "Run all tests"
task 'run' => ["unit", "scenarios"]
desc "Build C tests"
task 'build' => TEST_MODULES.map { |n| "tests/check_#{n}" }
task 'build' => TEST_MODULES.map { |n| "build/tests/check_#{n}" }
desc "Run C tests"
task 'unit' => 'build' do
TEST_MODULES.each do |n|
ENV['EF_DISABLE_BANNER'] = '1'
sh "./tests/check_#{n}"
sh "build/tests/check_#{n}"
end
end
@@ -38,29 +39,43 @@ namespace "test" do
end
end
def gcc_link(target, objects)
FileUtils.mkdir_p File.dirname( target )
sh "gcc #{LDFLAGS.join(' ')} "+
LIBS.map { |l| "-l#{l}" }.join(" ")+
" -I src" +
" -o #{target} "+
objects.join(" ")
end
rule 'flexnbd' => OBJECTS do |t|
rule 'build/flexnbd' => OBJECTS do |t|
gcc_link(t.name, t.sources)
end
rule(/tests\/check_[a-z]+$/ => [ proc { |target| [target+".o", "util.o"] } ]) do |t|
gcc_link(t.name, t.sources + [LIBCHECK])
TEST_MODULES.each do |m|
deps = ["tests/check_#{m}.c", "build/util.o"]
maybe_obj_name = "build/#{m}.o"
deps << maybe_obj_name if OBJECTS.include?( maybe_obj_name )
file "build/tests/check_#{m}" => deps do |t|
gcc_link(t.name, deps + [LIBCHECK])
end
end
rule '.o' => '.c' do |t|
sh "gcc -I. -c #{CCFLAGS.join(' ')} -o #{t.name} #{t.source} "
OBJECTS.zip( SOURCES ).each do |o,c|
file o => c do |t|
FileUtils.mkdir_p File.dirname( o )
sh "gcc -Isrc -c #{CCFLAGS.join(' ')} -o #{o} #{c} "
end
end
desc "Remove all build targets, binaries and temporary files"
rule 'clean' do
sh "rm -f *~ flexnbd " + (
OBJECTS +
sh "rm -rf *~ build " + (
TEST_MODULES.map { |n| ["tests/check_#{n}", "tests/check_#{n}.o"] }.flatten
).
join(" ")

View File

View File

View File

@@ -13,7 +13,7 @@ class NBDScenarios < Test::Unit::TestCase
@available_ports = [*40000..41000] - listening_ports
@port1 = @available_ports.shift
@port2 = @available_ports.shift
@nbd1 = FlexNBD.new("../flexnbd", @ip, @port1)
@nbd1 = FlexNBD.new("../build/flexnbd", @ip, @port1)
end
def teardown