Commit a23a4605 authored by Sam Ravnborg's avatar Sam Ravnborg

kbuild: Consolidated cc support function

Added three function to top-level Makefile:
cc-option (replacing check_gcc)
cc-option-yn (as cc-option but return y or n)
cc-version (numeric version of $(CC))
Documentation added to Documentation/kbuild/makefiles.txt

The check_gcc version is still present, but now spit out a arning if used.
The new naming where chosen to get consistent naming of all three functions
Signed-off-by: default avatarSam Ravnborg <sam@ravnborg.org>
parent f9a71d16
......@@ -37,6 +37,8 @@ This document describes the Linux kernel Makefiles.
--- 6.5 Building non-kbuild targets
--- 6.6 Commands useful for building a boot image
--- 6.7 Custom kbuild commands
--- 6.8 Preprocessing linker scripts
--- 6.9 $(CC) support functions
=== 7 Kbuild Variables
=== 8 Makefile language
......@@ -969,6 +971,59 @@ When kbuild executes the following steps are followed (roughly):
architecture specific files.
--- 6.9 $(CC) support functions
The kernel may be build with several different versions of
$(CC), each supporting a unique set of features and options.
kbuild provide basic support to check for valid options for $(CC).
$(CC) is useally the gcc compiler, but other alternatives are
available.
cc-option
cc-option is used to check if $(CC) support a given option, and not
supported to use an optional second option.
Example:
#arch/i386/Makefile
cflags-y += $(call cc-option,-march=pentium-mmx,-march=i586)
In the above example cflags-y will be assigned the option
-march=pentium-mmx if supported by $(CC), otherwise -march-i586.
The second argument to cc-option is optional, and if omitted
cflags-y will be assigned no value if first option is not supported.
cc-option-yn
cc-option-yn is used to check if gcc supports a given option
and return 'y' if supported, otherwise 'n'.
Example:
#arch/ppc/Makefile
biarch := $(call cc-option-yn, -m32)
aflags-$(biarch) += -a32
cflags-$(biarch) += -m32
In the above example $(biarch) is set to y if $(CC) supports the -m32
option. When $(biarch) equals to y the expanded variables $(aflags-y)
and $(cflags-y) will be assigned the values -a32 and -m32.
cc-version
cc-version return a numerical version of the $(CC) compiler version.
The format is <major><minor> where both are two digits. So for example
gcc 3.41 would return 0341.
cc-version is useful when a specific $(CC) version is faulty in one
area, for example the -mregparm=3 were broken in some gcc version
even though the option was accepted by gcc.
Example:
#arch/i386/Makefile
GCC_VERSION := $(call cc-version)
cflags-y += $(shell \
if [ $(GCC_VERSION) -ge 0300 ] ; then echo "-mregparm=3"; fi ;)
In the above example -mregparm=3 is only used for gcc version greater
than or equal to gcc 3.0.
=== 7 Kbuild Variables
The top Makefile exports the following variables:
......
......@@ -256,9 +256,32 @@ ifneq ($(findstring s,$(MAKEFLAGS)),)
quiet=silent_
endif
check_gcc = $(shell if $(CC) $(CFLAGS) $(1) -S -o /dev/null -xc /dev/null > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi ;)
export quiet Q KBUILD_VERBOSE
######
# cc support functions to be used (only) in arch/$(ARCH)/Makefile
# See documentation in Documentation/kbuild/makefiles.txt
# cc-option
# Usage: cflags-y += $(call gcc-option, -march=winchip-c6, -march=i586)
cc-option = $(shell if $(CC) $(CFLAGS) $(1) -S -o /dev/null -xc /dev/null \
> /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi ;)
# For backward compatibility
check_gcc = $(warning check_gcc is deprecated - use cc-option) \
$(call cc-option, $(1),$(2))
# cc-option-yn
# Usage: flag := $(call gcc-option-yn, -march=winchip-c6)
cc-option-yn = $(shell if $(CC) $(CFLAGS) $(1) -S -o /dev/null -xc /dev/null \
> /dev/null 2>&1; then echo "y"; else echo "n"; fi;)
# cc-version
# Usage gcc-ver := $(call cc-version $(CC))
cc-version = $(CONFIG_SHELL) $(srctree)/scripts/gcc-version.sh \
$(if $(1), $(1), $(CC))
export quiet Q KBUILD_VERBOSE check_gcc
# Look for make include files relative to root of kernel src
MAKEFLAGS += --include-dir=$(srctree)
......@@ -463,7 +486,7 @@ CFLAGS += -g
endif
# warn about C99 declaration after statement
CFLAGS += $(call check_gcc,-Wdeclaration-after-statement,)
CFLAGS += $(call cc-option,-Wdeclaration-after-statement,)
#
# INSTALL_PATH specifies where to place the updated kernel and system map
......
......@@ -23,43 +23,42 @@ CHECKFLAGS += -D__i386__=1
CFLAGS += -pipe -msoft-float
# prevent gcc from keeping the stack 16 byte aligned
CFLAGS += $(call check_gcc,-mpreferred-stack-boundary=2,)
align := $(subst -functions=0,,$(call check_gcc,-falign-functions=0,-malign-functions=0))
CFLAGS += $(call cc-option,-mpreferred-stack-boundary=2)
align := $(subst -functions=0,,$(call cc-option,-falign-functions=0,-malign-functions=0))
cflags-$(CONFIG_M386) += -march=i386
cflags-$(CONFIG_M486) += -march=i486
cflags-$(CONFIG_M586) += -march=i586
cflags-$(CONFIG_M586TSC) += -march=i586
cflags-$(CONFIG_M586MMX) += $(call check_gcc,-march=pentium-mmx,-march=i586)
cflags-$(CONFIG_M586MMX) += $(call cc-option,-march=pentium-mmx,-march=i586)
cflags-$(CONFIG_M686) += -march=i686
cflags-$(CONFIG_MPENTIUMII) += $(call check_gcc,-march=pentium2,-march=i686)
cflags-$(CONFIG_MPENTIUMIII) += $(call check_gcc,-march=pentium3,-march=i686)
cflags-$(CONFIG_MPENTIUMM) += $(call check_gcc,-march=pentium3,-march=i686)
cflags-$(CONFIG_MPENTIUM4) += $(call check_gcc,-march=pentium4,-march=i686)
cflags-$(CONFIG_MPENTIUMII) += $(call cc-option,-march=pentium2,-march=i686)
cflags-$(CONFIG_MPENTIUMIII) += $(call cc-option,-march=pentium3,-march=i686)
cflags-$(CONFIG_MPENTIUMM) += $(call cc-option,-march=pentium3,-march=i686)
cflags-$(CONFIG_MPENTIUM4) += $(call cc-option,-march=pentium4,-march=i686)
cflags-$(CONFIG_MK6) += -march=k6
# Please note, that patches that add -march=athlon-xp and friends are pointless.
# They make zero difference whatsosever to performance at this time.
cflags-$(CONFIG_MK7) += $(call check_gcc,-march=athlon,-march=i686 $(align)-functions=4)
cflags-$(CONFIG_MK8) += $(call check_gcc,-march=k8,$(call check_gcc,-march=athlon,-march=i686 $(align)-functions=4))
cflags-$(CONFIG_MK7) += $(call cc-option,-march=athlon,-march=i686 $(align)-functions=4)
cflags-$(CONFIG_MK8) += $(call cc-option,-march=k8,$(call cc-option,-march=athlon,-march=i686 $(align)-functions=4))
cflags-$(CONFIG_MCRUSOE) += -march=i686 $(align)-functions=0 $(align)-jumps=0 $(align)-loops=0
cflags-$(CONFIG_MWINCHIPC6) += $(call check_gcc,-march=winchip-c6,-march=i586)
cflags-$(CONFIG_MWINCHIP2) += $(call check_gcc,-march=winchip2,-march=i586)
cflags-$(CONFIG_MWINCHIP3D) += $(call check_gcc,-march=winchip2,-march=i586)
cflags-$(CONFIG_MCYRIXIII) += $(call check_gcc,-march=c3,-march=i486) $(align)-functions=0 $(align)-jumps=0 $(align)-loops=0
cflags-$(CONFIG_MVIAC3_2) += $(call check_gcc,-march=c3-2,-march=i686)
cflags-$(CONFIG_MWINCHIPC6) += $(call cc-option,-march=winchip-c6,-march=i586)
cflags-$(CONFIG_MWINCHIP2) += $(call cc-option,-march=winchip2,-march=i586)
cflags-$(CONFIG_MWINCHIP3D) += $(call cc-option,-march=winchip2,-march=i586)
cflags-$(CONFIG_MCYRIXIII) += $(call cc-option,-march=c3,-march=i486) $(align)-functions=0 $(align)-jumps=0 $(align)-loops=0
cflags-$(CONFIG_MVIAC3_2) += $(call cc-option,-march=c3-2,-march=i686)
# AMD Elan support
cflags-$(CONFIG_X86_ELAN) += -march=i486
# -mregparm=3 works ok on gcc-3.0 and later
#
GCC_VERSION := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-version.sh $(CC))
GCC_VERSION := $(call cc-version)
cflags-$(CONFIG_REGPARM) += $(shell if [ $(GCC_VERSION) -ge 0300 ] ; then echo "-mregparm=3"; fi ;)
# Disable unit-at-a-time mode, it makes gcc use a lot more stack
# due to the lack of sharing of stacklots.
CFLAGS += $(call check_gcc,-fno-unit-at-a-time,)
CFLAGS += $(call cc-option,-fno-unit-at-a-time)
CFLAGS += $(cflags-y)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment