Table of Contents
By far the simplest way to generate makefiles using Bakefile is to use so-called presets which are prepared skeletons of bakefiles that get you started quickly. Let's see how it works on an example of the famous Hello, world program written in C and implemented in hello.c file. Here is how our bakefile would look like:
<?xml version="1.0"?> <bakefile> <include file="presets/simple.bkl"/> <exe id="hello" template="simple"> <sources>hello.c</sources> </exe> </bakefile>
Presets are included by means of using the include command to include file named presets/NAME-OF-PRESET.bkl. In general, you can combine several presents, but in practice you must be careful when doing so and it's always good idea to check what the preset does in its code. The "simple" preset we include here defines a DEBUG option and a template simple. Generated makefiles will allow the user to build all targets that are based on this template as either debug or release build.
Let's generate some makefiles now. The bakefile command is used to do it. For example:
$ bakefile -f msvc hello.bkl
That's all. This will creates VC++ makefile makefile.vc. Of course, you can change the name of output file if you don't like the default:
$ bakefile -f msvc -o makefile hello.bkl
It's more complicated when using the Autoconf format. Autoconf uses Makefile.in files that are templates for makefiles and configure.in script that checks if the system has all required libraries and software installed. Bakefile is makefiles generator, it takes care of creating Makefile.ins, but configure.in remains your responsibility (except for a few things that Bakefile generates).
Autoconf format generates more than one file -- in addition to Makefile.in there's also file called autoconf_inc.m4 which must be included in configure.in to ensure proper function of Bakefile-generated makefiles. This is done by the AC_BAKEFILE macro. A minimal configure.in script for our example program would look like this:
AC_PREREQ(2.53) AC_INIT(aclocal.m4) AC_CANONICAL_SYSTEM DEBUG=0 AC_BAKEFILE([m4_include(autoconf_inc.m4)]) AC_OUTPUT([Makefile])
Note the part that sets DEBUG variable. If you use options in your bakefile (as you do when you use the simple preset), you must set their values before calling AC_BAKEFILE. Debug build is always disabled in the example above, proper handling would be a little more complicated:
AC_PREREQ(2.53) AC_INIT(aclocal.m4) AC_CANONICAL_SYSTEM AC_ARG_ENABLE(debug, [ --enable-debug Enable debugging information], USE_DEBUG="$enableval", USE_DEBUG="no") if test $USE_DEBUG = yes ; then DEBUG=1 dnl Bakefile doesn't touch {C,CPP,CXX,LD}FLAGS in autoconf format, we dnl have to do it ourselves. (Incorrectly) assuming GCC here: CFLAGS="$CFLAGS -g" else DEBUG=0 fi AC_BAKEFILE([m4_include(autoconf_inc.m4)]) AC_OUTPUT([Makefile])