mirror of
https://github.com/merbanan/rtl_433.git
synced 2026-07-30 18:17:45 -04:00
The vendored Mongoose 6.16 ships as one amalgamated src/mongoose.c
(~16k lines); compiling it with optimization needs a lot of RAM, and on
small machines the compiler can die building mongoose.c with an
out-of-memory error ("virtual memory exhausted", "cc1: out of memory").
Add an opt-in CMake option, ENABLE_COMPILE_LOW_MEMORY (default OFF),
that re-splits mongoose.c + include/mongoose.h back into their ~30
original modules at configure time via the new tools/unamalgam.py, so
each compiles as a small translation unit with a much lower memory peak.
The option name and help text mention "memory" and "mongoose.c" so it is
discoverable when that error is hit. The default build is unchanged: it
still compiles the amalgamated mongoose.c and needs no Python.
tools/unamalgam.py is a Python 3 port of Cesanta's own un-amalgamation
tool (splits on the #ifdef MG_MODULE_LINES / #line markers and restores
the /* Amalgamated: #include */ lines), plus the deterministic
adaptations rtl_433 needs to build the pieces as separate translation
units instead of one:
- an umbrella mongoose.h including the module headers in amalgamation
order, defining MG_INTERNAL empty for cross-TU linkage
- #include "mongoose.h" prepended to each module for its feature macros
- mg_uri.c + the mg_http*.c files combined into one TU
(mg_http_modules.c) as they share file-static state
- cross-TU prototypes, the feature-header includes before their guards,
the SSL backends' mg_internal.h include, and the moved MSG_NOSIGNAL
Generated output was verified byte-identical (bar one comment) to a
hand-split tree that was itself validated against upstream 6.16.
src/CMakeLists.txt is purely additive: mongoose.c stays in the
maintainer_update.py-generated r_433 source list; when the option is ON,
mongoose.c is excluded from compilation (HEADER_FILE_ONLY) and the
generated modules are added via target_sources. Generated modules land
in the build tree, so the source tree and the default build are
untouched. Mongoose 6.16 is end-of-life upstream, so the input is frozen.
Verified: both modes build and pass the full ctest suite (15/15,
including the HTTP/WS API tests); the split objects export the same
globals as the amalgamated object (plus the former MG_INTERNAL statics);
and GET / is byte-identical between the two binaries.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>