-
Notifications
You must be signed in to change notification settings - Fork 1
/
makefile
94 lines (78 loc) · 2.12 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
#
# This file is part of ucRegView
#
# ucRegView is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2, as
# published by the free Software Foundation.
#
#
# ucRegView is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with ucRegView. If not, see <http://www.gnu.org/licenses/>.
#
# Author: Maxime Vincent
#
#
# Basic Settings
TARGET ?= stm32f407xx
VERBOSE ?= 0
PREFIX ?= build
# Target specific include
include targets/$(TARGET)/rules.mk
# Toolchain settings
CC := $(CROSS_COMPILE)gcc
LD := $(CROSS_COMPILE)gcc
OBJCOPY := $(CROSS_COMPILE)objcopy
RM := rm -rf
# Convert all sources to OBJ and DEPS
OBJS := $(addprefix $(PREFIX)/,$(ASM_SRCS:.S=.o))
OBJS += $(addprefix $(PREFIX)/,$(C_SRCS:.c=.o))
DEPS := $(OBJS:.o=.d)
# Compile flags
CFLAGS += -ggdb3 -O0
LDFLAGS += -nostartfiles -ffreestanding
# Debug settings
ifeq ($(VERBOSE),1)
V :=
else
V := @
endif
# All Target
all: ucregview_$(TARGET).elf
# Toolchain calls
ucregview_$(TARGET).elf: $(OBJS)
@echo '[LD] $@'
$(V)$(LD) $(CFLAGS) $(LDFLAGS) -g3 -Xlinker --gc-sections -Wl,-Map,"ucregview_$(TARGET).map" -o $@ $(OBJS)
# Other Targets
clean:
@echo '[RM] Clean'
$(V)-$(RM) $(OBJS) $(ASM_DEPS) $(DEPS) ucregview_$(TARGET).elf ucregview_$(TARGET).map
-@echo ' '
print:
@echo C_SRCS: $(C_SRCS)
@echo
@echo S_SRCS: $(S_SRCS)
@echo
@echo OBJS: $(OBJS)
@echo
@echo DEPS: $(DEPS)
@echo
# [C] Generic build target
$(PREFIX)/%.o: %.c $(PREFIX)/%.d
@echo '[C] $<'
@mkdir -p $(dir $@)
$(V)$(CC) $(CFLAGS) -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -c -o "$@" "$<"
# [S] Generic build target
$(PREFIX)/%.o: %.S $(PREFIX)/%.d
@echo '[S] $<'
@mkdir -p $(dir $@)
$(V)$(CC) $(CFLAGS) -x assembler-with-cpp -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -c -o "$@" "$<"
# [D] For dependencies
$(PREFIX)/%.d: ;
.PRECIOUS: $(PREFIX)/%.d
.PHONY: all clean dependents
-include $(DEPS)