Minimalistic cross-platform Rakefile

From D Wiki
Jump to: navigation, search
Level: Novice
Cookbook Type: Recipe
Cookbook Status: Draft
Approximate reading time: 10 min
0.166 hr
D Version: D2


require 'rake/clean'
require 'rake/packagetask'

##################
# SETTING
##################
VERSION = '0.1.0'

SRC = FileList['*.d', './foo/*.d', './bar/*.d']
NAME = 'fun'
IMPORTS = ['./gun']

BUILD_DIR = "."
LIB_DIR = "."

COMPILER_OPT = ''
PKG_FILES = FileList["#{BUILD_DIR}/*.*"]
DMD = "dmd"

##############################
# CODING
##############################
FULL_NAME="#{BUILD_DIR}/#{NAME}"
IMPORTS_OPT = IMPORTS.empty? ? "" : "-I#{IMPORTS.join(':')}"  
SCRIPT = "#{DMD} #{COMPILER_OPT} -of#{FULL_NAME} #{IMPORTS_OPT} #{SRC}"

CLOBBER.include("#{FULL_NAME}")

directory BUILD_DIR

task :default => :compile

task :compile => FULL_NAME
file FULL_NAME => FileList[SRC] do |t|
  Rake::Task[:force].invoke
end

task :force do
  sh "#{SCRIPT}" 
end

task :make_script do
  File.open('build.sh', 'w') do |file|
    file.puts "#{SCRIPT}"
  end
end

task :ver do
  puts "#{VERSION}"
end

Rake::PackageTask.new(NAME, VERSION) do |p|
  p.need_tar_bz2 = true
  p.need_zip = false
  p.need_tar = false
  p.package_files = PKG_FILES
end