A perl script that creates a single C source file containing all files
that are #include
d via C preprocessor directives.
E.g. SQLite uses an amalgamated source file for easier distribution and more effective optimization.
Run amalgc --help
for usage information.
There has been interest in the Lua mailing list about a version of Lua, which is distributed as a single C source file. LHF, one of Lua's creators, posted a file that can be used to create such an amalgamated source file.
- Download the referenced file as
one.c
and put it into thesrc
directory of Lua's source code. - Run
amalgc -i . -l -o amalglua.c one.c
to create a fileamalglua.c
which includes all the sources for the Lua library, the standalone interpreter, and theluac
bytecode compiler. - Use the appropriate compiler incantation to compile the file. (E.g. to compile the standalone interpreter on my Linux box I use):
gcc -O2 -Wall -DLUA_COMPAT_ALL -DLUA_USE_LINUX -o amalglua amalglua.c -Wl,-E -lm -ldl -lreadline
The heuristic used to create the amalgamated source file is not perfect. In particular, it will fail for conditional inclusion of source files, like e.g.:
#ifdef SOME_DEFINE
#include "file.h"
#endif
/* ... */
#include "file.h"
The first #include
will be replaced by the file contents, the second
will just be ignored, so the resulting source file will only compile
if SOME_DEFINE
is #define
d.
Copyright (C) 2011 Philipp Janda
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License (see
below), or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.