Add KBOOT.

This commit is contained in:
László Monda
2016-08-10 01:45:15 +02:00
commit e6c1fce5b4
9392 changed files with 3751375 additions and 0 deletions

149
mk/common.mk Normal file
View File

@@ -0,0 +1,149 @@
#-------------------------------------------------------------------------------
# Copyright (c) 2012 Freescale Semiconductor, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# o Redistributions of source code must retain the above copyright notice, this list
# of conditions and the following disclaimer.
#
# o Redistributions in binary form must reproduce the above copyright notice, this
# list of conditions and the following disclaimer in the documentation and/or
# other materials provided with the distribution.
#
# o Neither the name of Freescale Semiconductor, Inc. nor the names of its
# contributors may be used to endorse or promote products derived from this
# software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# Utility
#-------------------------------------------------------------------------------
# Kludge to create a variable equal to a single space.
empty :=
space := $(empty) $(empty)
#-------------------------------------------------------------------------------
# OS
#-------------------------------------------------------------------------------
# Get the OS name. Known values are "Linux", "CYGWIN_NT-5.1", and "Darwin".
os_name := $(shell uname -s)
# Set to 1 if running on cygwin.
is_cygwin := $(and $(findstring CYGWIN,$(os_name)),1)
# Set to 1 if running on cygwin.
is_mingw := $(and $(findstring MINGW,$(os_name)),1)
# Set to 1 if running on redhat.
is_redhat := $(shell if [ -f /etc/redhat-release ]; then echo 1 ; fi)
# Disable parallel builds for cygwin since they hang.
ifeq "$(is_cygwin)" "1"
.NOTPARALLEL:
endif
ifeq "$(is_mingw)" "1"
.NOTPARALLEL:
endif
#-------------------------------------------------------------------------------
# Logging options
#-------------------------------------------------------------------------------
# Enable color output by default.
BUILD_SDK_COLOR ?= 1
# MAKE
MAKE := make
ifeq "$(is_cygwin)" "1"
MAKE := mingw32-make
endif
ifeq "$(is_mingw)" "1"
MAKE := mingw32-make
endif
# Normally, commands in recipes are prefixed with '@' so the command itself
# is not echoed by make. But if VERBOSE is defined (set to anything non-empty),
# then the '@' is removed from recipes. The 'at' variable is used to control
# this. Similarly, 'silent_make' is used to pass the -s option to child make
# invocations when not in VERBOSE mode.
ifeq "$(VERBOSE)" "1"
at :=
silent_make :=
else
at := @
silent_make := -s
endif
# These colors must be printed with the printf command. echo won't handle the
# escape sequences.
color_default = \033[00m
color_bold = \033[01m
color_red = \033[31m
color_green = \033[32m
color_yellow = \033[33m
color_blue = \033[34m
color_magenta = \033[35m
color_cyan = \033[36m
color_orange = \033[38;5;172m
color_light_blue = \033[38;5;039m
color_gray = \033[38;5;008m
color_purple = \033[38;5;097m
ifeq "$(BUILD_SDK_COLOR)" "1"
color_build := $(color_light_blue)
color_c := $(color_green)
color_cxx := $(color_green)
color_cpp := $(color_orange)
color_asm := $(color_magenta)
color_ar := $(color_yellow)
color_link := $(color_purple)
endif
# Used in printmessage if the color args are not present.
color_ :=
# Use in recipes to print color messages if printing to a terminal. If
# BUILD_SDK_COLOR is not set to 1, this reverts to a simple uncolorized printf.
# A newline is added to the end of the printed message.
#
# Arguments:
# 1 - name of the color variable (see above), minus the "color_" prefix
# 2 - first colorized part of the message
# 3 - first uncolorized part of the message
# 4 - color name for second colorized message
# 5 - second colorized message
# 6 - second uncolorized part of the message
# 7 - uncolorized prefix on the whole line; this is last because it is expected to be used rarely
#
# All arguments are optional.
#
# Use like:
# $(call printmessage,cyan,Building, remainder of the message...)
ifeq "$(BUILD_SDK_COLOR)" "1"
define printmessage
if [ -t 1 ]; then printf "$(7)$(color_$(1))$(2)$(color_default)$(3)$(color_$(4))$(5)$(color_default)$(6)\n" ; \
else printf "$(7)$(2)$(3)$(5)$(6)\n" ; fi
endef
else
define printmessage
printf "$(7)$(2)$(3)$(5)$(6)\n" ; fi
endef
endif

62
mk/config.mk Normal file
View File

@@ -0,0 +1,62 @@
#-------------------------------------------------------------------------------
# Copyright (c) 2012 Freescale Semiconductor, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# o Redistributions of source code must retain the above copyright notice, this list
# of conditions and the following disclaimer.
#
# o Redistributions in binary form must reproduce the above copyright notice, this
# list of conditions and the following disclaimer in the documentation and/or
# other materials provided with the distribution.
#
# o Neither the name of Freescale Semiconductor, Inc. nor the names of its
# contributors may be used to endorse or promote products derived from this
# software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# Target and board configuration
#-------------------------------------------------------------------------------
# Chip
ifeq "$(CHIP)" "K70F12"
CPU = cortex-m4
ARCH = armv7e-m
DEFINES += -DCPU_MK70FN1M0VMJ12
else ifeq "$(CHIP)" "K64F12"
CPU = cortex-m4
ARCH = armv7e-m
DEFINES += -DCPU_MK64FN1M0VMD12
else ifeq "$(CHIP)" "K22F51212"
CPU = cortex-m4
ARCH = armv7e-m
DEFINES += -DCPU_MK22FN512VDC12
else ifeq "$(CHIP)" "KL25Z4"
CPU = cortex-m0plus
ARCH = armv6-m
DEFINES += -DCPU_MKL25Z128VLK4
else ifdef TARGET
$(error Unknown target $(TARGET))
endif
# Not debug by default
ifeq "$(build)" "debug"
DEBUG := 1
else
DEBUG := 0
endif

143
mk/flags.mk Normal file
View File

@@ -0,0 +1,143 @@
#-------------------------------------------------------------------------------
# Copyright (c) 2012 Freescale Semiconductor, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# o Redistributions of source code must retain the above copyright notice, this list
# of conditions and the following disclaimer.
#
# o Redistributions in binary form must reproduce the above copyright notice, this
# list of conditions and the following disclaimer in the documentation and/or
# other materials provided with the distribution.
#
# o Neither the name of Freescale Semiconductor, Inc. nor the names of its
# contributors may be used to endorse or promote products derived from this
# software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# Compiler flags
#-------------------------------------------------------------------------------
# Enables all warnings
C_FLAGS_WARNINGS = -Wall
# Turn on all warnings.
COMMON_FLAGS += $(C_FLAGS_WARNINGS)
# Don't use common symbols. This is usually done in kernels. Makes
# code size slightly larger and increases performance.
COMMON_FLAGS += -fno-common
#Place each function or data item into its own section in the output file
COMMON_FLAGS += -ffunction-sections -fdata-sections
# Use a freestanding build environment. Standard for kernels, implies
# std library may not exist.
COMMON_FLAGS += -ffreestanding -fno-builtin
# Set the C standard to C99 with GNU extensions.
# Use traditional GNU inline function semantics.
C99_FLAGS = -std=gnu99
# Generate code specifically for cortex-mx CPU.
# Use the ARM Procedure Call Standard.
ARM_FLAGS = -mcpu=$(CPU) -mtune=$(CPU) -march=$(ARCH) -mapcs
ARM_FLAGS += -mthumb
# Use float-abi=softfp for soft floating point api with HW instructions.
# Alternatively, float-abi=hard for hw float instructions and pass float args in float regs.
# Here need to be modified.
ifeq "$(CPU)" "cortex-m4"
ifeq "$(CHOOSE_FLOAT)" "SOFT_FP"
ARM_FLAGS += -mfloat-abi=softfp -mfpu=fpv4-sp-d16
CC_LIB_POST := armv7e-m/softfp
else ifeq "$(CHOOSE_FLOAT)" "HARD_FP"
ARM_FLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16
CC_LIB_POST := armv7e-m/fpu
else
CC_LIB_POST := armv7e-m
endif
else ifeq "$(CPU)" "cortex-m0plus"
CC_LIB_POST := armv6-m
endif
# Debug setting
ifeq "$(DEBUG)" "1"
COMMON_FLAGS += -O0
COMMON_FLAGS += -g2 -gdwarf-2 -gstrict-dwarf
DEFINES += -D_DEBUG=1
else
COMMON_FLAGS += -Os
endif
# Build common flags shared by C and C++.
COMMON_FLAGS += $(ARM_FLAGS)
# C flags. Set C99 mode.
CFLAGS += $(COMMON_FLAGS) $(C99_FLAGS) -nostdinc
# C++ flags. Disable exceptions and RTTI.
CXXFLAGS += $(COMMON_FLAGS)
CXXFLAGS += -fno-exceptions -fno-rtti -nostdinc -nostdinc++
# AR flags.
ARFLAGS := -rucs
# AS flags.
# LD flags.
# Use newlib-nano. To disable it, specify USE_NANO=
USE_NANO = --specs=nano.specs
LDFLAGS := $(USE_NANO)
ifndef _START
SYSOBJ := $(LIBGCC_LDPATH)/crti.o \
$(LIBGCC_LDPATH)/crtn.o \
$(LIBC_LDPATH)/crt0.o
else
SYSOBJ :=
endif
LDFLAGS += $(COMMON_FLAGS) -nostartfiles -nodefaultlibs -nostdlib -Xlinker --gc-sections -Xlinker -cref -Xlinker -static -Xlinker -z -Xlinker muldefs
#-------------------------------------------------------------------------------
# Include paths
#-------------------------------------------------------------------------------
# These include paths have to be quoted because they may contain spaces,
# particularly under cygwin.
LDINC += -L '$(LIBGCC_LDPATH)' -L '$(LIBC_LDPATH)'
# Indicate gcc and newlib std includes as -isystem so gcc tags and
# treats them as system directories.
SYSTEM_INC = \
-isystem '$(CC_INCLUDE)' \
-isystem '$(CC_INCLUDE_FIXED)' \
-isystem '$(LIBC_INCLUDE)'
INCLUDES += \
$(SDK_ROOT)/platform \
$(SDK_ROOT)/platform/hal \
$(SDK_ROOT)/platform/drivers \
$(SDK_ROOT)/platform/utilities \
$(SDK_ROOT)/platform/CMSIS/Include \
$(SDK_ROOT)/platform/CMSIS/Include/device \
$(SDK_ROOT)/boards

55
mk/paths.mk Normal file
View File

@@ -0,0 +1,55 @@
#-------------------------------------------------------------------------------
# Copyright (c) 2012 Freescale Semiconductor, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# o Redistributions of source code must retain the above copyright notice, this list
# of conditions and the following disclaimer.
#
# o Redistributions in binary form must reproduce the above copyright notice, this
# list of conditions and the following disclaimer in the documentation and/or
# other materials provided with the distribution.
#
# o Neither the name of Freescale Semiconductor, Inc. nor the names of its
# contributors may be used to endorse or promote products derived from this
# software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# Root paths
#-------------------------------------------------------------------------------
# Build root directory paths.
SDK_LIB_ROOT = $(SDK_ROOT)/platform
APPS_ROOT = $(SDK_ROOT)/apps
BOARD_ROOT = $(SDK_ROOT)/boards/$(BOARD)
LD_FILE_ROOT = $(SDK_ROOT)/platform/linker/gcc
BOARD_COMMON_ROOT = $(SDK_ROOT)/boards/common
#-------------------------------------------------------------------------------
# Output file paths
#-------------------------------------------------------------------------------
# Build output directory paths.
#
# All build products will be placed in the project's own dir
#
ifneq "$(APP_NAME)" ""
OUTPUT_ROOT = ./output
else
OUTPUT_ROOT = ../output
endif

240
mk/targets.mk Normal file
View File

@@ -0,0 +1,240 @@
#-------------------------------------------------------------------------------
# Copyright (c) 2012 Freescale Semiconductor, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# o Redistributions of source code must retain the above copyright notice, this list
# of conditions and the following disclaimer.
#
# o Redistributions in binary form must reproduce the above copyright notice, this
# list of conditions and the following disclaimer in the documentation and/or
# other materials provided with the distribution.
#
# o Neither the name of Freescale Semiconductor, Inc. nor the names of its
# contributors may be used to endorse or promote products derived from this
# software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# Sources and objects
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# Different targets will be placed in separate folders.
#
# Libs: output/<Debug>
# output/<Release>
# Lib objs: output/<Debug>/obj
# output/<Release>/obj
#
# Apps: output/<Sram_Debug>
# output/<Sram_Rlease>
# output/<Flash_Debug>
# output/<Flash_Rlease>
# App objs: output/<Sram_Debug>/obj
# output/<Sram_Rlease>/obj
# output/<Flash_Debug>/obj
# output/<Flash_Rlease>/obj
#-------------------------------------------------------------------------------
ifneq "$(DEBUG)" "0"
DEBUG_OR_RELEASE := Debug
else
DEBUG_OR_RELEASE := Release
endif
ifneq "$(APP_NAME)" ""
ifeq "$(target)" "sram"
TARGET_OUTPUT_ROOT := $(OUTPUT_ROOT)/Sram_$(DEBUG_OR_RELEASE)
else
TARGET_OUTPUT_ROOT := $(OUTPUT_ROOT)/Flash_$(DEBUG_OR_RELEASE)
endif
else
TARGET_OUTPUT_ROOT := $(OUTPUT_ROOT)/$(DEBUG_OR_RELEASE)
endif
OBJS_ROOT = $(TARGET_OUTPUT_ROOT)/obj
# Strip sources.
SOURCES := $(strip $(SOURCES))
# Convert sources list to absolute paths and root-relative paths.
SOURCES_ABS := $(foreach s,$(SOURCES),$(abspath $(s)))
SOURCES_REL := $(subst $(SDK_ROOT)/,,$(SOURCES_ABS))
# Get a list of unique directories containing the source files.
SOURCE_DIRS_ABS := $(sort $(foreach f,$(SOURCES_ABS),$(dir $(f))))
SOURCE_DIRS_REL := $(subst $(SDK_ROOT)/,,$(SOURCE_DIRS_ABS))
OBJECTS_DIRS := $(addprefix $(OBJS_ROOT)/,$(SOURCE_DIRS_REL))
# Filter source files list into separate source types.
C_SOURCES = $(filter %.c,$(SOURCES_REL))
CXX_SOURCES = $(filter %.cpp,$(SOURCES_REL))
ASM_s_SOURCES = $(filter %.s,$(SOURCES_REL))
ASM_S_SOURCES = $(filter %.S,$(SOURCES_REL))
# Convert sources to objects.
OBJECTS_C := $(addprefix $(OBJS_ROOT)/,$(C_SOURCES:.c=.o))
OBJECTS_CXX := $(addprefix $(OBJS_ROOT)/,$(CXX_SOURCES:.cpp=.o))
OBJECTS_ASM := $(addprefix $(OBJS_ROOT)/,$(ASM_s_SOURCES:.s=.o))
OBJECTS_ASM_S := $(addprefix $(OBJS_ROOT)/,$(ASM_S_SOURCES:.S=.o))
# Complete list of all object files.
OBJECTS_ALL := $(sort $(OBJECTS_C) $(OBJECTS_CXX) $(OBJECTS_ASM) $(OBJECTS_ASM_S))
#-------------------------------------------------------------------------------
# The make target is lib or application.
#-------------------------------------------------------------------------------
# Construct full path name
ifneq "$(APP_NAME)" ""
MAKE_TARGET ?= $(TARGET_OUTPUT_ROOT)/$(APP_NAME).elf
else
MAKE_TARGET ?= $(TARGET_OUTPUT_ROOT)/$(LIB_NAME).a
endif
#-------------------------------------------------------------------------------
# Expand the include paths
#-------------------------------------------------------------------------------
INCLUDES := $(foreach includes, $(INCLUDES), -I$(includes))
#-------------------------------------------------------------------------------
# Default target
#-------------------------------------------------------------------------------
# Note that prerequisite order is important here. The subdirectories must be built first, or you
# may end up with files in the current directory not getting added to libraries. This would happen
# if subdirs modified the library file after local files were compiled but before they were added
# to the library.
.PHONY: all
all: $(MAKE_TARGET)
# Recipe to create the output object file directories.
$(OBJECTS_DIRS) :
$(at)mkdir -p $@
# Object files depend on the directories where they will be created.
#
# The dirs are made order-only prerequisites (by being listed after the '|') so they won't cause
# the objects to be rebuilt, as the modification date on a directory changes whenver its contents
# change. This would cause the objects to always be rebuilt if the dirs were normal prerequisites.
$(OBJECTS_ALL): | $(OBJECTS_DIRS)
#-------------------------------------------------------------------------------
# Pattern rules for compilation
#-------------------------------------------------------------------------------
# We cd into the source directory before calling the appropriate compiler. This must be done
# on a single command line since make calls individual recipe lines in separate shells, so
# '&&' is used to chain the commands.
#
# Generate make dependencies while compiling using the -MMD option, which excludes system headers.
# If system headers are included, there are path problems on cygwin. The -MP option creates empty
# targets for each header file so that a rebuild will be forced if the file goes missing, but
# no error will occur.
# Compile C sources.
$(OBJS_ROOT)/%.o: $(SDK_ROOT)/%.c
@$(call printmessage,c,Compiling, $(subst $(SDK_ROOT)/,,$<))
$(at)$(CC) $(CFLAGS) $(SYSTEM_INC) $(INCLUDES) $(DEFINES) -MMD -MF $(basename $@).d -MP -o $@ -c $<
# Compile C++ sources.
$(OBJS_ROOT)/%.o: $(SDK_ROOT)/%.cpp
@$(call printmessage,cxx,Compiling, $(subst $(SDK_ROOT)/,,$<))
$(at)$(CXX) $(CXXFLAGS) $(SYSTEM_INC) $(INCLUDES) $(DEFINES) -MMD -MF $(basename $@).d -MP -o $@ -c $<
# For .S assembly files, first run through the C preprocessor then assemble.
$(OBJS_ROOT)/%.o: $(SDK_ROOT)/%.S
@$(call printmessage,asm,Assembling, $(subst $(SDK_ROOT)/,,$<))
$(at)$(CPP) -D__LANGUAGE_ASM__ $(INCLUDES) $(DEFINES) -o $(basename $@).s $< \
&& $(AS) $(ASFLAGS) $(INCLUDES) -MD $(OBJS_ROOT)/$*.d -o $@ $(basename $@).s
# Assembler sources.
$(OBJS_ROOT)/%.o: $(SDK_ROOT)/%.s
@$(call printmessage,asm,Assembling, $(subst $(SDK_ROOT)/,,$<))
$(at)$(AS) $(ASFLAGS) $(INCLUDES) -MD $(basename $@).d -o $@ $<
#------------------------------------------------------------------------
# Build the tagrget
#------------------------------------------------------------------------
# If build a library
ifeq "$(APP_NAME)" ""
$(MAKE_TARGET): $(OBJECTS_ALL)
@$(call printmessage,ar,Archiving, $(?F) in $(@F))
$(at)mkdir -p $(dir $(@))
@$(AR) $(ARFLAGS) $@ $?
@$(at)cp -f $(MAKE_TARGET) '$(SDK_ROOT)/lib/gcc/$(CHIP)/output/$(DEBUG_OR_RELEASE)/$(LIB_NAME).a' 2>/dev/null || :
# If build an application
else
# Link the application
ifneq "$(LINK_LIB_NAME)" ""
LIBRARIES += $(foreach lib_name, $(LINK_LIB_NAME), $(SDK_ROOT)/lib/gcc/$(CHIP)/output/$(DEBUG_OR_RELEASE)/$(lib_name).a)
endif
app_bin = $(basename $(MAKE_TARGET)).bin
app_map = $(basename $(MAKE_TARGET)).map
LD_FILE = $(LD_FILE_ROOT)/$(CHIP)/$(LD_FILE_NAME)
$(LIBRARIES):
@if echo "$@" | grep -sq "platform_lib"; then \
$(MAKE) -C $(SDK_ROOT)/lib/gcc/$(CHIP)/platform_lib; \
else \
$(MAKE) -C $(BOARD_COMMON_ROOT)/$(shell basename $@ .a)/gcc/$(BOARD); \
fi
# Link the application.
# Wrap the link objects in start/end group so that ld re-checks each
# file for dependencies. Otherwise linking static libs can be a pain
# since order matters.
$(MAKE_TARGET): $(LIBRARIES) $(OBJECTS_ALL) $(LD_FILE)
@$(call printmessage,link,Linking, $(APP_NAME))
$(at)$(LD) $(LDFLAGS) \
-T$(LD_FILE) \
$(LDINC) \
-Xlinker --start-group \
$(OBJECTS_ALL) \
-lc -lgcc -lm \
$(LIBRARIES) \
-lnosys \
$(SYSOBJ) \
-Xlinker --end-group \
-o $@ \
-Xlinker -Map=$(app_map)
$(at)$(OBJCOPY) --gap-fill 0x00 -I elf32-little -O binary $@ $(app_bin)
@echo "Output ELF:" ; echo " $(MAKE_TARGET)"
@echo "Output binary:" ; echo " $(app_bin)"
endif
#-------------------------------------------------------------------------------
# Clean
#-------------------------------------------------------------------------------
.PHONY: clean cleanall
.PHONY: $(LINK_LIB_NAME)
cleanall: clean $(LINK_LIB_NAME)
clean:
-rm -rf $(OBJECTS_ALL) $(OBJECTS_DIRS) $(MAKE_TARGET) $(app_bin) $(app_map)
$(LINK_LIB_NAME):
@if [ "$@" = "platform_lib" ]; then \
$(MAKE) -C $(SDK_ROOT)/lib/gcc/$(CHIP)/platform_lib clean; \
else \
$(MAKE) -C $(BOARD_COMMON_ROOT)/$@/gcc/$(BOARD) clean; \
fi
rm -rf $(SDK_ROOT)/lib/gcc/$(CHIP)/output/$(DEBUG_OR_RELEASE)/*
# Include dependency files.
-include $(OBJECTS_ALL:.o=.d)