view rakefile @ 31:5d87d4191adf

Added JFace Snippets sources
author Frank Benoit <benoit@tionex.de>
date Mon, 23 Mar 2009 11:16:06 +0100
parents 93b0e7382fd5
children 712f3c7f7660
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"
OBJDIR  =File.expand_path("obj")
DIMPDIR =File.expand_path("imp")
LIBDIR  =File.expand_path("lib")
BINDIR  =File.expand_path("bin")
RSPNAME =File.expand_path("rsp")
ALL_RESDIRS= [ "base/res", "res" ]

LOG_STDOUT = File.expand_path("olog.txt")
LOG_STDERR = File.expand_path("elog.txt")

def isWindows
    Config::CONFIG['host_os'] =~ /mswin/
end

if isWindows
    ALL_RESDIRS << "org.eclipse.swt.win32.win32.x86/res"
    LIBEXT = ".lib"
    OBJEXT = ".obj"
    EXEEXT = ".exe"
else
    ALL_RESDIRS << "org.eclipse.swt.gtk.linux.x86/res"
    LIBEXT = ".a"
    OBJEXT = ".o"
    EXEEXT = ""
end

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

def buildTree( basedir, srcdir, resdir, dcargs="", libname="" )
    puts "Building #{basedir}/#{srcdir}"

    resdir_abs = File.expand_path( File.join( basedir, resdir ))
    srcdir_abs = File.expand_path( File.join( basedir, srcdir ))

    FileUtils.mkdir_p DIMPDIR
    FileUtils.mkdir_p OBJDIR

    rsp = File.new( RSPNAME, "w+" )
    rsp.puts "-H"
    rsp.puts "-I#{srcdir_abs.to_path}"
    rsp.puts "-I#{DIMPDIR.to_path}"
    rsp.puts "-J#{resdir_abs.to_path}"
    if dcargs.size > 0 then
        rsp.puts dcargs
    end
    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
        if isWindows
            cmd = "#{DMD} @#{RSPNAME.to_path}"
        else
            cmd = "cat #{RSPNAME.to_path} | xargs #{DMD}"
        end
        sh cmd, :verbose => false 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

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

    libobjs = Array.new
    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, trgfile )
            libobjs << File.join( OBJDIR, trgfile )
        end
    end

    if libname.size == 0
        libname = basedir
    end
    createLib( libobjs, libname )
end

def createLib( libobjs, name )
    FileUtils.mkdir_p LIBDIR.to_path
    rsp = File.new( RSPNAME, "w+" )
    rsp.puts "-p512 -n -c #{LIBDIR}/#{name}#{LIBEXT}"
    libobjs.each do |obj|
        rsp.puts obj.to_path
    end
    rsp.close
    cmd = "lib @#{RSPNAME} > #{LOG_STDOUT}"
    sh cmd, :verbose => false do |ok, res|
        if !ok then
            raise "librarian error"
        end
    end

end

desc "Clean"
task :clean do
    puts "Cleaning"
    FileUtils.rm_rf DIMPDIR
    FileUtils.rm_rf OBJDIR
    FileUtils.rm_rf LIBDIR
    FileUtils.rm RSPNAME
    FileUtils.rm LOG_STDOUT
    FileUtils.rm LOG_STDERR
end

desc "Build Base (Java Environment and Helpers)"
task :base do
    buildTree( "base", "src", "res", "", "dwt-base" )
end

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

desc "Build Equinox"
task :equinox do
    buildTree( "org.eclipse.osgi", "src", "res" )
    buildTree( "org.eclipse.osgi", "supplement/src", "res" )
    buildTree( "org.eclipse.equinox.common", "src", "res" )
end

desc "Build Eclipse Core"
task :core do
    buildTree( "org.eclipse.core.runtime", "src", "res" )
    buildTree( "org.eclipse.core.commands", "src", "res" )
    buildTree( "org.eclipse.core.jobs", "src", "res" )
end

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

desc "Build JFace.Text"
task :jfacetext do
    buildTree( "org.eclipse.text", "src", "res" )
    buildTree( "org.eclipse.jface.text", "projection", "res", "-Isrc", "org.eclipse.jface.text.projection" )
    buildTree( "org.eclipse.jface.text", "src", "res" )
end

desc "Build UI Forms"
task :uiforms do
    buildTree( "org.eclipse.ui.forms", "src", "res" )
end

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

desc "Build ALL"
task :all => [ :base, :swt, :equinox, :core, :jface, :jfacetext, :uiforms,
    :draw2d ]

desc "Clean, then build ALL"
task :default => [ :clean, :all ]


desc "Build SWT Snippet Collection"
task :swtsnippets, :explicit_snp do | t, args |

    snps_browser = [ "Snippet128", "Snippet136" ]
    snps_opengl = [ "Snippet174", "Snippet195" ]

    snps_exclude = snps_browser + snps_opengl
    allsnippets = FileList[ File.join("org.eclipse.swt.snippets", "src", "**/Snippet*.d" )]
    if args.explicit_snp != nil
        puts "Building #{args.explicit_snp}"
        buildApp( "org.eclipse.swt.snippets", "src", "res", "", args.explicit_snp )
    else
        allsnippets.each do | snp |
            puts "Building #{snp}"
            if snp =~ /.*(Snippet\w+)\.d$/
                snpname = $1
                if !snps_exclude.include? snpname
                    buildApp( "org.eclipse.swt.snippets", "src", "res", "", snpname )
                end
            else
                puts snp
                raise "Name does not match"
            end
        end
    end
end

def buildApp( basedir, srcdir, resdir, dflags, appname, filelist=nil )
    if filelist == nil
        filelist = FileList[ "**/#{appname}.d" ]
    end

    srcdir_abs = File.expand_path( File.join( basedir, srcdir))
    resdir_abs = File.expand_path( File.join( basedir, resdir))

    rsp = File.new( RSPNAME, "w+" )
    rsp.puts "-I#{srcdir_abs.to_path}"
    rsp.puts "-I#{DIMPDIR.to_path}"
    rsp.puts "-J#{resdir_abs.to_path}"
    if dflags.size > 0 then
        rsp.puts dflags
    end
    ALL_RESDIRS.each do | dir |
        rsp.puts "-J#{File.expand_path(dir).to_path}"
    end
    #rsp.puts "-L/NOMAP"
    #rsp.print "-L"
    #rsp.print "+advapi32"
    #rsp.print "+comctl32"
    #rsp.print "+comdlg32"
    #rsp.print "+gdi32"
    #rsp.print "+kernel32"
    #rsp.print "+shell32"
    #rsp.print "+ole32"
    #rsp.print "+oleaut32"
    #rsp.print "+olepro32"
    #rsp.print "+oleacc"
    #rsp.print "+user32"
    #rsp.print "+usp10"
    #rsp.print "+msimg32"
    #rsp.print "+opengl32"
    #rsp.print "+shlwapi"
    #rsp.print "+tango-user-dmd.lib"
    #rsp.print "+zlib.lib"
    #rsp.print "+dwt-base.lib"
    #rsp.print "+org.eclipse.swt.win32.win32.x86.lib"
    #rsp.print "+#{LIBDIR.to_path}\\"
    #rsp.puts

    rsp.puts "-L/NOM"
    rsp.puts "-L+advapi32"
    rsp.puts "-L+comctl32"
    rsp.puts "-L+comdlg32"
    rsp.puts "-L+gdi32"
    rsp.puts "-L+kernel32"
    rsp.puts "-L+shell32"
    rsp.puts "-L+ole32"
    rsp.puts "-L+oleaut32"
    rsp.puts "-L+olepro32"
    rsp.puts "-L+oleacc"
    rsp.puts "-L+user32"
    rsp.puts "-L+usp10"
    rsp.puts "-L+msimg32"
    rsp.puts "-L+opengl32"
    rsp.puts "-L+shlwapi"
    rsp.puts "-L+tango-user-dmd.lib"
    rsp.puts "-L+zlib.lib"
    rsp.puts "-L+dwt-base.lib"
    rsp.puts "-L+org.eclipse.swt.win32.win32.x86.lib"
    rsp.puts "-L+#{LIBDIR.to_path}\\"

    rsp.puts "-op"
    rsp.puts "-od#{OBJDIR.to_path}"
    applfile = File.join(BINDIR,appname+EXEEXT)
    rsp.puts "-of#{applfile.to_path}"
    filelist.each do |path|
        rsp.puts File.expand_path(path).to_path
    end
    rsp.close

    Dir.chdir(basedir) do
        if isWindows
            cmd = "#{DMD} @#{RSPNAME.to_path}"
        else
            cmd = "cat #{RSPNAME.to_path} | xargs #{DMD}"
        end
        sh cmd, :verbose => false do |ok, res|
            if !ok then
                raise "compile error"
            end
        end
    end

end