-
Notifications
You must be signed in to change notification settings - Fork 6
/
Makefile.include
69 lines (61 loc) · 2.31 KB
/
Makefile.include
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
# This file is part of the stenosaurus project.
#
# Copyright (C) 2013 Hesky Fisher <[email protected]>
#
# This library is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This library 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 Lesser General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this library. If not, see <http://www.gnu.org/licenses/>.
#
# This file provides common parameters used by both the bootloader and the
# application firmware.
PREFIX := arm-none-eabi
CC := $(PREFIX)-gcc
LD := $(PREFIX)-gcc
OBJCOPY := $(PREFIX)-objcopy
TOOLCHAIN_DIR := $(shell dirname `which $(CC)`)/../$(PREFIX)
OPENCM3_DIR := $(shell dirname $(lastword $(MAKEFILE_LIST)))/libopencm3
ARCH_FLAGS := -mthumb -mcpu=cortex-m3 -msoft-float
ALL_CFLAGS := -Os -g -std=gnu99 \
-Wall -Wextra -Wimplicit-function-declaration \
-Wredundant-decls -Wstrict-prototypes \
-Wundef -Wshadow \
-fno-common $(ARCH_FLAGS) -MD -DSTM32F1 \
-I$(OPENCM3_DIR)/include $(CFLAGS)
ALL_LDFLAGS := -lopencm3_stm32f1 --static -Wl,--start-group -lc -lgcc -lnosys -Wl,--end-group \
-T$(LDSCRIPT) -nostartfiles -Wl,--gc-sections \
$(ARCH_FLAGS) -mfix-cortex-m3-ldrd \
-L$(OPENCM3_DIR)/lib $(LDFLAGS)
.libopencm3_built:
@if [ ! "`ls -A $(OPENCM3_DIR)`" ] ; then \
printf "#### ERROR ####\n"; \
printf "\tlibopencm3 is not initialized.\n"; \
printf "\tPlease run:\n"; \
printf "\t$$ git submodule init\n"; \
printf "\t$$ git submodule update\n"; \
printf "\tbefore running make.\n"; \
printf "#### ERROR ####\n"; \
exit 1; \
fi
$(MAKE) --directory=$(OPENCM3_DIR) TARGETS=stm32/f1 > /dev/null
touch .libopencm3_built
%.o: %.c
$(CC) $(ALL_CFLAGS) -o $@ -c $<
%.elf: $(OBJECTS) $(LDSCRIPT) .libopencm3_built
$(LD) -o $@ $(OBJECTS) $(ALL_LDFLAGS)
%.bin: %.elf
$(OBJCOPY) -Obinary $< $@
clean:
rm -f *.o
rm -f *.d
rm -f *.elf
rm -f *.bin
rm .libopencm3_built