Back to home page

OSCL-LXR

 
 

    


0001 # SPDX-License-Identifier: GPL-2.0-only
0002 
0003 # cc-cross-prefix
0004 # Usage: CROSS_COMPILE := $(call cc-cross-prefix, m68k-linux-gnu- m68k-linux-)
0005 # Return first <prefix> where a <prefix>gcc is found in PATH.
0006 # If no gcc found in PATH with listed prefixes return nothing
0007 #
0008 # Note: '2>/dev/null' is here to force Make to invoke a shell. Otherwise, it
0009 # would try to directly execute the shell builtin 'command'. This workaround
0010 # should be kept for a long time since this issue was fixed only after the
0011 # GNU Make 4.2.1 release.
0012 cc-cross-prefix = $(firstword $(foreach c, $(1), \
0013                         $(if $(shell command -v -- $(c)gcc 2>/dev/null), $(c))))
0014 
0015 # output directory for tests below
0016 TMPOUT = $(if $(KBUILD_EXTMOD),$(firstword $(KBUILD_EXTMOD))/).tmp_$$$$
0017 
0018 # try-run
0019 # Usage: option = $(call try-run, $(CC)...-o "$$TMP",option-ok,otherwise)
0020 # Exit code chooses option. "$$TMP" serves as a temporary file and is
0021 # automatically cleaned up.
0022 try-run = $(shell set -e;               \
0023         TMP=$(TMPOUT)/tmp;              \
0024         trap "rm -rf $(TMPOUT)" EXIT;   \
0025         mkdir -p $(TMPOUT);             \
0026         if ($(1)) >/dev/null 2>&1;      \
0027         then echo "$(2)";               \
0028         else echo "$(3)";               \
0029         fi)
0030 
0031 # as-option
0032 # Usage: cflags-y += $(call as-option,-Wa$(comma)-isa=foo,)
0033 
0034 as-option = $(call try-run,\
0035         $(CC) $(KBUILD_CFLAGS) $(1) -c -x assembler /dev/null -o "$$TMP",$(1),$(2))
0036 
0037 # as-instr
0038 # Usage: cflags-y += $(call as-instr,instr,option1,option2)
0039 
0040 as-instr = $(call try-run,\
0041         printf "%b\n" "$(1)" | $(CC) $(KBUILD_AFLAGS) -c -x assembler -o "$$TMP" -,$(2),$(3))
0042 
0043 # __cc-option
0044 # Usage: MY_CFLAGS += $(call __cc-option,$(CC),$(MY_CFLAGS),-march=winchip-c6,-march=i586)
0045 __cc-option = $(call try-run,\
0046         $(1) -Werror $(2) $(3) -c -x c /dev/null -o "$$TMP",$(3),$(4))
0047 
0048 # cc-option
0049 # Usage: cflags-y += $(call cc-option,-march=winchip-c6,-march=i586)
0050 
0051 cc-option = $(call __cc-option, $(CC),\
0052         $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS),$(1),$(2))
0053 
0054 # cc-option-yn
0055 # Usage: flag := $(call cc-option-yn,-march=winchip-c6)
0056 cc-option-yn = $(call try-run,\
0057         $(CC) -Werror $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(1) -c -x c /dev/null -o "$$TMP",y,n)
0058 
0059 # cc-disable-warning
0060 # Usage: cflags-y += $(call cc-disable-warning,unused-but-set-variable)
0061 cc-disable-warning = $(call try-run,\
0062         $(CC) -Werror $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) -W$(strip $(1)) -c -x c /dev/null -o "$$TMP",-Wno-$(strip $(1)))
0063 
0064 # cc-ifversion
0065 # Usage:  EXTRA_CFLAGS += $(call cc-ifversion, -lt, 0402, -O1)
0066 cc-ifversion = $(shell [ $(CONFIG_GCC_VERSION)0 $(1) $(2)000 ] && echo $(3) || echo $(4))
0067 
0068 # ld-option
0069 # Usage: KBUILD_LDFLAGS += $(call ld-option, -X, -Y)
0070 ld-option = $(call try-run, $(LD) $(KBUILD_LDFLAGS) $(1) -v,$(1),$(2),$(3))
0071 
0072 # ld-ifversion
0073 # Usage:  $(call ld-ifversion, -ge, 22252, y)
0074 ld-ifversion = $(shell [ $(CONFIG_LD_VERSION)0 $(1) $(2)0 ] && echo $(3) || echo $(4))