2 # Copyright (c) 2009-2013, The OpenPilot Team, http://www.openpilot.org
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 # You should have received a copy of the GNU General Public License along
15 # with this program; if not, write to the Free Software Foundation, Inc.,
16 # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 ifndef FLIGHT_MAKEFILE
20 $(error Top level Makefile must be used to build this target
)
23 # Set to YES to compile for debugging
26 # Set to YES to compile C++ implemented features
29 # Set to YES to use the Servo output pins for debugging via scope or logic analyser
30 ENABLE_DEBUG_PINS ?
= NO
32 # Set to YES to enable the AUX UART which is mapped on the S1 (Tx) and S2 (Rx) servo outputs
35 # Include objects that are just nice information to show
37 DIAG_MIXERSTATUS ?
= NO
38 DIAG_RATEDESIRED ?
= NO
39 DIAG_I2C_WDG_STATS ?
= NO
41 DIAG_INSTRUMENTATION ?
= NO
43 # Or just turn on all the above diagnostics. WARNING: this consumes massive amounts of memory.
46 # Optimization level, can be [0, 1, 2, 3, s].
47 # 0 = turn off optimization. s = optimize for size.
48 # Note: 3 is not always the best optimization level.
55 # Output format (can be ihex or binary or both).
56 # binary to create a load-image in raw-binary format i.e. for SAM-BA,
57 # ihex to create a load-image in Intel hex format
65 # Place project-specific -D (define) and/or -U options for C here.
66 CDEFS
+= -DUSE_
$(BOARD
)
68 ifeq ($(ENABLE_DEBUG_PINS
), YES
)
69 CDEFS
+= -DPIOS_ENABLE_DEBUG_PINS
72 ifeq ($(ENABLE_AUX_UART
), YES
)
73 CDEFS
+= -DPIOS_ENABLE_AUX_UART
76 # The following Makefile command, ifneq (,$(filter) $(A), $(B) $(C))
77 # is equivalent to the pseudocode `if (A == B || A == C)`
78 ifneq (,$(filter YES
,$(DIAG_STACK
) $(DIAG_ALL
)))
79 CFLAGS
+= -DDIAG_STACK
82 ifneq (,$(filter YES
,$(DIAG_MIXERSTATUS
) $(DIAG_ALL
)))
83 CFLAGS
+= -DDIAG_MIXERSTATUS
86 ifneq (,$(filter YES
,$(DIAG_RATEDESIRED
) $(DIAG_ALL
)))
87 CFLAGS
+= -DDIAG_RATEDESIRED
90 ifneq (,$(filter YES
,$(DIAG_I2C_WDG_STATS
) $(DIAG_ALL
)))
91 CFLAGS
+= -DDIAG_I2C_WDG_STATS
94 ifneq (,$(filter YES
,$(DIAG_TASKS
) $(DIAG_ALL
)))
95 CFLAGS
+= -DDIAG_TASKS
98 ifneq (,$(filter YES
,$(DIAG_INSTRUMENTATION
) $(DIAG_ALL
)))
99 CFLAGS
+= -DPIOS_INCLUDE_INSTRUMENTATION
101 # Place project-specific -D and/or -U options for Assembler with preprocessor here.
102 #ADEFS = -DUSE_IRQ_ASM_WRAPPER
103 ADEFS
= -D__ASSEMBLY__
105 # Compiler flag to set the C Standard level.
107 # gnu89 - c89 plus GCC extensions
108 # c99 - ISO C99 standard (not yet fully implemented)
109 # gnu99 - c99 plus GCC extensions
110 CSTANDARD
= -std
=gnu99
114 # -g*: generate debugging information
115 # -O*: optimization level
116 # -f...: tuning, see GCC manual and avr-libc documentation
117 # -Wall...: warning level
118 # -Wa,...: tell GCC to pass this to the assembler.
119 # -adhlns...: create assembler listing
121 # Common architecture-specific flags from the device-specific library makefile
122 CFLAGS
+= $(ARCHFLAGS
)
125 CFLAGS
+= -g
$(DEBUGF
)
126 CFLAGS
+= -mapcs-frame
127 CFLAGS
+= -fomit-frame-pointer
128 CFLAGS
+= -Wall
-Wextra
129 CFLAGS
+= -Wfloat-equal
-Wdouble-promotion
132 CFLAGS
+= $(patsubst %,-I
%,$(EXTRAINCDIRS
)) -I.
133 CFLAGS
+= -Wa
,-adhlns
=$(addprefix $(OUTDIR
)/, $(notdir $(addsuffix .lst
, $(basename $<))))
135 # Provides board-specific defines
136 BOARD_CDEFS
+= -DBOARD_TYPE
=$(BOARD_TYPE
)
137 BOARD_CDEFS
+= -DBOARD_REVISION
=$(BOARD_REVISION
)
138 BOARD_CDEFS
+= -DHW_TYPE
=$(HW_TYPE
)
139 BOARD_CDEFS
+= -DBOOTLOADER_VERSION
=$(BOOTLOADER_VERSION
)
140 BOARD_CDEFS
+= -DFW_BANK_BASE
=$(FW_BANK_BASE
)
141 BOARD_CDEFS
+= -DFW_BANK_SIZE
=$(FW_BANK_SIZE
)
142 BOARD_CDEFS
+= -DFW_DESC_SIZE
=$(FW_DESC_SIZE
)
144 BOARD_CDEFS
+= -DBL_BANK_BASE
=$(BL_BANK_BASE
)
145 BOARD_CDEFS
+= -DBL_BANK_SIZE
=$(BL_BANK_SIZE
)
146 BOARD_CDEFS
+= -DBL_DESC_SIZE
=$(BL_DESC_SIZE
)
148 BOARD_CDEFS
+= -DEE_BANK_BASE
=$(EE_BANK_BASE
)
149 BOARD_CDEFS
+= -DEE_BANK_SIZE
=$(EE_BANK_SIZE
)
151 ifdef USER_EE_BANK_BASE
152 BOARD_CDEFS
+= -DUSER_EE_BANK_BASE
=$(USER_EE_BANK_BASE
)
153 BOARD_CDEFS
+= -DUSER_EE_BANK_SIZE
=$(USER_EE_BANK_SIZE
)
156 BOARD_CDEFS
+= -DSRAM_BANK_BASE
=$(SRAM_BANK_BASE
)
157 BOARD_CDEFS
+= -DSRAM_BANK_SIZE
=$(SRAM_BANK_SIZE
)
159 ifdef CCSRAM_BANK_BASE
160 BOARD_CDEFS
+= -DCCSRAM_BANK_BASE
=$(CCSRAM_BANK_BASE
)
161 BOARD_CDEFS
+= -DCCSRAM_BANK_SIZE
=$(CCSRAM_BANK_SIZE
)
163 CDEFS
+= $(BOARD_CDEFS
)
168 CFLAGS
+= -fdata-sections
-ffunction-sections
171 ifeq ($(USE_CXX
), YES
)
172 CPPFLAGS
+= -DPIOS_ENABLE_CXX
175 # Compiler flags to generate dependency files
176 CFLAGS
+= -MD
-MP
-MF
$(OUTDIR
)/dep
/$(@F
).d
179 #CONLYFLAGS += -Wnested-externs
180 CONLYFLAGS
+= $(CSTANDARD
) -Wunsuffixed-float-constants
183 # Note C++ compilation also uses CFLAGS. CONLYFLAGS has exclusions that
184 # can not be used with C++ compiler. C++ specific compile options are
185 # as set in CXXFLAGS. Note CPPFLAGS is for C pre-process and has not been
186 # used correctly - longer term move CDEFS to CPPFLAGS.
187 CXXFLAGS
+= -fno-rtti
-fno-exceptions
-std
=c
++11 -fno-use-cxa-atexit
190 # -Wa,...: tell GCC to pass this to the assembler.
191 # -ahlns: create listing
192 ASFLAGS
= -mcpu
=$(MCU
) -I.
-x assembler-with-cpp
194 ASFLAGS
+= $(patsubst %,-I
%,$(EXTRAINCDIRS
))
195 ASFLAGS
+= -Wa
,-adhlns
=$(addprefix $(OUTDIR
)/, $(notdir $(addsuffix .lst
, $(basename $<))))
198 # -Wl,...: tell GCC to pass this to linker.
199 # -Map: create map file
200 # --cref: add cross reference to map file
201 LDFLAGS
+= -nostartfiles
202 LDFLAGS
+= -Wl
,--warn-common
,--fatal-warnings
,--sort-common
,--sort-section
=alignment
,--gc-sections
203 LDFLAGS
+= -Wl
,-Map
=$(OUTDIR
)/$(TARGET
).map
,--cref
204 LDFLAGS
+= $(patsubst %,-L
%,$(EXTRA_LIBDIRS
))
205 LDFLAGS
+= $(patsubst %,-l
%,$(EXTRA_LIBS
))
208 ifneq ($(DEBUG
), YES
)
209 LDFLAGS
+= -Wl
,-static
212 # List of all source files.
213 ifeq ($(USE_CXX
), YES
)
214 ALLSRC
= $(CPPSRCARM
) $(CPPSRC
) $(ASRCARM
) $(ASRC
) $(SRCARM
) $(SRC
)
216 ALLSRC
= $(ASRCARM
) $(ASRC
) $(SRCARM
) $(SRC
)
219 # List of all source files without directory and file-extension.
220 ALLSRCBASE
= $(notdir $(basename $(ALLSRC
)))
222 # Define all object files.
223 ALLOBJ
= $(addprefix $(OUTDIR
)/, $(addsuffix .o
, $(ALLSRCBASE
))) $(EXTRAOBJ
)
225 ALLLD
= $(addprefix $(OUTDIR
)/, $(addsuffix .
ld, $(notdir $(basename $(LDSRC
)))))
227 # Define all listing files (used for make clean).
228 LSTFILES
= $(addprefix $(OUTDIR
)/, $(addsuffix .lst
, $(ALLSRCBASE
)))
229 # Define all depedency-files (used for make clean).
230 DEPFILES
= $(addprefix $(OUTDIR
)/dep
/, $(addsuffix .o.d
, $(ALLSRCBASE
)))
235 ifeq ($(LOADFORMAT
),ihex
)
237 else ifeq ($(LOADFORMAT
),binary
)
239 else ifeq ($(LOADFORMAT
),both
)
240 build
: elf hex bin sym
242 $(error
"$(MSG_FORMATERROR) $(FORMAT)")
245 # Generate code for PyMite
246 # $(OUTDIR)/pmlib_img.c $(OUTDIR)/pmlib_nat.c $(OUTDIR)/pmlibusr_img.c $(OUTDIR)/pmlibusr_nat.c $(OUTDIR)/pmfeatures.h: $(wildcard $(PYMITELIB)/*.py) $(wildcard $(PYMITEPLAT)/*.py) $(wildcard $(FLIGHTPLANLIB)/*.py) $(wildcard $(FLIGHTPLANS)/*.py)
247 # @echo $(MSG_PYMITEINIT) $(call toprel,$@)
248 # @$(PYTHON) $(PYMITETOOLS)/pmImgCreator.py -f $(PYMITEPLAT)/pmfeatures.py -c -s --memspace=flash -o $(OUTDIR)/pmlib_img.c --native-file=$(OUTDIR)/pmlib_nat.c $(PYMITELIB)/list.py $(PYMITELIB)/dict.py $(PYMITELIB)/__bi.py $(PYMITELIB)/sys.py $(PYMITELIB)/string.py $(wildcard $(FLIGHTPLANLIB)/*.py)
249 # @$(PYTHON) $(PYMITETOOLS)/pmGenPmFeatures.py $(PYMITEPLAT)/pmfeatures.py > $(OUTDIR)/pmfeatures.h
250 # @$(PYTHON) $(PYMITETOOLS)/pmImgCreator.py -f $(PYMITEPLAT)/pmfeatures.py -c -u -o $(OUTDIR)/pmlibusr_img.c --native-file=$(OUTDIR)/pmlibusr_nat.c $(FLIGHTPLANS)/test.py
252 # Link: create ELF output file from object files.
253 ifeq ($(USE_CXX
), YES
)
254 $(eval
$(call LINK_CXX_TEMPLATE
,$(OUTDIR
)/$(TARGET
).elf
,$(ALLOBJ
),$(ALLLIB
),$(ALLLD
)))
256 $(eval
$(call LINK_TEMPLATE
,$(OUTDIR
)/$(TARGET
).elf
,$(ALLOBJ
),$(ALLLIB
),$(ALLLD
)))
259 # Assemble: create object files from assembler source files.
260 $(foreach src
, $(ASRC
), $(eval
$(call ASSEMBLE_TEMPLATE
,$(src
))))
262 # Assemble: create object files from assembler source files. ARM-only
263 $(foreach src
, $(ASRCARM
), $(eval
$(call ASSEMBLE_ARM_TEMPLATE
,$(src
))))
265 # Compile: create object files from C source files.
266 $(foreach src
, $(SRC
), $(eval
$(call COMPILE_C_TEMPLATE
,$(src
))))
268 # Compile: create object files from C source files. ARM-only
269 $(foreach src
, $(SRCARM
), $(eval
$(call COMPILE_C_ARM_TEMPLATE
,$(src
))))
271 ifeq ($(USE_CXX
), YES
)
272 # Compile: create object files from C++ source files.
273 $(foreach src
, $(CPPSRC
), $(eval
$(call COMPILE_CXX_TEMPLATE
,$(src
))))
275 # Compile: create object files from C++ source files. ARM-only
276 $(foreach src
, $(CPPSRCARM
), $(eval
$(call COMPILE_CXX_ARM_TEMPLATE
,$(src
))))
279 # Compile: create assembler files from C source files. ARM/Thumb
280 $(eval
$(call PARTIAL_COMPILE_TEMPLATE
,SRC
))
282 # Compile: create assembler files from C source files. ARM only
283 $(eval
$(call PARTIAL_COMPILE_ARM_TEMPLATE
,SRCARM
))
285 # Preprocess: create linker scripts from .lds files.
286 $(foreach src
, $(LDSRC
), $(eval
$(call PREPROCESS_LDS_TEMPLATE
,$(src
))))
289 $(eval
$(call OPFW_TEMPLATE
,$(OUTDIR
)/$(TARGET
).bin
,$(BOARD_TYPE
),$(BOARD_REVISION
)))
291 $(OUTDIR
)/$(TARGET
).bin.o
: $(OUTDIR
)/$(TARGET
).bin
293 .PHONY
: elf lss sym hex bin bino opfw
294 elf
: $(OUTDIR
)/$(TARGET
).elf
295 lss
: $(OUTDIR
)/$(TARGET
).lss
296 sym
: $(OUTDIR
)/$(TARGET
).sym
297 hex
: $(OUTDIR
)/$(TARGET
).hex
298 bin
: $(OUTDIR
)/$(TARGET
).bin
299 bino
: $(OUTDIR
)/$(TARGET
).bin.o
300 opfw
: $(OUTDIR
)/$(TARGET
).opfw
302 # Display sizes of sections.
303 $(eval
$(call SIZE_TEMPLATE
,$(OUTDIR
)/$(TARGET
).elf
))
305 # Target: clean project
307 @echo
$(MSG_CLEANING
)
308 $(V1
) rm -f
$(OUTDIR
)/$(TARGET
).map
309 $(V1
) rm -f
$(OUTDIR
)/$(TARGET
).elf
310 $(V1
) rm -f
$(OUTDIR
)/$(TARGET
).hex
311 $(V1
) rm -f
$(OUTDIR
)/$(TARGET
).bin
312 $(V1
) rm -f
$(OUTDIR
)/$(TARGET
).sym
313 $(V1
) rm -f
$(OUTDIR
)/$(TARGET
).lss
314 $(V1
) rm -f
$(OUTDIR
)/$(TARGET
).bin.o
315 $(V1
) rm -f
$(OUTDIR
)/$(TARGET
).opfw
316 $(V1
) rm -f
$(wildcard $(OUTDIR
)/*.c
)
317 $(V1
) rm -f
$(wildcard $(OUTDIR
)/*.h
)
318 $(V1
) rm -f
$(ALLOBJ
)
319 $(V1
) rm -f
$(LSTFILES
)
320 $(V1
) rm -f
$(DEPFILES
)
321 $(V1
) rm -f
$(SRC
:.c
=.s
)
322 $(V1
) rm -f
$(SRCARM
:.c
=.s
)
323 $(V1
) rm -f
$(CPPSRC
:.
cpp=.s
)
324 $(V1
) rm -f
$(CPPSRCARM
:.
cpp=.s
)
326 # Create output files directory
327 # all known MS Windows OS define the ComSpec environment variable
328 $(shell mkdir
-p
$(OUTDIR
) 2>/dev
/null
)
330 # Include the dependency files.
331 -include $(shell mkdir
-p
$(OUTDIR
)/dep
2>/dev
/null
) $(wildcard $(OUTDIR
)/dep
/*)
333 # Listing of phony targets.
334 .PHONY
: all build
clean install