i2c-tools: Enable cross compilation
Subsystems (2)
PATCH 1/1 i2c-tools: Enable cross compilation
Currently, the Makefile fails to change CC, AR, and STRIP variables from their default values[^1] because it uses the conditional variable assignment operator. The Makefile also doesn't allow for cross compilation without modification.
Modify the Makefile to use unconditional assignment and allow the user to cross compile the software via the CROSS_COMPILE variable.
[^1]: https://www.gnu.org/software/make/manual/html_node/Implicit-Variables.html
--- Makefile | 9 ++++++--- README | 3 +++ 2 files changed, 9 insertions(+), 3 deletions(-)
Makefile +6 -3
@@ -24,9 +24,12 @@ INSTALL_PROGRAM := $(INSTALL) -m 755 LN := ln -sf RM := rm -f -CC ?= gcc -AR ?= ar -STRIP ?= strip +# Use CROSS_COMPILE to specify the toolchain prefix. E.g. +# make CROSS_COMPILE=aarch64-linux-gnu- + +CC = $(CROSS_COMPILE)gcc +AR = $(CROSS_COMPILE)ar +STRIP = $(CROSS_COMPILE)strip CFLAGS ?= -O2 # When debugging, use the following instead
README +3 -0
@@ -80,6 +80,9 @@ If you want to compile the tools against the static version of the library you can do: $ make USE_STATIC_LIB=1 +To compile for another platform, use the CROSS_COMPILE toolchain prefix option: + $ make CROSS_COMPILE=aarch64-linux-gnu- + Optionally, you can run "make strip" prior to "make install" if you want smaller binaries. However, be aware that this will prevent any further attempt to debug the library and tools.
---
base-commit: 5852f5375eea6ca9dabf31f4772cb8b8ecc905d8
change-id: 20260706-cross-compile-36f904256481
Thanks!
Signature · 2 lines
Brigham Campbell https://brighamcampbell.com
Wolfram Sang
AppliedQuoted 11 lines · Brigham Campbell
Currently, the
Makefilefails to change CC, AR, and STRIP variables from their default values[^1] because it uses the conditional variable assignment operator. TheMakefilealso doesn't allow for cross compilation without modification.Modify the
Makefileto use unconditional assignment and allow the user to cross compile the software via theCROSS_COMPILEvariable.[^1]: https://www.gnu.org/software/make/manual/html_node/Implicit-Variables.html
Signed-off-by Brigham Campbell <[email protected]>
Applied, thanks!