用Rant自動(dòng)化D語言程序構(gòu)建
上回說到 Rank 這個(gè) Ruby 世界最廣泛使用的構(gòu)建工具在 Windows 下有大bug,根本不能運(yùn)行。Python的scons太慢、自動(dòng)得過了頭,造成定制起來很麻煩.....
最終,我找到了一個(gè)叫 Rant 的Ruby構(gòu)建工具,用起來幾乎與 Rank一樣,而且特性更多,最重要的是能在 windows 下面正常運(yùn)行。因此我強(qiáng)烈推薦各位D語言的粉絲使用Rant作為軟件構(gòu)建工具,放棄那些不成熟的IDE。用Rant的好處是還能順帶學(xué)習(xí)一下Ruby語言,對(duì)于像我一樣的Ruby&&D雙料菜鳥,這是不可多得的學(xué)習(xí)機(jī)會(huì)。
如果沒有Ruby,請(qǐng)先下載安裝 Ruby。 然后在控制臺(tái)中輸入:gem --remote install rant,系統(tǒng)將會(huì)自動(dòng)安裝并配置好 rant
下面是我寫的 for DMD 萬用 Rantfile 模板,只要把它放到你的D程序所在的目錄,稍加修改就能使用。
RANTFILE 代碼
# The Rantfile for DMD
# Author: oldrev (wstringgmail.com)
# No copyrights, use it freely
import "AutoClean"
#require "rant/filelist"
# 請(qǐng)自行定義下面幾行
NAME = "foo.exe" # 可執(zhí)行文件名
SRC = "./src" # D 源程序在 ./src 目錄下(包括子目錄)
LIBS = ["advapi32.lib", "uuid.lib", "ole32.lib"] # 程序用到的附加 .lib
DEBUG_FLAGS = "-debug -g"
RELEASE_FLAGS ="-release -O"
DC = "dmd.exe"
IMPLIB = "implib.exe"
PROG = "#{NAME}"
PROG_DEBUG = "#{NAME}"
SRCS = Rant::FileList[SRC + "/**/*.d"]
OBJS = SRCS.ext "obj"
OBJS_DEBUG = SRCS.map {|file| file.sub /\.d$/, "_debug.obj"}
DEFS = Rant::FileList[SRC + "/**/*.def"]
ILIBS = DEFS.ext "lib"
task :default => :debug
task :release => :program
task :debug => :program_d
def dolink(target, t)
sys.sh "#{DC} -of#{target} #{t.prerequisites.join(' ')} #{LIBS.join(' ')}"
end
task :program => OBJS.entries + ILIBS.entries do |t|
dolink PROG_DEBUG, t
end
task :program_d => OBJS_DEBUG.entries + ILIBS.entries do |t|
dolink PROG, t
end
gen Rule, ".obj" => ".d" do |t|
sys.sh "#{DC} #{t.source} -c -I#{SRC} #{RELEASE_FLAGS} -of#{t.name}"
end
gen Rule, "_debug.obj" => ".d" do |t|
sys "#{DC} #{t.source} #{DEBUG_FLAGS} -c -I#{SRC} -of#{t.name}"
end
gen Rule, ".lib" => ".def" do |t|
# DigitalMars 的 implib.exe 程序不認(rèn)識(shí) '/' 分割的路徑
lib = t.name.gsub("/", "\\")
dotdef = t.source.gsub("/", "\\")
sys.sh "#{IMPLIB} /system #{lib} #{dotdef}"
end
task :clean do
sys.rm_f OBJS
sys.rm_f OBJS_DEBUG
sys.rm_f ILIBS
sys.rm_f PROG
sys.rm_f PROG_DEBUG
end
此 Rantfile 能掃描源程序目錄的所有.d文件,并自動(dòng)編譯連接。如果源程序目錄存在 .def 的 DLL 導(dǎo)入庫定義文件的話,也會(huì)自動(dòng)生成 .lib,并鏈接到程序中。
rant 的用法與make基本一致:
rant debug //建立 debug 版程序
rant release // 建立 release 版程序
rant clean // 清理零時(shí)文件
rant -f build.rb //指定build.rb為rantfile,而不是當(dāng)前目錄下的 Rantfile
更多信息請(qǐng)登陸http://61.191.27.74:802/ 最后,歡迎加入http://61.191.27.74:802/的會(huì)員
安徽新華電腦學(xué)校專業(yè)職業(yè)規(guī)劃師為你提供更多幫助【在線咨詢】