Move scripts/Makefile.<arch>preparch to arch/<arch>

Follow the model of the Linux kernel for adding arch
specific CFLAGS by using the Makefile and Kbuild combination
in the arch/<arch> directory.

This will also allow adding architecture specific targets and is
easy to maintain when alongside the architecture.

Change-Id: If51a78e8845baa71d9090c4a4f49fcd013354840
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
This commit is contained in:
Anas Nashif 2015-08-23 11:22:40 -04:00
commit e3ac0907df
10 changed files with 87 additions and 82 deletions

View file

@ -12,10 +12,12 @@ export SOURCE_DIR PROJECT MDEF_FILE KLIBC_DIR
# More info can be located in ./README # More info can be located in ./README
# Comments in this file are targeted only to the developer, do not # Comments in this file are targeted only to the developer, do not
# expect to learn how to build the kernel reading this file. # expect to learn how to build the kernel reading this file.
#
# Do not use make's built-in rules and variables # o Do not use make's built-in rules and variables
# (this increases performance and avoids hard-to-debug behaviour); # (this increases performance and avoids hard-to-debug behaviour);
MAKEFLAGS += -rR # o Look for make include files relative to root of kernel src
MAKEFLAGS += -rR --include-dir=$(CURDIR)
# Avoid funny character set dependencies # Avoid funny character set dependencies
unexport LC_ALL unexport LC_ALL
@ -561,9 +563,10 @@ include/config/auto.conf: ;
endif # $(dot-config) endif # $(dot-config)
#File that includes all prepare special embedded architecture targets. # File that includes all prepare special embedded architecture targets.
include $(srctree)/scripts/Makefile.preparch include $(srctree)/scripts/Makefile.preparch
sinclude $(srctree)/scripts/Makefile.$(SRCARCH).preparch
ifdef ZEPHYR_GCC_VARIANT ifdef ZEPHYR_GCC_VARIANT
include $(srctree)/scripts/Makefile.toolchain.$(ZEPHYR_GCC_VARIANT) include $(srctree)/scripts/Makefile.toolchain.$(ZEPHYR_GCC_VARIANT)
else else
@ -589,6 +592,8 @@ QEMU = $(QEMU_BIN_PATH)/$(QEMU_$(SRCARCH))
# Defaults to zephyr, but the arch makefile usually adds further targets # Defaults to zephyr, but the arch makefile usually adds further targets
all: zephyr all: zephyr
include arch/$(SRCARCH)/Makefile
ifdef CONFIG_READABLE_ASM ifdef CONFIG_READABLE_ASM
# Disable optimizations that make assembler listings hard to read. # Disable optimizations that make assembler listings hard to read.
# reorder blocks reorders the control in the function # reorder blocks reorders the control in the function
@ -599,8 +604,6 @@ KBUILD_CFLAGS += $(call cc-option,-fno-reorder-blocks,) \
$(call cc-option,-fno-partial-inlining) $(call cc-option,-fno-partial-inlining)
endif endif
ISA_FLAG=$(ISA_FLAG_$(SRCARCH))
STACK_CANARIES_FLAG_y = $(call cc-option,-fstack-protector-all,) STACK_CANARIES_FLAG_y = $(call cc-option,-fstack-protector-all,)
STACK_CANARIES_FLAG_ = $(call cc-option,-fno-stack-protector,) STACK_CANARIES_FLAG_ = $(call cc-option,-fno-stack-protector,)
STACK_CANARIES_FLAG = $(STACK_CANARIES_FLAG_$(CONFIG_STACK_CANARIES)) STACK_CANARIES_FLAG = $(STACK_CANARIES_FLAG_$(CONFIG_STACK_CANARIES))
@ -652,7 +655,6 @@ export x86_FLAGS arm_FLAGS arc_FLAGS LDFLAG_LINKERCMD OUTPUT_FORMAT OUTPUT_ARCH
ARCHFLAGS = $($(SRCARCH)_FLAGS) ARCHFLAGS = $($(SRCARCH)_FLAGS)
KBUILD_CFLAGS += $(SSE_FP_MATH_FLAG) \ KBUILD_CFLAGS += $(SSE_FP_MATH_FLAG) \
$(ISA_FLAG) \
$(STACK_CANARIES_FLAG) \ $(STACK_CANARIES_FLAG) \
$(ARCHFLAGS) $(ARCHFLAGS)
@ -661,7 +663,7 @@ KBUILD_CFLAGS += $(call cc-option, -femit-struct-debug-baseonly) \
$(call cc-option,-fno-var-tracking) $(call cc-option,-fno-var-tracking)
endif endif
KBUILD_CFLAGS += $(CFLAGS) KBUILD_CFLAGS += $(CFLAGS)
KBUILD_AFLAGS += $(ARCHFLAGS) $(ISA_FLAG) KBUILD_AFLAGS += $(ARCHFLAGS)
KBUILD_AFLAGS += $(CFLAGS) KBUILD_AFLAGS += $(CFLAGS)
ifdef CONFIG_FUNCTION_TRACER ifdef CONFIG_FUNCTION_TRACER

8
arch/arc/Kbuild Normal file
View file

@ -0,0 +1,8 @@
ccflags-y +=-I$(srctree)/arch/arc/platforms/$(strip $(CONFIG_PLATFORM))
asflags-y +=-I$(srctree)/arch/arc/platforms/$(strip $(CONFIG_PLATFORM))
obj-y = core/
obj-y += prep_c.o \
reset.o \
vector_table.o

View file

@ -1,8 +1,9 @@
ccflags-y +=-I$(srctree)/arch/arc/platforms/$(strip $(CONFIG_PLATFORM))
asflags-y +=-I$(srctree)/arch/arc/platforms/$(strip $(CONFIG_PLATFORM))
obj-y = core/
obj-y += prep_c.o \ KBUILD_CFLAGS += $(call cc-option,-ffunction-sections,) $(call cc-option,-fdata-sections,)
reset.o \ cflags-$(CONFIG_LTO) = $(call cc-option,-flto,)
vector_table.o cflags-$(CPU_ARCEM4) = $(call cc-option,-mARCv2EM) \
$(call cc-option,-mav2em,$(call cc-option,-mno-sdata))
KBUILD_CFLAGS += $(cflags-y)

4
arch/arm/Kbuild Normal file
View file

@ -0,0 +1,4 @@
obj-y = core/
obj-$(CONFIG_PLATFORM_FSL_FRDM_K64F) += platforms/fsl_frdm_k64f/
obj-$(CONFIG_PLATFORM_TI_LM3S6965) += platforms/ti_lm3s6965/

View file

@ -1,4 +1,21 @@
obj-y = core/
obj-$(CONFIG_PLATFORM_FSL_FRDM_K64F) += platforms/fsl_frdm_k64f/
obj-$(CONFIG_PLATFORM_TI_LM3S6965) += platforms/ti_lm3s6965/ KBUILD_CFLAGS += $(call cc-option,-ffunction-sections,) $(call cc-option,-fdata-sections,)
arch-$(CONFIG_CPU_CORTEX_M3) += $(call cc-option,-mthumb -mcpu=cortex-m3) \
$(call cc-option,-mthumb -march=armv7-m)
arch-$(CONFIG_CPU_CORTEX_M4) += $(call cc-option,-mthumb -mcpu=cortex-m4) \
$(call cc-option,-mthumb -march=armv7e-m)
cflags-$(CONFIG_LTO) = $(call cc-option,-flto,)
KBUILD_CFLAGS += $(cflags-y) $(arch-y)
KBUILD_AFLAGS += $(arch-y)
QEMU_CPU_TYPE_arm = cortex-m3
QEMU_FLAGS_arm = -cpu $(QEMU_CPU_TYPE_arm) \
-machine lm3s6965evb -nographic
QEMU_arm = qemu-system-arm
export QEMU_FLAGS_arm QEMU_arm

3
arch/x86/Kbuild Normal file
View file

@ -0,0 +1,3 @@
obj-y += core/
obj-$(CONFIG_PLATFORM_IA32_PCI) += platforms/ia32_pci/
obj-$(CONFIG_PLATFORM_IA32) += platforms/ia32/

View file

@ -1,3 +1,34 @@
obj-y += core/
obj-$(CONFIG_PLATFORM_IA32_PCI) += platforms/ia32_pci/
obj-$(CONFIG_PLATFORM_IA32) += platforms/ia32/ PERF_OPT=$(if $(filter -Os,$(KBUILD_CFLAGS)),,y)
cflags-y += $(call cc-option,-ffunction-sections,) $(call cc-option,-fdata-sections,)
cflags-$(PERF_OPT) += $(call cc-option,-mpreferred-stack-boundary=2)
cflags-$(PERF_OPT) += -DPERF_OPT
cflags-$(CONFIG_LTO) += $(call cc-option,-flto,)
ifneq ($(CONFIG_PLATFORM_IA32_PCI),y)
iSSE_FP_MATH_ = -mno-sse
iSSE_FP_MATH = ${iSSE_FP_MATH_${CONFIG_SSE_FP_MATH}}
endif
cflags-y += $(iSSE_FP_MATH)
arch-$(CONFIG_CPU_ATOM) += $(call cc-option,-march=atom) \
$(call cc-option,-mtune=atom,$(call cc-option,-mtune=generic))
arch-$(CONFIG_CPU_MINUTEIA) += $(call cc-option,-march=pentium)
KBUILD_CFLAGS += $(cflags-y) $(arch-y)
KBUILD_AFLAGS += $(arch-y)
QEMU_BIOS ?= /usr/share/qemu
QEMU_CPU_TYPE_x86 = qemu32
QEMU_FLAGS_x86 = -m 32 -cpu $(QEMU_CPU_TYPE_x86) \
-no-reboot -nographic -display none -net none \
-clock dynticks -no-acpi -balloon none \
-L $(QEMU_BIOS) -bios bios.bin \
-machine type=pc-0.14
QEMU_x86 = qemu-system-i386
export QEMU_FLAGS_x86 QEMU_x86 QEMU_CPU_TYPE_x86

View file

@ -1,6 +0,0 @@
LTO_FLAG-y = $(call cc-option,-flto,)
SECTION_GC_FLAG = $(call cc-option,-ffunction-sections,) $(call cc-option,-fdata-sections,)
arc_FLAGS += -mARCv2EM -mav2em -mno-sdata
export ISA_FLAG_arc

View file

@ -1,18 +0,0 @@
LTO_FLAG-y = $(call cc-option,-flto,)
SECTION_GC_FLAG = $(call cc-option,-ffunction-sections,) $(call cc-option,-fdata-sections,)
arm_FLAGS = $(call cc-option,-mthumb,)
ifeq ($(CONFIG_CPU_CORTEX_M3),y)
arm_FLAGS += -mcpu=cortex-m3 -march=armv7-m
endif
ifeq ($(CONFIG_CPU_CORTEX_M4),y)
arm_FLAGS += -mcpu=cortex-m4 -march=armv7e-m
endif
arm_FLAGS += $(SECTION_GC_FLAG)
arm_FLAGS += $(LTO_FLAG-$(CONFIG_LTO))
QEMU_CPU_TYPE_arm = cortex-m3
QEMU_FLAGS_arm = -cpu $(QEMU_CPU_TYPE_arm) \
-machine lm3s6965evb -nographic
QEMU_arm = qemu-system-arm
export QEMU_FLAGS_arm QEMU_arm

View file

@ -1,37 +0,0 @@
PERF_OPT_FLAG-y = -DPERF_OPT
ALIGN_STACK_FLAG- = -mpreferred-stack-boundary=2
SECTION_GC_FLAG = $(call cc-option,-ffunction-sections,) $(call cc-option,-fdata-sections,)
LTO_FLAG-y = $(call cc-option,-flto,)
PERF_OPT=$(if $(filter -Os,$(KBUILD_CFLAGS)),,y)
PERF_OPT_FLAG = $(PERF_OPT_FLAG-$(PERF_OPT))
ALIGN_STACK_FLAG = $(ALIGN_STACK_FLAG-$(PERF_OPT))
LTO_FLAG = $(LTO_FLAG-$(CONFIG_LTO))
ifneq ($(CONFIG_PLATFORM_IA32_PCI),y)
iSSE_FP_MATH_ ?= -mno-sse
iSSE_FP_MATH ?= ${iSSE_FP_MATH_${CONFIG_SSE_FP_MATH}}
endif
x86_FLAGS += $(ALIGN_STACK_FLAG)
x86_FLAGS += $(SECTION_GC_FLAG)
x86_FLAGS += $(LTO_FLAG)
x86_FLAGS += $(LTO_FLAG)
x86_FLAGS += $(PERF_OPT_FLAG)
x86_FLAGS += $(iSSE_FP_MATH)
ISA_FLAG_quark-$(CONFIG_CPU_MINUTEIA) = -march=pentium
ISA_FLAG_atom-$(CONFIG_CPU_ATOM) = -march=atom -mtune=atom
ISA_FLAG_x86 = $(strip $(ISA_FLAG_quark-y) $(ISA_FLAG_atom-y))
QEMU_BIOS ?= /usr/share/qemu
QEMU_CPU_TYPE_x86 = qemu32
QEMU_FLAGS_x86 = -m 32 -cpu $(QEMU_CPU_TYPE_x86) \
-no-reboot -nographic -display none -net none \
-clock dynticks -no-acpi -balloon none \
-L $(QEMU_BIOS) -bios bios.bin \
-machine type=pc-0.14
QEMU_x86 = qemu-system-i386
export ISA_FLAG_x86 QEMU_FLAGS_x86 QEMU_x86 QEMU_CPU_TYPE_x86