Getting started with Macaroni on Ubuntu
Wednesday December 12, 2012 05:15:29


I recently got Macaroni compiled in Ubuntu and passing all the unit tests. The integration tests weren't so lucky, perhaps due to configuration issues in how I'm using Boost Build. Despite that, I've released the Ubuntu build on Macaroni's homepage. Here's a little tutorial on how to use it in Ubuntu, which I'm writing as I run Macaroni for the first time in a fresh virtual machine.

First, download Macaroni from this link. I unzipped mine to ~/Tools/macaroni, so the final directory was ~/Tools/macaroni/macaroni-0.1.0.25-ubuntu-64.

The Macaroni binary won't have the execute permission set, so fix that with:

$ chmod 700 ~/Tools/macaroni/macaroni-0.1.0.25-ubuntu-64/macaroni

Macaroni needs a settings file to be present at ~/Macaroni. This is for global settings which need to be changed on a per-machine basis, though for this project we won't need it all.

$ mkdir -p ~/Macaroni
$ echo "properties={}" > ~/Macaroni/init.lua

Unlike the Windows version, we'll need to specify each path to the various Lua scripts (the ability to avoid this might be coming to the Linux version soon, but currently it seems a little complicated). So we'll create an alias to do all this for us.

$ MPATH=~/Tools/macaroni/macaroni-0.1.0.25-ubuntu-64
$ alias mcpp="$MPATH/macaroni generatorPath $MPATH/Generators \
    libraryRepoPath $MPATH/Libraries messagesPath $MPATH/"

At this point typing “mcpp” will run Macaroni.

Create a new directory for an example project. Mine is ~/Work/mexample. In that directory, create the following file called “project.lua”:

import('Macaroni', 'ProjectTemplates', '1')
require 'SimpleProject'
GenerateCpp{group='Junk', project='Junk', version='0'};

This project file is simple to the point of absurdity. It uses the “GenerateCpp” function, which does nothing other than parse Macaroni files in the directory “src” and write C++ files to the directory “target”. If you want, you can change these directories with the “src” and “target” named arguments to GenerateCpp.

Of course, we'll need a Macaroni source file in the “src” directory. First, create the “src” directory, and then create the following file in that directory named “Example.mcpp” (actually, it can be called anything at all so long as it ends in .mcpp).

~import std::cout;

class Class1 { public Class1() { cout << "Class1!" } };

class Class2 { public Class2() { cout << "Class2!" } };

Finally, generate C++ code by running the following:

$ mcpp generate
Macaroni for C++
Version 0.1.0.25 built at 2012-12-11-10:45:52

Creating new Environment with the following AppPaths:
Message file : /home/tim/Tools/macaroni/macaroni-0.1.0.25-ubuntu-64/
Library Paths : [/home/tim/Tools/macaroni/macaroni-0.1.0.25-ubuntu-64/Libraries/home/tim/Macaroni/Libraries]
Generator Paths : [/home/tim/Tools/macaroni/macaroni-0.1.0.25-ubuntu-64/Generators]
LoadProjectEnvironment
Parsing file project.lua...
Running /home/tim/Tools/macaroni/macaroni-0.1.0.25-ubuntu-64/Libraries/Macaroni/Project-Lua/0/src/project-init.lua...
Running /home/tim/Macaroni/init.lua...
LoadProjectEnvironment
Parsing file /home/tim/Tools/macaroni/macaroni-0.1.0.25-ubuntu-64/Libraries/Macaroni/ProjectTemplates/1/project-final.lua...
Running /home/tim/Tools/macaroni/macaroni-0.1.0.25-ubuntu-64/Libraries/Macaroni/Project-Lua/0/src/project-init.lua...
Running /home/tim/Macaroni/init.lua...

Program finished.

$ ls -la target
total 24
drwxrwxr-x 2 tim tim 4096 Dec 12 00:07 .
drwxrwxr-x 4 tim tim 4096 Dec 12 00:07 ..
-rw-rw-r-- 1 tim tim 1329 Dec 12 00:07 Class1.cpp
-rw-rw-r-- 1 tim tim  366 Dec 12 00:07 Class1.h
-rw-rw-r-- 1 tim tim 1329 Dec 12 00:07 Class2.cpp
-rw-rw-r-- 1 tim tim  366 Dec 12 00:07 Class2.h
$ cat target/Class1.h
#ifndef MACARONI_COMPILE_GUARD_Class1_H
#define MACARONI_COMPILE_GUARD_Class1_H

// This class was originally defined in Example.mcpp
// Forward declaration necessary for anything which also depend on this.
class Class1;

// Define class Class1
class  Class1
{
	public    : Class1();

}; // End of class Class1

#endif // end of MACARONI_COMPILE_GUARD_Class1_H

Hurray! You've now used Macaroni. If all you're interested in is getting rid of the duplication between header and implementation files, then you're good.

Hopefully I'll soon find time to write more blog posts soon detailing how to use Macaroni to do other things such as build projects using Boost Build, write glue code for Lua, as well as some other entries explaining the ideas behind Macaroni for anyone who's interested in writing their own code generators.



Installing MinGW and Boost on Windows XP
Friday November 23, 2012 14:40:17

MinGW is the premiere free non-Microsoft compiler for Windows. Even if you're primarily using Microsoft's compiler, compiling with MinGW, which is based on GCC, can give you a great head start to making your code compile with Unix. Additionally, if you want to use C++11 features, you can forget about doing it from a Windows XP box using a Microsoft compiler. Their cool new tools will compile to Windows XP, but can only be used on Windows 7 and up.

Installing MinGW it is fall off a log simple, but as I'm doing it on my old netbook right now I thought I'd document the process.

First, visiti the getting started page on MinGW's official website and download and run mingw-get-inst (you'll see it linked in the first few steps). Select “Download the latest repository catalogues” during the installation. Keep the default directory of C:\MinGW (the short path and lack of spaces helps with some tools). You can also select various compilers during the graphical installer, but don't, to relish the wonderful experience of installing these components from the command line.

Now add “C:\MinGW\bin” to the path.

Now install the following:

mingw-get install gcc
mingw-get install g++
mingw-get install mingw32-make

Working with Boost

The best way to work with Boost is to download the code and compile the libraries yourself. It's not easy, but controlling it yourself can offer insight into how these libraries are created and an appreciation for how portable it is.

Boost uses a special tool called Boost Build. You can think of this as an extremely flexible Make- once you've created your build script, you can build multiple configurations. For example, you can create a release version using Microsoft Visual C++ by invoking Boost Build one way, and then create a debug version with Gcc by invoking it another. Given that so much of C++ (and C) centers around how you build your code, it's nice that Boost Build abstracts this decision away from you until the end.

When you compile Boost itself, you need to be aware though that some options aren't configurable. One is whether or not you use the C++11 extensions for Gcc- Boost Build currently is not aware of this feature, so you need to remember it yourself. If you compile Boost for GCC without the C++11 flags set, it won't work with anything you compile using the C++ flags. So however you choose to use GCC, be consistent!

I recommend you use the GNU extensions because it works a little better with the Boost libraries. This involves passing the argument “-std=gnu++11” to the gcc compiler.

Building Boost

Download Boost from the official site. I have a program for all my tools, which I creatively named “C:\Tools”. Under this, I have a directory named “Boost”, and under that there's directories for every version of Boost I've downloaded.

I'm downloading Boost 1.52, so it's going to live in C:\Tools\Boost\boost_1_52_0.

Set the environment variable BOOST_ROOT to this path (again, ]I use a batch file to set up all these environment variables to avoid polluting the path). That's because Boost Build needs to have this set to work properly.

Now, in a command prompt enter that directory and type the following:

bootstrap.bat gcc
b2 --toolset=gcc cxxflags=-std=gnu++11 --build-type=complete stage cxxflags="-include cmath "

Again, gnu++11 is to make sure you build Boost with the C++11 features plus certain Gnu compiler extensions for maximum compatibility with Boost. The “-include cmath” works around a current issue building parts of Boost Python.

At this point go defrost a turkey because building Boost takes forever.

Once it's finished, congratulations! You can now take advantage of Boost in your programs.



Ken's ending from Street Fighter II as seen on Amiga
Monday November 5, 2012 03:25:21

This version of Street Fighter was understandably missing a few things, but the sprite work for Ken's fiance Lisa had to have been done by one of the developers as a joke (skip to 18:17).



Introducing Macaroni for C++
Monday October 1, 2012 00:28:20

It's with great pride and trepidation that I announce a project I've been working on for the past four years.

It's finally reached the point where I think it might be usable to people other than myself, so without further adieu I present “Macaroni for C++,” a sort of compiler for C++ that attempts to make working with C++ easier and more enjoyable.

Find out more here.





<---2013-01-02 03:01:23 history 2012-09-30 17:53:21--->



-All material © 2007 Tim Simpson unless otherwise noted-