forked from EGG-electric-unicycle/firmware-gen2_boards
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
executable file
·84 lines (71 loc) · 3.09 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
# Copyright (C) 2015 Joerg Hoener
#
# This program 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 program 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 this program. If not, see <http://www.gnu.org/licenses/>.
TCPREFIX = arm-none-eabi-
CC = $(TCPREFIX)gcc
AS = $(TCPREFIX)as
LD = $(TCPREFIX)gcc -v # use GCC and not LD so the math functions work like atan2()
CP = $(TCPREFIX)objcopy
OD = $(TCPREFIX)objdump
GDB = $(TCPREFIX)gdb
SIZE = $(TCPREFIX)size
# Optimization level, can be [0, 1, 2, 3, s].
# 0 = Turn off optimization. Reduce compilation time and make debugging
# produce the expected results.
# 1 = The compiler tries to reduce code size and execution time, without
# performing any optimizations that take a great deal of compilation time.
# 2 = GCC performs nearly all supported optimizations that do not involve a
# space-speed tradeoff. As compared to -O1, this option increases
# both compilation time and the performance of the generated code.
# 3 = Optimize yet more. Turns on -finline-functions and more.
# s = -Os enables all -O2 optimizations that do not typically increase code
# size.
# (See gcc manual for further information)
OPT = 0
# -mfix-cortex-m3-ldrd should be enabled by default for Cortex M3.
# CFLAGS -H show header files
AFLAGS = -I -Ispl/CMSIS -Ispl/inc -c -g -mcpu=cortex-m3 -mthumb
CFLAGS = -I./ -I./spl/CMSIS -I./spl/CMSIS/inc -I./spl/inc -I./libfixmath -DSTM32F10X_MD -DUSE_STDPERIPH_DRIVER -c -fno-common -O$(OPT) -g -mcpu=cortex-m3 -mthumb -ffunction-sections -fdata-sections
# Need following option for LTO as LTO will treat retarget functions as
# unused without following option
CFLAGS+ = -fno-builtin
LFLAGS = -Tstm32_flash.ld -L/usr/lib/gcc/arm-none-eabi/4.9.3/armv7-m -lgcc -lm -nostartfiles -lnosys -mcpu=cortex-m3 -mthumb -Wl,--gc-sections
#LFLAGS += --specs=nano.specs # to use newlib nano
#LFLAGS += -u _printf_float # newlib nano printf use floats
#LFLAGS += -u _scanf_float # newlib nano scanf use floats
CPFLAGS = -Obinary
ODFLAGS = -S
SOURCES=$(shell find ./ -type f -iname '*.c')
OBJECTS=$(foreach x, $(basename $(SOURCES)), $(x).o)
all: main.bin size
clean:
rm -f main.lst main.elf main.bin
find *.o | xargs rm
flash: main.bin
$(STM32FLASH) main.bin
size:
@echo "Size:"
$(SIZE) main.elf
main.bin: main.elf
@echo "...copying"
$(CP) $(CPFLAGS) main.elf main.bin
$(OD) $(ODFLAGS) main.elf > main.lst
main.elf: $(OBJECTS) startup_stm32f10x_md.o
@echo "..linking"
$(LD) $^ $(LFLAGS) -o $@
%.o: %.c
@echo ".compiling"
$(CC) $(CFLAGS) $< -o $@
startup_stm32f10x_md.o:
$(AS) $(ASFLAGS) startup_stm32f10x_md.s -o startup_stm32f10x_md.o