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 use the Servo output pins for debugging via scope or logic analyser
27 ENABLE_DEBUG_PINS ?
= NO
29 # Set to YES to enable the AUX UART which is mapped on the S1 (Tx) and S2 (Rx) servo outputs
32 # Include objects that are just nice information to show
34 DIAG_MIXERSTATUS ?
= NO
35 DIAG_RATEDESIRED ?
= NO
36 DIAG_I2C_WDG_STATS ?
= NO
38 DIAG_INSTRUMENTATION ?
= NO
40 # Or just turn on all the above diagnostics. WARNING: this consumes massive amounts of memory.
43 # Optimization level, can be [0, 1, 2, 3, s].
44 # 0 = turn off optimization. s = optimize for size.
45 # Note: 3 is not always the best optimization level.
52 # Output format (can be ihex or binary or both).
53 # binary to create a load-image in raw-binary format i.e. for SAM-BA,
54 # ihex to create a load-image in Intel hex format
62 # Place project-specific -D (define) and/or -U options for C here.
63 CDEFS
+= -DUSE_
$(BOARD
)
65 ifeq ($(ENABLE_DEBUG_PINS
), YES
)
66 CDEFS
+= -DPIOS_ENABLE_DEBUG_PINS
69 ifeq ($(ENABLE_AUX_UART
), YES
)
70 CDEFS
+= -DPIOS_ENABLE_AUX_UART
73 # The following Makefile command, ifneq (,$(filter) $(A), $(B) $(C))
74 # is equivalent to the pseudocode `if (A == B || A == C)`
75 ifneq (,$(filter YES
,$(DIAG_STACK
) $(DIAG_ALL
)))
76 CFLAGS
+= -DDIAG_STACK
79 ifneq (,$(filter YES
,$(DIAG_MIXERSTATUS
) $(DIAG_ALL
)))
80 CFLAGS
+= -DDIAG_MIXERSTATUS
83 ifneq (,$(filter YES
,$(DIAG_RATEDESIRED
) $(DIAG_ALL
)))
84 CFLAGS
+= -DDIAG_RATEDESIRED
87 ifneq (,$(filter YES
,$(DIAG_I2C_WDG_STATS
) $(DIAG_ALL
)))
88 CFLAGS
+= -DDIAG_I2C_WDG_STATS
91 ifneq (,$(filter YES
,$(DIAG_TASKS
) $(DIAG_ALL
)))
92 CFLAGS
+= -DDIAG_TASKS
95 ifneq (,$(filter YES
,$(DIAG_INSTRUMENTATION
) $(DIAG_ALL
)))
96 CFLAGS
+= -DPIOS_INCLUDE_INSTRUMENTATION
98 # Place project-specific -D and/or -U options for Assembler with preprocessor here.
99 #ADEFS = -DUSE_IRQ_ASM_WRAPPER
100 ADEFS
= -D__ASSEMBLY__
102 # Compiler flag to set the C Standard level.
104 # gnu89 - c89 plus GCC extensions
105 # c99 - ISO C99 standard (not yet fully implemented)
106 # gnu99 - c99 plus GCC extensions
107 CSTANDARD
= -std
=gnu99
111 # -g*: generate debugging information
112 # -O*: optimization level
113 # -f...: tuning, see GCC manual and avr-libc documentation
114 # -Wall...: warning level
115 # -Wa,...: tell GCC to pass this to the assembler.
116 # -adhlns...: create assembler listing
118 # Common architecture-specific flags from the device-specific library makefile
119 CFLAGS
+= $(ARCHFLAGS
)
122 CFLAGS
+= -g
$(DEBUGF
)
123 CFLAGS
+= -mapcs-frame
124 CFLAGS
+= -fomit-frame-pointer
125 CFLAGS
+= -Wall
-Wextra
126 CFLAGS
+= -Wfloat-equal
-Wunsuffixed-float-constants
-Wdouble-promotion
129 CFLAGS
+= $(patsubst %,-I
%,$(EXTRAINCDIRS
)) -I.
130 CFLAGS
+= -Wa
,-adhlns
=$(addprefix $(OUTDIR
)/, $(notdir $(addsuffix .lst
, $(basename $<))))
132 # Provides board-specific defines
133 BOARD_CDEFS
+= -DBOARD_TYPE
=$(BOARD_TYPE
)
134 BOARD_CDEFS
+= -DBOARD_REVISION
=$(BOARD_REVISION
)
135 BOARD_CDEFS
+= -DHW_TYPE
=$(HW_TYPE
)
136 BOARD_CDEFS
+= -DBOOTLOADER_VERSION
=$(BOOTLOADER_VERSION
)
137 BOARD_CDEFS
+= -DFW_BANK_BASE
=$(FW_BANK_BASE
)
138 BOARD_CDEFS
+= -DFW_BANK_SIZE
=$(FW_BANK_SIZE
)
139 BOARD_CDEFS
+= -DFW_DESC_SIZE
=$(FW_DESC_SIZE
)
141 BOARD_CDEFS
+= -DBL_BANK_BASE
=$(BL_BANK_BASE
)
142 BOARD_CDEFS
+= -DBL_BANK_SIZE
=$(BL_BANK_SIZE
)
143 BOARD_CDEFS
+= -DBL_DESC_SIZE
=$(BL_DESC_SIZE
)
145 BOARD_CDEFS
+= -DEE_BANK_BASE
=$(EE_BANK_BASE
)
146 BOARD_CDEFS
+= -DEE_BANK_SIZE
=$(EE_BANK_SIZE
)
148 ifdef USER_EE_BANK_BASE
149 BOARD_CDEFS
+= -DUSER_EE_BANK_BASE
=$(USER_EE_BANK_BASE
)
150 BOARD_CDEFS
+= -DUSER_EE_BANK_SIZE
=$(USER_EE_BANK_SIZE
)
152 CDEFS
+= $(BOARD_CDEFS
)
157 CFLAGS
+= -fdata-sections
-ffunction-sections
160 # Compiler flags to generate dependency files
161 CFLAGS
+= -MD
-MP
-MF
$(OUTDIR
)/dep
/$(@F
).d
164 #CONLYFLAGS += -Wnested-externs
165 CONLYFLAGS
+= $(CSTANDARD
)
168 # -Wa,...: tell GCC to pass this to the assembler.
169 # -ahlns: create listing
170 ASFLAGS
= -mcpu
=$(MCU
) -I.
-x assembler-with-cpp
172 ASFLAGS
+= $(patsubst %,-I
%,$(EXTRAINCDIRS
))
173 ASFLAGS
+= -Wa
,-adhlns
=$(addprefix $(OUTDIR
)/, $(notdir $(addsuffix .lst
, $(basename $<))))
176 # -Wl,...: tell GCC to pass this to linker.
177 # -Map: create map file
178 # --cref: add cross reference to map file
179 LDFLAGS
+= -nostartfiles
180 LDFLAGS
+= -Wl
,--warn-common
,--fatal-warnings
,--sort-common
,--sort-section
=alignment
,--gc-sections
181 LDFLAGS
+= -Wl
,-Map
=$(OUTDIR
)/$(TARGET
).map
,--cref
182 LDFLAGS
+= $(patsubst %,-L
%,$(EXTRA_LIBDIRS
))
183 LDFLAGS
+= $(patsubst %,-l
%,$(EXTRA_LIBS
))
186 ifneq ($(DEBUG
), YES
)
187 LDFLAGS
+= -Wl
,-static
190 # List of all source files.
191 ALLSRC
= $(ASRCARM
) $(ASRC
) $(SRCARM
) $(SRC
) $(CPPSRCARM
) $(CPPSRC
)
192 # List of all source files without directory and file-extension.
193 ALLSRCBASE
= $(notdir $(basename $(ALLSRC
)))
195 # Define all object files.
196 ALLOBJ
= $(addprefix $(OUTDIR
)/, $(addsuffix .o
, $(ALLSRCBASE
))) $(EXTRAOBJ
)
198 # Define all listing files (used for make clean).
199 LSTFILES
= $(addprefix $(OUTDIR
)/, $(addsuffix .lst
, $(ALLSRCBASE
)))
200 # Define all depedency-files (used for make clean).
201 DEPFILES
= $(addprefix $(OUTDIR
)/dep
/, $(addsuffix .o.d
, $(ALLSRCBASE
)))
206 ifeq ($(LOADFORMAT
),ihex
)
208 else ifeq ($(LOADFORMAT
),binary
)
210 else ifeq ($(LOADFORMAT
),both
)
211 build
: elf hex bin sym
213 $(error
"$(MSG_FORMATERROR) $(FORMAT)")
216 # Generate code for PyMite
217 # $(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)
218 # @$(ECHO) $(MSG_PYMITEINIT) $(call toprel, $@)
219 # @$(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)
220 # @$(PYTHON) $(PYMITETOOLS)/pmGenPmFeatures.py $(PYMITEPLAT)/pmfeatures.py > $(OUTDIR)/pmfeatures.h
221 # @$(PYTHON) $(PYMITETOOLS)/pmImgCreator.py -f $(PYMITEPLAT)/pmfeatures.py -c -u -o $(OUTDIR)/pmlibusr_img.c --native-file=$(OUTDIR)/pmlibusr_nat.c $(FLIGHTPLANS)/test.py
223 # Link: create ELF output file from object files.
224 $(eval
$(call LINK_TEMPLATE
, $(OUTDIR
)/$(TARGET
).elf
, $(ALLOBJ
), $(ALLLIB
)))
226 # Assemble: create object files from assembler source files.
227 $(foreach src
, $(ASRC
), $(eval
$(call ASSEMBLE_TEMPLATE
, $(src
))))
229 # Assemble: create object files from assembler source files. ARM-only
230 $(foreach src
, $(ASRCARM
), $(eval
$(call ASSEMBLE_ARM_TEMPLATE
, $(src
))))
232 # Compile: create object files from C source files.
233 $(foreach src
, $(SRC
), $(eval
$(call COMPILE_C_TEMPLATE
, $(src
))))
235 # Compile: create object files from C source files. ARM-only
236 $(foreach src
, $(SRCARM
), $(eval
$(call COMPILE_C_ARM_TEMPLATE
, $(src
))))
238 # Compile: create object files from C++ source files.
239 $(foreach src
, $(CPPSRC
), $(eval
$(call COMPILE_CPP_TEMPLATE
, $(src
))))
241 # Compile: create object files from C++ source files. ARM-only
242 $(foreach src
, $(CPPSRCARM
), $(eval
$(call COMPILE_CPP_ARM_TEMPLATE
, $(src
))))
244 # Compile: create assembler files from C source files. ARM/Thumb
245 $(eval
$(call PARTIAL_COMPILE_TEMPLATE
, SRC
))
247 # Compile: create assembler files from C source files. ARM only
248 $(eval
$(call PARTIAL_COMPILE_ARM_TEMPLATE
, SRCARM
))
251 $(eval
$(call OPFW_TEMPLATE
,$(OUTDIR
)/$(TARGET
).bin
,$(BOARD_TYPE
),$(BOARD_REVISION
)))
253 $(OUTDIR
)/$(TARGET
).bin.o
: $(OUTDIR
)/$(TARGET
).bin
255 .PHONY
: elf lss sym hex bin bino opfw
256 elf
: $(OUTDIR
)/$(TARGET
).elf
257 lss
: $(OUTDIR
)/$(TARGET
).lss
258 sym
: $(OUTDIR
)/$(TARGET
).sym
259 hex
: $(OUTDIR
)/$(TARGET
).hex
260 bin
: $(OUTDIR
)/$(TARGET
).bin
261 bino
: $(OUTDIR
)/$(TARGET
).bin.o
262 opfw
: $(OUTDIR
)/$(TARGET
).opfw
264 # Display sizes of sections.
265 $(eval
$(call SIZE_TEMPLATE
, $(OUTDIR
)/$(TARGET
).elf
))
267 # Target: clean project
269 @echo
$(MSG_CLEANING
)
270 $(V1
) $(RM
) -f
$(OUTDIR
)/$(TARGET
).map
271 $(V1
) $(RM
) -f
$(OUTDIR
)/$(TARGET
).elf
272 $(V1
) $(RM
) -f
$(OUTDIR
)/$(TARGET
).hex
273 $(V1
) $(RM
) -f
$(OUTDIR
)/$(TARGET
).bin
274 $(V1
) $(RM
) -f
$(OUTDIR
)/$(TARGET
).sym
275 $(V1
) $(RM
) -f
$(OUTDIR
)/$(TARGET
).lss
276 $(V1
) $(RM
) -f
$(OUTDIR
)/$(TARGET
).bin.o
277 $(V1
) $(RM
) -f
$(OUTDIR
)/$(TARGET
).opfw
278 $(V1
) $(RM
) -f
$(wildcard $(OUTDIR
)/*.c
)
279 $(V1
) $(RM
) -f
$(wildcard $(OUTDIR
)/*.h
)
280 $(V1
) $(RM
) -f
$(ALLOBJ
)
281 $(V1
) $(RM
) -f
$(LSTFILES
)
282 $(V1
) $(RM
) -f
$(DEPFILES
)
283 $(V1
) $(RM
) -f
$(SRC
:.c
=.s
)
284 $(V1
) $(RM
) -f
$(SRCARM
:.c
=.s
)
285 $(V1
) $(RM
) -f
$(CPPSRC
:.
cpp=.s
)
286 $(V1
) $(RM
) -f
$(CPPSRCARM
:.
cpp=.s
)
288 # Create output files directory
289 # all known MS Windows OS define the ComSpec environment variable
290 $(shell $(MKDIR
) -p
$(OUTDIR
) 2>/dev
/null
)
292 # Include the dependency files.
293 -include $(shell $(MKDIR
) -p
$(OUTDIR
)/dep
2>/dev
/null
) $(wildcard $(OUTDIR
)/dep
/*)
295 # Listing of phony targets.
296 .PHONY
: all build
clean install