forked from Damme/LandLord
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
executable file
·121 lines (100 loc) · 3.56 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
BASE:=/usr
GCCPATH:=$(BASE)
#TARGETNAME:=$(firstword $(basename $(wildcard *.c)))
TARGETNAME:=main
SYSINC:=common
U8GPATH:=u8g
FREERTOSPATH=FreeRTOS
FREERTOSGCCPATH=FreeRTOS/gcc
LDSCRIPTDIR:=$(SYSINC)
SRC:=$(wildcard *.c)
MCPU:=cortex-m3
STARTUP:=$(wildcard $(SYSINC)/gcc*.S)
SYSSRC:=$(wildcard $(LDSCRIPTDIR)/*.c)
LDSCRIPT:=$(wildcard $(LDSCRIPTDIR)/*.ld)
#================================================
# Main part of the Makefile starts here. Usually no changes are needed.
# U8G Source files
U8GSRC:=$(wildcard $(U8GPATH)/*.c)
FREETROSSRC:=$(wildcard $(FREERTOSPATH)/*.c)
FREETROSGCCSRC:=$(wildcard $(FREERTOSGCCPATH)/*.c)
# Internal Variable Names
ELFNAME:=$(TARGETNAME).elf
BINNAME:=$(TARGETNAME).bin
HEXNAME:=$(TARGETNAME).hex
DISNAME:=$(TARGETNAME).dis
MAPNAME:=$(TARGETNAME).map
OBJ:=$(SRC:.c=.o) $(SYSSRC:.c=.o) $(FREETROSSRC:.c=.o) $(FREETROSGCCSRC:.c=.o) $(U8GSRC:.c=.o) $(STARTUP:.S=.o)
OBJSMALL:=$(SRC:.c=.o) $(SYSSRC:.c=.o) $(STARTUP:.S=.o)
# Replace standard build tools by avr tools
CC:=$(GCCPATH)/bin/arm-none-eabi-gcc
AR:=$(GCCPATH)/bin/arm-none-eabi-ar
AS:=$(GCCPATH)/bin/arm-none-eabi-gcc
OBJCOPY:=$(GCCPATH)/bin/arm-none-eabi-objcopy
OBJDUMP:=$(GCCPATH)/bin/arm-none-eabi-objdump
SIZE:=$(GCCPATH)/bin/arm-none-eabi-size
# Common flags
COMMON_FLAGS = -mthumb -mcpu=$(MCPU)
COMMON_FLAGS += -g
COMMON_FLAGS += -Wall -Wno-unknown-pragmas
COMMON_FLAGS += -I. -I$(SYSINC) -I$(U8GPATH) -I$(FREERTOSPATH) -I$(FREERTOSGCCPATH)
# default stack size is 0x0c00
COMMON_FLAGS += -D__STACK_SIZE=0x0a00 -DdebugPrintf -DLOWSTACKWARNING
COMMON_FLAGS += -Os -flto
COMMON_FLAGS += -ffunction-sections -fdata-sections
# Assembler flags
ASFLAGS:=$(COMMON_FLAGS) -D__STARTUP_CLEAR_BSS -D__START=main
# C flags
CFLAGS:=$(COMMON_FLAGS) -std=gnu99
# LD flags
GC:=-Wl,--gc-sections
MAP:=-Wl,-Map=$(MAPNAME)
LFLAGS:=$(COMMON_FLAGS) $(GC) $(MAP)
#without debug
LDLIBS:=--specs=nano.specs -lc -lc -lnosys -L$(LDSCRIPTDIR) -T $(LDSCRIPT)
#With debug stdout -> openocd
#LDLIBS:=--specs=rdimon.specs -lc -lrdimon -L$(LDSCRIPTDIR) -T $(LDSCRIPT)
# Additional Suffixes
.SUFFIXES: .elf .hex .dis .bin
# Targets
.PHONY: all
all: $(DISNAME) $(HEXNAME) $(BINNAME)
@echo -e "Output: $(DISNAME) $(HEXNAME) $(BINNAME)\e[1;36m"
@echo
@$(SIZE) --format=SysV -x $(ELFNAME)
@$(SIZE) $(ELFNAME)
@echo
@stat main.bin -c "%y %n Size: %s"
@echo -e "\e[0m"
# cp $(BINNAME) /cygdrive/c/Prog/Dev/openOCD/share/openocd/scripts/main.bin
.PHONY: upload
upload: $(DISNAME) $(HEXNAME) $(ELFNAME)
# $(FLASHTOOL) HEXFILE\($(HEXNAME),NOCHECKSUMS,FILL,PROTECTISP\) COM\(5,38400\) DEVICE\($(FLASHMAGICDEVICE),12.000,0\)
# $(SIZE) $(ELFNAME)
.PHONY: clean
clean:
@echo -e "\e[1;37mRemoving all files...\e[0m\e[1;37m"
@$(RM) $(OBJ) $(HEXNAME) $(BINNAME) $(ELFNAME) $(DISNAME) $(MAPNAME)
cleansmall:
@echo -e "\e[1;37mRemoving some files...\e[0m\e[1;37m"
@$(RM) $(OBJSMALL) $(HEXNAME) $(BINNAME) $(ELFNAME) $(DISNAME) $(MAPNAME)
# implicit rules
%.o: %.c
@echo -e "\e[1;37mCC \e[0m$< > $@\e[1;33m"
@$(CC) $(CFLAGS) -c -o $@ $< 2>&1
# | sed -e 's/error/\\e[1;31merror\\e[0m/g' -e 's/warning/\\e[1;33mwarning\\e[0m/g'
.S.o:
@echo -e "\e[1;37mASM \e[0m$< > $@\e[1;37m"
@$(PREPROCESS.S) $(COMMON_FLAGS) $(patsubst %.s,%.S,$<) > tmp.s
@$(COMPILE.s) -c -o $@ tmp.s
@$(RM) tmp.s
.elf.hex:
@$(OBJCOPY) -O ihex $< $@
.elf.bin:
@$(OBJCOPY) -O binary $< $@
# explicit rules
$(ELFNAME): $(OBJ)
@echo -e "\e[1;37mLINKING \e[0m*.o > $@\e[1;37m"
@$(LINK.o) $(LFLAGS) $(OBJ) $(LDLIBS) -o $@
$(DISNAME): $(ELFNAME)
@$(OBJDUMP) -S $< > $@