# 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 'rbconfig' require 'rake/clean' def rbconfig RbConfig::CONFIG end CLOWNFISH_RUBY_DIR = File.absolute_path('.') CLOWNFISH_INCLUDE_DIR = File.join('..','include') CLOWNFISH_SRC_DIR = File.join('..','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 => [: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 require_relative 'ext/Clownfish/CFC' hierarchy = Clownfish::CFC::Model::Hierarchy.new(:dest => "autogen") hierarchy.build core_binding = Clownfish::CFC::Binding::Core.new(:hierarchy => hierarchy, :header => autogen_header, :footer => '') core_binding.write_all_modified 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 # 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 cc_command rbconfig["CC"] end def extra_ccflags ccflags = '-DCFCRUBY ' if defined?(rbconfig["CFLAGS"]) ccflags += rbconfig['CFLAGS'] + ' ' end if ENV.has_key?('CFLAGS') ccflags += ENV['CFLAGS'] end if ENV.has_key?('LUCY_VALGRIND') ccflags += "-fno-inline-functions " end # Compile as C++ under MSVC. Turn off stupid warnings, too. if cc_command =~ /^cl\b/ ccflags += '/TP -D_CRT_SECURE_NO_WARNINGS ' end # Blindly include GCC-specific flags even though we don't know that the # compiler is GCC. if ccflags !~ /-std=/ ccflags += "-std=gnu99 " end if ccflags !~ /-D_GNU_SOURCE/ ccflags += "-D_GNU_SOURCE " end return ccflags end def includes return "-I#{CLOWNFISH_INCLUDE_DIR} -I#{CLOWNFISH_SRC_DIR}" end def make_command command = rbconfig["make-prog"] if !command if RUBY_PLATFORM =~ /mswin/i if cc_command =~ /^cl\b/ command = "nmake" end end end if !command command = 'make' end return command end def run_make(dir, params) current_dir = Dir.pwd chdir(dir) if dir command = params.clone command.unshift("CC=#{cc_command}") if RUBY_PLATFORM =~ /(mswin|mingw)/i if cc_command =~ /^cl\b/ command.unshift("-f", "Makefile.MSVC") else command.unshift("-f", "Makefile.MinGW") end end command.unshift(make_command) success = system(*command) if !success raise "Make failed" end chdir(current_dir) if dir end def autogen_header " /*********************************************** !!!! DO NOT EDIT !!!! This file was auto-generated by Rakefile. ***********************************************/ " end