aboutsummaryrefslogtreecommitdiff
path: root/examples/examples.mk
blob: f6b0acb16434703c122b7e0a014cb415aed890dd (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
# vim:ts=4:sw=4:sts=4:noexpandtab
MAKEFLAGS += --no-builtin-rules
# Note this file is included to Makefiles in lower directories so all paths here
# are like thy would be from lower directory.

# You have to define EXAMPLE_NAME variable
ifndef EXAMPLE_NAME
$(error Before including examples.mk define EXAMPLE_NAME)
endif
ifndef SRC
$(error Before including examples.mk define SRC)
endif

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

CONFIG = .config

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

# Edit here help like you ever want
.PHONY: help
help:
	@echo  "AVR-IOE $(EXAMPLE_NAME) example"
	@echo  " all         - Build example"
	@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 $(EXAMPLE_NAME).elf $(EXAMPLE_NAME).hex"
	$(Q)$(RM) $(EXAMPLE_NAME).elf $(EXAMPLE_NAME).hex
	$(Q)$(MAKE) -C ../.. clean O=examples/$(EXAMPLE_NAME)

# Building targets are available only if configuration is generated
ifneq ("$(wildcard $(CONFIG))","")
-include $(CONFIG)
# 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 = -I../../include -mmcu=$(MMCU) -imacros build/config.h \
	 $(shell echo $(CCFLAGS)) $(shell echo -DF_CPU=$(F_CPU)000L)
CC = $(CHOST)gcc
OBJCOPY = $(CHOST)objcopy

$(EXAMPLE_NAME).elf: libioe.a
$(EXAMPLE_NAME).elf: $(OBJ)
	@echo " LD       $@"
	$(Q)$(CC) -Os -mmcu=$(MMCU) $(filter %.o,$^) -o $@ -L. -lioe

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

$(OBJ): %.o: %.c libioe.a
	@echo " CC       $@"
	$(Q)$(CC) $(CFLAGS) -c -o $@ $<

libioe.a: $(CONFIG)
	$(Q)$(MAKE) -C ../.. examples/$(EXAMPLE_NAME)/libioe.a O=examples/$(EXAMPLE_NAME)
endif

TOOL_PATH=../../tools
IOEROOT=../../
include ../../tools/kconfig.mk