Alright, I’ve spammed the twitterverse enough.

Here’s something I started playing with today, and finished just a few hours later, satisfied. Premake. In essence, it’s a build script and project file maker, just like CMake and Scons. It uses Lua scripting, to contrast custom and python for the others (CMake a Scons respectfully).

If you weren’t me, you could save yourself a slew of portability headaches with this simple script.

(From here)

Stick that in a folder with code, or code found in some directories. Then from a command-line, invoke the tool premake4 as follows:

premake4 --file=myfile.lua vs2008

Blam! Your prize, a Visual Studio 2008 project file and solution. Want 2010? Just change the argument.

Want it building elsewhere? Walk over to your Linux box, or your Cygwin/MinGW shell, and do this:

premake4 --file=myfile.lua gmake

You now have a makefile.

Of course, anyone that’s done project management knows that the above is just your most basic of projects. Standard C/C++ libraries, and whatnot. Per platform you still need to link versus external libraries (OpenGL, SDL, etc). No problem, just add new sections to your targets. includedirs, libs, libdirs, and so on. Want to apply a setting to both? just place it a level up in the hierarchy. Nearly everything you would normally do on a platform, there’s a means of adding content to that.

Honestly, there’s little point having me regurgitate how to start using it, as the docs have a wonderful tutorial that steps through it. And once you get to the files stage of the tutorial, you can generate a usable project file with just that. Here’s the link:

http://industriousone.com/solutions-and-projects

My one last tip though, is that the scripting interface is doing some housekeeping behind the scenes. The functions Solution, Project, and Configuration specifically. Calling them changes the scope of the calls that follow. This is important to note if you try to use normal Lua scripting activities, a “printf” will write to the console as the project is generated, but not while it runs. There’s a command for setting the actions at each stage.

Oh, and you can invoke MSBUILD from the command-line if you want to live in shell land (like me). Start a Visual Studio 2008 shell (under Start Menu/Visual Studio 2008/Visual Studio Tools/..), then browse to and invoke it as follows.

msbuild MySolution.sln /property:Configuration=Debug

And presto. Your actual errors will be logged to the console window.

* * *

So hey, ahem, back on topic. If you’re not me, you can use something like this to do your project management work. I however have and REALLY LIKE a fancy GNU make based build system I wrote. Unfortunately, this only helps me when I’m developing for Windows, Linux, and certain devices. It does no good when I am actually required to use Visual Studio (certain libraries, DRM, SDK’s), or Xcode on Mac. But that’s where Premake comes in, to take care of that stuff for me.

I have some wild plans ahead, but I wanted my original working script available somewhere. Hit the jump for the full listing.

Remember, it’s Lua, so double dashes are line comments.

And oh, hey, a bonus! My MSBUILD batch file (conveniently named make.bat).