2013-02-23 20:05:59 -04:00
|
|
|
#
|
2014-04-26 06:48:43 -03:00
|
|
|
# Copyright (C) 2012-2014 PX4 Development Team. All rights reserved.
|
2013-02-23 20:05:59 -04:00
|
|
|
#
|
|
|
|
# Redistribution and use in source and binary forms, with or without
|
|
|
|
# modification, are permitted provided that the following conditions
|
|
|
|
# are met:
|
|
|
|
#
|
|
|
|
# 1. Redistributions of source code must retain the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer.
|
|
|
|
# 2. 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.
|
|
|
|
# 3. Neither the name PX4 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 OWNER 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.
|
|
|
|
#
|
|
|
|
|
2013-01-06 01:46:50 -04:00
|
|
|
#
|
|
|
|
# Definitions for a generic GNU ARM-EABI toolchain
|
|
|
|
#
|
|
|
|
|
2013-02-23 16:23:34 -04:00
|
|
|
#$(info TOOLCHAIN gnu-arm-eabi)
|
2013-01-17 01:02:09 -04:00
|
|
|
|
2013-02-23 19:11:57 -04:00
|
|
|
# Toolchain commands. Normally only used inside this file.
|
|
|
|
#
|
2013-01-06 01:46:50 -04:00
|
|
|
CROSSDEV = arm-none-eabi-
|
|
|
|
|
|
|
|
CC = $(CROSSDEV)gcc
|
|
|
|
CXX = $(CROSSDEV)g++
|
|
|
|
CPP = $(CROSSDEV)gcc -E
|
|
|
|
LD = $(CROSSDEV)ld
|
|
|
|
AR = $(CROSSDEV)ar rcs
|
|
|
|
NM = $(CROSSDEV)nm
|
|
|
|
OBJCOPY = $(CROSSDEV)objcopy
|
|
|
|
OBJDUMP = $(CROSSDEV)objdump
|
|
|
|
|
2014-05-22 08:58:12 -03:00
|
|
|
# Check if the right version of the toolchain is available
|
|
|
|
#
|
2014-05-23 07:38:29 -03:00
|
|
|
CROSSDEV_VER_SUPPORTED = 4.7
|
2014-05-22 08:58:12 -03:00
|
|
|
CROSSDEV_VER_FOUND = $(shell $(CC) -dumpversion)
|
|
|
|
|
2014-05-23 07:38:29 -03:00
|
|
|
ifeq (,$(findstring $(CROSSDEV_VER_SUPPORTED),$(CROSSDEV_VER_FOUND)))
|
|
|
|
$(error Unsupported version of $(CC), found: $(CROSSDEV_VER_FOUND) instead of $(CROSSDEV_VER_SUPPORTED).x)
|
2014-05-22 08:58:12 -03:00
|
|
|
endif
|
|
|
|
|
|
|
|
|
2013-01-06 01:46:50 -04:00
|
|
|
# XXX this is pulled pretty directly from the fmu Make.defs - needs cleanup
|
|
|
|
|
2013-06-07 16:16:31 -03:00
|
|
|
MAXOPTIMIZATION ?= -O3
|
2013-01-06 01:46:50 -04:00
|
|
|
|
2013-02-23 19:11:57 -04:00
|
|
|
# Base CPU flags for each of the supported architectures.
|
|
|
|
#
|
2013-01-06 01:46:50 -04:00
|
|
|
ARCHCPUFLAGS_CORTEXM4F = -mcpu=cortex-m4 \
|
|
|
|
-mthumb \
|
|
|
|
-march=armv7e-m \
|
|
|
|
-mfpu=fpv4-sp-d16 \
|
|
|
|
-mfloat-abi=hard
|
|
|
|
|
|
|
|
ARCHCPUFLAGS_CORTEXM4 = -mcpu=cortex-m4 \
|
|
|
|
-mthumb \
|
|
|
|
-march=armv7e-m \
|
|
|
|
-mfloat-abi=soft
|
|
|
|
|
|
|
|
ARCHCPUFLAGS_CORTEXM3 = -mcpu=cortex-m3 \
|
|
|
|
-mthumb \
|
2013-01-17 01:02:09 -04:00
|
|
|
-march=armv7-m \
|
2013-01-06 01:46:50 -04:00
|
|
|
-mfloat-abi=soft
|
|
|
|
|
2013-06-06 14:12:10 -03:00
|
|
|
ARCHINSTRUMENTATIONDEFINES_CORTEXM4F = -finstrument-functions \
|
|
|
|
-ffixed-r10
|
|
|
|
|
|
|
|
ARCHINSTRUMENTATIONDEFINES_CORTEXM4 = -finstrument-functions \
|
|
|
|
-ffixed-r10
|
|
|
|
|
2014-05-22 08:58:12 -03:00
|
|
|
ARCHINSTRUMENTATIONDEFINES_CORTEXM3 =
|
2013-06-06 14:12:10 -03:00
|
|
|
|
2013-02-23 19:11:57 -04:00
|
|
|
# Pick the right set of flags for the architecture.
|
|
|
|
#
|
2013-01-06 01:46:50 -04:00
|
|
|
ARCHCPUFLAGS = $(ARCHCPUFLAGS_$(CONFIG_ARCH))
|
2013-01-17 01:02:09 -04:00
|
|
|
ifeq ($(ARCHCPUFLAGS),)
|
|
|
|
$(error Must set CONFIG_ARCH to one of CORTEXM4F, CORTEXM4 or CORTEXM3)
|
|
|
|
endif
|
2013-01-06 01:46:50 -04:00
|
|
|
|
2013-08-13 04:34:11 -03:00
|
|
|
# Set the board flags
|
|
|
|
#
|
|
|
|
ifeq ($(CONFIG_BOARD),)
|
|
|
|
$(error Board config does not define CONFIG_BOARD)
|
|
|
|
endif
|
|
|
|
ARCHDEFINES += -DCONFIG_ARCH_BOARD_$(CONFIG_BOARD)
|
|
|
|
|
2013-01-06 01:46:50 -04:00
|
|
|
# optimisation flags
|
2013-02-23 19:11:57 -04:00
|
|
|
#
|
2013-01-06 01:46:50 -04:00
|
|
|
ARCHOPTIMIZATION = $(MAXOPTIMIZATION) \
|
2013-01-17 01:02:09 -04:00
|
|
|
-g \
|
2013-01-06 01:46:50 -04:00
|
|
|
-fno-strict-aliasing \
|
|
|
|
-fno-strength-reduce \
|
|
|
|
-fomit-frame-pointer \
|
|
|
|
-funsafe-math-optimizations \
|
|
|
|
-fno-builtin-printf \
|
|
|
|
-ffunction-sections \
|
|
|
|
-fdata-sections
|
|
|
|
|
|
|
|
# enable precise stack overflow tracking
|
|
|
|
# note - requires corresponding support in NuttX
|
2013-06-06 14:12:10 -03:00
|
|
|
INSTRUMENTATIONDEFINES = $(ARCHINSTRUMENTATIONDEFINES_$(CONFIG_ARCH))
|
|
|
|
|
2013-02-23 19:11:57 -04:00
|
|
|
# Language-specific flags
|
|
|
|
#
|
2013-01-06 01:46:50 -04:00
|
|
|
ARCHCFLAGS = -std=gnu99
|
|
|
|
ARCHCXXFLAGS = -fno-exceptions -fno-rtti -std=gnu++0x
|
2013-02-23 19:11:57 -04:00
|
|
|
|
|
|
|
# Generic warnings
|
|
|
|
#
|
2013-01-06 01:46:50 -04:00
|
|
|
ARCHWARNINGS = -Wall \
|
|
|
|
-Wextra \
|
|
|
|
-Wdouble-promotion \
|
|
|
|
-Wshadow \
|
|
|
|
-Wfloat-equal \
|
|
|
|
-Wframe-larger-than=1024 \
|
|
|
|
-Wpointer-arith \
|
|
|
|
-Wlogical-op \
|
|
|
|
-Wmissing-declarations \
|
|
|
|
-Wpacked \
|
2014-04-21 16:30:57 -03:00
|
|
|
-Wno-unused-parameter \
|
|
|
|
-Werror=format-security \
|
|
|
|
-Werror=array-bounds \
|
|
|
|
-Wfatal-errors \
|
2014-07-07 19:11:46 -03:00
|
|
|
-Wformat=1 \
|
|
|
|
-Werror=unused-but-set-variable \
|
|
|
|
-Werror=unused-variable \
|
|
|
|
-Werror=double-promotion \
|
|
|
|
-Werror=reorder
|
2013-01-06 01:46:50 -04:00
|
|
|
# -Wcast-qual - generates spurious noreturn attribute warnings, try again later
|
|
|
|
# -Wconversion - would be nice, but too many "risky-but-safe" conversions in the code
|
|
|
|
# -Wcast-align - would help catch bad casts in some cases, but generates too many false positives
|
|
|
|
|
2013-02-23 19:11:57 -04:00
|
|
|
# C-specific warnings
|
|
|
|
#
|
2013-01-06 01:46:50 -04:00
|
|
|
ARCHCWARNINGS = $(ARCHWARNINGS) \
|
|
|
|
-Wbad-function-cast \
|
|
|
|
-Wstrict-prototypes \
|
|
|
|
-Wold-style-declaration \
|
|
|
|
-Wmissing-parameter-type \
|
|
|
|
-Wmissing-prototypes \
|
2014-01-04 20:49:21 -04:00
|
|
|
-Wnested-externs
|
2013-02-23 19:11:57 -04:00
|
|
|
|
|
|
|
# C++-specific warnings
|
|
|
|
#
|
2014-04-26 06:48:43 -03:00
|
|
|
ARCHWARNINGSXX = $(ARCHWARNINGS) \
|
|
|
|
-Wno-missing-field-initializers
|
2013-01-06 01:46:50 -04:00
|
|
|
|
|
|
|
# pull in *just* libm from the toolchain ... this is grody
|
2013-01-17 01:02:09 -04:00
|
|
|
LIBM := $(shell $(CC) $(ARCHCPUFLAGS) -print-file-name=libm.a)
|
2013-01-06 01:46:50 -04:00
|
|
|
EXTRA_LIBS += $(LIBM)
|
|
|
|
|
2013-02-23 19:11:57 -04:00
|
|
|
# Flags we pass to the C compiler
|
|
|
|
#
|
2013-01-06 01:46:50 -04:00
|
|
|
CFLAGS = $(ARCHCFLAGS) \
|
|
|
|
$(ARCHCWARNINGS) \
|
|
|
|
$(ARCHOPTIMIZATION) \
|
|
|
|
$(ARCHCPUFLAGS) \
|
|
|
|
$(ARCHINCLUDES) \
|
|
|
|
$(INSTRUMENTATIONDEFINES) \
|
|
|
|
$(ARCHDEFINES) \
|
|
|
|
$(EXTRADEFINES) \
|
2013-05-05 20:48:05 -03:00
|
|
|
$(EXTRACFLAGS) \
|
2013-02-21 01:12:59 -04:00
|
|
|
-fno-common \
|
|
|
|
$(addprefix -I,$(INCLUDE_DIRS))
|
2013-01-06 01:46:50 -04:00
|
|
|
|
2013-02-23 19:11:57 -04:00
|
|
|
# Flags we pass to the C++ compiler
|
|
|
|
#
|
2013-01-06 01:46:50 -04:00
|
|
|
CXXFLAGS = $(ARCHCXXFLAGS) \
|
|
|
|
$(ARCHWARNINGSXX) \
|
|
|
|
$(ARCHOPTIMIZATION) \
|
|
|
|
$(ARCHCPUFLAGS) \
|
|
|
|
$(ARCHXXINCLUDES) \
|
|
|
|
$(INSTRUMENTATIONDEFINES) \
|
|
|
|
$(ARCHDEFINES) \
|
2013-04-26 20:14:32 -03:00
|
|
|
-DCONFIG_WCHAR_BUILTIN \
|
2013-05-05 20:48:05 -03:00
|
|
|
$(EXTRADEFINES) \
|
|
|
|
$(EXTRACXXFLAGS) \
|
2013-02-21 01:12:59 -04:00
|
|
|
$(addprefix -I,$(INCLUDE_DIRS))
|
2013-01-06 01:46:50 -04:00
|
|
|
|
2013-02-23 19:11:57 -04:00
|
|
|
# Flags we pass to the assembler
|
|
|
|
#
|
2013-05-05 20:48:05 -03:00
|
|
|
AFLAGS = $(CFLAGS) -D__ASSEMBLY__ \
|
|
|
|
$(EXTRADEFINES) \
|
|
|
|
$(EXTRAAFLAGS)
|
2013-01-06 01:46:50 -04:00
|
|
|
|
2013-02-23 19:11:57 -04:00
|
|
|
# Flags we pass to the linker
|
|
|
|
#
|
2013-01-06 01:46:50 -04:00
|
|
|
LDFLAGS += --warn-common \
|
|
|
|
--gc-sections \
|
2013-05-05 20:48:05 -03:00
|
|
|
$(EXTRALDFLAGS) \
|
2013-02-23 18:33:53 -04:00
|
|
|
$(addprefix -T,$(LDSCRIPT)) \
|
2013-01-06 01:46:50 -04:00
|
|
|
$(addprefix -L,$(LIB_DIRS))
|
|
|
|
|
2013-02-23 19:11:57 -04:00
|
|
|
# Compiler support library
|
|
|
|
#
|
2013-01-06 01:46:50 -04:00
|
|
|
LIBGCC := $(shell $(CC) $(ARCHCPUFLAGS) -print-libgcc-file-name)
|
|
|
|
|
2013-02-23 19:11:57 -04:00
|
|
|
# Files that the final link depends on
|
|
|
|
#
|
2013-01-06 01:46:50 -04:00
|
|
|
LINK_DEPS += $(LDSCRIPT)
|
|
|
|
|
2013-02-23 19:11:57 -04:00
|
|
|
# Files to include to get automated dependencies
|
|
|
|
#
|
2013-01-06 01:46:50 -04:00
|
|
|
DEP_INCLUDES = $(subst .o,.d,$(OBJS))
|
|
|
|
|
2013-02-23 19:11:57 -04:00
|
|
|
# Compile C source $1 to object $2
|
2013-01-06 01:46:50 -04:00
|
|
|
# as a side-effect, generate a dependency file
|
2013-02-23 19:11:57 -04:00
|
|
|
#
|
2013-01-06 01:46:50 -04:00
|
|
|
define COMPILE
|
2013-02-23 19:11:57 -04:00
|
|
|
@$(ECHO) "CC: $1"
|
2013-02-23 18:33:53 -04:00
|
|
|
@$(MKDIR) -p $(dir $2)
|
2013-05-05 20:48:05 -03:00
|
|
|
$(Q) $(CC) -MD -c $(CFLAGS) $(abspath $1) -o $2
|
2013-01-06 01:46:50 -04:00
|
|
|
endef
|
|
|
|
|
2013-02-23 19:11:57 -04:00
|
|
|
# Compile C++ source $1 to $2
|
2013-01-06 01:46:50 -04:00
|
|
|
# as a side-effect, generate a dependency file
|
2013-02-23 19:11:57 -04:00
|
|
|
#
|
2013-01-06 01:46:50 -04:00
|
|
|
define COMPILEXX
|
2013-02-23 19:11:57 -04:00
|
|
|
@$(ECHO) "CXX: $1"
|
2013-02-23 18:33:53 -04:00
|
|
|
@$(MKDIR) -p $(dir $2)
|
2013-05-05 20:48:05 -03:00
|
|
|
$(Q) $(CXX) -MD -c $(CXXFLAGS) $(abspath $1) -o $2
|
2013-01-06 01:46:50 -04:00
|
|
|
endef
|
|
|
|
|
2013-02-23 19:11:57 -04:00
|
|
|
# Assemble $1 into $2
|
|
|
|
#
|
2013-01-06 01:46:50 -04:00
|
|
|
define ASSEMBLE
|
2013-02-23 19:11:57 -04:00
|
|
|
@$(ECHO) "AS: $1"
|
2013-02-23 18:33:53 -04:00
|
|
|
@$(MKDIR) -p $(dir $2)
|
2013-05-05 20:48:05 -03:00
|
|
|
$(Q) $(CC) -c $(AFLAGS) $(abspath $1) -o $2
|
2013-01-06 01:46:50 -04:00
|
|
|
endef
|
|
|
|
|
2013-02-23 19:11:57 -04:00
|
|
|
# Produce partially-linked $1 from files in $2
|
|
|
|
#
|
2013-01-06 01:46:50 -04:00
|
|
|
define PRELINK
|
2013-02-23 18:33:53 -04:00
|
|
|
@$(ECHO) "PRELINK: $1"
|
|
|
|
@$(MKDIR) -p $(dir $1)
|
2013-05-26 15:51:20 -03:00
|
|
|
$(Q) $(LD) -Ur -Map $1.map -o $1 $2 && $(OBJCOPY) --localize-hidden $1
|
2013-01-06 01:46:50 -04:00
|
|
|
endef
|
|
|
|
|
2013-02-23 19:11:57 -04:00
|
|
|
# Update the archive $1 with the files in $2
|
|
|
|
#
|
2013-01-06 01:46:50 -04:00
|
|
|
define ARCHIVE
|
2013-02-23 19:11:57 -04:00
|
|
|
@$(ECHO) "AR: $2"
|
2013-02-23 18:33:53 -04:00
|
|
|
@$(MKDIR) -p $(dir $1)
|
2013-01-06 01:46:50 -04:00
|
|
|
$(Q) $(AR) $1 $2
|
|
|
|
endef
|
|
|
|
|
2013-02-23 19:11:57 -04:00
|
|
|
# Link the objects in $2 into the binary $1
|
|
|
|
#
|
2013-01-06 01:46:50 -04:00
|
|
|
define LINK
|
2013-02-23 19:11:57 -04:00
|
|
|
@$(ECHO) "LINK: $1"
|
2013-02-23 18:33:53 -04:00
|
|
|
@$(MKDIR) -p $(dir $1)
|
2013-05-23 18:58:25 -03:00
|
|
|
$(Q) $(LD) $(LDFLAGS) -Map $1.map -o $1 --start-group $2 $(LIBS) $(EXTRA_LIBS) $(LIBGCC) --end-group
|
2013-01-06 01:46:50 -04:00
|
|
|
endef
|
|
|
|
|
2013-02-23 19:11:57 -04:00
|
|
|
# Convert $1 from a linked object to a raw binary in $2
|
|
|
|
#
|
2013-01-06 01:46:50 -04:00
|
|
|
define SYM_TO_BIN
|
2013-02-23 19:11:57 -04:00
|
|
|
@$(ECHO) "BIN: $2"
|
2013-02-23 18:33:53 -04:00
|
|
|
@$(MKDIR) -p $(dir $2)
|
2013-01-06 01:46:50 -04:00
|
|
|
$(Q) $(OBJCOPY) -O binary $1 $2
|
|
|
|
endef
|
2013-02-23 18:33:53 -04:00
|
|
|
|
2014-05-22 08:58:12 -03:00
|
|
|
# Take the raw binary $1 and make it into an object file $2.
|
2013-02-23 18:33:53 -04:00
|
|
|
# The symbol $3 points to the beginning of the file, and $3_len
|
|
|
|
# gives its length.
|
|
|
|
#
|
|
|
|
# - compile an empty file to generate a suitable object file
|
|
|
|
# - relink the object and insert the binary file
|
|
|
|
# - edit symbol names to suit
|
|
|
|
#
|
2013-05-12 18:04:57 -03:00
|
|
|
# NOTE: exercise caution using this with absolute pathnames; it looks
|
|
|
|
# like the MinGW tools insert an extra _ in the binary symbol name; e.g.
|
|
|
|
# the path:
|
|
|
|
#
|
|
|
|
# /d/px4/firmware/Build/px4fmu_default.build/romfs.img
|
|
|
|
#
|
|
|
|
# is assigned symbols like:
|
|
|
|
#
|
|
|
|
# _binary_d__px4_firmware_Build_px4fmu_default_build_romfs_img_size
|
|
|
|
#
|
|
|
|
# when we would expect
|
|
|
|
#
|
|
|
|
# _binary__d_px4_firmware_Build_px4fmu_default_build_romfs_img_size
|
|
|
|
#
|
2013-02-23 18:33:53 -04:00
|
|
|
define BIN_SYM_PREFIX
|
|
|
|
_binary_$(subst /,_,$(subst .,_,$1))
|
|
|
|
endef
|
|
|
|
define BIN_TO_OBJ
|
2013-02-23 19:11:57 -04:00
|
|
|
@$(ECHO) "OBJ: $2"
|
2013-02-23 18:33:53 -04:00
|
|
|
@$(MKDIR) -p $(dir $2)
|
|
|
|
$(Q) $(ECHO) > $2.c
|
|
|
|
$(call COMPILE,$2.c,$2.c.o)
|
2013-02-23 19:11:57 -04:00
|
|
|
$(Q) $(LD) -r -o $2 $2.c.o -b binary $1
|
|
|
|
$(Q) $(OBJCOPY) $2 \
|
2013-02-23 18:33:53 -04:00
|
|
|
--redefine-sym $(call BIN_SYM_PREFIX,$1)_start=$3 \
|
|
|
|
--redefine-sym $(call BIN_SYM_PREFIX,$1)_size=$3_len \
|
2013-05-23 18:58:59 -03:00
|
|
|
--strip-symbol $(call BIN_SYM_PREFIX,$1)_end \
|
|
|
|
--rename-section .data=.rodata
|
2013-05-12 18:04:57 -03:00
|
|
|
$(Q) $(REMOVE) $2.c $2.c.o
|
2013-02-23 18:33:53 -04:00
|
|
|
endef
|