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 OPENPILOT_IS_COOL
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
168 # Compiler flags to generate dependency files
169 CFLAGS
+= -MD
-MP
-MF
$(OUTDIR
)/dep
/$(@F
).d
172 #CONLYFLAGS += -Wnested-externs
173 CONLYFLAGS
+= $(CSTANDARD
) -Wunsuffixed-float-constants
176 # Note C++ compilation also uses CFLAGS. CONLYFLAGS has exclusions that
177 # can not be used with C++ compiler. C++ specific compile options are
178 # as set in CXXFLAGS. Note CPPFLAGS is for C pre-process and has not been
179 # used correctly - longer term move CDEFS to CPPFLAGS.
180 CXXFLAGS
+= -fno-rtti
-fno-exceptions
-std
=c
++11 -fno-use-cxa-atexit
183 # -Wa,...: tell GCC to pass this to the assembler.
184 # -ahlns: create listing
185 ASFLAGS
= -mcpu
=$(MCU
) -I.
-x assembler-with-cpp
187 ASFLAGS
+= $(patsubst %,-I
%,$(EXTRAINCDIRS
))
188 ASFLAGS
+= -Wa
,-adhlns
=$(addprefix $(OUTDIR
)/, $(notdir $(addsuffix .lst
, $(basename $<))))
191 # -Wl,...: tell GCC to pass this to linker.
192 # -Map: create map file
193 # --cref: add cross reference to map file
194 LDFLAGS
+= -nostartfiles
195 LDFLAGS
+= -Wl
,--warn-common
,--fatal-warnings
,--sort-common
,--sort-section
=alignment
,--gc-sections
196 LDFLAGS
+= -Wl
,-Map
=$(OUTDIR
)/$(TARGET
).map
,--cref
197 LDFLAGS
+= $(patsubst %,-L
%,$(EXTRA_LIBDIRS
))
198 LDFLAGS
+= $(patsubst %,-l
%,$(EXTRA_LIBS
))
201 ifneq ($(DEBUG
), YES
)
202 LDFLAGS
+= -Wl
,-static
205 # List of all source files.
206 ifeq ($(USE_CXX
), YES
)
207 ALLSRC
= $(CPPSRCARM
) $(CPPSRC
) $(ASRCARM
) $(ASRC
) $(SRCARM
) $(SRC
)
209 ALLSRC
= $(ASRCARM
) $(ASRC
) $(SRCARM
) $(SRC
)
212 # List of all source files without directory and file-extension.
213 ALLSRCBASE
= $(notdir $(basename $(ALLSRC
)))
215 # Define all object files.
216 ALLOBJ
= $(addprefix $(OUTDIR
)/, $(addsuffix .o
, $(ALLSRCBASE
))) $(EXTRAOBJ
)
218 # Define all listing files (used for make clean).
219 LSTFILES
= $(addprefix $(OUTDIR
)/, $(addsuffix .lst
, $(ALLSRCBASE
)))
220 # Define all depedency-files (used for make clean).
221 DEPFILES
= $(addprefix $(OUTDIR
)/dep
/, $(addsuffix .o.d
, $(ALLSRCBASE
)))
226 ifeq ($(LOADFORMAT
),ihex
)
228 else ifeq ($(LOADFORMAT
),binary
)
230 else ifeq ($(LOADFORMAT
),both
)
231 build
: elf hex bin sym
233 $(error
"$(MSG_FORMATERROR) $(FORMAT)")
236 # Generate code for PyMite
237 # $(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)
238 # @$(ECHO) $(MSG_PYMITEINIT) $(call toprel, $@)
239 # @$(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)
240 # @$(PYTHON) $(PYMITETOOLS)/pmGenPmFeatures.py $(PYMITEPLAT)/pmfeatures.py > $(OUTDIR)/pmfeatures.h
241 # @$(PYTHON) $(PYMITETOOLS)/pmImgCreator.py -f $(PYMITEPLAT)/pmfeatures.py -c -u -o $(OUTDIR)/pmlibusr_img.c --native-file=$(OUTDIR)/pmlibusr_nat.c $(FLIGHTPLANS)/test.py
243 # Link: create ELF output file from object files.
244 ifeq ($(USE_CXX
), YES
)
245 $(eval
$(call LINK_CXX_TEMPLATE
, $(OUTDIR
)/$(TARGET
).elf
, $(ALLOBJ
), $(ALLLIB
)))
247 $(eval
$(call LINK_TEMPLATE
, $(OUTDIR
)/$(TARGET
).elf
, $(ALLOBJ
), $(ALLLIB
)))
250 # Assemble: create object files from assembler source files.
251 $(foreach src
, $(ASRC
), $(eval
$(call ASSEMBLE_TEMPLATE
, $(src
))))
253 # Assemble: create object files from assembler source files. ARM-only
254 $(foreach src
, $(ASRCARM
), $(eval
$(call ASSEMBLE_ARM_TEMPLATE
, $(src
))))
256 # Compile: create object files from C source files.
257 $(foreach src
, $(SRC
), $(eval
$(call COMPILE_C_TEMPLATE
, $(src
))))
259 # Compile: create object files from C source files. ARM-only
260 $(foreach src
, $(SRCARM
), $(eval
$(call COMPILE_C_ARM_TEMPLATE
, $(src
))))
262 ifeq ($(USE_CXX
), YES
)
263 # Compile: create object files from C++ source files.
264 $(foreach src
, $(CPPSRC
), $(eval
$(call COMPILE_CXX_TEMPLATE
, $(src
))))
266 # Compile: create object files from C++ source files. ARM-only
267 $(foreach src
, $(CPPSRCARM
), $(eval
$(call COMPILE_CXX_ARM_TEMPLATE
, $(src
))))
270 # Compile: create assembler files from C source files. ARM/Thumb
271 $(eval
$(call PARTIAL_COMPILE_TEMPLATE
, SRC
))
273 # Compile: create assembler files from C source files. ARM only
274 $(eval
$(call PARTIAL_COMPILE_ARM_TEMPLATE
, SRCARM
))
277 $(eval
$(call OPFW_TEMPLATE
,$(OUTDIR
)/$(TARGET
).bin
,$(BOARD_TYPE
),$(BOARD_REVISION
)))
279 $(OUTDIR
)/$(TARGET
).bin.o
: $(OUTDIR
)/$(TARGET
).bin
281 .PHONY
: elf lss sym hex bin bino opfw
282 elf
: $(OUTDIR
)/$(TARGET
).elf
283 lss
: $(OUTDIR
)/$(TARGET
).lss
284 sym
: $(OUTDIR
)/$(TARGET
).sym
285 hex
: $(OUTDIR
)/$(TARGET
).hex
286 bin
: $(OUTDIR
)/$(TARGET
).bin
287 bino
: $(OUTDIR
)/$(TARGET
).bin.o
288 opfw
: $(OUTDIR
)/$(TARGET
).opfw
290 # Display sizes of sections.
291 $(eval
$(call SIZE_TEMPLATE
, $(OUTDIR
)/$(TARGET
).elf
))
293 # Target: clean project
295 @echo
$(MSG_CLEANING
)
296 $(V1
) $(RM
) -f
$(OUTDIR
)/$(TARGET
).map
297 $(V1
) $(RM
) -f
$(OUTDIR
)/$(TARGET
).elf
298 $(V1
) $(RM
) -f
$(OUTDIR
)/$(TARGET
).hex
299 $(V1
) $(RM
) -f
$(OUTDIR
)/$(TARGET
).bin
300 $(V1
) $(RM
) -f
$(OUTDIR
)/$(TARGET
).sym
301 $(V1
) $(RM
) -f
$(OUTDIR
)/$(TARGET
).lss
302 $(V1
) $(RM
) -f
$(OUTDIR
)/$(TARGET
).bin.o
303 $(V1
) $(RM
) -f
$(OUTDIR
)/$(TARGET
).opfw
304 $(V1
) $(RM
) -f
$(wildcard $(OUTDIR
)/*.c
)
305 $(V1
) $(RM
) -f
$(wildcard $(OUTDIR
)/*.h
)
306 $(V1
) $(RM
) -f
$(ALLOBJ
)
307 $(V1
) $(RM
) -f
$(LSTFILES
)
308 $(V1
) $(RM
) -f
$(DEPFILES
)
309 $(V1
) $(RM
) -f
$(SRC
:.c
=.s
)
310 $(V1
) $(RM
) -f
$(SRCARM
:.c
=.s
)
311 $(V1
) $(RM
) -f
$(CPPSRC
:.
cpp=.s
)
312 $(V1
) $(RM
) -f
$(CPPSRCARM
:.
cpp=.s
)
314 # Create output files directory
315 # all known MS Windows OS define the ComSpec environment variable
316 $(shell $(MKDIR
) -p
$(OUTDIR
) 2>/dev
/null
)
318 # Include the dependency files.
319 -include $(shell $(MKDIR
) -p
$(OUTDIR
)/dep
2>/dev
/null
) $(wildcard $(OUTDIR
)/dep
/*)
321 # Listing of phony targets.
322 .PHONY
: all build
clean install