Skip to content

configure: fix cross-compilation best practices#3183

Merged
IvanNardi merged 4 commits into
ntop:devfrom
IvanNardi:fix/cross-compilation
May 26, 2026
Merged

configure: fix cross-compilation best practices#3183
IvanNardi merged 4 commits into
ntop:devfrom
IvanNardi:fix/cross-compilation

Conversation

@IvanNardi

Copy link
Copy Markdown
Collaborator
  • Move Darwin clang/clang++ preference (: ${CC:=clang}) before AC_PROG_CC so the hint actually takes effect; previously it ran after CC was already chosen.
  • Remove global AC_LANG_WERROR; it caused false-negative feature checks with strict cross-compilers.
  • Add cross-compilation warning block (fires when build != host) that alerts the user when PKG_CONFIG_SYSROOT_DIR / PKG_CONFIG_LIBDIR are unset and when build-host paths (Homebrew, DPDK, PCAP_HOME+PF_RING) may not apply to the target.
  • Guard Homebrew include/lib injection with test "$cross_compiling" != yes so it is skipped when cross-compiling from a macOS host.
  • Make pfring_config execution conditional on the binary being present and executable (guards against absent or target-arch binary).
  • Save and restore PKG_CONFIG_PATH around the custom libpcap pkg-config lookup to prevent it leaking into subsequent checks; also quote $PKG_CONFIG in the shell interpolation.
  • Quote previously unquoted variables in test expressions: $OS_TYPE, $HOMEBREW_DIR, $HOME/DPDK, $PCAP_HOME.
  • Replace BSD-only date -r FILE with stat -c/stat -f fallback chain that works on both GNU/Linux and macOS.

Also add utils/cross-compile-test.sh: a self-contained script that exercises the cross-compilation path on Ubuntu x86-64 targeting AArch64 (aarch64-linux-gnu). Supports a fast --library-only mode and a --full mode that installs arm64 multiarch dev libraries, configures with PKG_CONFIG_SYSROOT_DIR, builds examples and unit tests, and runs ndpiReader -H under QEMU user-mode emulation to verify the resulting binary executes correctly on the build host.

IvanNardi and others added 4 commits May 25, 2026 19:08
- Move Darwin clang/clang++ preference (`: ${CC:=clang}`) before
  AC_PROG_CC so the hint actually takes effect; previously it ran after
  CC was already chosen.
- Remove global AC_LANG_WERROR; it caused false-negative feature checks
  with strict cross-compilers.
- Add cross-compilation warning block (fires when build != host) that
  alerts the user when PKG_CONFIG_SYSROOT_DIR / PKG_CONFIG_LIBDIR are
  unset and when build-host paths (Homebrew, DPDK, PCAP_HOME+PF_RING)
  may not apply to the target.
- Guard Homebrew include/lib injection with `test "$cross_compiling" != yes`
  so it is skipped when cross-compiling from a macOS host.
- Make pfring_config execution conditional on the binary being present
  and executable (guards against absent or target-arch binary).
- Save and restore PKG_CONFIG_PATH around the custom libpcap pkg-config
  lookup to prevent it leaking into subsequent checks; also quote
  $PKG_CONFIG in the shell interpolation.
- Quote previously unquoted variables in test expressions: $OS_TYPE,
  $HOMEBREW_DIR, $HOME/DPDK, $PCAP_HOME.
- Replace BSD-only `date -r FILE` with `stat -c`/`stat -f` fallback
  chain that works on both GNU/Linux and macOS.

Also add utils/cross-compile-test.sh: a self-contained script that
exercises the cross-compilation path on Ubuntu x86-64 targeting
AArch64 (aarch64-linux-gnu).  Supports a fast --library-only mode and
a --full mode that installs arm64 multiarch dev libraries, configures
with PKG_CONFIG_SYSROOT_DIR, builds examples and unit tests, and runs
ndpiReader -H under QEMU user-mode emulation to verify the resulting
binary executes correctly on the build host.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Move AC_CANONICAL_HOST before PKG_PROG_PKG_CONFIG so the source-level
ordering matches the required expansion order (PKG_PROG_PKG_CONFIG uses
AC_PATH_TOOL which requires AC_CANONICAL_HOST).

Remove AC_PROG_CPP_WERROR: it makes all AC_CHECK_HEADERS calls use
-Werror on the preprocessor, which can produce false negatives when
cross-compiling with a stricter cross-compiler. Same rationale as the
earlier removal of AC_LANG_WERROR.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@sonarqubecloud

Copy link
Copy Markdown

@IvanNardi IvanNardi merged commit 6dcb262 into ntop:dev May 26, 2026
36 of 46 checks passed
@IvanNardi IvanNardi deleted the fix/cross-compilation branch May 26, 2026 08:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant