-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakefile
More file actions
57 lines (43 loc) · 1.52 KB
/
makefile
File metadata and controls
57 lines (43 loc) · 1.52 KB
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
CC = avr-gcc
CFLAGS = -Os -DF_CPU=12000000 -flto
CPPFLAGS = -std=c++14
TARGET_ARCH = -mmcu=atmega644p
DEPFLAGS = -MT $@ -MMD -MP -MF .$*.d
COMPILE.c = $(CC) $(DEPFLAGS) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c
# Create our phony targets to avoid files interfering
.PHONY: clean install
# Generate a list of sources and objects
C_SOURCES = $(wildcard *.c)
CPP_SOURCES = $(wildcard *.cpp)
ASM_SOURCES = $(wildcard *.s)
OBJECTS = $(C_SOURCES:%.c=.%.o) $(CPP_SOURCES:%.cpp=.%.o) $(ASM_SOURCES:%.s=.%.o)
program.hex: program.elf
@ avr-objcopy -O ihex program.elf program.hex
# The final target, with dependancies generated from the sources list
program.elf: $(OBJECTS)
@ $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -Wl,--gc-sections -o $@ $^
# The install target
install: program.hex
@ avrdude -c usbasp -p m644p -D -U $<
# Clean up everything that we generate
clean:
@ rm -f program.hex program.elf .*.o .*.d
# Delete the built-in rules for building object files from .c files...
%.o : %.c
# ...so that our rule is used instead.
.%.o : %.c .%.d makefile
@ $(COMPILE.c) $(OUTPUT_OPTION) $<
%.o : %.cpp
.%.o : %.cpp .%.d makefile
@ $(COMPILE.c) $(OUTPUT_OPTION) $<
%.o : %.s
.%.o : %.s .%.d makefile
@ avr-as --MD .$*.d -c -o $@ $<
# Create a pattern rule with an empty recipe, so that
# `make` won’t fail if the dependency file doesn’t exist.
.%.d: ;
# Mark the dependency files precious, so they won’t be
# automatically deleted as intermediate files.
.PRECIOUS: .%.d
# Include all of the dependency files
include $(wildcard .*.d)