require 'rake'
require 'rake/clean'
require 'rake/tasklib'

CLEAN.include("**/*.o")                             # all object files
CLOBBER.include("libffi.a")

# source files must be in appropriate subdirectories ('objc', 'ruby', or 'resources')
#@c_files      = FileList['src/*.c'] + FileList['src/*/*.c']
#@s_files   = FileList['src/*/*.S']
#@gcc_files   = @s_files + @c_files


@gcc_files = FileList.new(%w{types.o prep_cif.o x86/ffi_darwin.o x86/darwin.o powerpc/ffi_darwin.o powerpc/darwin.o powerpc/darwin_closure.o}.map{|f| "src/"+f})

@gcc_objects = @gcc_files.sub(/\.c$/, '.o').sub(/\.S$/, '.o').uniq

@cc = "gcc"

@arch = "-arch i386 -arch ppc"

@cflags = "-g -O3 -Wall -DMACOSX -Iinclude -I. -Isrc"

@ldflags = ""

rule ".o" => [".S"] do |t|
  sh "#{@cc} #{@cflags} #{@arch} #{@includes} -c -o #{t.name} #{t.source}"
end

rule ".o" => [".c"] do |t|
  sh "#{@cc} #{@cflags} #{@arch} #{@includes} -c -o #{t.name} #{t.source}"
end

file "libffi.a" => @gcc_objects do |t|
  sh "libtool -static -o #{t.name} #{@gcc_objects}"
  sh "ranlib #{t.name}"
end

task :default => "libffi.a"

