2010-04-29 05:57:11 +08:00
|
|
|
#
|
2010-04-29 06:08:39 +08:00
|
|
|
# Copyright (c) 2007, 2009 Hyperic, Inc.
|
|
|
|
# Copyright (c) 2009 SpringSource, Inc.
|
|
|
|
# Copyright (c) 2010 VMware, Inc.
|
2010-04-29 05:57:11 +08:00
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
#
|
|
|
|
|
2007-09-03 08:49:22 +08:00
|
|
|
require 'mkmf'
|
2009-07-19 06:58:59 +08:00
|
|
|
require 'rbconfig'
|
2007-09-03 08:49:22 +08:00
|
|
|
|
2010-01-18 10:26:31 +08:00
|
|
|
extension_name = 'sigar'
|
2007-09-03 08:49:22 +08:00
|
|
|
|
2009-02-16 07:21:59 +08:00
|
|
|
print 'Ruby platform=' + RUBY_PLATFORM + "\n"
|
2007-09-03 08:49:22 +08:00
|
|
|
|
2009-02-16 07:21:59 +08:00
|
|
|
case RUBY_PLATFORM
|
|
|
|
when /darwin/
|
|
|
|
os = 'darwin'
|
|
|
|
sdks = Dir.glob('/Developer/SDKs/MacOSX10.*.sdk').sort.reverse
|
|
|
|
if sdks.length == 0
|
|
|
|
print "Xcode Developer Tools not installed\n"
|
|
|
|
print "Download from http://developer.apple.com/technology/xcode.html\n"
|
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
print "Available SDKs...\n(*) " + sdks.join("\n ") + "\n"
|
|
|
|
sdk = sdks[0]
|
|
|
|
end
|
|
|
|
if File.file?("/usr/include/libproc.h")
|
|
|
|
$CPPFLAGS += ' -DDARWIN_HAS_LIBPROC_H'
|
|
|
|
end
|
|
|
|
$CPPFLAGS += ' -DDARWIN -I/Developer/Headers/FlatCarbon -isysroot ' + sdk
|
|
|
|
$LDFLAGS += ' -Wl,-syslibroot,' + sdk + ' -framework CoreServices -framework IOKit'
|
|
|
|
when /bsd/
|
|
|
|
os = 'darwin'
|
|
|
|
have_library("kvm")
|
2009-02-17 05:50:25 +08:00
|
|
|
when /mswin|mingw|cygwin|bccwin/
|
2009-02-16 07:21:59 +08:00
|
|
|
os = 'win32'
|
2009-02-16 12:15:22 +08:00
|
|
|
require 'ftools'
|
2009-02-16 07:21:59 +08:00
|
|
|
$CPPFLAGS += ' -DWIN32'
|
|
|
|
is_win32 = true
|
|
|
|
have_library("kernel32")
|
|
|
|
have_library("user32")
|
|
|
|
have_library("advapi32")
|
|
|
|
have_library("ws2_32")
|
|
|
|
have_library("netapi32")
|
|
|
|
have_library("shell32")
|
|
|
|
have_library("pdh")
|
|
|
|
have_library("version")
|
|
|
|
when /linux/
|
|
|
|
os = 'linux'
|
|
|
|
when /solaris|sun/
|
|
|
|
os = 'solaris'
|
|
|
|
have_library("nsl")
|
|
|
|
have_library("socket")
|
|
|
|
have_library("kstat")
|
|
|
|
when /hpux/
|
|
|
|
os = 'hpux'
|
2009-02-16 11:55:57 +08:00
|
|
|
#XXX have_libary no workie on hpux?
|
|
|
|
$LDFLAGS += ' -lnsl -lnm'
|
2009-02-16 07:21:59 +08:00
|
|
|
when /aix/
|
|
|
|
os = 'aix'
|
2009-02-16 08:08:15 +08:00
|
|
|
have_library("odm")
|
|
|
|
have_library("cfg")
|
|
|
|
have_library("perfstat")
|
2009-02-16 07:21:59 +08:00
|
|
|
else
|
|
|
|
os = RUBY_PLATFORM
|
|
|
|
end
|
2007-09-03 08:49:22 +08:00
|
|
|
|
2009-02-16 07:21:59 +08:00
|
|
|
osdir = "../../src/os/#{os}"
|
|
|
|
$CPPFLAGS += ' -I../../include' + ' -I' + osdir
|
|
|
|
$CPPFLAGS += ' -U_FILE_OFFSET_BITS' unless is_win32
|
2007-09-03 08:49:22 +08:00
|
|
|
|
2009-03-26 11:10:19 +08:00
|
|
|
if RUBY_VERSION > '1.8.4'
|
|
|
|
$CPPFLAGS += ' -DRB_HAS_RE_ERROR'
|
|
|
|
end
|
|
|
|
if RUBY_VERSION >= '1.9.0'
|
|
|
|
$CPPFLAGS += ' -DRB_RUBY_19'
|
|
|
|
end
|
|
|
|
|
2009-02-17 09:53:10 +08:00
|
|
|
#incase of nfs shared dir...
|
|
|
|
unless is_win32
|
|
|
|
if File.exist?('Makefile')
|
|
|
|
cmd = 'make distclean'
|
|
|
|
print cmd + "\n"
|
|
|
|
system(cmd)
|
|
|
|
end
|
|
|
|
Dir["./*.c"].each do |file|
|
|
|
|
if File.lstat(file).symlink?
|
|
|
|
print "unlink #{file}\n"
|
|
|
|
File.delete(file)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-05-28 23:23:32 +08:00
|
|
|
$distcleanfiles = ['rbsigar_generated.rx','sigar_version.c']
|
|
|
|
|
2007-09-03 08:49:22 +08:00
|
|
|
system('perl -Mlib=.. -MSigarWrapper -e generate Ruby .')
|
2009-07-19 06:58:59 +08:00
|
|
|
libname = extension_name + '.' + CONFIG['DLEXT']
|
2010-05-28 23:23:32 +08:00
|
|
|
filters =
|
|
|
|
'ARCHNAME=' + RUBY_PLATFORM + ' ' +
|
|
|
|
'ARCHLIB=' + libname + ' ' +
|
|
|
|
'BINNAME=' + libname
|
|
|
|
|
|
|
|
system('perl -Mlib=.. -MSigarBuild -e version_file ' + filters)
|
|
|
|
|
|
|
|
if is_win32
|
|
|
|
system('perl -Mlib=.. -MSigarBuild -e resource_file ' + filters)
|
|
|
|
system('rc /r sigar.rc')
|
|
|
|
$LDFLAGS += ' sigar.res'
|
|
|
|
$distcleanfiles << ['sigar.rc', 'sigar.res']
|
2010-05-28 23:59:09 +08:00
|
|
|
#do not want dynamic runtime else "MSVCR80.dll was not found"
|
|
|
|
$CFLAGS = $CFLAGS.gsub('-MD', '')
|
2010-05-28 23:23:32 +08:00
|
|
|
end
|
2007-09-03 08:49:22 +08:00
|
|
|
|
2009-02-16 07:21:59 +08:00
|
|
|
#XXX seems mkmf forces basename on srcs
|
|
|
|
#XXX should be linking against libsigar anyhow
|
2009-08-06 08:22:08 +08:00
|
|
|
(Dir["../../src/*.c"] + Dir["#{osdir}/*.c"] + Dir["#{osdir}/*.cpp"]).each do |file|
|
2009-02-16 07:21:59 +08:00
|
|
|
cf = File.basename(file)
|
|
|
|
print file + ' -> ' + cf + "\n"
|
|
|
|
if is_win32
|
|
|
|
File.copy(file, cf)
|
|
|
|
else
|
|
|
|
File.symlink(file, cf) unless File.file?(cf)
|
|
|
|
end
|
|
|
|
$distcleanfiles.push(cf)
|
|
|
|
end
|
|
|
|
|
|
|
|
dir_config(extension_name)
|
|
|
|
|
2007-09-03 08:49:22 +08:00
|
|
|
create_makefile(extension_name)
|