-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
165 lines (116 loc) · 4.68 KB
/
Makefile
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
163
164
165
# @file Makefile
# @brief Master build file for FX3 and apps
# @author Florin Iucha <[email protected]>
# @copyright Apache License, Version 2.0
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# This file is part of FX3 RTOS for ARM Cortex-M4
.DEFAULT_GOAL=artifacts
ifndef COMPILER
COMPILER:=gcc
endif
ifeq ($(RELEASE),true)
FLAVOR:=.rel
else
FLAVOR:=
endif
include tools/build/compiler-$(COMPILER).mk
.SUFFIXES: # Delete the default suffixes
.SUFFIXES: .c .cpp .o .elf .map .img # Define our suffix list
include config.mk
include source/kernel/kernel.mk
include source/drivers/drivers.mk
CHIP_FRAGMENTS:=$(wildcard source/chips/*/chip.mk)
include $(CHIP_FRAGMENTS)
BOARD_FRAGMENTS:=$(wildcard source/boards/*/board.mk)
include $(BOARD_FRAGMENTS)
APP_FRAGMENTS:=$(wildcard source/apps/*/app.mk)
include $(APP_FRAGMENTS)
COMPONENT_FRAGMENTS:=$(wildcard source/components/*/component.mk)
include $(COMPONENT_FRAGMENTS)
MYPATH=$(dir $(lastword $(MAKEFILE_LIST)))
#
# Arguments:
# 1: Application name
# 2: Board name
# 3: Components, separated by space
#
define TARGET_template=
ifdef BOARD_$(2)_MCU
$(1)_$(2)_OBJDIR:=$(MYPATH)obj.$(COMPILER)$(FLAVOR)
$$($(1)_$(2)_OBJDIR):
mkdir -p $$($(1)_$(2)_OBJDIR)
TARGETS+=$$($(1)_$(2)_OBJDIR)/$$(APP_$(1)_TARGET).img $(MYPATH)tags
DIR_TO_CLEAN+=$$($(1)_$(2)_OBJDIR) $(MYPATH)tags $(MYPATH)tagsinput
$(1)_$(2)_OBJ_LIST:=$(APP_$(1)_OBJECTS) $(BOARD_$(2)_OBJECTS) $(FX3_OBJECTS) $(foreach comp,$(3),$(COMPONENT_$(comp)_OBJECTS))
$(1)_$(2)_PREC_LIST:=$$($(1)_$(2)_OBJ_LIST:.o=.i)
$(1)_$(2)_OBJECTS:=$$(addprefix $$($(1)_$(2)_OBJDIR)/,$$($(1)_$(2)_OBJ_LIST))
$(1)_$(2)_PREC_FILES:=$$(addprefix $$($(1)_$(2)_OBJDIR)/,$$($(1)_$(2)_PREC_LIST))
$$($(1)_$(2)_OBJECTS): CFLAGS=$(foreach comp,$(3),$$(COMPONENT_$(comp)_CFLAGS)) $$(BOARD_$(2)_CFLAGS) $(COMPILER_CFLAGS) $$(BOARD_$(2)_INCLUDES) $(FX3_INCLUDES) $(DRIVERS_INCLUDES) $(foreach comp,$(3),$$(COMPONENT_$(comp)_INCLUDES)) -I$(MYPATH) -Ibuild/common-config
$$($(1)_$(2)_PREC_FILES): CFLAGS=$(foreach comp,$(3),$$(COMPONENT_$(comp)_CFLAGS)) $$(BOARD_$(2)_CFLAGS) $(COMPILER_CFLAGS) $$(BOARD_$(2)_INCLUDES) $(FX3_INCLUDES) $(DRIVERS_INCLUDES) $(foreach comp,$(3),$$(COMPONENT_$(comp)_INCLUDES)) -I$(MYPATH) -Ibuild/common-config
$$($(1)_$(2)_OBJECTS): AFLAGS=$$(BOARD_$(2)_AFLAGS) $(COMPILER_AFLAGS)
$$($(1)_$(2)_OBJDIR)/$$(APP_$(1)_TARGET).elf: LFLAGS=$$(BOARD_$(2)_LFLAGS) $(COMPILER_LFLAGS) -Wl,-Map=$$($(1)_$(2)_OBJDIR)/$$(APP_$(1)_TARGET).map
$$($(1)_$(2)_OBJDIR)/$$(APP_$(1)_TARGET).elf: $$($(1)_$(2)_OBJECTS)
ifeq ($(VERBOSE),true)
$(LD) $$(LFLAGS) -o $$@ $$^ $$(LDLIBS)
else
@echo LD $$@
@$(LD) $$(LFLAGS) -o $$@ $$^ $$(LDLIBS)
endif
@$(SIZE) $$@
$$($(1)_$(2)_OBJDIR)/$$(APP_$(1)_TARGET).img: $$($(1)_$(2)_OBJDIR)/$$(APP_$(1)_TARGET).elf
@echo IMG $$@
@$(OBJDUMP) $$< > $$@
$(MYPATH)tags: $$($(1)_$(2)_OBJDIR)/$$(APP_$(1)_TARGET).elf
@echo tags $(MYPATH)
@cat $$($(1)_$(2)_OBJDIR)/*.d | tr " " "\n" | grep ".h$$$$" | sort | uniq > $$($(1)_$(2)_OBJDIR)/headers.list
@python tools/build/make_relative_path.py $(MYPATH) $$($(1)_$(2)_OBJDIR)/sources.list $$($(1)_$(2)_OBJDIR)/headers.list > $(MYPATH)tagsinput
@cd $(MYPATH) && ctags -L tagsinput --c++-kinds=+p --fields=+iaS --extra=+q
$$($(1)_$(2)_OBJDIR)/%.o: %.S | $$($(1)_$(2)_OBJDIR)
ifeq ($(VERBOSE),true)
$(AS) $$(AFLAGS) -c -o $$@ $$<
else
@echo AS $$(<F)
@$(AS) $$(AFLAGS) -c -o $$@ $$<
endif
$$($(1)_$(2)_OBJDIR)/%.o: %.c | $$($(1)_$(2)_OBJDIR)
ifeq ($(VERBOSE),true)
$(CC) $$(CFLAGS) -c -o $$@ $$<
else
@echo CC $$(<F)
@$(CC) $$(CFLAGS) -c -o $$@ $$<
endif
$$(file >>$$($(1)_$(2)_OBJDIR)/sources.list,$$<)
$$($(1)_$(2)_OBJDIR)/%.i: %.c | $$($(1)_$(2)_OBJDIR)
$(CC) $$(CFLAGS) -E -o $$@ $$<
vpath %.c \
$(APP_$(1)_C_VPATH) \
$(BOARD_$(2)_C_VPATH) \
$(FX3_C_VPATH) \
$(DRIVERS_C_VPATH) \
$(foreach comp,$(3),$(COMPONENT_$(comp)_C_VPATH))
vpath %.S \
$(BOARD_$(2)_S_VPATH) \
$(FX3_S_VPATH)
$(1)_$(2)_DEPS:=$$($(1)_$(2)_OBJECTS:.o=.d)
-include $$($(1)_$(2)_DEPS)
endif # checking for BOARD definitions
endef # TARGET_template
TARGET_FRAGMENTS:=$(wildcard build/*/target.mk)
include $(TARGET_FRAGMENTS)
artifacts: $(TARGETS)
clean:
$(RM) -r $(DIR_TO_CLEAN) docs/generated
docs:
@doxygen
.PHONY: all clean artifacts docs