blob: b82e7339b68ab6f7b9fbf3dcd350e3a950def10e [file] [log] [blame]
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You 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.
require 'rake/clean'
require 'rake/extensiontask'
import '../../runtime/ruby/Rakefile.common'
def exe_path(*args)
File.join(args).ext(RbConfig::CONFIG["EXEEXT"])
end
BASE_PATH = '..'
CFC_DIR = File.join( BASE_PATH, '..', 'compiler', 'ruby' );
CFC_BUILD = File.join( CFC_DIR, 'Build' );
COMMON_SOURCE_DIR = File.join(BASE_PATH, "common")
CHARMONIZER_C = File.join(COMMON_SOURCE_DIR, 'charmonizer.c')
CHARMONIZER_EXE_PATH = File.absolute_path(exe_path('charmonizer'))
CHARMONIZER_ORIG_DIR = File.absolute_path( File.join( BASE_PATH, '..', '..', 'charmonizer' ) )
CHARMONY_H_PATH = 'charmony.h'
CHARMONY_RB_PATH = 'Charmony.rb'
CORE_SOURCE_DIR = File.absolute_path( BASE_PATH, 'core' );
LIB_DIR = 'lib';
Rake::ExtensionTask.new do |ext|
ext.name = 'Bind'
ext.ext_dir = './ext'
ext.lib_dir = './lib'
ext.tmp_dir = './tmp'
ext.source_pattern = "*.c"
ext.config_options << '-std=gnu99 -D_GNU_SOURCE -fvsibility=hidden'
end
desc "Build Clownfish"
task :build_clownfish => [:charmony] do
puts "Building Clownfish"
old_dir = Dir.pwd
chdir(CFC_DIR);
if ( File.exists?('Rakefile') )
puts "\nBuilding Clownfish compiler... "
if system("rake").nil?
abort "Couldn't build rake"
end
puts "\nFinished building Clownfish compiler.\n"
end
chdir(old_dir);
require_relative '../../compiler/ruby/ext/Clownfish/CFC'
hierarchy = Clownfish::CFC::Model::Hierarchy.new(:dest => "autogen")
hierarchy.add_source_dir('../core')
hierarchy.add_source_dir('ext')
hierarchy.add_source_dir('autogen/source')
hierarchy.build
core_binding = Clownfish::CFC::Binding::Core.new(:hierarchy => hierarchy, :header => autogen_header, :footer => '')
modified = core_binding.write_all_modified
ruby_binding = Clownfish::CFC::Binding::Ruby.new(
:parcel => "Clownfish",
:hierarchy => hierarchy,
:lib_dir => LIB_DIR,
:boot_class => "Clownfish",
:header => autogen_header,
:footer => ''
)
if (modified)
puts "Building Binding Code"
ruby_binding.write_boot
ruby_binding.write_hostdefs
end
Rake::Task['compile'].invoke
end
desc "Build and run charmonizer, creating charmony.h and charmony.rb"
task :charmony do
# Compile charmonizer executable.
if !uptodate? CHARMONIZER_EXE_PATH, [CHARMONIZER_C]
outflag = cc_command.match(/cl\b/) ? "/Fe" : "-o "
command = "#{cc_command} #{outflag}#{CHARMONIZER_EXE_PATH} #{CHARMONIZER_C}"
puts command
if !system(command)
raise "Failed to compile #{CHARMONIZER_EXE_PATH}"
end
end
# Return if charmonizer output is current.
if uptodate? CHARMONY_RB_PATH, [CHARMONIZER_EXE_PATH]
next
end
puts "Running #{CHARMONIZER_EXE_PATH}...\n"
# Prepare arguments to charmonizer.
command = [
CHARMONIZER_EXE_PATH,
'--cc=' + cc_command,
'--enable-c',
'--enable-ruby',
'--',
all_ccflags,
]
if (ENV['CHARM_VALGRIND'])
command.unshift("valgrind", "--leak-check=yes")
end
# Run charmonizer.
puts command.join(" ")
if !system(*command)
raise "Failed to run #{CHARMONIZER_EXE_PATH}: " + $?.to_s
end
end
CLEAN.include(CHARMONIZER_EXE_PATH)
CLEAN.include(CHARMONY_H_PATH)
CLEAN.include(CHARMONY_RB_PATH)
# Clean up after charmonizer if it doesn't succeed on its own.
CLEAN.include("_charm*")
task :default => [:build_clownfish]