-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
97 lines (78 loc) · 3.16 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
# Universal Makefile Version: 14.03.2015
#
# Requires GNU 'make' and 'find'.
# Target Architecture
BOARD := LaFortuna
MCU := at90usb1286
F_CPU := 8000000UL
# Tool Options
CFLAGS := -Os -mmcu=$(MCU) -DF_CPU=$(F_CPU)
# CFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm # floating point support
CFLAGS += -fno-strict-aliasing # FATfs does not adhere to strict aliasing
CFLAGS += -Wno-main # main() will never return
CFLAGS += -Wall -Wextra -pedantic
CFLAGS += -Wstrict-overflow=5 -fstrict-overflow -Winline
# CHKFLAGS := -fsyntax-only
CHKFLAGS :=
BUILD_DIR := _build
# Ignoring hidden directories; sorting to drop duplicates:
CFILES := $(shell find . ! -path "*/\.*" -type f -name "*.c")
CPATHS := $(sort $(dir $(CFILES)))
vpath %.c $(CPATHS)
HFILES := $(shell find . ! -path "*/\.*" -type f -name "*.h")
HPATHS := $(sort $(dir $(HFILES)))
vpath %.h $(HPATHS)
CFLAGS += $(addprefix -I ,$(HPATHS))
DEPENDENCIES := $(patsubst %.c,$(BUILD_DIR)/%.d,$(notdir $(CFILES)))
OBJFILES := $(patsubst %.c,$(BUILD_DIR)/%.o,$(notdir $(CFILES)))
.PHONY: upld prom clean check-syntax ?
upld: $(BUILD_DIR)/main.hex
$(info )
$(info =========== ${BOARD} =============)
dfu-programmer $(MCU) erase
dfu-programmer $(MCU) flash $(BUILD_DIR)/main.hex
prom: $(BUILD_DIR)/main.eep upld
$(info ======== EEPROM: ${BOARD} ========)
dfu-programmer $(MCU) flash-eeprom $(BUILD_DIR)/main.eep
$(BUILD_DIR)/%.o: %.c Makefile | $(BUILD_DIR)
@avr-gcc $(CFLAGS) -MMD -MP -c $< -o $@
$(BUILD_DIR)/%.elf: $(OBJFILES)
@avr-gcc -mmcu=$(MCU) -o $@ $^
$(BUILD_DIR)/%.hex %.hex: $(BUILD_DIR)/%.elf
@avr-objcopy -R .eeprom -R .fuse -R .lock -R .signature -O ihex $< "$@"
$(BUILD_DIR)/%.eep %.eep: $(BUILD_DIR)/%.elf
@avr-objcopy -j .eeprom --change-section-lma .eeprom=0 -O ihex $< "$@"
-include $(sort $(DEPENDENCIES))
$(BUILD_DIR):
@mkdir -p $(BUILD_DIR)
# Emacs flymake support
check-syntax:
@avr-gcc $(CFLAGS) $(CHKFLAGS) -o /dev/null -S $(CHK_SOURCES)
clean:
@$(RM) -rf $(BUILD_DIR)
?%:
@echo '$*=$($*)'
?:
$(info -------------------------------------------------)
$(info Usage:)
$(info Source files can be grouped into subdirectories.)
$(info To build an executable and attempt to upload it,)
$(info use just "make". If the executable requires EEPROM)
$(info initialization, use "make prom".)
$(info )
$(info make mymain.hex --> to build a hex-file for mymain.c)
$(info make mymain.eep --> for an EEPROM file for mymain.c)
$(info make ?CFILES --> show source files to be used)
$(info make ?CPATHS --> show source locations)
$(info make ?HFILES --> show header files found)
$(info make ?HPATHS --> show header locations)
$(info make ?CFLAGS --> show compiler options)
$(info -------------------------------------------------)
@:
# Copyright 2014-2015 Klaus-Peter Zauner
# At your option this work is licensed under a Creative Commons
# Attribution-NonCommercial 3.0 Unported License [1], or under a
# Creative Commons Attribution-ShareAlike 3.0 Unported License [2].
# [1]: See: http://creativecommons.org/licenses/by-nc/3.0/
# [2]: See: http://creativecommons.org/licenses/by-sa/3.0/
#===================================================================