Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add amalgamate scripts #7

Merged
merged 12 commits into from
Sep 3, 2023
2 changes: 2 additions & 0 deletions single_include/upa/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.cpp
*.h
12 changes: 12 additions & 0 deletions tools/amalgamate.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@echo off

REM the directory path of this file
set p=%~dp0

REM CD to repository root folder
%~d0
cd %p%..

REM Amalgamate
python tools/amalgamate/amalgamate.py -c tools/amalgamate/config-cpp.json -s . -p tools/amalgamate/config-cpp.prologue
python tools/amalgamate/amalgamate.py -c tools/amalgamate/config-h.json -s .
12 changes: 12 additions & 0 deletions tools/amalgamate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh

# the directory path of this file
# https://stackoverflow.com/q/59895
p="$(dirname "$0")"

# CD to repository root folder
cd $p/..

# Amalgamate
python3 tools/amalgamate/amalgamate.py -c tools/amalgamate/config-cpp.json -s . -p tools/amalgamate/config-cpp.prologue
python3 tools/amalgamate/amalgamate.py -c tools/amalgamate/config-h.json -s .
27 changes: 27 additions & 0 deletions tools/amalgamate/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
amalgamate.py - Amalgamate C source and header files
Copyright (c) 2012, Erik Edlund <[email protected]>

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

* Neither the name of Erik Edlund, nor the names of its contributors may
be used to endorse or promote products derived from this software without
specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
66 changes: 66 additions & 0 deletions tools/amalgamate/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@

# amalgamate.py - Amalgamate C source and header files

Origin: https://bitbucket.org/erikedlund/amalgamate

Mirror: https://github.com/edlund/amalgamate

`amalgamate.py` aims to make it easy to use SQLite-style C source and header
amalgamation in projects.

For more information, please refer to: http://sqlite.org/amalgamation.html

## Here be dragons

`amalgamate.py` is quite dumb, it only knows the bare minimum about C code
required in order to be able to handle trivial include directives. It can
produce weird results for unexpected code.

Things to be aware of:

`amalgamate.py` will not handle complex include directives correctly:

#define HEADER_PATH "path/to/header.h"
#include HEADER_PATH

In the above example, `path/to/header.h` will not be included in the
amalgamation (HEADER_PATH is never expanded).

`amalgamate.py` makes the assumption that each source and header file which
is not empty will end in a new-line character, which is not immediately
preceded by a backslash character (see 5.1.1.2p1.2 of ISO C99).

`amalgamate.py` should be usable with C++ code, but raw string literals from
C++11 will definitely cause problems:

R"delimiter(Terrible raw \ data " #include <sneaky.hpp>)delimiter"
R"delimiter(Terrible raw \ data " escaping)delimiter"

In the examples above, `amalgamate.py` will stop parsing the raw string literal
when it encounters the first quotation mark, which will produce unexpected
results.

## Installing amalgamate.py

Python v.2.7.0 or higher is required.

`amalgamate.py` can be tested and installed using the following commands:

./test.sh && sudo -k cp ./amalgamate.py /usr/local/bin/

## Using amalgamate.py

amalgamate.py [-v] -c path/to/config.json -s path/to/source/dir \
[-p path/to/prologue.(c|h)]

* The `-c, --config` option should specify the path to a JSON config file which
lists the source files, include paths and where to write the resulting
amalgamation. Have a look at `test/source.c.json` and `test/include.h.json`
to see two examples.

* The `-s, --source` option should specify the path to the source directory.
This is useful for supporting separate source and build directories.

* The `-p, --prologue` option should specify the path to a file which will be
added to the beginning of the amalgamation. It is optional.

Loading