-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile.common
55 lines (40 loc) · 1.26 KB
/
Makefile.common
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
C_SRCS = $(filter %.c, $(SRCS))
AS_SRCS = $(filter %.S, $(SRCS))
C_OBJS = $(C_SRCS:.c=.o)
AS_OBJS = $(AS_SRCS:.S=.o)
OBJ_DIR = obj
_OBJECTS = $(C_OBJS) $(AS_OBJS)
OBJECTS = $(patsubst %,$(OBJ_DIR)/%,$(_OBJECTS))
DEPS = $(OBJECTS:.o=.d)
CROSS = avr
CC = $(CROSS)-gcc
AS = $(CROSS)-gcc
SIZE = $(CROSS)-size
OBJCOPY = $(CROSS)-objcopy
CFLAGS = -Wall
CFLAGS += -Os
CFLAGS += -mmcu=$(MCU) -DF_CPU=$(FREQ)
CFLAGS += -ffunction-sections -fdata-sections
ASFLAGS += $(CFLAGS)
LDFLAGS = -Wl,-Map,$(OBJ_DIR)/$(TARGET).map
LDFLAGS += -Wl,--gc-sections
all: $(OBJ_DIR)/$(TARGET).hex
-include $(DEPS)
$(OBJ_DIR)/%.o : %.S
@mkdir -p $(OBJ_DIR)
$(CC) $(ASFLAGS) $(CPPFLAGS) -c -MM -MF $(patsubst %.o,%.d,$@) $<
@sed -i 's/.*\.o/$(OBJ_DIR)\/&/' $(patsubst %.o,%.d,$@)
$(AS) $(ASFLAGS) $(CPPFLAGS) -c -o $@ $<
$(OBJ_DIR)/%.o : %.c
@mkdir -p $(OBJ_DIR)
$(CC) $(CFLAGS) $(CPPFLAGS) -c -MM -MF $(patsubst %.o,%.d,$@) $<
@sed -i 's/.*\.o/$(OBJ_DIR)\/&/' $(patsubst %.o,%.d,$@)
$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<
$(OBJ_DIR)/$(TARGET).elf : $(OBJECTS)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^
$(OBJ_DIR)/$(TARGET).hex : $(OBJ_DIR)/$(TARGET).elf
$(SIZE) -C --mcu=$(MCU) $^
$(OBJCOPY) -O ihex -j .text $^ $@
.PHONY: clean
clean:
@rm -rf $(OBJ_DIR)