diff --git a/build_tests/configure/check_lib_libpath1.rb b/build_tests/configure/check_lib_libpath1.rb new file mode 100644 index 0000000..c5897ce --- /dev/null +++ b/build_tests/configure/check_lib_libpath1.rb @@ -0,0 +1,5 @@ +build do + Environment.new(echo: :command) do |env| + env.Library("usr2/libfrobulous.a", "two.c") + end +end diff --git a/build_tests/configure/check_lib_libpath2.rb b/build_tests/configure/check_lib_libpath2.rb new file mode 100644 index 0000000..c0998c2 --- /dev/null +++ b/build_tests/configure/check_lib_libpath2.rb @@ -0,0 +1,10 @@ +configure do + check_lib "m", check_libpath: ["./usr1"] + check_lib "frobulous", check_libpath: ["./usr2"] +end + +build do + Environment.new(echo: :command) do |env| + env.Program("simple.exe", "simple.c") + end +end diff --git a/build_tests/configure/two.c b/build_tests/configure/two.c new file mode 100644 index 0000000..12f64b2 --- /dev/null +++ b/build_tests/configure/two.c @@ -0,0 +1,4 @@ +int two(void) +{ + return 42; +} diff --git a/lib/rscons/configure_op.rb b/lib/rscons/configure_op.rb index ac3fa10..ed63dd5 100644 --- a/lib/rscons/configure_op.rb +++ b/lib/rscons/configure_op.rb @@ -235,6 +235,7 @@ module Rscons # Check for a library. def check_lib(lib, options = {}) + check_libpath = [nil] + (options[:check_libpath] || []) Ansi.write($stdout, "Checking for library '", :cyan, lib, :reset, "'... ") File.open("#{@work_dir}/cfgtest.c", "wb") do |fh| fh.puts <<-EOF @@ -249,8 +250,21 @@ module Rscons "_SOURCES" => "#{@work_dir}/cfgtest.c", "_TARGET" => "#{@work_dir}/cfgtest.exe", } - command = BasicEnvironment.new.build_command("${LDCMD}", vars) - _, _, status = log_and_test_command(command) + status = 1 + check_libpath.each do |libpath| + env = BasicEnvironment.new + if libpath + env["LIBPATH"] += Array(libpath) + end + command = env.build_command("${LDCMD}", vars) + _, _, status = log_and_test_command(command) + if status == 0 + if libpath + store_append({"LIBPATH" => Array(libpath)}, options) + end + break + end + end if status == 0 store_append({"LIBS" => [lib]}, options) end diff --git a/spec/build_tests_spec.rb b/spec/build_tests_spec.rb index 3c51917..dacf906 100644 --- a/spec/build_tests_spec.rb +++ b/spec/build_tests_spec.rb @@ -1986,6 +1986,23 @@ EOF expect(result.stdout).to match /Checking for library 'm'... found/ expect(result.stdout).to_not match /-lm/ end + + it "modifies LIBPATH based on check_libpath" do + test_dir "configure" + FileUtils.mkdir_p("usr1") + FileUtils.mkdir_p("usr2") + result = run_rscons(rsconscript: "check_lib_libpath1.rb") + expect(result.stderr).to eq "" + expect(result.status).to eq 0 + result = run_rscons(rsconscript: "check_lib_libpath2.rb", op: "configure") + expect(result.stderr).to eq "" + expect(result.status).to eq 0 + result = run_rscons(rsconscript: "check_lib_libpath2.rb") + expect(result.stderr).to eq "" + expect(result.status).to eq 0 + expect(result.stdout).to match %r{-L\./usr2} + expect(result.stdout).to_not match %r{-L\./usr1} + end end context "check_program" do