require 'rake' require 'rake/clean' require 'rake/tasklib' require 'vstudioide' require 'win32rc' require 'leaves/core_ext/string' require 'leaves/rake_ext/tasklib' require 'leaves/version' module Rake module Leaves class VisualStudioTask < TaskLib attr_accessor :solution attr_accessor :config def initialize(name = '') @name = (name.to_s.empty? ? nil : name) solution = FileList.new('*.sln').to_a.first @solution = solution if solution @config = name.to_s.camelize yield self if block_given? define end def define if @name desc "Build using Microsoft Visual Studio." task paste("build_", @name) => [paste("compile_", @name)] task paste("compile_", @name) do sh "devenv \"#{@solution}\" /build \"#{@config}\" 2>&1" end task paste("clean_", @name) do sh "devenv \"#{@solution}\" /clean \"#{@config}\" 2>&1" end else sln = VStudioIDE::Solution.new(@solution) sln.configurations.each do |cfg| name = cfg.underscore config = cfg.dup desc "Build using Microsoft Visual Studio." task paste("build_", name) => [paste("compile_", name)] task paste("compile_", name) do sh "devenv \"#{@solution}\" /build \"#{config}\" 2>&1" end task paste("clean_", name) do sh "devenv \"#{@solution}\" /clean \"#{config}\" 2>&1" end end end self end end class NmakeTask < TaskLib attr_accessor :makefile attr_accessor :macrodefs attr_accessor :target def initialize(name = nil) @name = name @makefile = "Makefile.msvc" yield self if block_given? define end def define desc "Build using Microsoft Program Maintenance Utility (NMAKE.EXE)." task upaste("build", @name) => [upaste("compile", @name)] task upaste("compile", @name) do cmd = "nmake /f \"#{@makefile}\"" cmd << " #{@macrodefs}" if @macrodefs cmd << " #{@target}" if @target cmd << " 2>&1" sh cmd end task upaste("clean", @name) do sh "nmake /f \"#{@makefile}\" clean 2>&1" end self end end class RCVersionTask < TaskLib attr_accessor :resource attr_accessor :version def initialize resource = FileList.new('*.rc').to_a.first @resource = resource if resource yield self if block_given? define end def define task :version_rc do rc = Win32RC::Resource.new(@resource) rc.version = @version rc.save end self end end end end