-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
93 lines (72 loc) · 2.2 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
#2015 by tmoe, id10101 (and the internet :) )
#Name of the binary/project
TARGET=hello
#Known issues:
#obj dir is not actually used, obj's are placed under source
#Tools
CROSS_COMPILE=arm-none-eabi-
CC=$(CROSS_COMPILE)gcc
OBJCOPY=$(CROSS_COMPILE)objcopy
GDB=$(CROSS_COMPILE)gdb
MKDIR=mkdir -p
RM=rm -f
RMDIR=rm -rf
STUTIL=utils/st-util-daemon.sh
#Directories
SOURCE_DIR=./src
OBJ_DIR=./obj # not used yet
BUILD_DIR=./build
LIB_DIR=./libs
#Architecture flags
FP_FLAGS?=-mfpu=fpv4-sp-d16 -mfloat-abi=softfp
ARCH_FLAGS=-mthumb -mcpu=cortex-m4 $(FP_FLAGS)
#Compiler, Linker Options
CPPFLAGS=-I$(LIB_DIR)/BSP -I$(LIB_DIR)/sGUI
CFLAGS=$(ARCH_FLAGS) -O0 -ffunction-sections -fdata-sections -g
LDFLAGS=-Wl,--start-group -lm -Wl,--end-group -static -Wl,-cref,-u,Reset_Handler
LDFLAGS+=-Wl,-Map=$(BUILD_DIR)/$(TARGET).map
LDFLAGS+=-Wl,--gc-sections -Wl,--defsym=malloc_getpagesize_P=0x1000
#Finding Input files
CFILES=$(shell find $(SOURCE_DIR) -name '*.c')
#CFILES=$(notdir $(wildcard $(SOURCE_DIR)/*.c))
SFILES=$(shell find $(SOURCE_DIR) -name '*.s')
#Generate corresponding obj names
SOBJS=$(SFILES:.s=.o)
COBJS=$(CFILES:.c=.o)
OBJS=$(SOBJS) $(COBJS)
#Keep the objects files
.SECONDARY: $(OBJS)
#Mark targets which are not "file-targets"
.PHONY: all debug flash clean
# List of all binaries to build
all: $(BUILD_DIR)/$(TARGET).elf $(BUILD_DIR)/$(TARGET).bin
start:
$(STUTIL) start
stop:
$(STUTIL) stop
#objects to elf
%.elf : $(OBJS)
@echo Linking...
$(MKDIR) $(BUILD_DIR)
$(CC) -o $@ $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -T./utils/stm32f4_flash.ld $^
#elf to binary
%.bin: %.elf
$(OBJCOPY) -O binary $< $@
#Asm files to objects
%.o: %.s
@echo Assembling $<...
$(CC) -x assembler-with-cpp $(CFLAGS) $(CPPFLAGS) -c $< -o $@
#C files to objects
%.o: %.c
@echo Compiling $<...
$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<
#Clean Obj files and builded stuff
clean:
$(RMDIR) $(BUILD_DIR) $(OBJ_DIR)
$(RM) $(SOURCE_DIR)/*.o
#Debug target: starts the st-util server and gdb and leaves it open
debug: start all
$(GDB) $(BUILD_DIR)/$(TARGET).elf -x ./utils/gdb.script
#Flash target: starts the st-util server flashes the elf with gdb and exits afterwards
flash: start all
$(GDB) $(BUILD_DIR)/$(TARGET).elf -x ./utils/gdb.script -batch