From e3ac0907df20da5331e095623a8a477c380d3140 Mon Sep 17 00:00:00 2001 From: Anas Nashif Date: Sun, 23 Aug 2015 11:22:40 -0400 Subject: [PATCH] Move scripts/Makefile.preparch to arch/ Follow the model of the Linux kernel for adding arch specific CFLAGS by using the Makefile and Kbuild combination in the 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 --- Makefile | 20 ++++++++++--------- arch/arc/Kbuild | 8 ++++++++ arch/arc/Makefile | 13 ++++++------ arch/arm/Kbuild | 4 ++++ arch/arm/Makefile | 23 +++++++++++++++++++--- arch/x86/Kbuild | 3 +++ arch/x86/Makefile | 37 ++++++++++++++++++++++++++++++++--- scripts/Makefile.arc.preparch | 6 ------ scripts/Makefile.arm.preparch | 18 ----------------- scripts/Makefile.x86.preparch | 37 ----------------------------------- 10 files changed, 87 insertions(+), 82 deletions(-) create mode 100644 arch/arc/Kbuild create mode 100644 arch/arm/Kbuild create mode 100644 arch/x86/Kbuild delete mode 100644 scripts/Makefile.arc.preparch delete mode 100644 scripts/Makefile.arm.preparch delete mode 100644 scripts/Makefile.x86.preparch diff --git a/Makefile b/Makefile index 624a0255fd0..d44c149e699 100644 --- a/Makefile +++ b/Makefile @@ -12,10 +12,12 @@ export SOURCE_DIR PROJECT MDEF_FILE KLIBC_DIR # More info can be located in ./README # Comments in this file are targeted only to the developer, do not # expect to learn how to build the kernel reading this file. +# -# Do not use make's built-in rules and variables -# (this increases performance and avoids hard-to-debug behaviour); -MAKEFLAGS += -rR +# o Do not use make's built-in rules and variables +# (this increases performance and avoids hard-to-debug behaviour); +# o Look for make include files relative to root of kernel src +MAKEFLAGS += -rR --include-dir=$(CURDIR) # Avoid funny character set dependencies unexport LC_ALL @@ -561,9 +563,10 @@ include/config/auto.conf: ; 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 -sinclude $(srctree)/scripts/Makefile.$(SRCARCH).preparch + + ifdef ZEPHYR_GCC_VARIANT include $(srctree)/scripts/Makefile.toolchain.$(ZEPHYR_GCC_VARIANT) else @@ -589,6 +592,8 @@ QEMU = $(QEMU_BIN_PATH)/$(QEMU_$(SRCARCH)) # Defaults to zephyr, but the arch makefile usually adds further targets all: zephyr +include arch/$(SRCARCH)/Makefile + ifdef CONFIG_READABLE_ASM # Disable optimizations that make assembler listings hard to read. # 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) endif -ISA_FLAG=$(ISA_FLAG_$(SRCARCH)) - STACK_CANARIES_FLAG_y = $(call cc-option,-fstack-protector-all,) STACK_CANARIES_FLAG_ = $(call cc-option,-fno-stack-protector,) 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) KBUILD_CFLAGS += $(SSE_FP_MATH_FLAG) \ - $(ISA_FLAG) \ $(STACK_CANARIES_FLAG) \ $(ARCHFLAGS) @@ -661,7 +663,7 @@ KBUILD_CFLAGS += $(call cc-option, -femit-struct-debug-baseonly) \ $(call cc-option,-fno-var-tracking) endif KBUILD_CFLAGS += $(CFLAGS) -KBUILD_AFLAGS += $(ARCHFLAGS) $(ISA_FLAG) +KBUILD_AFLAGS += $(ARCHFLAGS) KBUILD_AFLAGS += $(CFLAGS) ifdef CONFIG_FUNCTION_TRACER diff --git a/arch/arc/Kbuild b/arch/arc/Kbuild new file mode 100644 index 00000000000..2c33a78404a --- /dev/null +++ b/arch/arc/Kbuild @@ -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 diff --git a/arch/arc/Makefile b/arch/arc/Makefile index 2c33a78404a..4f7c94cf90f 100644 --- a/arch/arc/Makefile +++ b/arch/arc/Makefile @@ -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 \ - reset.o \ - vector_table.o +KBUILD_CFLAGS += $(call cc-option,-ffunction-sections,) $(call cc-option,-fdata-sections,) +cflags-$(CONFIG_LTO) = $(call cc-option,-flto,) +cflags-$(CPU_ARCEM4) = $(call cc-option,-mARCv2EM) \ + $(call cc-option,-mav2em,$(call cc-option,-mno-sdata)) + +KBUILD_CFLAGS += $(cflags-y) + diff --git a/arch/arm/Kbuild b/arch/arm/Kbuild new file mode 100644 index 00000000000..8f12275bac1 --- /dev/null +++ b/arch/arm/Kbuild @@ -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/ diff --git a/arch/arm/Makefile b/arch/arm/Makefile index 8f12275bac1..933a6899480 100644 --- a/arch/arm/Makefile +++ b/arch/arm/Makefile @@ -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 diff --git a/arch/x86/Kbuild b/arch/x86/Kbuild new file mode 100644 index 00000000000..a6cdde263af --- /dev/null +++ b/arch/x86/Kbuild @@ -0,0 +1,3 @@ +obj-y += core/ +obj-$(CONFIG_PLATFORM_IA32_PCI) += platforms/ia32_pci/ +obj-$(CONFIG_PLATFORM_IA32) += platforms/ia32/ diff --git a/arch/x86/Makefile b/arch/x86/Makefile index a6cdde263af..18726c4fd74 100644 --- a/arch/x86/Makefile +++ b/arch/x86/Makefile @@ -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 diff --git a/scripts/Makefile.arc.preparch b/scripts/Makefile.arc.preparch deleted file mode 100644 index 5f925a25f91..00000000000 --- a/scripts/Makefile.arc.preparch +++ /dev/null @@ -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 diff --git a/scripts/Makefile.arm.preparch b/scripts/Makefile.arm.preparch deleted file mode 100644 index ec76e589518..00000000000 --- a/scripts/Makefile.arm.preparch +++ /dev/null @@ -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 diff --git a/scripts/Makefile.x86.preparch b/scripts/Makefile.x86.preparch deleted file mode 100644 index a00bec8493d..00000000000 --- a/scripts/Makefile.x86.preparch +++ /dev/null @@ -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