пятница, 13 июня 2014 г.

пятница, 16 мая 2014 г.

Small and fast build tools: SVMK, NINJA

There are many build tools. One of them tracks dependencies and build result output via special file with dependencies-tree description, another generates such file from universal format (Premake, Bakefile, CMake, etc.). There are 2 big classes of such tools: with special syntax in its' Makefiles, and with supporting of some general-purpose language (Waf, Scoons, etc.). Difference is that in the 2nd kind you can solve absolutely any tasks without writing special plugins (sometimes is impossible to extend "Makefile" in natural way, only with command line utilities)...

If you want very small and fast build tools (and not Make:) you can see next: Ninja and Tcl-based Svmk. Another Tcl-based make tools are here.


Ninja is very simple and fast. It have not functions, if-else-for-while operators, nothing, only variables, rules... But it can be used to process automatically generated "Makefile". Example:
DMD = c:/dmd2/windows/bin/dmd.exe
LINK = c:/dmd2/windows/bin/link.exe

INC = -Ic:/dmd2/src/phobos -Ic:/dmd2/src/druntime/import

rule mkprj
    command = $DMD -I$PKGDIR $INC -of$out $in
    description = Compile D program $out

PKGDIR = misc/scripts
build $PKGDIR/email.exe: mkprj $PKGDIR/characterencodings.d $PKGDIR/email.d
Save it in build.ninja, call ninja misc/scripts/email.exe and you will get result: email.exe in misc/scripts directory. rule creates rule which has attribute command to call when it's applied. build set dependency: email.exe will be built from 2 .d files with mkprj rule by calling it command. Nothing else. Simple, fast. ninja is only ONE FILE: ninja.exe and is about 800Kb! If no target (misc/scripts/email.exe), then ninja will build it.


It's Tcl-based make alternatives. So you have all power of Tcl (use Tclkit Shell!) in one little Tcl-script: svmk.tcl. Example of the same:
# vi:set ft=tcl:

set DHOME c:/dmd2/windows/bin
set DMD $DHOME/dmd.exe

proc dcomp {out in {dflags ""}} {
    global DMD
    if [llength $dflags] {
        system $DMD $dflags -of$out {*}$in
    } else {
        system $DMD -of$out {*}$in

target email.exe {
    cd misc/scripts
    set SRC "characterencodings.d email.d"
    depend $SRC {
        dcomp email.exe $SRC
We create dcomp procedure for compiling of D applications. Then create rule "email.exe" which is PHONY :) Common usage is target TARGET { depend DEPENDENCIES { commands... } }. You can see: we can use any Tcl commands, even download something via Net :) All what you need is: tclkitsh.exe: 740Kb, svmk.tcl: 10Kb!
To run:
tclkitsh.exe svmk.tcl email.exe
And sure you can (and have) to use original D build tool (if we are talking about D;) - dub.