aboutsummaryrefslogtreecommitdiff
path: root/makefiles/application.mk
blob: 24be729ccdefbb8f5a0d0ee423ed6a59e59e968f (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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#
# Framework makefile for PX4 applications
#
# This makefile is invoked by firmware.mk to build each of the applications
# that will subsequently be linked into the firmware image.
#
# Applications are built as prelinked objects with a limited set of exported
# symbols, as the global namespace is shared between all apps. Normally an 
# application will just export one or more <command>_main functions.
#

#
# Variables that can be set by the application's app.mk:
#
#
# SRCS			(required)
#	Lists the .c, cpp and .S files that should be compiled/assembled to
#	produce the application.
#
# APP_NAME		(optional)
# APP_ENTRYPOINT	(optional if APP_NAME is set)
# APP_STACKSIZE		(optional if APP_NAME is set)
# APP_PRIORITY		(optional if APP_NAME is set)
#	Defines a single builtin command exported by the application.
#	APP_NAME must be unique for any configuration, but need not be the 
#	same as the app directory name.
#	
#	If APP_ENTRYPOINT is set, it names the function (which must be exported)
#	that will be the entrypoint for the builtin command. It defaults to
#	$(APP_NAME)_main.
#
#	If APP_STACKSIZE is set, it is the size in bytes of the stack to be
#	allocated for the builtin command. If it is not set, it defaults
#	to CONFIG_PTHREAD_STACK_DEFAULT.
#
#	If APP_PRIORITY is set, it is the thread priority for the builtin
#	command. If it is not set, it defaults to SCHED_PRIORITY_DEFAULT.
#
# APP_COMMANDS		(optional)
#	Defines builtin commands exported by the application. Each word in
#	the list should be formatted as: 
#		<command>.<priority>.<stacksize>.<entrypoint>
#

#
# Variables visible to the application's app.mk:
#
# CONFIG
# BOARD
# APP_WORK_DIR
# Anything set in setup.mk, board_$(BOARD).mk and the toolchain file.
# Anything exported from config_$(CONFIG).mk
#

################################################################################
# No user-serviceable parts below.
################################################################################

ifeq ($(APP_MK),)
$(error No application makefile specified)
endif

#
# Get path and tool config
#
include $(PX4_BASE)/makefiles/setup.mk

#
# Get the board/toolchain config
#
include $(PX4_MK_DIR)/board_$(BOARD).mk

#
# Get the application's config
#
include $(APP_MK)
APP_SRC_DIR		:= $(dir $(APP_MK))

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

################################################################################
# Builtin command definitions
################################################################################

ifneq ($(APP_NAME),)
APP_ENTRYPOINT		?= $(APP_NAME)_main
APP_STACKSIZE		?= CONFIG_PTHREAD_STACK_DEFAULT
APP_PRIORITY		?= SCHED_PRIORITY_DEFAULT
APP_COMMANDS		+= $(APP_NAME).$(APP_PRIORITY).$(APP_STACKSIZE).$(APP_ENTRYPOINT)
endif

ifneq ($(APP_COMMANDS),)
APP_COMMAND_FILES	:= $(addprefix $(WORK_DIR)/builtin_commands/COMMAND.,$(APP_COMMANDS))

.PHONY: $(APP_COMMAND_FILES)
$(APP_COMMAND_FILES): $(GLOBAL_DEPS)
	@echo %% registering: $(word 2,$(subst ., ,$(notdir $(@))))
	@mkdir -p $@
	$(Q) touch $@
endif

################################################################################
# Build rules
################################################################################

#
# What we're going to build
#
app:			$(APP_OBJ) $(APP_COMMAND_FILES)

#
# Locate sources (allows relative source paths in app.mk)
#
define SRC_SEARCH
	$(firstword $(wildcard $(APP_SRC_DIR)/$1) MISSING_$1)
endef

ABS_SRCS		:= $(foreach src,$(SRCS),$(call SRC_SEARCH,$(src)))
MISSING_SRCS		:= $(subst MISSING_,,$(filter MISSING_%,$(ABS_SRCS)))
ifneq ($(MISSING_SRCS),)
$(error $(APP_MK): missing in SRCS: $(MISSING_SRCS))
endif
ifeq ($(ABS_SRCS),)
$(error $(APP_MK): nothing to compile in SRCS)
endif

#
# Object files we will generate from sources
#
OBJS			:= $(foreach src,$(ABS_SRCS),$(APP_WORK_DIR)/$(src).o)

#
# SRCS -> OBJS rules
#

$(OBJS):		$(GLOBAL_DEPS)

$(filter %.c.o,$(OBJS)): $(APP_WORK_DIR)/%.c.o: %.c
	$(call COMPILE,$<,$@)

$(filter %.cpp.o,$(OBJS)): $(APP_WORK_DIR)/%.cpp.o: %.cpp $(GLOBAL_DEPS)
	$(call COMPILEXX,$<,$@)

$(filter %.S.o,$(OBJS)): $(APP_WORK_DIR)/%.S.o: %.S $(GLOBAL_DEPS)
	$(call ASSEMBLE,$<,$@)

#
# Built product rules
#

$(APP_OBJ):		$(OBJS) $(GLOBAL_DEPS)
	$(call PRELINK,$@,$(OBJS))

#
# Utility rules
#

clean:
	$(Q) $(REMOVE) $(APP_PRELINK) $(OBJS)