2012-11-28 07:22:47 -05:00
|
|
|
# -*- coding: us-ascii -*-
|
2017-07-14 02:15:58 -04:00
|
|
|
# frozen_string_literal: true
|
2010-03-28 17:49:37 -04:00
|
|
|
require 'mkmf'
|
|
|
|
|
2022-03-29 04:45:33 -04:00
|
|
|
if $mswin or $mingw or $cygwin
|
|
|
|
$CPPFLAGS << " -DYAML_DECLARE_STATIC"
|
|
|
|
end
|
2012-11-27 23:34:41 -05:00
|
|
|
|
2022-03-29 04:45:33 -04:00
|
|
|
yaml_source = with_config("libyaml-source-dir") || enable_config("bundled-libyaml", false)
|
2022-03-29 05:42:00 -04:00
|
|
|
unless yaml_source # default to pre-installed libyaml
|
|
|
|
pkg_config('yaml-0.1')
|
|
|
|
dir_config('libyaml')
|
|
|
|
unless find_header('yaml.h') && find_library('yaml', 'yaml_get_version')
|
|
|
|
yaml_source = true # fallback to the bundled source if exists
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-03-29 04:45:33 -04:00
|
|
|
if yaml_source == true
|
2022-03-29 05:42:00 -04:00
|
|
|
# search the latest libyaml source under $srcdir
|
2022-03-29 04:45:33 -04:00
|
|
|
yaml_source = Dir.glob("#{$srcdir}/yaml{,-*}/").max_by {|n| File.basename(n).scan(/\d+/).map(&:to_i)}
|
|
|
|
unless yaml_source
|
2022-04-04 14:10:29 -04:00
|
|
|
download_failure = "failed to download libyaml source"
|
|
|
|
begin
|
|
|
|
require_relative '../../tool/extlibs.rb'
|
|
|
|
extlibs = ExtLibs.new(cache_dir: File.expand_path("../../tmp/download_cache", $srcdir))
|
|
|
|
unless extlibs.process_under($srcdir)
|
|
|
|
raise download_failure
|
|
|
|
end
|
|
|
|
rescue
|
|
|
|
# Implicitly captures Exception#cause. Newer rubies show it in the backtrace.
|
|
|
|
raise download_failure
|
2022-03-29 04:45:33 -04:00
|
|
|
end
|
|
|
|
yaml_source, = Dir.glob("#{$srcdir}/yaml-*/")
|
2022-03-29 05:42:00 -04:00
|
|
|
raise "libyaml not found" unless yaml_source
|
2022-03-25 04:33:30 -04:00
|
|
|
end
|
2022-03-29 04:45:33 -04:00
|
|
|
elsif yaml_source
|
|
|
|
yaml_source = yaml_source.gsub(/\$\((\w+)\)|\$\{(\w+)\}/) {ENV[$1||$2]}
|
|
|
|
end
|
|
|
|
if yaml_source
|
2022-03-31 11:45:31 -04:00
|
|
|
yaml_source = yaml_source.chomp("/")
|
2022-03-29 04:45:33 -04:00
|
|
|
yaml_configure = "#{File.expand_path(yaml_source)}/configure"
|
|
|
|
unless File.exist?(yaml_configure)
|
|
|
|
raise "Configure script not found in #{yaml_source.quote}"
|
2012-11-27 23:34:41 -05:00
|
|
|
end
|
|
|
|
|
2022-03-29 04:45:33 -04:00
|
|
|
puts("Configuring libyaml source in #{yaml_source.quote}")
|
|
|
|
yaml = "libyaml"
|
|
|
|
Dir.mkdir(yaml) unless File.directory?(yaml)
|
2022-03-31 06:29:24 -04:00
|
|
|
shared = $enable_shared || !$static
|
2022-03-31 11:45:31 -04:00
|
|
|
args = [
|
|
|
|
yaml_configure,
|
|
|
|
"--enable-#{shared ? 'shared' : 'static'}",
|
|
|
|
"--host=#{RbConfig::CONFIG['host'].sub(/-unknown-/, '-')}",
|
2022-03-31 23:38:47 -04:00
|
|
|
"CC=#{RbConfig::CONFIG['CC']}",
|
2022-03-31 11:45:31 -04:00
|
|
|
*(["CFLAGS=-w"] if RbConfig::CONFIG["GCC"] == "yes"),
|
|
|
|
]
|
|
|
|
puts(args.quote.join(' '))
|
|
|
|
unless system(*args, chdir: yaml)
|
2022-03-29 04:45:33 -04:00
|
|
|
raise "failed to configure libyaml"
|
|
|
|
end
|
|
|
|
inc = yaml_source.start_with?("#$srcdir/") ? "$(srcdir)#{yaml_source[$srcdir.size..-1]}" : yaml_source
|
|
|
|
$INCFLAGS << " -I#{yaml}/include -I#{inc}/include"
|
2022-03-31 11:45:31 -04:00
|
|
|
puts("INCFLAGS=#$INCFLAGS")
|
2022-03-31 06:29:24 -04:00
|
|
|
libyaml = "libyaml.#$LIBEXT"
|
|
|
|
$cleanfiles << libyaml
|
2022-03-29 04:45:33 -04:00
|
|
|
$LOCAL_LIBS.prepend("$(LIBYAML) ")
|
2012-11-27 23:34:41 -05:00
|
|
|
end
|
2010-03-28 17:49:37 -04:00
|
|
|
|
2019-11-28 20:16:33 -05:00
|
|
|
create_makefile 'psych' do |mk|
|
2022-03-29 04:45:33 -04:00
|
|
|
mk << "LIBYAML = #{libyaml}".strip << "\n"
|
2022-03-31 06:29:24 -04:00
|
|
|
mk << "LIBYAML_OBJDIR = libyaml/src#{shared ? '/.libs' : ''}\n"
|
|
|
|
mk << "OBJEXT = #$OBJEXT"
|
|
|
|
mk << "RANLIB = #{config_string('RANLIB') || config_string('NULLCMD')}\n"
|
2019-11-28 20:16:33 -05:00
|
|
|
end
|
2010-03-28 17:49:37 -04:00
|
|
|
|
|
|
|
# :startdoc:
|