Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Build oniguruma with daedalus.

  • Loading branch information...
commit a080a183c91bceb0b07cd4b4c45d115c060b8b88 1 parent 655ffb3
Brian Shirai brixen authored
2  Rakefile
View
@@ -33,7 +33,7 @@ end
require config_rb
BUILD_CONFIG = Rubinius::BUILD_CONFIG
-unless BUILD_CONFIG[:config_version] == 154
+unless BUILD_CONFIG[:config_version] == 155
STDERR.puts "Your configuration is outdated, please run ./configure first"
exit 1
end
49 configure
View
@@ -118,7 +118,7 @@ class Configure
@libversion = "2.0"
@version = "#{@libversion}.0dev"
@release_date = "yyyy-mm-dd"
- @config_version = 154
+ @config_version = 155
# TODO: add conditionals for platforms
if RbConfig::CONFIG["build_os"] =~ /darwin/
@@ -726,10 +726,17 @@ Unsupported language version requested: #{ver}. Options are #{@supported_version
end
def write_have_defines(f)
+ f.puts
+ @defines.each { |d| f.puts "#define #{d.ljust(20)} 1" }
+ end
+
+ def write_have_sizeof_defines(f)
+ f.puts
@sizeof.keys.sort.each { |k| f.puts "#define HAVE_#{k}".ljust(30) + "1" }
end
def write_sizeof_defines(f)
+ f.puts
@sizeof.keys.sort.each { |k| f.puts "#define SIZEOF_#{k}".ljust(30) + @sizeof[k].to_s }
end
@@ -975,6 +982,26 @@ int main() { return tgetnum(""); }
@defines << "HAVE_ALLOCA_H"
end
+ if has_header("string.h")
+ @defines << "HAVE_STRING_H"
+ end
+
+ if has_header("sys/time.h")
+ @defines << "HAVE_SYS_TIME_H"
+ end
+
+ if has_header("sys/times.h")
+ @defines << "HAVE_SYS_TIMES_H"
+ end
+
+ if has_header("sys/types.h")
+ @defines << "HAVE_SYS_TYPES_H"
+ end
+
+ if has_header("unistd.h")
+ @defines << "HAVE_UNISTD_H"
+ end
+
@vendor_zlib = true if @features["vendor-zlib"]
end
@@ -1208,14 +1235,25 @@ end
end
end
- @defines.each do |d|
- f.puts "#define #{d.ljust(20)} 1"
- end
+ write_have_defines f
end
FileUtils.cp vm_config_h, "vm/capi/18/include/rbx_config.h"
FileUtils.cp vm_config_h, "vm/capi/19/include/rbx_config.h"
+ # Write the config file for vendor/oniguruma.
+ File.open "vendor/oniguruma/config.h", "wb" do |f|
+ f.puts <<-EOC
+/* This file is generated by the Rubinius build system. Your edits
+ * will be lost. See the configure script.
+ */
+ EOC
+
+ write_have_defines f
+ write_have_sizeof_defines f
+ write_sizeof_defines f
+ end
+
# Write the config file used in the C-API.
config_h = "vm/capi/18/include/config.h"
File.open config_h, "wb" do |f|
@@ -1230,8 +1268,7 @@ end
EOC
- write_have_defines f
- f.puts
+ write_have_sizeof_defines f
write_sizeof_defines f
if @windows
230 projects/daedalus/daedalus.rb
View
@@ -148,6 +148,8 @@ def initialize(compiler, linker, logger, blueprint)
@log = logger
@blueprint = blueprint
+ set_ldshared
+
@mod_times = Hash.new do |h,k|
h[k] = (File.exists?(k) ? File.mtime(k) : Time.at(0))
end
@@ -168,6 +170,60 @@ def initialize(compiler, linker, logger, blueprint)
attr_accessor :mtime_only
+ def set_ldshared
+ # TODO: This should flow from the configure step.
+ #
+ # Extracted from rakelib/ext_helper.rb
+ # (Adapted from EventMachine. Thank you EventMachine and tmm1 !)
+ #
+ case RUBY_PLATFORM
+ when /mswin/, /mingw/, /bccwin32/
+ # TODO: discovery helpers
+ #check_heads(%w[windows.h winsock.h], true)
+ #check_libs(%w[kernel32 rpcrt4 gdi32], true)
+
+ if RUBY_PLATFORM =~ /mingw/
+ @ldshared = "#{@linker} -shared -lstdc++"
+ else
+ @cflags << "-EHs" << "-GR"
+ end
+
+ when /solaris/
+ @cflags << "-DOS_SOLARIS8" << "-fPIC"
+
+ if $CC == "cc" and `cc -flags 2>&1` =~ /Sun/ # detect SUNWspro compiler
+ # SUN CHAIN
+ @cflags << "-DCC_SUNWspro" << "-KPIC"
+ @ldshared = "#{@compiler} -G -KPIC -lCstd"
+ else
+ # GNU CHAIN
+ # on Unix we need a g++ link, not gcc.
+ @ldshared = "#{@linker} -shared -G -fPIC"
+ end
+
+ when /openbsd/
+ # OpenBSD branch contributed by Guillaume Sellier.
+
+ # on Unix we need a g++ link, not gcc. On OpenBSD, linking against
+ # libstdc++ have to be explicitly done for shared libs
+ @ldshared = "#{@linker} -shared -lstdc++ -fPIC"
+ @cflags << "-fPIC"
+
+ when /darwin/
+ # on Unix we need a g++ link, not gcc.
+ # Ff line contributed by Daniel Harple.
+ @ldshared = "#{@linker} -bundle -undefined suppress -flat_namespace -lstdc++"
+
+ when /aix/
+ @ldshared = "#{@linker} -shared -Wl,-G -Wl,-brtl"
+
+ else
+ # on Unix we need a g++ link, not gcc.
+ @ldshared = "#{@linker} -shared -lstdc++"
+ @cflags << "-fPIC"
+ end
+ end
+
def header_directories
dirs = []
@cflags.each do |fl|
@@ -207,7 +263,7 @@ def sha1(path)
end
def compile(source, object)
- @log.show "CC" , source
+ @log.show "CC", source
@log.command "#{@compiler} #{@cflags.join(' ')} -c -o #{object} #{source}"
end
@@ -216,6 +272,17 @@ def link(path, files)
@log.command "#{@linker} -o #{path} #{files.join(' ')} #{@libraries.join(' ')} #{@ldflags.join(' ')}"
end
+ def ar(library, objects)
+ @log.show "AR", library
+ @log.command "ar rv #{library} #{objects.join(' ')}"
+ @log.command "ranlib #{library}"
+ end
+
+ def ldshared(library, objects)
+ @log.show "LDSHARED", library
+ @log.command "#{@ldshared} #{objects.join(' ')} -o #{library}"
+ end
+
def calculate_deps(path)
dirs = header_directories() + ["/usr/include"]
flags = @cflags.join(' ')
@@ -332,7 +399,7 @@ def sha1(ctx)
end
rescue StandardError
recalc_depedencies(ctx)
-
+
sha1 = Digest::SHA1.new
sha1 << ctx.sha1(@path)
@@ -519,6 +586,161 @@ def describe(ctx)
end
end
+ class Library
+ attr_reader :sources
+
+ def initialize(path, base, compiler)
+ @base = base
+ @compiler = compiler
+
+ @directory = File.dirname path
+ @library = File.basename path
+ @sources = []
+
+ yield self if block_given?
+
+ source_files "#{path}.c" if @sources.empty?
+ end
+
+ def path
+ File.join @base, @directory, library
+ end
+
+ def name
+ File.join @directory, library
+ end
+
+ def source_files(*patterns)
+ Dir.chdir @base do
+ patterns.each do |t|
+ Dir[t].each do |f|
+ @sources << SourceFile.new(f)
+ end
+ end
+ end
+ end
+
+ def object_files
+ @sources.map { |s| s.object_path }
+ end
+
+ def out_of_date?(compiler)
+ Dir.chdir @base do
+ return true unless File.exists? name
+ @sources.each do |s|
+ return true if File.mtime(s.object_path) > File.mtime(name)
+ end
+ @sources.any? { |s| s.out_of_date? compiler }
+ end
+ end
+
+ def consider(compiler, tasks)
+ tasks.pre << self if out_of_date? compiler
+ end
+
+ def clean
+ Dir.chdir @base do
+ @sources.each { |s| s.clean }
+ File.delete name if File.exists? name
+ end
+ end
+ end
+
+ class StaticLibrary < Library
+ def library
+ "#{@library}.a"
+ end
+
+ def build(compiler)
+ Dir.chdir @base do
+ # TODO: out of date checking should be subsumed in building
+ @sources.each { |s| s.build @compiler if s.out_of_date? @compiler }
+ @compiler.ar name, object_files
+ end
+ end
+ end
+
+ class SharedLibrary < Library
+ def library
+ "#{@library}.#{RbConfig::CONFIG["DLEXT"]}"
+ end
+
+ def build(compiler)
+ Dir.chdir @base do
+ # TODO: out of date checking should be subsumed in building
+ @sources.each { |s| s.build @compiler if s.out_of_date? @compiler }
+ @compiler.ldshared name, object_files
+ end
+ end
+ end
+
+ # The purpose of a LibraryGroup is to combine multiple static and shared
+ # libraries into a unit. Static libraries are used to statically link a
+ # program, while shared libraries may be dynamically loaded by that program
+ # or another program.
+ #
+ # NOTE: The current protocol for getting a list of static libraries is the
+ # #objects method. This should be changed when reworking Daedalus.
+ class LibraryGroup
+ attr_accessor :cflags, :ldflags
+
+ def initialize(base, compiler)
+ @base = base
+ @static_libraries = []
+ @shared_libraries = []
+ @compiler = Compiler.new(ENV['CC'] || "gcc",
+ ENV['CXX'] || "g++",
+ compiler.log, nil)
+
+ yield self
+
+ compiler.add_library self
+
+ @compiler.cflags.concat cflags if cflags
+ @compiler.ldflags.concat ldflags if ldflags
+ end
+
+ def depends_on(file, command)
+ # TODO: HACK, the agony, this should be implicit
+ unless File.exists? File.join(@base, file)
+ raise "library group #{@base} depends on #{file}, please run #{command}"
+ end
+ end
+
+ # TODO: change the way files are sorted
+ def path
+ @base
+ end
+
+ def static_library(path, &block)
+ @static_libraries << StaticLibrary.new(path, @base, @compiler, &block)
+ end
+
+ def shared_library(path, &block)
+ @shared_libraries << SharedLibrary.new(path, @base, @compiler, &block)
+ end
+
+ # TODO: Fix this protocol
+ def objects
+ @static_libraries.map { |l| l.path }
+ end
+
+ def libraries
+ @static_libraries + @shared_libraries
+ end
+
+ def consider(compiler, tasks)
+ # TODO: Note we are using @compiler, not compiler. There should not be a
+ # global compiler. There should be a global configuration object that is
+ # specialized by specific libraries as needed.
+ libraries.each { |l| l.consider @compiler, tasks }
+ end
+
+ def clean
+ libraries.each { |l| l.clean }
+ end
+ end
+
class Program < Path
def initialize(path, files)
super path
@@ -733,6 +955,10 @@ def external_lib(path)
ex
end
+ def library_group(path, &block)
+ LibraryGroup.new(path, @compiler, &block)
+ end
+
def gcc!
@compiler = Compiler.new(ENV['CC'] || "gcc",
ENV['CXX'] || "g++",
38 rakelib/blueprint.rb
View
@@ -145,15 +145,36 @@
end
end
- oniguruma = i.external_lib "vendor/oniguruma" do |l|
- l.cflags = ["-Ivendor/oniguruma"]
- l.objects = [l.file("libonig.a")]
- l.to_build do |x|
- unless File.exists?("Makefile") and File.mtime("Makefile") > File.mtime("configure")
- x.command "sh -c ./configure"
- end
- x.command make
+ oniguruma = i.library_group "vendor/oniguruma" do |g|
+ g.depends_on "config.h", "configure"
+
+ gcc.cflags << "-Ivendor/oniguruma"
+ g.cflags = ["-DHAVE_CONFIG_H", "-I.", "-I../../vm/capi/19/include"]
+
+ g.static_library "libonig" do |l|
+ l.source_files "*.c", "enc/*.c"
end
+
+ g.shared_library "enc/trans/big5"
+ g.shared_library "enc/trans/chinese"
+ g.shared_library "enc/trans/emoji"
+ g.shared_library "enc/trans/emoji_iso2022_kddi"
+ g.shared_library "enc/trans/emoji_sjis_docomo"
+ g.shared_library "enc/trans/emoji_sjis_kddi"
+ g.shared_library "enc/trans/emoji_sjis_softbank"
+ g.shared_library "enc/trans/escape"
+ g.shared_library "enc/trans/gb18030"
+ g.shared_library "enc/trans/gbk"
+ g.shared_library "enc/trans/iso2022"
+ g.shared_library "enc/trans/japanese"
+ g.shared_library "enc/trans/japanese_euc"
+ g.shared_library "enc/trans/japanese_sjis"
+ g.shared_library "enc/trans/korean"
+ g.shared_library "enc/trans/newline"
+ g.shared_library "enc/trans/single_byte"
+ g.shared_library "enc/trans/transdb"
+ g.shared_library "enc/trans/utf8_mac"
+ g.shared_library "enc/trans/utf_16_32"
end
gdtoa = i.external_lib "vendor/libgdtoa" do |l|
@@ -206,7 +227,6 @@
gcc.add_library udis
gcc.add_library ffi
gcc.add_library gdtoa
- gcc.add_library oniguruma
gcc.add_library ltm
Rubinius::BUILD_CONFIG[:include_dirs].each do |path|
Please sign in to comment.
Something went wrong with that request. Please try again.