Skip to content

Commit

Permalink
Makefile: move more flags to the top Makefile
Browse files Browse the repository at this point in the history
Before this commit, most of compiler flags were defined in config.mk.
But it is redundant because config.mk is included from all recursive make.

This commit moves many complier flags to the top Makefile
and export them.
And we use new vaiarables to store them:
KBUILD_CPPFLAGS, KBUILD_CFLAGS, KBUILD_AFLAGS.
This will allow us to switch more smoothly to Kbuild.

Signed-off-by: Masahiro Yamada <[email protected]>
  • Loading branch information
masahir0y authored and trini committed Feb 19, 2014
1 parent bf4b3de commit 2b3c9d3
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 37 deletions.
35 changes: 35 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,46 @@ CHECK = sparse
CHECKFLAGS := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ \
-Wbitwise -Wno-return-void -D__CHECK_ENDIAN__ $(CF)

KBUILD_CPPFLAGS := -D__KERNEL__

KBUILD_CFLAGS := -Wall -Wstrict-prototypes \
-Wno-format-security \
-fno-builtin -ffreestanding
KBUILD_AFLAGS := -D__ASSEMBLY__

export CONFIG_SHELL HOSTCC HOSTCFLAGS HOSTLDFLAGS CROSS_COMPILE AS LD CC
export CPP AR NM LDR STRIP OBJCOPY OBJDUMP
export MAKE AWK
export DTC CHECK CHECKFLAGS

export KBUILD_CPPFLAGS
export KBUILD_CFLAGS KBUILD_AFLAGS

KBUILD_CFLAGS += -Os #-fomit-frame-pointer

ifdef BUILD_TAG
KBUILD_CFLAGS += -DBUILD_TAG='"$(BUILD_TAG)"'
endif

KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)

KBUILD_CFLAGS += -g
# $(KBUILD_AFLAGS) sets -g, which causes gcc to pass a suitable -g<format>
# option to the assembler.
KBUILD_AFLAGS += -g

# Report stack usage if supported
KBUILD_CFLAGS += $(call cc-option,-fstack-usage)

KBUILD_CFLAGS += $(call cc-option,-Wno-format-nonliteral)

# turn jbsr into jsr for m68k
ifeq ($(ARCH),m68k)
ifeq ($(findstring 3.4,$(shell $(CC) --version)),3.4)
KBUILD_AFLAGS += -Wa,-gstabs,-S
endif
endif

# load other configuration
include $(TOPDIR)/config.mk

Expand Down
41 changes: 4 additions & 37 deletions config.mk
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,13 @@ endif

#########################################################################

# We don't actually use $(ARFLAGS) anywhere anymore, so catch people
# who are porting old code to latest mainline but not updating $(AR).
ARFLAGS = $(error update your Makefile to use cmd_link_o_target and not AR)
RELFLAGS= $(PLATFORM_RELFLAGS)
DBGFLAGS= -g # -DDEBUG
OPTFLAGS= -Os #-fomit-frame-pointer

OBJCFLAGS += --gap-fill=0xff

gccincdir := $(shell $(CC) -print-file-name=include)

CPPFLAGS := $(DBGFLAGS) $(OPTFLAGS) $(RELFLAGS) \
-D__KERNEL__
CPPFLAGS = $(KBUILD_CPPFLAGS) $(RELFLAGS)

# Enable garbage collection of un-used sections for SPL
ifeq ($(CONFIG_SPL_BUILD),y)
Expand Down Expand Up @@ -134,26 +128,10 @@ CPPFLAGS += -I$(OBJTREE)/include
endif

CPPFLAGS += -I$(TOPDIR)/include -I$(SRCTREE)/arch/$(ARCH)/include
CPPFLAGS += -fno-builtin -ffreestanding -nostdinc \
CPPFLAGS += -nostdinc \
-isystem $(gccincdir) -pipe $(PLATFORM_CPPFLAGS)

CFLAGS := $(CPPFLAGS) -Wall -Wstrict-prototypes

ifdef BUILD_TAG
CFLAGS += -DBUILD_TAG='"$(BUILD_TAG)"'
endif

CFLAGS_SSP := $(call cc-option,-fno-stack-protector)
CFLAGS += $(CFLAGS_SSP)
# Some toolchains enable security related warning flags by default,
# but they don't make much sense in the u-boot world, so disable them.
CFLAGS_WARN := $(call cc-option,-Wno-format-nonliteral) \
$(call cc-option,-Wno-format-security)
CFLAGS += $(CFLAGS_WARN)

# Report stack usage if supported
CFLAGS_STACK := $(call cc-option,-fstack-usage)
CFLAGS += $(CFLAGS_STACK)
CFLAGS := $(KBUILD_CFLAGS) $(CPPFLAGS)

BCURDIR = $(subst $(SRCTREE)/,,$(CURDIR:$(obj)%=%))

Expand All @@ -165,18 +143,7 @@ endif
endif
endif

# $(CPPFLAGS) sets -g, which causes gcc to pass a suitable -g<format>
# option to the assembler.
AFLAGS_DEBUG :=

# turn jbsr into jsr for m68k
ifeq ($(ARCH),m68k)
ifeq ($(findstring 3.4,$(shell $(CC) --version)),3.4)
AFLAGS_DEBUG := -Wa,-gstabs,-S
endif
endif

AFLAGS := $(AFLAGS_DEBUG) -D__ASSEMBLY__ $(CPPFLAGS)
AFLAGS := $(KBUILD_AFLAGS) $(CPPFLAGS)

LDFLAGS += $(PLATFORM_LDFLAGS)
LDFLAGS_FINAL += -Bstatic
Expand Down

0 comments on commit 2b3c9d3

Please sign in to comment.