From b4a702f27d42ac141dea7e880360670ed054599e Mon Sep 17 00:00:00 2001 From: take_cheeze Date: Thu, 1 May 2014 16:42:34 +0900 Subject: Implement header search for gcc and clang. --- tasks/mruby_build_commands.rake | 12 ++++++++++++ tasks/toolchains/gcc.rake | 24 ++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/tasks/mruby_build_commands.rake b/tasks/mruby_build_commands.rake index 4beb7e743..4fbfaa785 100644 --- a/tasks/mruby_build_commands.rake +++ b/tasks/mruby_build_commands.rake @@ -54,6 +54,18 @@ module MRuby @compile_options = '%{flags} -o %{outfile} -c %{infile}' end + alias header_search_paths include_paths + def search_header_path(name) + header_search_paths.find do |v| + File.exist? build.filename("#{v}/#{name}").sub(/^"(.*)"$/, '\1') + end + end + + def search_header(name) + path = search_header_path name + path && build.filename("#{path}/#{name}").sub(/^"(.*)"$/, '\1') + end + def all_flags(_defineds=[], _include_paths=[], _flags=[]) define_flags = [defines, _defineds].flatten.map{ |d| option_define % d } include_path_flags = [include_paths, _include_paths].flatten.map do |f| diff --git a/tasks/toolchains/gcc.rake b/tasks/toolchains/gcc.rake index a25f840c5..d33910875 100644 --- a/tasks/toolchains/gcc.rake +++ b/tasks/toolchains/gcc.rake @@ -28,4 +28,28 @@ MRuby::Toolchain.new(:gcc) do |conf| linker.option_library_path = '-L%s' linker.link_options = '%{flags} -o %{outfile} %{objs} %{flags_before_libraries} %{libs} %{flags_after_libraries}' end + + [[conf.cc, 'c'], [conf.cxx, 'c++']].each do |cc, lang| + cc.define_singleton_method(:header_search_paths) do + if @header_search_command != command + result = `echo | #{build.filename command} -x#{lang} -Wp,-v - -fsyntax-only 2>&1` + result = `echo | #{command} -x#{lang} -Wp,-v - -fsyntax-only 2>&1` if $?.exitstatus != 0 + return include_paths if $?.exitstatus != 0 + + @frameworks = [] + @header_search_paths = result.lines.map { |v| + framework = v.match(/^ (.*)(?: \(framework directory\))$/) + if framework + @frameworks << framework[1] + next nil + end + + v.match(/^ (.*)$/) + }.compact.map { |v| v[1] }.select { |v| File.directory? v } + @header_search_paths += include_paths + @header_search_command = command + end + @header_search_paths + end + end end -- cgit v1.2.3 From 052fe512799c2aba7dc9171ebe4e2558b6b6db65 Mon Sep 17 00:00:00 2001 From: take_cheeze Date: Thu, 1 May 2014 16:49:00 +0900 Subject: Use header searcher to find readline and linenoise. --- mrbgems/mruby-bin-mirb/mrbgem.rake | 7 ++++++- mrbgems/mruby-bin-mirb/tools/mirb/mirb.c | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/mrbgems/mruby-bin-mirb/mrbgem.rake b/mrbgems/mruby-bin-mirb/mrbgem.rake index ffef67a39..4c9cdf29e 100644 --- a/mrbgems/mruby-bin-mirb/mrbgem.rake +++ b/mrbgems/mruby-bin-mirb/mrbgem.rake @@ -3,7 +3,12 @@ MRuby::Gem::Specification.new('mruby-bin-mirb') do |spec| spec.author = 'mruby developers' spec.summary = 'mirb command' - spec.linker.libraries << 'readline' if spec.cc.defines.include? "ENABLE_READLINE" + if spec.build.cc.search_header_path 'readline/readline.h' + spec.cc.defines << "ENABLE_READLINE" + spec.linker.libraries << 'readline' + elsif spec.build.cc.search_header_path 'linenoise.h' + spec.cc.defines << "ENABLE_LINENOISE" + end spec.bins = %w(mirb) end diff --git a/mrbgems/mruby-bin-mirb/tools/mirb/mirb.c b/mrbgems/mruby-bin-mirb/tools/mirb/mirb.c index 62f9e62fe..e7bc69495 100644 --- a/mrbgems/mruby-bin-mirb/tools/mirb/mirb.c +++ b/mrbgems/mruby-bin-mirb/tools/mirb/mirb.c @@ -22,7 +22,7 @@ #define MIRB_WRITE_HISTORY(path) write_history(path) #define MIRB_READ_HISTORY(path) read_history(path) #define MIRB_USING_HISTORY() using_history() -#elif ENABLE_LINENOISE +#elif defined(ENABLE_LINENOISE) #define ENABLE_READLINE #include #define MIRB_ADD_HISTORY(line) linenoiseHistoryAdd(line) -- cgit v1.2.3