# # mkmf-gnome2.rb # # Extended mkmf for Ruby-GNOME2 and Ruby/GLib based libraries. # # Copyright(C) 2003-2005 Ruby-GNOME2 Project. # # This program is licenced under the same # license of Ruby-GNOME2. # require 'mkmf' require 'pkg-config' require 'glib-mkenums' unless defined?(macro_defined?) def macro_defined?(macro, src, opt="") try_cpp(src + <\n") STDOUT.print "yes\n" $G_PLATFORM_WIN32 = true else STDOUT.print "no\n" end if $G_PLATFORM_WIN32 STDOUT.print("checking for G_OS_WIN32... ") STDOUT.flush if macro_defined?('G_OS_WIN32', "#include \n") STDOUT.print "yes\n" $G_OS_WIN32 = true if $cc_is_gcc if /^2\./ =~ `#{Config::CONFIG['CC']} -dumpversion`.chomp $CFLAGS += ' -fnative-struct' else $CFLAGS += ' -mms-bitfields' end end else STDOUT.print "no\n" end # STDOUT.print("checking for G_WITH_CYGWIN... ") # STDOUT.flush # if macro_defined?('G_WITH_CYGWIN', "#include \n") # STDOUT.print "yes\n" # $G_WITH_CYGWIN = true # else # STDOUT.print "no\n" # end end nil end def set_output_lib(target_name) if /cygwin|mingw/ =~ RUBY_PLATFORM filename = "libruby-#{target_name}.a" if RUBY_VERSION > "1.8.0" $DLDFLAGS << ",--out-implib=#{filename}" if filename elsif RUBY_VERSION > "1.8" $DLDFLAGS.gsub!(/ -Wl,--out-implib=[^ ]+/, '') $DLDFLAGS << " -Wl,--out-implib=#{filename}" if filename else $DLDFLAGS.gsub!(/ --output-lib\s+[^ ]+/, '') $DLDFLAGS << " --output-lib #{filename}" if filename end elsif /mswin32/ =~ RUBY_PLATFORM filename = "libruby-#{target_name}.lib" $DLDFLAGS.gsub!(/ --output-lib\s+[^ ]+/, '') $DLDFLAGS.gsub!(/ \/IMPLIB:[^ ]+/, '') $DLDFLAGS << " /IMPLIB:#{filename}" if filename end end def setup_win32(target_name) check_win32 set_output_lib(target_name) end #add_depend_package("glib2", "glib/src", "/...../ruby-gnome2") def add_depend_package(target_name, target_srcdir, top_srcdir) [top_srcdir, $configure_args['--topdir']].each do |topdir| topdir = File.expand_path(topdir) if RUBY_VERSION < "1.8.5" $CFLAGS = "-I#{File.join(topdir, target_srcdir)} #{$CFLAGS}" else $INCFLAGS = "-I#{File.join(topdir, target_srcdir)} #{$INCFLAGS}" end if /cygwin|mingw/ =~ RUBY_PLATFORM $libs << " -lruby-#{target_name}" $LDFLAGS << " -L#{topdir}/#{target_srcdir}" elsif /mswin32/ =~ RUBY_PLATFORM $DLDFLAGS << " /libpath:#{topdir}/#{target_srcdir}" $libs << " libruby-#{target_name}.lib" end end end def add_distcleanfile(file) $distcleanfiles ||= [] $distcleanfiles << file end def create_makefile_at_srcdir(pkg_name, srcdir, defs = nil) base_dir = File.basename(Dir.pwd) builddir = srcdir[(srcdir.rindex(base_dir) + base_dir.size + 1)..-1] builddir ||= "." FileUtils.mkdir_p(builddir) Dir.chdir(builddir) do yield if block_given? $defs << defs if defs pattern = "*.{#{SRC_EXT.join(',')}}" srcs = Dir[File.join(srcdir, pattern)] srcs |= Dir[File.join(".", pattern)] $objs = srcs.collect do |src| File.basename(src, ".*") + ".o" end.flatten.uniq create_makefile(pkg_name, srcdir) end end def create_top_makefile(sub_dirs = ["src"]) mfile = File.open("Makefile", "w") if /mswin32/ =~ RUBY_PLATFORM mfile.print < (major) || \\ (#{app_name}_MAJOR_VERSION == (major) && #{app_name}_MINOR_VERSION > (minor)) || \\ (#{app_name}_MAJOR_VERSION == (major) && #{app_name}_MINOR_VERSION == (minor) && \\ #{app_name}_MICRO_VERSION >= (micro))) #endif /* __RB#{app_name}_VERSION_H__ */ ] out.close end def check_ruby_func $CPPFLAGS << " -I$(sitearchdir) " #Other options have_func("rb_define_alloc_func") # for ruby-1.8 have_func("rb_block_proc") # for ruby-1.8 STDOUT.print("checking for new allocation framework... ") # for ruby-1.7 if Object.respond_to? :allocate STDOUT.print "yes\n" $defs << "-DHAVE_OBJECT_ALLOCATE" else STDOUT.print "no\n" end STDOUT.print("checking for attribute assignment... ") # for ruby-1.7 STDOUT.flush if defined? try_compile and try_compile <