1999-01-19 23:59:39 -05:00
|
|
|
# module to create Makefile for extension modules
|
1998-01-16 07:19:09 -05:00
|
|
|
# invoke like: ruby -r mkmf extconf.rb
|
|
|
|
|
|
|
|
require 'rbconfig'
|
1999-01-19 23:59:39 -05:00
|
|
|
require 'find'
|
1998-01-16 07:19:09 -05:00
|
|
|
|
1999-12-06 04:04:03 -05:00
|
|
|
CONFIG = Config::MAKEFILE_CONFIG
|
2000-12-21 22:22:25 -05:00
|
|
|
ORIG_LIBPATH = ENV['LIB']
|
1998-01-16 07:19:09 -05:00
|
|
|
|
1999-08-13 01:45:20 -04:00
|
|
|
SRC_EXT = ["c", "cc", "m", "cxx", "cpp", "C"]
|
|
|
|
|
1998-01-16 07:19:09 -05:00
|
|
|
$config_cache = CONFIG["compile_dir"]+"/ext/config.cache"
|
|
|
|
|
|
|
|
$srcdir = CONFIG["srcdir"]
|
1999-08-13 01:45:20 -04:00
|
|
|
$libdir = CONFIG["libdir"]+"/ruby/"+CONFIG["MAJOR"]+"."+CONFIG["MINOR"]
|
1998-01-16 07:19:09 -05:00
|
|
|
$archdir = $libdir+"/"+CONFIG["arch"]
|
2000-04-12 01:06:23 -04:00
|
|
|
$sitelibdir = CONFIG["sitedir"]+"/"+CONFIG["MAJOR"]+"."+CONFIG["MINOR"]
|
|
|
|
$sitearchdir = $sitelibdir+"/"+CONFIG["arch"]
|
1998-01-16 07:19:09 -05:00
|
|
|
|
|
|
|
if File.exist? $archdir + "/ruby.h"
|
|
|
|
$hdrdir = $archdir
|
|
|
|
elsif File.exist? $srcdir + "/ruby.h"
|
|
|
|
$hdrdir = $srcdir
|
|
|
|
else
|
|
|
|
STDERR.print "can't find header files for ruby.\n"
|
|
|
|
exit 1
|
|
|
|
end
|
1999-08-13 01:45:20 -04:00
|
|
|
$topdir = $hdrdir
|
2000-12-21 22:22:25 -05:00
|
|
|
# $hdrdir.gsub!('/', '\\') if RUBY_PLATFORM =~ /mswin32/
|
1998-01-16 07:19:09 -05:00
|
|
|
|
|
|
|
CFLAGS = CONFIG["CFLAGS"]
|
1999-08-13 01:45:20 -04:00
|
|
|
if RUBY_PLATFORM == "m68k-human"
|
1998-01-16 07:19:09 -05:00
|
|
|
CFLAGS.gsub!(/-c..-stack=[0-9]+ */, '')
|
2000-08-28 05:53:42 -04:00
|
|
|
elsif RUBY_PLATFORM =~ /-nextstep|-rhapsody|-darwin/
|
1999-08-13 01:45:20 -04:00
|
|
|
CFLAGS.gsub!( /-arch\s\w*/, '' )
|
1998-01-16 07:19:09 -05:00
|
|
|
end
|
2000-07-03 05:37:17 -04:00
|
|
|
|
|
|
|
if FileTest.readable? 'nul'
|
|
|
|
$null = open('nul', 'w')
|
|
|
|
elsif FileTest.readable? '/dev/null'
|
|
|
|
$null = open('/dev/null', 'w')
|
1999-01-19 23:59:39 -05:00
|
|
|
else
|
2000-07-03 05:37:17 -04:00
|
|
|
$null = open('test.log', 'w')
|
1999-01-19 23:59:39 -05:00
|
|
|
end
|
2000-07-03 05:37:17 -04:00
|
|
|
|
2001-01-09 02:32:00 -05:00
|
|
|
LINK = "#{CONFIG['CC']} -o conftest -I#{$hdrdir} #{CFLAGS} -I#{CONFIG['includedir']} %s %s #{CONFIG['LDFLAGS']} %s conftest.c %s %s #{CONFIG['LIBS']}"
|
2000-12-25 01:29:27 -05:00
|
|
|
CPP = "#{CONFIG['CPP']} -E %s -I#{$hdrdir} #{CFLAGS} -I#{CONFIG['includedir']} %s %s conftest.c"
|
1999-01-19 23:59:39 -05:00
|
|
|
|
2000-05-28 22:10:22 -04:00
|
|
|
def rm_f(*files)
|
|
|
|
targets = []
|
|
|
|
for file in files
|
|
|
|
targets.concat Dir[file]
|
|
|
|
end
|
|
|
|
if not targets.empty?
|
|
|
|
File::chmod 0777, *targets
|
|
|
|
File::unlink *targets
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
$orgerr = $stderr.dup
|
|
|
|
$orgout = $stdout.dup
|
|
|
|
def xsystem command
|
|
|
|
if $DEBUG
|
|
|
|
print command, "\n"
|
|
|
|
return system(command)
|
|
|
|
end
|
|
|
|
$stderr.reopen($null)
|
|
|
|
$stdout.reopen($null)
|
|
|
|
r = system(command)
|
|
|
|
$stderr.reopen($orgerr)
|
|
|
|
$stdout.reopen($orgout)
|
|
|
|
return r
|
1998-01-16 07:19:09 -05:00
|
|
|
end
|
|
|
|
|
1999-08-13 01:45:20 -04:00
|
|
|
def try_link0(src, opt="")
|
|
|
|
cfile = open("conftest.c", "w")
|
|
|
|
cfile.print src
|
|
|
|
cfile.close
|
2000-12-21 22:22:25 -05:00
|
|
|
ldflags = $LDFLAGS
|
|
|
|
if /mswin32/ =~ RUBY_PLATFORM and !$LIBPATH.empty?
|
|
|
|
ENV['LIB'] = ($LIBPATH + [ORIG_LIBPATH]).compact.join(';')
|
|
|
|
else
|
|
|
|
$LDFLAGS = ldflags.dup
|
|
|
|
$LIBPATH.each {|d| $LDFLAGS << " -L" + d}
|
|
|
|
end
|
|
|
|
begin
|
|
|
|
xsystem(format(LINK, $CFLAGS, $CPPFLAGS, $LDFLAGS, opt, $LOCAL_LIBS))
|
|
|
|
ensure
|
|
|
|
$LDFLAGS = ldflags
|
|
|
|
ENV['LIB'] = ORIG_LIBPATH if /mswin32/ =~ RUBY_PLATFORM
|
|
|
|
end
|
1998-01-16 07:19:09 -05:00
|
|
|
end
|
|
|
|
|
1999-08-13 01:45:20 -04:00
|
|
|
def try_link(src, opt="")
|
|
|
|
begin
|
|
|
|
try_link0(src, opt)
|
|
|
|
ensure
|
2000-05-28 22:10:22 -04:00
|
|
|
rm_f "conftest*"
|
1999-08-13 01:45:20 -04:00
|
|
|
end
|
1999-01-19 23:59:39 -05:00
|
|
|
end
|
|
|
|
|
1999-08-13 01:45:20 -04:00
|
|
|
def try_cpp(src, opt="")
|
|
|
|
cfile = open("conftest.c", "w")
|
|
|
|
cfile.print src
|
|
|
|
cfile.close
|
|
|
|
begin
|
2000-12-25 01:29:27 -05:00
|
|
|
xsystem(format(CPP, $CPPFLAGS, $CFLAGS, opt))
|
1999-08-13 01:45:20 -04:00
|
|
|
ensure
|
2000-05-28 22:10:22 -04:00
|
|
|
rm_f "conftest*"
|
1999-08-13 01:45:20 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def egrep_cpp(pat, src, opt="")
|
|
|
|
cfile = open("conftest.c", "w")
|
|
|
|
cfile.print src
|
|
|
|
cfile.close
|
|
|
|
begin
|
2000-12-25 01:29:27 -05:00
|
|
|
xsystem(format(CPP+"|egrep #{pat}", $CPPFLAGS, $CFLAGS, opt))
|
1999-08-13 01:45:20 -04:00
|
|
|
ensure
|
2000-05-28 22:10:22 -04:00
|
|
|
rm_f "conftest*"
|
1999-08-13 01:45:20 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def try_run(src, opt="")
|
|
|
|
begin
|
|
|
|
if try_link0(src, opt)
|
|
|
|
if xsystem("./conftest")
|
|
|
|
true
|
|
|
|
else
|
|
|
|
false
|
|
|
|
end
|
|
|
|
else
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
ensure
|
2000-05-28 22:10:22 -04:00
|
|
|
rm_f "conftest*"
|
1999-08-13 01:45:20 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2000-04-12 01:06:23 -04:00
|
|
|
def install_rb(mfile, dest, srcdir = nil)
|
1999-08-13 01:45:20 -04:00
|
|
|
libdir = "lib"
|
|
|
|
libdir = srcdir + "/" + libdir if srcdir
|
1999-01-19 23:59:39 -05:00
|
|
|
path = []
|
|
|
|
dir = []
|
2000-09-21 21:02:44 -04:00
|
|
|
if File.directory? libdir
|
|
|
|
Find.find(libdir) do |f|
|
|
|
|
next unless /\.rb$/ =~ f
|
|
|
|
f = f[libdir.length+1..-1]
|
|
|
|
path.push f
|
2000-12-05 06:07:49 -05:00
|
|
|
dir |= [File.dirname(f)]
|
2000-09-21 21:02:44 -04:00
|
|
|
end
|
1999-01-19 23:59:39 -05:00
|
|
|
end
|
|
|
|
for f in dir
|
|
|
|
next if f == "."
|
2000-04-12 01:06:23 -04:00
|
|
|
mfile.printf "\t@$(RUBY) -r ftools -e 'File::makedirs(*ARGV)' %s/%s\n", dest, f
|
1999-01-19 23:59:39 -05:00
|
|
|
end
|
|
|
|
for f in path
|
2001-03-10 11:03:56 -05:00
|
|
|
d = '/' + File::dirname(f)
|
|
|
|
d = '' if d == '/.'
|
|
|
|
mfile.printf "\t@$(RUBY) -r ftools -e 'File::install(ARGV[0], ARGV[1], 0644, true)' %s/%s %s%s\n", libdir, f, dest, d
|
1999-08-13 01:45:20 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def append_library(libs, lib)
|
|
|
|
if /mswin32/ =~ RUBY_PLATFORM
|
|
|
|
lib + ".lib " + libs
|
|
|
|
else
|
|
|
|
"-l" + lib + " " + libs
|
1999-01-19 23:59:39 -05:00
|
|
|
end
|
1998-01-16 07:19:09 -05:00
|
|
|
end
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
def have_library(lib, func="main")
|
1998-01-16 07:19:09 -05:00
|
|
|
printf "checking for %s() in -l%s... ", func, lib
|
|
|
|
STDOUT.flush
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
if func && func != ""
|
1999-08-13 01:45:20 -04:00
|
|
|
libs = append_library($libs, lib)
|
2000-05-13 12:13:31 -04:00
|
|
|
if /mswin32|mingw/ =~ RUBY_PLATFORM
|
1999-08-13 01:45:20 -04:00
|
|
|
r = try_link(<<"SRC", libs)
|
|
|
|
#include <windows.h>
|
|
|
|
#include <winsock.h>
|
1998-01-16 07:19:09 -05:00
|
|
|
int main() { return 0; }
|
2000-06-05 04:46:59 -04:00
|
|
|
int t() { #{func}(); return 0; }
|
|
|
|
SRC
|
|
|
|
unless r
|
|
|
|
r = try_link(<<"SRC", libs)
|
|
|
|
#include <windows.h>
|
|
|
|
#include <winsock.h>
|
|
|
|
int main() { return 0; }
|
1999-08-13 01:45:20 -04:00
|
|
|
int t() { void ((*p)()); p = (void ((*)()))#{func}; return 0; }
|
|
|
|
SRC
|
2000-06-05 04:46:59 -04:00
|
|
|
end
|
1998-01-16 07:19:09 -05:00
|
|
|
else
|
1999-08-13 01:45:20 -04:00
|
|
|
r = try_link(<<"SRC", libs)
|
|
|
|
int main() { return 0; }
|
|
|
|
int t() { #{func}(); return 0; }
|
|
|
|
SRC
|
|
|
|
end
|
|
|
|
unless r
|
|
|
|
print "no\n"
|
|
|
|
return false
|
1998-01-16 07:19:09 -05:00
|
|
|
end
|
1999-08-13 01:45:20 -04:00
|
|
|
else
|
|
|
|
libs = append_library($libs, lib)
|
1998-01-16 07:19:09 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
$libs = libs
|
1999-08-13 01:45:20 -04:00
|
|
|
print "yes\n"
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
def find_library(lib, func, *paths)
|
|
|
|
printf "checking for %s() in -l%s... ", func, lib
|
|
|
|
STDOUT.flush
|
|
|
|
|
2000-12-21 22:22:25 -05:00
|
|
|
libpath = $LIBPATH
|
1999-08-13 01:45:20 -04:00
|
|
|
libs = append_library($libs, lib)
|
|
|
|
until try_link(<<"SRC", libs)
|
|
|
|
int main() { return 0; }
|
|
|
|
int t() { #{func}(); return 0; }
|
|
|
|
SRC
|
|
|
|
if paths.size == 0
|
2000-12-21 22:22:25 -05:00
|
|
|
$LIBPATH = libpath
|
1999-08-13 01:45:20 -04:00
|
|
|
print "no\n"
|
|
|
|
return false
|
|
|
|
end
|
2000-12-21 22:22:25 -05:00
|
|
|
$LIBPATH = libpath | [paths.shift]
|
1999-08-13 01:45:20 -04:00
|
|
|
end
|
|
|
|
$libs = libs
|
1998-01-16 07:19:09 -05:00
|
|
|
print "yes\n"
|
1999-08-13 01:45:20 -04:00
|
|
|
return true
|
1998-01-16 07:19:09 -05:00
|
|
|
end
|
|
|
|
|
2000-06-22 04:29:58 -04:00
|
|
|
def have_func(func, header=nil)
|
1998-01-16 07:19:09 -05:00
|
|
|
printf "checking for %s()... ", func
|
|
|
|
STDOUT.flush
|
|
|
|
|
|
|
|
libs = $libs
|
2000-06-22 04:29:58 -04:00
|
|
|
src =
|
|
|
|
if /mswin32|mingw/ =~ RUBY_PLATFORM
|
|
|
|
r = <<"SRC"
|
1999-08-13 01:45:20 -04:00
|
|
|
#include <windows.h>
|
|
|
|
#include <winsock.h>
|
2000-06-22 04:29:58 -04:00
|
|
|
SRC
|
|
|
|
else
|
|
|
|
""
|
|
|
|
end
|
|
|
|
unless header.nil?
|
|
|
|
src << <<"SRC"
|
|
|
|
#include <#{header}>
|
|
|
|
SRC
|
|
|
|
end
|
|
|
|
r = try_link(src + <<"SRC", libs)
|
1999-08-13 01:45:20 -04:00
|
|
|
int main() { return 0; }
|
2000-06-05 04:46:59 -04:00
|
|
|
int t() { #{func}(); return 0; }
|
|
|
|
SRC
|
2000-06-22 04:29:58 -04:00
|
|
|
unless r
|
|
|
|
r = try_link(src + <<"SRC", libs)
|
2000-06-05 04:46:59 -04:00
|
|
|
int main() { return 0; }
|
1999-08-13 01:45:20 -04:00
|
|
|
int t() { void ((*p)()); p = (void ((*)()))#{func}; return 0; }
|
|
|
|
SRC
|
|
|
|
end
|
|
|
|
unless r
|
|
|
|
print "no\n"
|
|
|
|
return false
|
1998-01-16 07:19:09 -05:00
|
|
|
end
|
|
|
|
$defs.push(format("-DHAVE_%s", func.upcase))
|
|
|
|
print "yes\n"
|
1999-08-13 01:45:20 -04:00
|
|
|
return true
|
1998-01-16 07:19:09 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def have_header(header)
|
|
|
|
printf "checking for %s... ", header
|
|
|
|
STDOUT.flush
|
|
|
|
|
1999-08-13 01:45:20 -04:00
|
|
|
unless try_cpp(<<"SRC")
|
|
|
|
#include <#{header}>
|
|
|
|
SRC
|
|
|
|
print "no\n"
|
|
|
|
return false
|
1998-01-16 07:19:09 -05:00
|
|
|
end
|
2000-12-21 22:22:25 -05:00
|
|
|
header.tr!("a-z./\055", "A-Z___")
|
1998-01-16 07:19:09 -05:00
|
|
|
$defs.push(format("-DHAVE_%s", header))
|
|
|
|
print "yes\n"
|
1999-08-13 01:45:20 -04:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
def arg_config(config, default=nil)
|
|
|
|
unless defined? $configure_args
|
|
|
|
$configure_args = {}
|
|
|
|
for arg in CONFIG["configure_args"].split + ARGV
|
|
|
|
next unless /^--/ =~ arg
|
|
|
|
if /=/ =~ arg
|
|
|
|
$configure_args[$`] = $'
|
|
|
|
else
|
|
|
|
$configure_args[arg] = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
$configure_args.fetch(config, default)
|
|
|
|
end
|
|
|
|
|
|
|
|
def with_config(config, default=nil)
|
|
|
|
unless /^--with-/ =~ config
|
|
|
|
config = '--with-' + config
|
|
|
|
end
|
|
|
|
arg_config(config, default)
|
|
|
|
end
|
|
|
|
|
|
|
|
def enable_config(config, default=nil)
|
|
|
|
if arg_config("--enable-"+config, default)
|
|
|
|
true
|
|
|
|
elsif arg_config("--disable-"+config, false)
|
|
|
|
false
|
|
|
|
else
|
|
|
|
default
|
|
|
|
end
|
1998-01-16 07:19:09 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def create_header()
|
|
|
|
print "creating extconf.h\n"
|
|
|
|
STDOUT.flush
|
|
|
|
if $defs.length > 0
|
|
|
|
hfile = open("extconf.h", "w")
|
|
|
|
for line in $defs
|
|
|
|
line =~ /^-D(.*)/
|
|
|
|
hfile.printf "#define %s 1\n", $1
|
|
|
|
end
|
|
|
|
hfile.close
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2000-08-24 02:21:43 -04:00
|
|
|
def dir_config(target, idefault=nil, ldefault=nil)
|
|
|
|
if idefault && ldefault == nil
|
|
|
|
default = idefault
|
|
|
|
idefault = default + "/include"
|
|
|
|
ldefault = default + "/lib"
|
|
|
|
end
|
|
|
|
dir = with_config("%s-dir"%target, default)
|
1999-08-13 01:45:20 -04:00
|
|
|
if dir
|
|
|
|
idir = " -I"+dir+"/include"
|
2000-12-21 22:22:25 -05:00
|
|
|
ldir = dir+"/lib"
|
1999-08-13 01:45:20 -04:00
|
|
|
end
|
|
|
|
unless idir
|
2000-08-24 02:21:43 -04:00
|
|
|
dir = with_config("%s-include"%target, idefault)
|
1999-08-13 01:45:20 -04:00
|
|
|
idir = " -I"+dir if dir
|
|
|
|
end
|
|
|
|
unless ldir
|
2000-12-21 22:22:25 -05:00
|
|
|
ldir = with_config("%s-lib"%target, ldefault)
|
1999-08-13 01:45:20 -04:00
|
|
|
end
|
|
|
|
|
2000-12-21 22:22:25 -05:00
|
|
|
$CPPFLAGS += idir if idir
|
|
|
|
$LIBPATH |= [ldir] if ldir
|
1999-08-13 01:45:20 -04:00
|
|
|
end
|
|
|
|
|
2000-12-21 22:22:25 -05:00
|
|
|
def create_makefile(target, srcdir = File.dirname($0))
|
2001-03-12 05:20:01 -05:00
|
|
|
save_libs = $libs.dup
|
|
|
|
save_libpath = $LIBPATH.dup
|
1998-01-16 07:19:09 -05:00
|
|
|
print "creating Makefile\n"
|
2000-05-28 22:10:22 -04:00
|
|
|
rm_f "conftest*"
|
1998-01-16 07:19:09 -05:00
|
|
|
STDOUT.flush
|
2000-10-02 03:48:42 -04:00
|
|
|
if target.rindex(%r!/!) #/
|
2000-08-28 22:52:41 -04:00
|
|
|
target = $'
|
|
|
|
target_prefix = "/"+$`
|
|
|
|
else
|
|
|
|
target_prefix = ""
|
|
|
|
end
|
1999-08-13 01:45:20 -04:00
|
|
|
if CONFIG["DLEXT"] == $OBJEXT
|
1998-01-16 07:19:09 -05:00
|
|
|
libs = $libs.split
|
|
|
|
for lib in libs
|
|
|
|
lib.sub!(/-l(.*)/, '"lib\1.a"')
|
|
|
|
end
|
|
|
|
$defs.push(format("-DEXTLIB='%s'", libs.join(",")))
|
|
|
|
end
|
1999-01-19 23:59:39 -05:00
|
|
|
$DLDFLAGS = CONFIG["DLDFLAGS"]
|
|
|
|
|
2001-01-15 02:01:00 -05:00
|
|
|
$libs = CONFIG["LIBRUBYARG"] + " " + $libs
|
2001-03-13 00:45:13 -05:00
|
|
|
$configure_args['--enable-shared'] or $LIBPATH |= [$topdir]
|
2001-01-15 02:01:00 -05:00
|
|
|
$LIBPATH |= [CONFIG["libdir"]]
|
2000-05-09 00:53:16 -04:00
|
|
|
|
1999-08-13 01:45:20 -04:00
|
|
|
defflag = ''
|
2000-05-13 12:13:31 -04:00
|
|
|
if RUBY_PLATFORM =~ /cygwin|mingw/
|
2001-04-02 21:16:14 -04:00
|
|
|
if not File.exist? target + '.def'
|
|
|
|
open(target + '.def', 'wb') do |f|
|
|
|
|
f.print "EXPORTS\n", "Init_", target, "\n"
|
|
|
|
end
|
1999-08-13 01:45:20 -04:00
|
|
|
end
|
2000-07-05 10:12:27 -04:00
|
|
|
defflag = "--def=" + target + ".def"
|
1999-08-13 01:45:20 -04:00
|
|
|
end
|
|
|
|
|
2000-12-21 22:22:25 -05:00
|
|
|
if RUBY_PLATFORM =~ /mswin32/
|
|
|
|
libpath = $LIBPATH.join(';')
|
|
|
|
else
|
|
|
|
$LIBPATH.each {|d| $DLDFLAGS << " -L" << d}
|
|
|
|
end
|
|
|
|
drive = File::PATH_SEPARATOR == ';' ? /\A\w:/ : /\A/
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
unless $objs then
|
1999-08-13 01:45:20 -04:00
|
|
|
$objs = []
|
2000-12-21 22:22:25 -05:00
|
|
|
for f in Dir[File.join(srcdir || ".", "*.{#{SRC_EXT.join(%q{,})}}")]
|
1999-08-13 01:45:20 -04:00
|
|
|
f = File.basename(f)
|
|
|
|
f.sub!(/(#{SRC_EXT.join(%q{|})})$/, $OBJEXT)
|
|
|
|
$objs.push f
|
1998-01-16 07:19:09 -05:00
|
|
|
end
|
2000-07-17 05:38:10 -04:00
|
|
|
else
|
|
|
|
for i in $objs
|
|
|
|
i.sub!(/\.o\z/, ".#{$OBJEXT}")
|
|
|
|
end
|
1998-01-16 07:19:09 -05:00
|
|
|
end
|
|
|
|
$objs = $objs.join(" ")
|
|
|
|
|
|
|
|
mfile = open("Makefile", "w")
|
2000-05-14 05:36:29 -04:00
|
|
|
mfile.binmode if /mingw/ =~ RUBY_PLATFORM
|
1998-01-16 07:19:09 -05:00
|
|
|
mfile.print <<EOMF
|
|
|
|
SHELL = /bin/sh
|
|
|
|
|
|
|
|
#### Start of system configuration section. ####
|
|
|
|
|
2000-12-21 22:22:25 -05:00
|
|
|
srcdir = #{srcdir || $srcdir}
|
1999-08-13 01:45:20 -04:00
|
|
|
topdir = #{$topdir}
|
1998-01-16 07:19:09 -05:00
|
|
|
hdrdir = #{$hdrdir}
|
2000-12-21 22:22:25 -05:00
|
|
|
VPATH = $(srcdir)
|
1998-01-16 07:19:09 -05:00
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
CC = #{CONFIG["CC"]}
|
1998-01-16 07:19:09 -05:00
|
|
|
|
2000-08-03 05:50:41 -04:00
|
|
|
CFLAGS = #{CONFIG["CCDLFLAGS"]} #{CFLAGS} #{$CFLAGS}
|
2000-12-21 22:22:25 -05:00
|
|
|
CPPFLAGS = -I$(hdrdir) -I#{CONFIG["includedir"]} #{$defs.join(" ")} #{CONFIG["CPPFLAGS"]} #{$CPPFLAGS}
|
1999-01-19 23:59:39 -05:00
|
|
|
CXXFLAGS = $(CFLAGS)
|
|
|
|
DLDFLAGS = #{$DLDFLAGS} #{$LDFLAGS}
|
1999-08-13 01:45:20 -04:00
|
|
|
LDSHARED = #{CONFIG["LDSHARED"]} #{defflag}
|
2000-12-21 22:22:25 -05:00
|
|
|
LIBPATH = #{libpath}
|
1998-01-16 07:19:09 -05:00
|
|
|
|
2000-01-04 23:41:21 -05:00
|
|
|
RUBY_INSTALL_NAME = #{CONFIG["RUBY_INSTALL_NAME"]}
|
2000-08-03 05:50:41 -04:00
|
|
|
RUBY_SO_NAME = #{CONFIG["RUBY_SO_NAME"]}
|
2000-12-21 22:22:25 -05:00
|
|
|
#{
|
|
|
|
if destdir = CONFIG["prefix"].scan(drive)[0] and !destdir.empty?
|
|
|
|
"\nDESTDIR = " + destdir
|
|
|
|
else
|
|
|
|
""
|
|
|
|
end
|
|
|
|
}
|
|
|
|
prefix = $(DESTDIR)#{CONFIG["prefix"].sub(drive, '')}
|
|
|
|
exec_prefix = $(DESTDIR)#{CONFIG["exec_prefix"].sub(drive, '')}
|
|
|
|
libdir = $(DESTDIR)#{$libdir.sub(drive, '')}#{target_prefix}
|
|
|
|
archdir = $(DESTDIR)#{$archdir.sub(drive, '')}#{target_prefix}
|
|
|
|
sitelibdir = $(DESTDIR)#{$sitelibdir.sub(drive, '')}#{target_prefix}
|
|
|
|
sitearchdir = $(DESTDIR)#{$sitearchdir.sub(drive, '')}#{target_prefix}
|
1998-01-16 07:19:09 -05:00
|
|
|
|
|
|
|
#### End of system configuration section. ####
|
|
|
|
|
1999-08-13 01:45:20 -04:00
|
|
|
LOCAL_LIBS = #{$LOCAL_LIBS} #{$local_flags}
|
1998-01-16 07:19:09 -05:00
|
|
|
LIBS = #{$libs}
|
|
|
|
OBJS = #{$objs}
|
|
|
|
|
1999-08-13 01:45:20 -04:00
|
|
|
TARGET = #{target}
|
|
|
|
DLLIB = $(TARGET).#{CONFIG["DLEXT"]}
|
1998-01-16 07:19:09 -05:00
|
|
|
|
1999-08-13 01:45:20 -04:00
|
|
|
RUBY = #{CONFIG["ruby_install_name"]}
|
2000-07-04 12:27:19 -04:00
|
|
|
RM = $(RUBY) -r ftools -e 'File::rm_f(*Dir[ARGV.join(" ")])'
|
1998-01-16 07:19:09 -05:00
|
|
|
|
1999-08-13 01:45:20 -04:00
|
|
|
EXEEXT = #{CONFIG["EXEEXT"]}
|
1998-01-16 07:19:09 -05:00
|
|
|
|
1999-08-13 01:45:20 -04:00
|
|
|
all: $(DLLIB)
|
1998-01-16 07:19:09 -05:00
|
|
|
|
2000-05-28 22:10:22 -04:00
|
|
|
clean:; @$(RM) *.#{$OBJEXT} *.so *.sl *.a $(DLLIB)
|
2000-05-30 23:10:07 -04:00
|
|
|
@$(RM) $(TARGET).lib $(TARGET).exp $(TARGET).ilk *.pdb
|
2000-06-12 03:48:31 -04:00
|
|
|
|
|
|
|
distclean: clean
|
2000-05-28 22:10:22 -04:00
|
|
|
@$(RM) Makefile extconf.h conftest.*
|
|
|
|
@$(RM) core ruby$(EXEEXT) *~
|
1998-01-16 07:19:09 -05:00
|
|
|
|
2000-06-12 03:48:31 -04:00
|
|
|
realclean: distclean
|
1998-01-16 07:19:09 -05:00
|
|
|
|
1999-08-13 01:45:20 -04:00
|
|
|
install: $(archdir)/$(DLLIB)
|
1998-01-16 07:19:09 -05:00
|
|
|
|
2000-04-12 01:06:23 -04:00
|
|
|
site-install: $(sitearchdir)/$(DLLIB)
|
|
|
|
|
1999-08-13 01:45:20 -04:00
|
|
|
$(archdir)/$(DLLIB): $(DLLIB)
|
|
|
|
@$(RUBY) -r ftools -e 'File::makedirs(*ARGV)' $(libdir) $(archdir)
|
|
|
|
@$(RUBY) -r ftools -e 'File::install(ARGV[0], ARGV[1], 0555, true)' $(DLLIB) $(archdir)/$(DLLIB)
|
1998-01-16 07:19:09 -05:00
|
|
|
EOMF
|
2001-02-08 08:23:48 -05:00
|
|
|
install_rb(mfile, "$(libdir)", srcdir)
|
2000-04-12 01:06:23 -04:00
|
|
|
mfile.printf "\n"
|
|
|
|
|
|
|
|
mfile.printf <<EOMF
|
|
|
|
$(sitearchdir)/$(DLLIB): $(DLLIB)
|
|
|
|
@$(RUBY) -r ftools -e 'File::makedirs(*ARGV)' $(libdir) $(sitearchdir)
|
|
|
|
@$(RUBY) -r ftools -e 'File::install(ARGV[0], ARGV[1], 0555, true)' $(DLLIB) $(sitearchdir)/$(DLLIB)
|
|
|
|
EOMF
|
2001-02-08 08:23:48 -05:00
|
|
|
install_rb(mfile, "$(sitelibdir)", srcdir)
|
1998-01-16 07:19:09 -05:00
|
|
|
mfile.printf "\n"
|
|
|
|
|
2000-12-21 22:22:25 -05:00
|
|
|
if /mswin32/ !~ RUBY_PLATFORM
|
2000-08-03 05:50:41 -04:00
|
|
|
mfile.print "
|
2000-12-21 22:22:25 -05:00
|
|
|
.c.#{$OBJEXT}:
|
2000-08-03 05:50:41 -04:00
|
|
|
$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<
|
2001-03-28 05:35:40 -05:00
|
|
|
|
|
|
|
.cc.#{$OBJEXT}:
|
|
|
|
$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c -o $@ $<
|
|
|
|
.cpp.#{$OBJEXT}:
|
|
|
|
$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c -o $@ $<
|
|
|
|
.cxx.#{$OBJEXT}:
|
|
|
|
$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c -o $@ $<
|
|
|
|
.C.#{$OBJEXT}:
|
|
|
|
$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c -o $@ $<
|
2000-12-21 22:22:25 -05:00
|
|
|
"
|
|
|
|
elsif /nmake/i =~ $make
|
|
|
|
mfile.print "
|
|
|
|
{$(srcdir)}.c.#{$OBJEXT}:
|
|
|
|
$(CC) $(CFLAGS) -I$(<D) $(CPPFLAGS) -c $(<:/=\\)
|
|
|
|
.c.#{$OBJEXT}:
|
|
|
|
$(CC) $(CFLAGS) -I$(<D) $(CPPFLAGS) -c $(<:/=\\)
|
2001-03-28 09:47:44 -05:00
|
|
|
|
|
|
|
{$(srcdir)}.cc{}.#{$OBJEXT}:
|
|
|
|
$(CXX) -I. -I$(<D) $(CXXFLAGS) $(CPPFLAGS) -c $(<:/=\\)
|
|
|
|
.cc.#{$OBJEXT}:
|
|
|
|
$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $(<:/=\\)
|
|
|
|
{$(srcdir)}.cpp{}.#{$OBJEXT}:
|
|
|
|
$(CXX) -I. -I$(<D) $(CXXFLAGS) $(CPPFLAGS) -c $(<:/=\\)
|
|
|
|
.cpp.#{$OBJEXT}:
|
|
|
|
$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $(<:/=\\)
|
|
|
|
{$(srcdir)}.cxx{}.#{$OBJEXT}:
|
|
|
|
$(CXX) -I. -I$(<D) $(CXXFLAGS) $(CPPFLAGS) -c $(<:/=\\)
|
|
|
|
.cxx.#{$OBJEXT}:
|
|
|
|
$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $(<:/=\\)
|
2000-08-09 00:32:24 -04:00
|
|
|
"
|
|
|
|
else
|
|
|
|
mfile.print "
|
2000-12-21 22:22:25 -05:00
|
|
|
.SUFFIXES: .#{$OBJEXT}
|
|
|
|
|
2000-08-09 00:32:24 -04:00
|
|
|
.c.#{$OBJEXT}:
|
2000-12-21 22:22:25 -05:00
|
|
|
$(CC) $(CFLAGS) $(CPPFLAGS) -c $(subst /,\\\\,$<)
|
2001-03-28 09:47:44 -05:00
|
|
|
|
|
|
|
.cc.#{$OBJEXT} .cpp.#{$OBJEXT} .cxx.#{$OBJEXT} .C.#{$OBJEXT}:
|
|
|
|
$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $(subst /,\\\\,$<)
|
2000-08-03 05:50:41 -04:00
|
|
|
"
|
|
|
|
end
|
|
|
|
|
1999-08-13 01:45:20 -04:00
|
|
|
if CONFIG["DLEXT"] != $OBJEXT
|
2000-08-03 05:50:41 -04:00
|
|
|
mfile.print "$(DLLIB): $(OBJS)\n"
|
|
|
|
if /mswin32/ =~ RUBY_PLATFORM
|
2000-12-21 22:22:25 -05:00
|
|
|
if /nmake/i =~ $make
|
|
|
|
mfile.print "\tset LIB=$(LIBPATH:/=\\);$(LIB)\n"
|
|
|
|
else
|
|
|
|
mfile.print "\tenv LIB='$(subst /,\\\\,$(LIBPATH));$(LIB)' \\\n"
|
|
|
|
end
|
2000-08-03 05:50:41 -04:00
|
|
|
end
|
|
|
|
mfile.print "\t$(LDSHARED) $(DLDFLAGS) -o $(DLLIB) $(OBJS) $(LIBS) $(LOCAL_LIBS)\n"
|
1999-08-13 01:45:20 -04:00
|
|
|
elsif not File.exist?(target + ".c") and not File.exist?(target + ".cc")
|
|
|
|
mfile.print "$(DLLIB): $(OBJS)\n"
|
|
|
|
case RUBY_PLATFORM
|
1998-01-16 07:19:09 -05:00
|
|
|
when "m68k-human"
|
1999-08-13 01:45:20 -04:00
|
|
|
mfile.printf "ar cru $(DLLIB) $(OBJS)\n"
|
1998-01-16 07:19:09 -05:00
|
|
|
else
|
1999-08-13 01:45:20 -04:00
|
|
|
mfile.printf "ld $(DLDFLAGS) -r -o $(DLLIB) $(OBJS)\n"
|
1998-01-16 07:19:09 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if File.exist?("depend")
|
|
|
|
dfile = open("depend", "r")
|
|
|
|
mfile.printf "###\n"
|
|
|
|
while line = dfile.gets()
|
2000-07-17 05:38:10 -04:00
|
|
|
mfile.printf "%s", line.gsub(/\.o\b/, ".#{$OBJEXT}")
|
1998-01-16 07:19:09 -05:00
|
|
|
end
|
|
|
|
dfile.close
|
|
|
|
end
|
|
|
|
mfile.close
|
2001-03-12 05:20:01 -05:00
|
|
|
$libs = save_libs
|
|
|
|
$LIBPATH = save_libpath
|
1998-01-16 07:19:09 -05:00
|
|
|
end
|
|
|
|
|
1999-08-13 01:45:20 -04:00
|
|
|
$OBJEXT = CONFIG["OBJEXT"]
|
1998-01-16 07:19:09 -05:00
|
|
|
$objs = nil
|
2000-05-09 00:53:16 -04:00
|
|
|
$libs = CONFIG["DLDLIBS"]
|
1999-08-13 01:45:20 -04:00
|
|
|
$local_flags = ""
|
|
|
|
case RUBY_PLATFORM
|
|
|
|
when /mswin32/
|
2000-12-21 22:22:25 -05:00
|
|
|
$local_flags = "-link /INCREMENTAL:no /EXPORT:Init_$(TARGET)"
|
1999-08-13 01:45:20 -04:00
|
|
|
end
|
|
|
|
$LOCAL_LIBS = ""
|
1998-01-16 07:19:09 -05:00
|
|
|
$defs = []
|
1999-08-13 01:45:20 -04:00
|
|
|
|
2000-12-21 22:22:25 -05:00
|
|
|
$make = with_config("make-prog", ENV["MAKE"] || "make")
|
1999-08-13 01:45:20 -04:00
|
|
|
dir = with_config("opt-dir")
|
|
|
|
if dir
|
|
|
|
idir = "-I"+dir+"/include"
|
2000-12-21 22:22:25 -05:00
|
|
|
ldir = dir+"/lib"
|
1999-08-13 01:45:20 -04:00
|
|
|
end
|
|
|
|
unless idir
|
|
|
|
dir = with_config("opt-include")
|
|
|
|
idir = "-I"+dir if dir
|
|
|
|
end
|
|
|
|
unless ldir
|
2000-12-21 22:22:25 -05:00
|
|
|
ldir = with_config("opt-lib")
|
1999-08-13 01:45:20 -04:00
|
|
|
end
|
|
|
|
|
2000-12-21 22:22:25 -05:00
|
|
|
$CFLAGS = with_config("cflags", "")
|
|
|
|
$CPPFLAGS = [with_config("cppflags", ""), idir].compact.join(" ")
|
|
|
|
$LDFLAGS = with_config("ldflags", "")
|
|
|
|
$LIBPATH = [ldir].compact
|