Skip to contentSkip to conversation

i2c-tools: Enable cross compilation

PATCH Applied Brigham Campbell 2 participants 2 messages Jul 6 – Jul 7

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

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
index a0d4269..2a51485 100644
@@ -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
index 502132f..1c83561 100644
@@ -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
Applied
#1 lore raw
Quoted 11 lines · 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

Applied, thanks!