view rakefile @ 10:eb8ff453285d

Added java.util collection classes.
author Frank Benoit <benoit@tionex.de>
date Fri, 13 Mar 2009 16:57:07 +0100
parents 2847134a5fc0
children bc29606a740c
line wrap: on
line source

#
# RSP : Create a response file for the compiler, which lists all files from the packages
# Compile and create Headers
# Move objects to unique names
#
require 'find'
require 'fileutils'

#DMD="c:\\project\\dmd-2.026\\dmd\\windows\\bin\\dmd.exe"
DMD="dmd"
LOCALOBJDIR="obj"
OBJDIR="obj"
DIMPDIR="imp"
RSPNAME="rsp"
ALL_RESDIRS= [ "java/res", "org.eclipse.swt.win32.win32.x86/res" ]

class String
    def to_path
        self.gsub( '/', '\\' );
    end
end

def buildTree( basedir, srcdir, resdir )

    objdir_abs = File.expand_path( OBJDIR )
    dimpdir_abs = File.expand_path( DIMPDIR )
    resdir_abs = File.expand_path( File.join( basedir, resdir ))
    srcdir_abs = File.expand_path( File.join( basedir, srcdir ))
    rspfile_abs = File.expand_path( RSPNAME )

    FileUtils.mkdir_p dimpdir_abs
    FileUtils.mkdir_p objdir_abs

    puts "Create response file"
    rsp = File.new( rspfile_abs, "w+" )
    rsp.puts "-H"
    rsp.puts "-I#{srcdir_abs.to_path}"
    rsp.puts "-I#{dimpdir_abs.to_path}"
    rsp.puts "-J#{resdir_abs.to_path}"
    ALL_RESDIRS.each do | dir |
        rsp.puts "-J#{File.expand_path(dir).to_path}"
    end
    rsp.puts "-c"
    rsp.puts "-op"
    Find.find( srcdir_abs ) do |path|
        if path =~ /\.d$/ then
            rsp.puts path.to_path
        end
    end
    rsp.close

    Dir.chdir(basedir) do
        puts "Compile"
        sh "#{DMD} @#{rspfile_abs.to_path}" do |ok, res|

            if !ok then
                Find.find( srcdir_abs ) do |path|
                    if FileTest.file?(path) && path =~ /\.di$/ then
                        FileUtils.rm path
                    end
                end

                raise "compile error"
            end
        end
    end

    puts "Move D Headers"
    Find.find( srcdir_abs ) do |path|
        if FileTest.file?(path) && path =~ /\.di$/ then
            trgfile = File.join( dimpdir_abs, path[ srcdir_abs.length+1 .. -1 ])
            FileUtils.mkdir_p File.dirname(trgfile)
            FileUtils.mv path, trgfile
        end
    end

    puts "Move Objects"
    srcdirparts = split_all( srcdir_abs ).length
    Find.find( srcdir_abs ) do |path|
        if FileTest.file?(path) && path =~ /\.o(bj)?$/ then
            trgfile = split_all( path )[ srcdirparts .. -1 ].join( "-" )
            FileUtils.mv path, File.join( objdir_abs, trgfile )
        end
    end

end

desc "Clean"
task :clean do
    FileUtils.rm_rf DIMPDIR
    FileUtils.rm_rf OBJDIR
    FileUtils.rm_rf RSPNAME
end

desc "Build Java"
task :java do
    buildTree( "java", "src", "res" )
end

desc "Build SWT"
task :swt do
    buildTree( "org.eclipse.swt.win32.win32.x86", "src", "res" )
end

desc "Build jface"
task :jface do
    buildTree( "org.eclipse.jface", "src", "res" )
end