Skip to content

Commit 910b404

Browse files
author
Sam Ravnborg
committed
kbuild: introduce cc-cross-prefix
cc-cross-prefix is useful for the architecture that like to provide a default CROSS_COMPILE value, but may have several to select between. Sample usage: ifneq ($(SUBARCH),$(ARCH)) ifeq ($(CROSS_COMPILE),) CROSS_COMPILE := $(call cc-cross-prefix, m68k-linux-gnu- m68k-linux-) endif endif Actual usage by the different archs will taken care of later. Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
1 parent 50a8ec3 commit 910b404

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

‎Documentation/kbuild/makefiles.txt‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,28 @@ more details, with real examples.
518518
In this example for a specific GCC version the build will error out explaining
519519
to the user why it stops.
520520

521+
cc-cross-prefix
522+
cc-cross-prefix is used to check if there exist a $(CC) in path with
523+
one of the listed prefixes. The first prefix where there exist a
524+
prefix$(CC) in the PATH is returned - and if no prefix$(CC) is found
525+
then nothing is returned.
526+
Additional prefixes are separated by a single space in the
527+
call of cc-cross-prefix.
528+
This functionality is usefull for architecture Makefile that try
529+
to set CROSS_COMPILE to well know values but may have several
530+
values to select between.
531+
It is recommended only to try to set CROSS_COMPILE is it is a cross
532+
build (host arch is different from target arch). And is CROSS_COMPILE
533+
is already set then leave it with the old value.
534+
535+
Example:
536+
#arch/m68k/Makefile
537+
ifneq ($(SUBARCH),$(ARCH))
538+
ifeq ($(CROSS_COMPILE),)
539+
CROSS_COMPILE := $(call cc-cross-prefix, m68k-linux-gnu-)
540+
endif
541+
endif
542+
521543
=== 4 Host Program support
522544

523545
Kbuild supports building executables on the host for use during the

‎scripts/Kbuild.include‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,17 @@ endef
5656
# gcc support functions
5757
# See documentation in Documentation/kbuild/makefiles.txt
5858

59+
# cc-cross-prefix
60+
# Usage: CROSS_COMPILE := $(call cc-cross-prefix, m68k-linux-gnu- m68k-linux-)
61+
# Return first prefix where a prefix$(CC) is found in PATH.
62+
# If no $(CC) found in PATH with listed prefixes return nothing
63+
cc-cross-prefix = \
64+
$(word 1, $(foreach c,$(1), \
65+
$(shell set -e; \
66+
if (which $(strip $(c))$(CC)) > /dev/null 2>&1 ; then \
67+
echo $(c); \
68+
fi)))
69+
5970
# output directory for tests below
6071
TMPOUT := $(if $(KBUILD_EXTMOD),$(firstword $(KBUILD_EXTMOD))/)
6172

0 commit comments

Comments
 (0)