-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
99 lines (76 loc) · 2.42 KB
/
Makefile
File metadata and controls
99 lines (76 loc) · 2.42 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
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
TARGET = testprojekt
MCU = atmega328p
PROGR = avrispmkii
F_CPU = 16000000
# Debugging format.
# Native formats for AVR-GCC's -g are dwarf-2 [default] or stabs.
# AVR Studio 4.10 requires dwarf-2.
# AVR [Extended] COFF format requires stabs, plus an avr-objcopy run.
DEBUG = dwarf-2
# List any extra directories to look for include files here.
# Each directory must be seperated by a space.
# Use forward slashes for directory separators.
# For a directory that has spaces, enclose it in quotes.
EXTRAINCDIRS =
CC = avr-gcc
OBJCOPY = avr-objcopy
AVRDUDE = avrdude
SIZE = avr-size
CFLAGS = -g$(DEBUG)
CFLAGS += -DF_CPU=$(F_CPU)UL
CFLAGS += -Wall -Werror -Os -std=c99
CFLAGS += -funsigned-char
CFLAGS += -funsigned-bitfields
CFLAGS += -fpack-struct
CFLAGS += -fshort-enums
CFLAGS += -Wstrict-prototypes
# CFLAGS += -mshort-calls
# CFLAGS += -fno-unit-at-a-time
# CFLAGS += -Wundef
# CFLAGS += -Wunreachable-code
# CFLAGS += -Wsign-compare
CFLAGS += -Wa,-adhlns=$(<:%.c=$(OBJDIR)/%.lst)
CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
PFLAGS = -B1
SRCDIR = .
OBJDIR = obj
BINDIR = bin
SOURCES := $(wildcard $(SRCDIR)/*.c)
HEADERS := $(wildcard $(SRCDIR)/*.h)
OBJECTS := $(SOURCES:$(SRCDIR)/%.c=$(OBJDIR)/%.o)
complete: clean all program
all: $(BINDIR)/$(TARGET).hex
$(BINDIR)/$(TARGET).elf: $(OBJECTS) | $(BINDIR)
$(CC) -mmcu=$(MCU) $(CFLAGS) -o $@ $^
$(OBJDIR)/%.o: $(SRCDIR)/%.c $(HEADERS) | $(OBJDIR)
$(CC) -c -mmcu=$(MCU) $(CFLAGS) -o $@ $<
$(OBJDIR):
@mkdir $(OBJDIR)
$(BINDIR):
@mkdir $(BINDIR)
$(BINDIR)/%.hex: $(BINDIR)/%.elf
$(OBJCOPY) -j .text -j .data -O ihex $< $@
@echo.
@echo $(MCU)
@echo ==================================================================
@$(SIZE) --target=elf32-avr $(BINDIR)/$(TARGET).elf
@echo ==================================================================
@echo.
program: $(BINDIR)/$(TARGET).hex
$(AVRDUDE) -c $(PROGR) -P usb -p $(MCU) $(PFLAGS) -U flash:w:$<
clean:
ifeq ($(OS),Windows_NT)
@rmdir /s /q $(OBJDIR)
@rmdir /s /q $(BINDIR)
else
@rm -f $(OBJDIR)/*.*
@rm -f $(BINDIR)/*.*
@rm -rf $(OBJDIR)
@rm -rf $(BINDIR)
endif
# Create object files directory
#$(shell mkdir $(OBJDIR) 2>/dev/null)
# Include the dependency files.
#-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
# Listing of phony targets.
.PHONY : all build clean program