Linux I2C development
 help / color / mirror / Atom feed
* [PATCH] i2c-tools: Enable cross compilation
@ 2026-07-06  8:02 Brigham Campbell
  2026-07-07 20:25 ` Wolfram Sang
  0 siblings, 1 reply; 2+ messages in thread
From: Brigham Campbell @ 2026-07-06  8:02 UTC (permalink / raw)
  To: linux-i2c, Jean Delvare; +Cc: Wolfram Sang, Brigham Campbell

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

Signed-off-by: Brigham Campbell <me@brighamcampbell.com>
---
 Makefile | 9 ++++++---
 README   | 3 +++
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/Makefile b/Makefile
index a0d4269..2a51485 100644
--- a/Makefile
+++ b/Makefile
@@ -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
diff --git a/README b/README
index 502132f..1c83561 100644
--- a/README
+++ b/README
@@ -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!
-- 
Brigham Campbell
https://brighamcampbell.com


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-07-07 20:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-06  8:02 [PATCH] i2c-tools: Enable cross compilation Brigham Campbell
2026-07-07 20:25 ` Wolfram Sang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox