automaker - Automatically create Makefiles for C projects
automaker is designed to automatically generate Makefile
s for C projects. The idea is that you declare dependencies explicitly in your source files, then run automaker
, and your Makefile
will be created.
For example, given a source file greeter.c
, to produce a Makefile
that will produce the greeter
executable along with any dependencies, run:
Here’s how it works: automaker
opens greeter.c
and looks for a comment section of the following format:
/*
%use io_getline;
%use io_put;
%use io_putline;
*/
The above would mean greeter
needs to be linked with io_getline.o
, io_put.o
, io_putline
and any dependencies that come along with them (as defined in io_getline.c
, io_put.c
, and io_putline.c
). (A completely flat file structure is expected: automaker
is meant for small(ish) C projects.) Each file (with a .o
suffix) would be added to greeter
’s Makefile
entry, along with any more dependencies generated after checking the file (with a .c
suffix) for any of its dependencies, recursively. It then outputs a fully functioning Makefile
capable of building greeter
.
You may supply more than one main source file. For example:
The above constructs a Makefile that creates executables myprog1
, myprog2
, and myprog3
, linking them with all necessary dependencies.
To give a more complete example, the source code for greeter.c
might look like:
Then, to produce the Makefile
necessary to build test, run:
This will produce the following Makefile
:
The code is on GitHub and, like most of my work, is public domain.