[make] miscellaneous make system tweaks

-Have arch set the default optimization level. Most will use
 O2, but arm-m sets to Os.
-Make the link time garbage collection be optional. Only set
 for arm-m.
This commit is contained in:
Travis Geiselbrecht
2014-03-22 21:03:03 -07:00
parent 450de308e6
commit f21ad5d749
5 changed files with 30 additions and 14 deletions

View File

@@ -128,6 +128,8 @@ MODULE_ARM_OVERRIDE_SRCS := \
GLOBAL_DEFINES += \
ARCH_DEFAULT_STACK_SIZE=4096
ARCH_OPTFLAGS := -O2
endif
ifeq ($(SUBARCH),arm-m)
MODULE_SRCS += \
@@ -140,8 +142,12 @@ MODULE_SRCS += \
GLOBAL_INCLUDES += \
$(LOCAL_DIR)/arm-m/CMSIS/Include
# we're building for small binaries
GLOBAL_DEFINES += \
ARCH_DEFAULT_STACK_SIZE=1024
ARCH_OPTFLAGS := -Os
WITH_LINKER_GC := 1
endif
# try to find the toolchain
@@ -196,9 +202,6 @@ $(error missing MEMBASE or MEMSIZE variable, please set in target rules.mk)
endif
LIBGCC := $(shell $(TOOLCHAIN_PREFIX)gcc $(GLOBAL_COMPILEFLAGS) $(THUMBCFLAGS) -print-libgcc-file-name)
$(info LIBGCC = $(LIBGCC))
$(info GLOBAL_COMPILEFLAGS = $(GLOBAL_COMPILEFLAGS) $(THUMBCFLAGS))
# potentially generated files that should be cleaned out with clean make rule
GENERATED += \

View File

@@ -28,6 +28,8 @@ MODULE_SRCS += \
GLOBAL_DEFINES += \
ARCH_DEFAULT_STACK_SIZE=8192
ARCH_OPTFLAGS := -O2
# try to find the toolchain
ifndef TOOLCHAIN_PREFIX
TOOLCHAIN_PREFIX := aarch64-elf-
@@ -51,9 +53,7 @@ ifeq ($(MEMVARS_SET),0)
$(error missing MEMBASE or MEMSIZE variable, please set in target rules.mk)
endif
LIBGCC := $(shell $(TOOLCHAIN_PREFIX)gcc $(GLOBAL_COMPILEFLAGS) $(THUMBCFLAGS) -print-libgcc-file-name)
$(info LIBGCC = $(LIBGCC))
$(info GLOBAL_COMPILEFLAGS = $(GLOBAL_COMPILEFLAGS) $(THUMBCFLAGS))
LIBGCC := $(shell $(TOOLCHAIN_PREFIX)gcc $(GLOBAL_COMPILEFLAGS) -print-libgcc-file-name)
# potentially generated files that should be cleaned out with clean make rule
GENERATED += \

View File

@@ -32,6 +32,8 @@ GLOBAL_CFLAGS += $(call cc-option,$(CC),-fno-stack-protector,)
GLOBAL_COMPILEFLAGS += -fasynchronous-unwind-tables
GLOBAL_COMPILEFLAGS += -gdwarf-2
ARCH_OPTFLAGS := -O2
# potentially generated files that should be cleaned out with clean make rule
GENERATED += \
$(BUILDDIR)/kernel.ld

View File

@@ -44,7 +44,7 @@ OUTELF := $(BUILDDIR)/lk.elf
CONFIGHEADER := $(BUILDDIR)/config.h
GLOBAL_INCLUDES := $(BUILDDIR) $(LKROOT)/include $(addsuffix /include,$(LKINC))
GLOBAL_OPTFLAGS ?= -Os
GLOBAL_OPTFLAGS ?= $(ARCH_OPTFLAGS)
GLOBAL_COMPILEFLAGS := -g -fno-builtin -finline -W -Wall -Wno-multichar -Wno-unused-parameter -Wno-unused-function -include $(CONFIGHEADER)
GLOBAL_CFLAGS := --std=gnu99 -Werror-implicit-function-declaration -Wstrict-prototypes
#GLOBAL_CFLAGS += -Werror
@@ -53,8 +53,6 @@ GLOBAL_CPPFLAGS := -fno-exceptions -fno-rtti -fno-threadsafe-statics
GLOBAL_ASMFLAGS := -DASSEMBLY
GLOBAL_LDFLAGS :=
GLOBAL_COMPILEFLAGS += -ffunction-sections -fdata-sections
GLOBAL_LDFLAGS += --gc-sections
GLOBAL_LDFLAGS += -L $(LKROOT)
# top level rule
@@ -100,6 +98,12 @@ EXTRA_OBJS :=
# if someone defines this, the build id will be pulled into lib/version
BUILDID ?=
# if this is set to 1, use ld's garbage collector for unused functions and data
WITH_LINKER_GC ?= 0
# comment out or override if you want to see the full output of each command
NOECHO ?= @
# try to include the project file
-include project/$(PROJECT).mk
ifndef TARGET
@@ -172,6 +176,9 @@ CPPFILT := $(TOOLCHAIN_PREFIX)c++filt
SIZE := $(TOOLCHAIN_PREFIX)size
NM := $(TOOLCHAIN_PREFIX)nm
# the logic to compile and link stuff is in here
include make/build.mk
# put all of the global build flags in config.h to force a rebuild if any change
GLOBAL_DEFINES += GLOBAL_INCLUDES=\"$(subst $(SPACE),_,$(GLOBAL_INCLUDES))\"
GLOBAL_DEFINES += GLOBAL_COMPILEFLAGS=\"$(subst $(SPACE),_,$(GLOBAL_COMPILEFLAGS))\"
@@ -181,9 +188,6 @@ GLOBAL_DEFINES += GLOBAL_CPPFLAGS=\"$(subst $(SPACE),_,$(GLOBAL_CPPFLAGS))\"
GLOBAL_DEFINES += GLOBAL_ASMFLAGS=\"$(subst $(SPACE),_,$(GLOBAL_ASMFLAGS))\"
GLOBAL_DEFINES += GLOBAL_LDFLAGS=\"$(subst $(SPACE),_,$(GLOBAL_LDFLAGS))\"
# comment out or override if you want to see the full output of each command
NOECHO ?= @
ifneq ($(OBJS),)
$(warning OBJS=$(OBJS))
$(error OBJS is not empty, please convert to new module format)
@@ -201,8 +205,9 @@ $(warning CPPFLAGS=$(CPPFLAGS))
$(error CPPFLAGS is not empty, please use GLOBAL_CPPFLAGS or MODULE_CPPFLAGS)
endif
# the logic to compile and link stuff is in here
include make/build.mk
$(info LIBGCC = $(LIBGCC))
$(info GLOBAL_COMPILEFLAGS = $(GLOBAL_COMPILEFLAGS))
$(info GLOBAL_OPTFLAGS = $(GLOBAL_OPTFLAGS))
# make all object files depend on any targets in GLOBAL_SRCDEPS
$(ALLOBJS): $(GLOBAL_SRCDEPS)

View File

@@ -1,3 +1,9 @@
# use linker garbage collection, if requested
ifeq ($(WITH_LINKER_GC),1)
GLOBAL_COMPILEFLAGS += -ffunction-sections -fdata-sections
GLOBAL_LDFLAGS += --gc-sections
endif
$(OUTBIN): $(OUTELF)
@echo generating image: $@
$(NOECHO)$(SIZE) $<