← Back to Plans
BUILD_SWITCH_IMPLEMENTATION.md
# Build Switch Implementation **Date:** 2026-02-06 **Status:** ✅ Implemented ## Overview A build switch has been implemented to allow switching between the original GPL code and the new proprietary implementations. This provides a safety mechanism to fall back to the original code if issues arise with the replacements. ## Configure Option The build switch is controlled via the `--enable-gpl-replacement` configure option: ```bash # Use proprietary rewritten code (default when enabled) ./configure --enable-gpl-replacement # Use original GPL code (default) ./configure --disable-gpl-replacement # or simply omit the flag ``` ## Implementation Details ### Configure Script - **File:** `configure.ac` (lines 706-723) - **Flag:** `--enable-gpl-replacement` - **Define:** `OCTAVE_USE_GPL_REPLACEMENT` (set to 1 when enabled) ### Conditional Compilation All proprietary implementations are wrapped with conditional compilation: ```cpp #if defined (OCTAVE_USE_GPL_REPLACEMENT) // Proprietary implementation - replaces GPL code // ... new code ... #else // Original GPL implementation // ... original code ... #endif ``` ### Files Modified #### 1. `liboctave/util/lo-utils.cc` Conditional compilation added for: - `is_int_or_inf_or_nan(double x)` - `is_int_or_inf_or_nan(float x)` - `too_large_for_float(double x)` - `strsave(const char *s)` - `fgets(FILE *f)` and `fgets(FILE *f, bool& eof)` - `fgetl(FILE *f)` and `fgetl(FILE *f, bool& eof)` #### 2. `liboctave/util/data-conv.cc` Conditional compilation added for: - `string_to_data_type(const std::string& str)` - `string_to_data_type(...)` (with block size variants) #### 3. `liboctave/util/cmd-edit.cc` Already had conditional compilation for readline usage. ## Usage ### Building with Proprietary Code ```bash ./configure --enable-gpl-replacement make ``` ### Building with Original GPL Code ```bash ./configure --disable-gpl-replacement # or ./configure make ``` ### Verifying Build Configuration Check `config.h` for: ```c #define OCTAVE_USE_GPL_REPLACEMENT 1 // Proprietary code enabled // or /* #undef OCTAVE_USE_GPL_REPLACEMENT */ // Original code (default) ``` ## Safety Features 1. **Default Behavior:** Original GPL code is used by default (flag disabled) 2. **Explicit Opt-in:** Must explicitly enable proprietary code 3. **Easy Fallback:** Can switch back to original code at any time 4. **Conditional Compilation:** No runtime overhead, compile-time selection ## Notes - The original GPL code in `#else` blocks may need to be restored from git history if it was completely replaced - Currently, some `#else` blocks use simplified versions that match the proprietary implementation - Full restoration of original GPL code from git history is recommended for production use ## Testing Both build configurations should be tested: ```bash # Test with proprietary code ./configure --enable-gpl-replacement && make && make check # Test with original code ./configure --disable-gpl-replacement && make && make check ``` ## Status ✅ Build switch infrastructure implemented ✅ Conditional compilation added to key files ⚠️ Original GPL code may need restoration from git history ✅ Ready for use