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.sh, so
each compiles as a small translation unit with a much lower memory peak.
The default build is unchanged: it still compiles the amalgamated
mongoose.c.
tools/unamalgam.sh is a POSIX sh + awk implementation (no Python): it
needs only sh and awk, which the Linux/embedded hosts this option targets
have out of the box (e.g. via busybox). It splits on the amalgamation's
#ifdef MG_MODULE_LINES / #line markers, restores the
/* Amalgamated: #include */ lines, and applies 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
The generated tree is byte-identical to the reference splitter's output
(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 (GCC/Linux, sh=dash): both modes build and pass the full ctest
suite (15/15, including the HTTP/WS API tests); ON mode compiles the
split modules and not mongoose.c; and GET / is byte-identical between the
two binaries. The generator runs clean under dash (strict POSIX).
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>