OP-1156 fixed wrong callback ID assignment for pathfollower callback diagnostics
[librepilot.git] / make / common-defs.mk
blobe7b60e1eb19cb4528897b5c38d7fb5b5b08d9458
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
12 # for more details.
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)
21 endif
23 # Set to YES to compile for debugging
24 DEBUG ?= NO
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
30 ENABLE_AUX_UART ?= NO
32 # Include objects that are just nice information to show
33 DIAG_STACK ?= NO
34 DIAG_MIXERSTATUS ?= NO
35 DIAG_RATEDESIRED ?= NO
36 DIAG_I2C_WDG_STATS ?= NO
37 DIAG_TASKS ?= NO
38 DIAG_INSTRUMENTATION ?= NO
40 # Or just turn on all the above diagnostics. WARNING: this consumes massive amounts of memory.
41 DIAG_ALL ?= NO
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.
46 ifeq ($(DEBUG), YES)
47 OPT = 0
48 else
49 OPT = s
50 endif
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
55 #LOADFORMAT = ihex
56 #LOADFORMAT = binary
57 LOADFORMAT = both
59 # Debugging format.
60 DEBUGF = dwarf-2
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
67 endif
69 ifeq ($(ENABLE_AUX_UART), YES)
70 CDEFS += -DPIOS_ENABLE_AUX_UART
71 endif
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
77 endif
79 ifneq (,$(filter YES,$(DIAG_MIXERSTATUS) $(DIAG_ALL)))
80 CFLAGS += -DDIAG_MIXERSTATUS
81 endif
83 ifneq (,$(filter YES,$(DIAG_RATEDESIRED) $(DIAG_ALL)))
84 CFLAGS += -DDIAG_RATEDESIRED
85 endif
87 ifneq (,$(filter YES,$(DIAG_I2C_WDG_STATS) $(DIAG_ALL)))
88 CFLAGS += -DDIAG_I2C_WDG_STATS
89 endif
91 ifneq (,$(filter YES,$(DIAG_TASKS) $(DIAG_ALL)))
92 CFLAGS += -DDIAG_TASKS
93 endif
95 ifneq (,$(filter YES,$(DIAG_INSTRUMENTATION) $(DIAG_ALL)))
96 CFLAGS += -DPIOS_INCLUDE_INSTRUMENTATION
97 endif
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.
103 # c89 - "ANSI" C
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
109 # Compiler flags.
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)
120 CFLAGS += $(CDEFS)
121 CFLAGS += -O$(OPT)
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
127 CFLAGS += -Wshadow
128 CFLAGS += -Werror
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)
144 ifdef EE_BANK_BASE
145 BOARD_CDEFS += -DEE_BANK_BASE=$(EE_BANK_BASE)
146 BOARD_CDEFS += -DEE_BANK_SIZE=$(EE_BANK_SIZE)
147 endif
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)
151 endif
152 CDEFS += $(BOARD_CDEFS)
154 ifeq ($(DEBUG), YES)
155 CFLAGS += -DDEBUG
156 else
157 CFLAGS += -fdata-sections -ffunction-sections
158 endif
160 # Compiler flags to generate dependency files
161 CFLAGS += -MD -MP -MF $(OUTDIR)/dep/$(@F).d
163 # Flags only for C
164 #CONLYFLAGS += -Wnested-externs
165 CONLYFLAGS += $(CSTANDARD)
167 # Assembler flags.
168 # -Wa,...: tell GCC to pass this to the assembler.
169 # -ahlns: create listing
170 ASFLAGS = -mcpu=$(MCU) -I. -x assembler-with-cpp
171 ASFLAGS += $(ADEFS)
172 ASFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
173 ASFLAGS += -Wa,-adhlns=$(addprefix $(OUTDIR)/, $(notdir $(addsuffix .lst, $(basename $<))))
175 # Linker flags.
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))
184 LDFLAGS += -lc -lgcc
186 ifneq ($(DEBUG), YES)
187 LDFLAGS += -Wl,-static
188 endif
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)))
203 # Default target.
204 all: build
206 ifeq ($(LOADFORMAT),ihex)
207 build: elf hex sym
208 else ifeq ($(LOADFORMAT),binary)
209 build: elf bin sym
210 else ifeq ($(LOADFORMAT),both)
211 build: elf hex bin sym
212 else
213 $(error "$(MSG_FORMATERROR) $(FORMAT)")
214 endif
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))
250 # Add opfw target
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
268 clean:
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