aboutsummaryrefslogtreecommitdiff
path: root/template/Makefile
blob: 59218a2b214f14ac3decbbc8781c964581782ade (plain)
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
MAKEFLAGS += --no-builtin-rules
# Change PROJNAME value to you project name
# Care to not make any space at the end!
PROJNAME = template

# Add new source files to this variable
SRC = main.c

OBJ = $(patsubst %.c,%.o,$(SRC)) # This creates list of *.o files from *.c
Q ?= @ # This can be overwritten to show commands

.PHONY: all
ifneq ("$(wildcard ioeconfig)","") # Checking if configuration exists
all: $(PROJNAME).hex
	@echo Now you can flash $< to your chip.
else
all: help .config
endif

# Edit here help like you ever want
.PHONY: help
help:
	@echo  "This is avr-ioe template project"
	@echo  " all         - Build project"
	@echo  " config      - Start configuration program"
	@echo  " menuconfig  - NCurses based configuration program"
	@echo  " help        - Prints this text"
	@echo  " clean       - Removing all object files generated from source files"

.PHONY: clean
clean:
	@echo " CLEAN OBJ"
	$(Q)$(RM) $(OBJ)
	@echo " CLEAN $(PROJNAME).elf $(PROJNAME).hex"
	$(Q)$(RM) $(PROJNAME).elf $(PROJNAME).hex
	$(Q)$(MAKE) -C avr-ioe clean CONFIG="$$( readlink -f ioeconfig )"

# Building targets are available only if configuration is generated
ifneq ("$(wildcard ioeconfig)","")
include ioeconfig
# If you want change some standard CFLAGS, change them in configuration not here.
# Add here only options that should not be applied to avr-ioe also.
CFLAGS = -Iavr-ioe/include -mmcu=$(MMCU) -imacros avr-ioe/build/config.h \
	 $(shell echo $(CCFLAGS)) $(shell echo -DF_CPU=$(F_CPU)000L)
CC = $(CHOST)gcc
AR = $(CHOST)ar
CPP = $(CHOST)cpp
OBJCOPY = $(CHOST)objcopy

$(PROJNAME).elf: avr-ioe/libioe.a
$(PROJNAME).elf: $(OBJ)
	@echo " LD       $@"
	$(Q)$(CC) -Os -mmcu=$(MMCU) $^ -o $@ -Lavr-ioe -lioe

$(PROJNAME).hex: $(PROJNAME).elf
	@echo " OBJCOPY  $@"
	$(Q)$(OBJCOPY) -O ihex -R .eeprom $< $@

$(OBJ): %.o: %.c avr-ioe/build/config.h
	@echo " CC       $@"
	$(Q)$(CC) $(CFLAGS) -c -o $@ $<

avr-ioe/libioe.a: ioeconfig
	$(Q)+$(MAKE) -C avr-ioe libioe.a CONFIG="$$( readlink -f ioeconfig )"
avr-ioe/build/config.h: ioeconfig
	$(Q)+$(MAKE) -C avr-ioe build/config.h CONFIG="$$( readlink -f ioeconfig )"
endif

.config:
	@echo Please generate configuration first using config or menuconfig target
	@exit 1

.PHONY: config
config:
	$(Q)$(MAKE) -C avr-ioe menuconfig CONFIG="$$( readlink -f ioeconfig )"

.PHONY: menuconfig
menuconfig:
	$(Q)$(MAKE) -C avr-ioe menuconfig CONFIG="$$( readlink -f ioeconfig )"