Skip to content

Commit

Permalink
Build oniguruma with daedalus.
Browse files Browse the repository at this point in the history
  • Loading branch information
brixen committed Feb 16, 2012
1 parent 655ffb3 commit a080a18
Show file tree
Hide file tree
Showing 4 changed files with 301 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Rakefile
Expand Up @@ -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
Expand Down
49 changes: 43 additions & 6 deletions configure
Expand Up @@ -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/
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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|
Expand All @@ -1230,8 +1268,7 @@ end
EOC

write_have_defines f
f.puts
write_have_sizeof_defines f
write_sizeof_defines f

if @windows
Expand Down
230 changes: 228 additions & 2 deletions projects/daedalus/daedalus.rb
Expand Up @@ -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
Expand All @@ -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|
Expand Down Expand Up @@ -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

Expand All @@ -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(' ')
Expand Down Expand Up @@ -332,7 +399,7 @@ def sha1(ctx)
end
rescue StandardError
recalc_depedencies(ctx)

sha1 = Digest::SHA1.new
sha1 << ctx.sha1(@path)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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++",
Expand Down

0 comments on commit a080a18

Please sign in to comment.