A PowerShell make clone – poshmake

After i read Ayendes post about psake i remembered on something that i written in January because it is also an PowerShell based build system. Back in 2008 i saw a video from Bruce Payette at Channel 9 where he shows a PowerShell based build system as demonstration how easy it is to write a domain specific language in PowerShell.

As i saw a lot guys talking about drop NAnt or MSBuid and move to rake at the begin of 2009 and i dont like rake because i think it isnt a good idea to force developers to use a completely new framework instead of allowing them to use the .Net Framework. So i remind me on this video.I searched a while if he ever published this code, but i never found something and i did not stumbled upon psake at this time (first before some weeks). So ive decided to investigate some time to extend my PowerShell skills and and reverse engineered it.

And here is it (Download)

And this is how it looks like (its the makefile.ps1 from the example directory):

target all clean hello.exe cshello.exe

target test all {
	"*" * 40
	"Running hello.exe"
	"All done"
	"*" * 40

target clean  {
 write-host "cleaning files";
 remove-item -force *.exe,*.obj,*.dll

# build hello.exe
target hello.exe main.obj,do_hello.obj,{write-host "after"}
target main.obj main.c
target do_hello.obj do_hello.c,message.h

# build cshello.exe
target cshello.exe ((dir "test*.cs") + "mylib.dll")

# build the dll used by cshello.exe
target mylib.dll mylib.cs

target output {
	echo "this is a output"

To build it, simply start PowerShell, got to the example directory and type:


First, it is not feature complete and not ready for production code, so be careful.

How it works? Target is a function, which takes as first parameter the name of the new target and then a list of dependency in priority order. The special on it is that a target can be a file, an expression that returns a list of files or a script. So at example, the target clean has an script block as dependency, every time the target clean is called, the scriptblock gets executed. As other example the target cshello.exe has a list of cs files and one dll as dependency.

But where the build happens? Poshmake has an dictionary which contains predefined build targets and its dependency’s for some files types. In example there is a target for *.exe which can be have *.obj or *.cs as dependency’s. So for the cshello.exe it looks into the dependency array and found cs files it calles the csc with all cs files and uses all dll files in the dependency array to build the exe. When there obj files, it will call link to link them together, and so forth. Currently only the cs and dll targets are really compiling, the other targets currently only printing its dependent files.

But what if i want to change the parameters of the csc build? Simply put a script action before the *.cs files which adds the your parameter to the $CSCFLAGS variable.

If you want to build a special target (default is all), you simply can call

poshmake clean

If you want to know which targets available simply call

poskmake -list

If you have a problem and you dont know what poshmake dose use the -verbose parameter which gives you a detailed hint what poshmake dose.

poskmake all -verbose

So happy playing with it 🙂

Update: How to enable Google Gears in Mozilla Prism

In the current version of Gears you can enable the extension with the trick i posted here, but the applications failes to load Gears. Thanks to gera0ul which pointed out how to make it work.

The problem turns out to be the detection code in components/stub.js in the xpi.
Before creating the zip/xpi, if I change the function getLibFilename in
components/stub.js to return “ff30”, and *then* install the xpi in Prism, it works.

So all you need to do is to grab the Gears xpi file and let the getLibFilename function in components/stub.js directly in line 1 return “ff30” if you use Firefox 3.0 or return “ff35” if you use Firefox 3.5. And now you can install the xpi as any other Firefox extension. But it is important to edit the file before you install the extension, because otherwise it dose not work.

This is a hack, but since the issue is in the Gears bugtracker and it it set to accepted, we can hope that it will get fixed in the near future.