| 1 | # amalgamate.py - Amalgamate C source and header files |
| 2 | |
| 3 | Origin: https://bitbucket.org/erikedlund/amalgamate |
| 4 | |
| 5 | Mirror: https://github.com/edlund/amalgamate |
| 6 | |
| 7 | `amalgamate.py` aims to make it easy to use SQLite-style C source and header |
| 8 | amalgamation in projects. |
| 9 | |
| 10 | For more information, please refer to: http://sqlite.org/amalgamation.html |
| 11 | |
| 12 | ## Here be dragons |
| 13 | |
| 14 | `amalgamate.py` is quite dumb, it only knows the bare minimum about C code |
| 15 | required in order to be able to handle trivial include directives. It can |
| 16 | produce weird results for unexpected code. |
| 17 | |
| 18 | Things to be aware of: |
| 19 | |
| 20 | `amalgamate.py` will not handle complex include directives correctly: |
| 21 | |
| 22 | #define HEADER_PATH "path/to/header.h" |
| 23 | #include HEADER_PATH |
| 24 | |
| 25 | In the above example, `path/to/header.h` will not be included in the |
| 26 | amalgamation (HEADER_PATH is never expanded). |
| 27 | |
| 28 | `amalgamate.py` makes the assumption that each source and header file which |
| 29 | is not empty will end in a new-line character, which is not immediately |
| 30 | preceded by a backslash character (see 5.1.1.2p1.2 of ISO C99). |
| 31 | |
| 32 | `amalgamate.py` should be usable with C++ code, but raw string literals from |
| 33 | C++11 will definitely cause problems: |
| 34 | |
| 35 | R"delimiter(Terrible raw \ data " #include <sneaky.hpp>)delimiter" |
| 36 | R"delimiter(Terrible raw \ data " escaping)delimiter" |
| 37 | |
| 38 | In the examples above, `amalgamate.py` will stop parsing the raw string literal |
| 39 | when it encounters the first quotation mark, which will produce unexpected |
| 40 | results. |
| 41 | |
| 42 | ## Installing amalgamate.py |
| 43 | |
| 44 | Python v.2.7.0 or higher is required. |
| 45 | |
| 46 | `amalgamate.py` can be tested and installed using the following commands: |
| 47 | |
| 48 | ./test.sh && sudo -k cp ./amalgamate.py /usr/local/bin/ |
| 49 | |
| 50 | ## Using amalgamate.py |
| 51 | |
| 52 | amalgamate.py [-v] -c path/to/config.json -s path/to/source/dir \ |
| 53 | [-p path/to/prologue.(c|h)] |
| 54 | |
| 55 | * The `-c, --config` option should specify the path to a JSON config file which |
| 56 | lists the source files, include paths and where to write the resulting |
| 57 | amalgamation. Have a look at `test/source.c.json` and `test/include.h.json` |
| 58 | to see two examples. |
| 59 | |
| 60 | * The `-s, --source` option should specify the path to the source directory. |
| 61 | This is useful for supporting separate source and build directories. |
| 62 | |
| 63 | * The `-p, --prologue` option should specify the path to a file which will be |
| 64 | added to the beginning of the amalgamation. It is optional. |
| 65 |