https://github.com/cjhdev/sea_pool
A tool for combining many C and/or C++ files into one file
https://github.com/cjhdev/sea_pool
Last synced: 4 months ago
JSON representation
A tool for combining many C and/or C++ files into one file
- Host: GitHub
- URL: https://github.com/cjhdev/sea_pool
- Owner: cjhdev
- Created: 2024-02-17T14:34:38.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2024-11-24T18:22:55.000Z (over 1 year ago)
- Last Synced: 2025-01-21T03:42:34.137Z (over 1 year ago)
- Language: Ruby
- Size: 8.79 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
SeaPool
=======
A tool for combining many C and/or C++ files into one file.
~~~ ruby
SeaPool.new do |a|
# these files will be combined into output
a.add_input 'src/input1.cpp'
a.add_input 'src/input2.cpp'
a.add_input 'src/sub/input3.cpp'
a.add_input 'src/input4.cpp', 'src/input5.cpp', 'src/input6.cpp'
# search for files here (e.g. #include "some_file.cpp")
a.add_include 'include'
a.add_include 'src'
a.add_include 'src/sub'
a.add_include 'src/another1', 'src/another2'
# search for system files here (e.g. #include )
a.add_system_include '/opt/somearch/include'
a.add_system_include '/opt/somearch2/include', '/opt/somearch3/include'
# never expand these files
a.add_ignore 'include/to_be_ignored.h'
a.add_ignore 'include/another_to_be_ignored1.h', 'include/another_to_be_ignored2.h'
# the combined output file (can only be one file)
a.set_output 'combined.cpp'
).run
~~~
Or, a shorter version of the same example in the terminal:
~~~ bash
bundle exec sea_pool --include=include --system=/opt/somearch/include --ignore=include/to_be_ignored.h --output=combined.cpp src/input1.cpp src/input2.cpp
~~~
## Features
- expands `#include`
- `#include""` if a file is found in the `include` search path
- `#include<>` if a file is found in the `system_include` search path
- will not expand an `#include` if
- no match is found in the search path
- a match is found in the exclude list
- non-exluded match has already been expanded
- comments out `#include` which have already been expanded (also a limitation)
- inserts `#file` into output so that compile time messages can be referenced back to the original files
- non-recursive and line based
- depends only on Ruby stdlib (should work with your system Ruby)
- available as standalone executable via bin/sea_pool_exporter
## Limitations
- does not evaluate include guards or `#pragma once`
- does not support including same file multiple times (workaround for the above)
- does not interpret preprocessor variables
- input files must be written in a way that makes them suitable for amalgamation
- ensure no file static name collisions
- ensure no 'using namespace' in c++
- it's a preprocessor, it won't check if your code can compile
- lines that are not UTF-8 are passed through to output without any processing
- doesn't consider if a file is a link
## Exporting Standalone Executable
~~~ bash
bundle exec sea_pool_exporter > your_executable_file
~~~
or
~~~ bash
bundle exec sea_pool_exporter --output=your_executable_file
~~~
This file can be kept with your project.
## The Future
- might evaluate guards
- might expand other macros
- might fix file static name problems
## Hints
- Don't combine C and C++ into the same file unless you want to compile C with a C++ compiler
- ensure file static preprocessor macros are `#undef` at end of a file
## Why?
- sometimes fewer source files can make a project easier to distribute
- sometimes fewer source files will speed up compile time (Arduino + GNU tools ported to Windows!)