summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2022-03-19 20:29:17 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2022-03-27 19:37:29 +0900
commit54a9ba9d10b4a87c2a2e98d64ed974531da9b546 (patch)
tree45a4a67bc465466f61bf56ba422b8fbedb9ed22b /ext
parent0d8b0aecc4079147e3afe30ece641a4a74e437d7 (diff)
downloadpsych-54a9ba9d10b4a87c2a2e98d64ed974531da9b546.tar.gz
Configure libyaml from the original source
Diffstat (limited to 'ext')
-rw-r--r--ext/psych/depend10
-rw-r--r--ext/psych/extconf.rb64
2 files changed, 43 insertions, 31 deletions
diff --git a/ext/psych/depend b/ext/psych/depend
index 10d643c..4a2ed3f 100644
--- a/ext/psych/depend
+++ b/ext/psych/depend
@@ -1,4 +1,12 @@
-$(OBJS): $(YAML_H)
+$(TARGET_SO): $(LIBYAML)
+
+libyaml $(LIBYAML):
+ cd libyaml && $(MAKE)
+clean-so::
+ -cd libyaml && $(MAKE) clean
+distclean-so::
+ -cd libyaml && $(MAKE) distclean
+ -$(Q)$(RMDIRS) libyaml/* libyaml
$(OBJS): $(HDRS) $(ruby_headers) \
$(hdrdir)/ruby/encoding.h \
diff --git a/ext/psych/extconf.rb b/ext/psych/extconf.rb
index 7da7376..05e3f4a 100644
--- a/ext/psych/extconf.rb
+++ b/ext/psych/extconf.rb
@@ -1,43 +1,47 @@
# -*- coding: us-ascii -*-
# frozen_string_literal: true
require 'mkmf'
-require 'fileutils'
-# :stopdoc:
-
-dir_config 'libyaml'
-
-if enable_config("bundled-libyaml", false) || !pkg_config('yaml-0.1') && !(find_header('yaml.h') && find_library('yaml', 'yaml_get_version'))
- # Embed libyaml since we could not find it.
-
- $VPATH << "$(srcdir)/yaml"
- $INCFLAGS << " -I$(srcdir)/yaml"
-
- $srcs = Dir.glob("#{$srcdir}/{,yaml/}*.c").map {|n| File.basename(n)}.sort
+if $mswin or $mingw or $cygwin
+ $CPPFLAGS << " -DYAML_DECLARE_STATIC"
+end
- header = 'yaml/yaml.h'
- header = "{$(VPATH)}#{header}" if $nmake
- if have_macro("_WIN32")
- $CPPFLAGS << " -DYAML_DECLARE_STATIC -DHAVE_CONFIG_H"
+yaml_source = with_config("libyaml-source-dir") || enable_config("bundled-libyaml", false)
+if yaml_source == true
+ yaml_source = Dir.glob("#{$srcdir}/yaml{,-*}/").max_by {|n| File.basename(n).scan(/\d+/).map(&:to_i)}
+elsif yaml_source
+ yaml_source = yaml_source.gsub(/\$\((\w+)\)|\$\{(\w+)\}/) {ENV[$1||$2]}
+end
+if yaml_source
+ yaml_configure = "#{File.expand_path(yaml_source)}/configure"
+ unless File.exist?(yaml_configure)
+ raise "Configure script not found in #{yaml_source.quote}"
end
- have_header 'dlfcn.h'
- have_header 'inttypes.h'
- have_header 'memory.h'
- have_header 'stdint.h'
- have_header 'stdlib.h'
- have_header 'strings.h'
- have_header 'string.h'
- have_header 'sys/stat.h'
- have_header 'sys/types.h'
- have_header 'unistd.h'
-
- find_header 'yaml.h'
- have_header 'config.h'
+ puts("Configuring libyaml source in #{yaml_source.quote}")
+ yaml = "libyaml"
+ Dir.mkdir(yaml) unless File.directory?(yaml)
+ unless system(yaml_configure, "-q",
+ "--enable-#{$enable_shared || !$static ? 'shared' : 'static'}",
+ chdir: yaml)
+ raise "failed to configure libyaml"
+ end
+ Logging.message("libyaml configured\n")
+ inc = yaml_source.start_with?("#$srcdir/") ? "$(srcdir)#{yaml_source[$srcdir.size..-1]}" : yaml_source
+ $INCFLAGS << " -I#{yaml}/include -I#{inc}/include"
+ Logging.message("INCLFAG=#$INCLFAG\n")
+ libyaml = "#{yaml}/src/.libs/libyaml.#$LIBEXT"
+ $LOCAL_LIBS.prepend("$(LIBYAML) ")
+else
+ pkg_config('yaml-0.1')
+ dir_config('libyaml')
+ unless find_header('yaml.h') && find_library('yaml', 'yaml_get_version')
+ raise "libyaml not found"
+ end
end
create_makefile 'psych' do |mk|
- mk << "YAML_H = #{header}".strip << "\n"
+ mk << "LIBYAML = #{libyaml}".strip << "\n"
end
# :startdoc: