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
)
155 CDEFS
+= $(BOARD_CDEFS
)
160 CFLAGS
+= -fdata-sections
-ffunction-sections
163 ifeq ($(USE_CXX
), YES
)
164 CPPFLAGS
+= -DPIOS_ENABLE_CXX
167 # Compiler flags to generate dependency files
168 CFLAGS
+= -MD
-MP
-MF
$(OUTDIR
)/dep
/$(@F
).d
171 #CONLYFLAGS += -Wnested-externs
172 CONLYFLAGS
+= $(CSTANDARD
) -Wunsuffixed-float-constants
175 # Note C++ compilation also uses CFLAGS. CONLYFLAGS has exclusions that
176 # can not be used with C++ compiler. C++ specific compile options are
177 # as set in CXXFLAGS. Note CPPFLAGS is for C pre-process and has not been
178 # used correctly - longer term move CDEFS to CPPFLAGS.
179 CXXFLAGS
+= -fno-rtti
-fno-exceptions
-std
=c
++11 -fno-use-cxa-atexit
182 # -Wa,...: tell GCC to pass this to the assembler.
183 # -ahlns: create listing
184 ASFLAGS
= -mcpu
=$(MCU
) -I.
-x assembler-with-cpp
186 ASFLAGS
+= $(patsubst %,-I
%,$(EXTRAINCDIRS
))
187 ASFLAGS
+= -Wa
,-adhlns
=$(addprefix $(OUTDIR
)/, $(notdir $(addsuffix .lst
, $(basename $<))))
190 # -Wl,...: tell GCC to pass this to linker.
191 # -Map: create map file
192 # --cref: add cross reference to map file
193 LDFLAGS
+= -nostartfiles
194 LDFLAGS
+= -Wl
,--warn-common
,--fatal-warnings
,--sort-common
,--sort-section
=alignment
,--gc-sections
195 LDFLAGS
+= -Wl
,-Map
=$(OUTDIR
)/$(TARGET
).map
,--cref
196 LDFLAGS
+= $(patsubst %,-L
%,$(EXTRA_LIBDIRS
))
197 LDFLAGS
+= $(patsubst %,-l
%,$(EXTRA_LIBS
))
200 ifneq ($(DEBUG
), YES
)
201 LDFLAGS
+= -Wl
,-static
204 # List of all source files.
205 ifeq ($(USE_CXX
), YES
)
206 ALLSRC
= $(CPPSRCARM
) $(CPPSRC
) $(ASRCARM
) $(ASRC
) $(SRCARM
) $(SRC
)
208 ALLSRC
= $(ASRCARM
) $(ASRC
) $(SRCARM
) $(SRC
)
211 # List of all source files without directory and file-extension.
212 ALLSRCBASE
= $(notdir $(basename $(ALLSRC
)))
214 # Define all object files.
215 ALLOBJ
= $(addprefix $(OUTDIR
)/, $(addsuffix .o
, $(ALLSRCBASE
))) $(EXTRAOBJ
)
217 # Define all listing files (used for make clean).
218 LSTFILES
= $(addprefix $(OUTDIR
)/, $(addsuffix .lst
, $(ALLSRCBASE
)))
219 # Define all depedency-files (used for make clean).
220 DEPFILES
= $(addprefix $(OUTDIR
)/dep
/, $(addsuffix .o.d
, $(ALLSRCBASE
)))
225 ifeq ($(LOADFORMAT
),ihex
)
227 else ifeq ($(LOADFORMAT
),binary
)
229 else ifeq ($(LOADFORMAT
),both
)
230 build
: elf hex bin sym
232 $(error
"$(MSG_FORMATERROR) $(FORMAT)")
235 # Generate code for PyMite
236 # $(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)
237 # @echo $(MSG_PYMITEINIT) $(call toprel, $@)
238 # @$(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)
239 # @$(PYTHON) $(PYMITETOOLS)/pmGenPmFeatures.py $(PYMITEPLAT)/pmfeatures.py > $(OUTDIR)/pmfeatures.h
240 # @$(PYTHON) $(PYMITETOOLS)/pmImgCreator.py -f $(PYMITEPLAT)/pmfeatures.py -c -u -o $(OUTDIR)/pmlibusr_img.c --native-file=$(OUTDIR)/pmlibusr_nat.c $(FLIGHTPLANS)/test.py
242 # Link: create ELF output file from object files.
243 ifeq ($(USE_CXX
), YES
)
244 $(eval
$(call LINK_CXX_TEMPLATE
, $(OUTDIR
)/$(TARGET
).elf
, $(ALLOBJ
), $(ALLLIB
)))
246 $(eval
$(call LINK_TEMPLATE
, $(OUTDIR
)/$(TARGET
).elf
, $(ALLOBJ
), $(ALLLIB
)))
249 # Assemble: create object files from assembler source files.
250 $(foreach src
, $(ASRC
), $(eval
$(call ASSEMBLE_TEMPLATE
, $(src
))))
252 # Assemble: create object files from assembler source files. ARM-only
253 $(foreach src
, $(ASRCARM
), $(eval
$(call ASSEMBLE_ARM_TEMPLATE
, $(src
))))
255 # Compile: create object files from C source files.
256 $(foreach src
, $(SRC
), $(eval
$(call COMPILE_C_TEMPLATE
, $(src
))))
258 # Compile: create object files from C source files. ARM-only
259 $(foreach src
, $(SRCARM
), $(eval
$(call COMPILE_C_ARM_TEMPLATE
, $(src
))))
261 ifeq ($(USE_CXX
), YES
)
262 # Compile: create object files from C++ source files.
263 $(foreach src
, $(CPPSRC
), $(eval
$(call COMPILE_CXX_TEMPLATE
, $(src
))))
265 # Compile: create object files from C++ source files. ARM-only
266 $(foreach src
, $(CPPSRCARM
), $(eval
$(call COMPILE_CXX_ARM_TEMPLATE
, $(src
))))
269 # Compile: create assembler files from C source files. ARM/Thumb
270 $(eval
$(call PARTIAL_COMPILE_TEMPLATE
, SRC
))
272 # Compile: create assembler files from C source files. ARM only
273 $(eval
$(call PARTIAL_COMPILE_ARM_TEMPLATE
, SRCARM
))
276 $(eval
$(call OPFW_TEMPLATE
,$(OUTDIR
)/$(TARGET
).bin
,$(BOARD_TYPE
),$(BOARD_REVISION
)))
278 $(OUTDIR
)/$(TARGET
).bin.o
: $(OUTDIR
)/$(TARGET
).bin
280 .PHONY
: elf lss sym hex bin bino opfw
281 elf
: $(OUTDIR
)/$(TARGET
).elf
282 lss
: $(OUTDIR
)/$(TARGET
).lss
283 sym
: $(OUTDIR
)/$(TARGET
).sym
284 hex
: $(OUTDIR
)/$(TARGET
).hex
285 bin
: $(OUTDIR
)/$(TARGET
).bin
286 bino
: $(OUTDIR
)/$(TARGET
).bin.o
287 opfw
: $(OUTDIR
)/$(TARGET
).opfw
289 # Display sizes of sections.
290 $(eval
$(call SIZE_TEMPLATE
, $(OUTDIR
)/$(TARGET
).elf
))
292 # Target: clean project
294 @echo
$(MSG_CLEANING
)
295 $(V1
) rm -f
$(OUTDIR
)/$(TARGET
).map
296 $(V1
) rm -f
$(OUTDIR
)/$(TARGET
).elf
297 $(V1
) rm -f
$(OUTDIR
)/$(TARGET
).hex
298 $(V1
) rm -f
$(OUTDIR
)/$(TARGET
).bin
299 $(V1
) rm -f
$(OUTDIR
)/$(TARGET
).sym
300 $(V1
) rm -f
$(OUTDIR
)/$(TARGET
).lss
301 $(V1
) rm -f
$(OUTDIR
)/$(TARGET
).bin.o
302 $(V1
) rm -f
$(OUTDIR
)/$(TARGET
).opfw
303 $(V1
) rm -f
$(wildcard $(OUTDIR
)/*.c
)
304 $(V1
) rm -f
$(wildcard $(OUTDIR
)/*.h
)
305 $(V1
) rm -f
$(ALLOBJ
)
306 $(V1
) rm -f
$(LSTFILES
)
307 $(V1
) rm -f
$(DEPFILES
)
308 $(V1
) rm -f
$(SRC
:.c
=.s
)
309 $(V1
) rm -f
$(SRCARM
:.c
=.s
)
310 $(V1
) rm -f
$(CPPSRC
:.
cpp=.s
)
311 $(V1
) rm -f
$(CPPSRCARM
:.
cpp=.s
)
313 # Create output files directory
314 # all known MS Windows OS define the ComSpec environment variable
315 $(shell mkdir
-p
$(OUTDIR
) 2>/dev
/null
)
317 # Include the dependency files.
318 -include $(shell mkdir
-p
$(OUTDIR
)/dep
2>/dev
/null
) $(wildcard $(OUTDIR
)/dep
/*)
320 # Listing of phony targets.
321 .PHONY
: all build
clean install