blob: 82771b819d6dd3058a1124ee231dbfc205da88b4 [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'
import '../../runtime/ruby/Rakefile.common'
def rbconfig
RbConfig::CONFIG
end
def exe_path(*args)
File.join(args).ext(RbConfig::CONFIG["EXEEXT"])
end
BASE_PATH = '..'
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'
CLOWNFISH_RUBY_DIR = File.absolute_path('.')
CLOWNFISH_INCLUDE_DIR = File.join(CLOWNFISH_RUBY_DIR,'..','include')
CLOWNFISH_RUNTIME = File.join('..','..','runtime','ruby')
CLOWNFISH_SRC_DIR = File.join(CLOWNFISH_RUBY_DIR,'..','src')
LEMON_SRC_DIR = File.join('..','..','lemon')
RUBY_EXT_CFC = File.join('.','ext','Clownfish')
desc "Build lemon"
task :build_lemon do
puts "Building lemon"
run_make(LEMON_SRC_DIR,[])
end
desc "Build Clownfish"
task :clownfish => [:charmony, :parse_y_files] do
Dir.glob(File.join(CLOWNFISH_SRC_DIR, '**', '*.c')).each do|c_file|
obj_file = c_file.ext(rbconfig['OBJEXT'])
next if uptodate?(obj_file, [c_file])
command = "#{cc_command} #{includes} #{extra_ccflags} -o #{obj_file} -c #{c_file}"
puts command
if system(command).nil?
abort "Failed cc compile"
end
end
Rake::Task['cfc_ext'].invoke
end
# Clean up compiled object files.
obj_glob = File.join(CLOWNFISH_SRC_DIR, '**', '*.' + rbconfig['OBJEXT'])
Dir.glob(obj_glob).each do |file|
CLEAN.include(file);
end
desc "Build CFC Ext"
task :cfc_ext => [:clownfish] do
makefile_path = File.join('ext', 'Clownfish', 'Makefile')
dependencies = Dir.glob(File.join(CLOWNFISH_SRC_DIR, '**', '*.h'))
dependencies << File.join(RUBY_EXT_CFC, "extconf.rb")
dependencies << 'Rakefile'
if !uptodate?(makefile_path, dependencies)
Dir.chdir(RUBY_EXT_CFC) do
ruby 'extconf.rb'
end
end
Dir.chdir(RUBY_EXT_CFC) do
if system('make').nil?
abort "Failed to make cfc ruby extension"
end
end
end
# Clean up Ruby extension.
Dir.glob(File.join('ext', '**', '*.' + rbconfig['OBJEXT'])).each do |file|
CLEAN.include(file);
end
Dir.glob(File.join('ext', '**', '*.' + rbconfig['DLEXT'])).each do |file|
CLEAN.include(file);
end
CLEAN.include(File.join('ext', 'Clownfish', 'Makefile'))
desc "Lemonize the y file"
task :parse_y_files => [:build_lemon] do
puts "Parsing y files"
Dir.glob(File.join(CLOWNFISH_SRC_DIR, '**', '*.y')).each do |y_file|
c_file = y_file.ext('c')
h_file = y_file.ext('h')
report_file = y_file.ext('out')
next if uptodate?(c_file, [y_file]);
command = File.join(LEMON_SRC_DIR,'lemon') + ' -c ' + y_file
puts command
if system(command).nil?
abort "Problem parsing y file with lemon"
end
end
puts "Done."
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*")
# Clean up after Lemonized files.
Dir.glob(File.join(CLOWNFISH_SRC_DIR, '**', '*.y')).each do |y_file|
CLEAN.include(y_file.ext('c'))
CLEAN.include(y_file.ext('h'))
CLEAN.include(y_file.ext('out'))
end
task :default => [:clownfish]
def includes
return "-I#{CLOWNFISH_INCLUDE_DIR} -I#{CLOWNFISH_SRC_DIR} -I#{CLOWNFISH_RUBY_DIR} -I#{CLOWNFISH_RUNTIME}"
end