aboutsummaryrefslogtreecommitdiff
path: root/makefiles/firmware.mk
blob: 3f41ec6521cfc65014a3c9184f5bf710de8b3833 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#
# Generic Makefile for PX4 firmware.
#
# Currently this assumes that we're just compiling SRCS
# and then linking the whole thing together.
#

#
# Work out where this file is, so we can find other makefiles in the
# same directory.
#
# If PX4_BASE wasn't set previously, set it here now.
#
export PX4_MK_INCLUDE	?= $(dir $(lastword $(MAKEFILE_LIST)))
ifeq ($(PX4_BASE),)
export PX4_BASE		:= $(abspath $(PX4_MK_INCLUDE)/..)
endif

#
# Use the linker script from the NuttX export
#
LDSCRIPT		 = $(WORK_DIR)/nuttx-export/build/ld.script

#
# Add directories from the NuttX export to the relevant search paths
#
INCLUDE_DIRS		+= $(WORK_DIR)/nuttx-export/include
LIB_DIRS		+= $(WORK_DIR)/nuttx-export/libs
LIBS			+= -lapps -lnuttx

#
# Things that, if they change, might affect everything
#
GLOBAL_DEPS		+= $(MAKEFILE_LIST)

#
# Include the platform configuration
#
include $(PX4_MK_INCLUDE)/$(PLATFORM).mk

#
# What we're going to build
#
PRODUCT_BUNDLE		 = $(WORK_DIR)/firmware.px4
PRODUCT_BIN		 = $(WORK_DIR)/firmware.bin
PRODUCT_SYM		 = $(WORK_DIR)/firmware.sym
PRODUCTS		 = $(PRODUCT_BIN) $(PRODUCT_SYM)

.PHONY:			all
all:			$(PRODUCTS)

#
# Rules for building objects
#
OBJS			 = $(foreach src,$(SRCS),$(WORK_DIR)/$(src).o)

$(filter %.c.o,$(OBJS)): $(WORK_DIR)/%.c.o: %.c
	@echo compile $<
	@mkdir -p $(dir $@)
	$(call COMPILE,$<,$@)

$(filter %.cpp.o,$(OBJS)): $(WORK_DIR)/%.cpp.o: %.cpp
	@mkdir -p $(dir $@)
	$(call COMPILEXX,$<,$@)

$(filter %.S.o,$(OBJS)): $(WORK_DIR)/%.S.o: %.S
	@mkdir -p $(dir $@)
	$(call ASSEMBLE,$<,$@)

-include $(DEP_INCLUDES)

$(PRODUCT_BIN):		$(PRODUCT_SYM)
	$(call SYM_TO_BIN,$<,$@)

$(PRODUCT_SYM):		$(OBJS) $(GLOBAL_DEPS) $(LINK_DEPS)
	$(call LINK,$@,$(OBJS))