| 1 |
#!/usr/bin/ruby |
| 2 |
# frozen_string_literal: true |
| 3 |
require 'fileutils' |
| 4 |
|
| 5 |
basedir = File.dirname(__FILE__) |
| 6 |
conf = {} |
| 7 |
enable = {} |
| 8 |
until ARGV.empty? |
| 9 |
arg = ARGV.shift |
| 10 |
case arg |
| 11 |
when '-C' |
| 12 |
# ignore |
| 13 |
when /\A--srcdir=(.*)/ |
| 14 |
conf['SRCDIR'] = srcdir = $1 |
| 15 |
when /\A(CC|CFLAGS|CXX|CXXFLAGS|LD|LDFLAGS)=(.*)/ |
| 16 |
conf[$1] = $2 |
| 17 |
when /\A--host=(.*)/ |
| 18 |
host = $1 |
| 19 |
when /\A--enable-([^=]+)(?:=(.*))?/ |
| 20 |
enable[$1] = $2 || true |
| 21 |
when /\A--disable-([^=]+)/ |
| 22 |
enable[$1] = false |
| 23 |
end |
| 24 |
end |
| 25 |
|
| 26 |
File.foreach("#{srcdir}/configure.ac") do |line| |
| 27 |
if /^AC_INIT\((.*)\)/ =~ line |
| 28 |
version = $1.split(/,\s*/)[1] |
| 29 |
version.gsub!(/\A\[|\]\z/, '') |
| 30 |
conf['VERSION'] = version |
| 31 |
break |
| 32 |
end |
| 33 |
end |
| 34 |
|
| 35 |
builddir = srcdir == "." ? (enable['builddir'] || ".") : "." |
| 36 |
conf['TARGET'] = /^x64/ =~ host ? "X86_WIN64" : "X86_WIN32" |
| 37 |
|
| 38 |
FileUtils.mkdir_p([builddir, "#{builddir}/include", "#{builddir}/src/x86"]) |
| 39 |
FileUtils.cp("#{basedir}/fficonfig.h", ".", preserve: true) |
| 40 |
|
| 41 |
hdr = File.binread("#{srcdir}/include/ffi.h.in") |
| 42 |
hdr.gsub!(/@(\w+)@/) {conf[$1] || $&} |
| 43 |
hdr.gsub!(/^(#if\s+)@\w+@/, '\10') |
| 44 |
File.binwrite("#{builddir}/include/ffi.h", hdr) |
| 45 |
|
| 46 |
mk = File.binread("#{basedir}/libffi.mk.tmpl") |
| 47 |
mk.gsub!(/@(\w+)@/) {conf[$1] || $&} |
| 48 |
File.binwrite("Makefile", mk) |