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