1389 |
miho |
1 |
############################################################################### |
|
|
2 |
# Makefile for the project Tykadlo |
|
|
3 |
############################################################################### |
|
|
4 |
# (c)miho www.mlab.cz |
1399 |
miho |
5 |
# 1.00 - new makefile |
|
|
6 |
# 1.01 - solved problem with default rules (invalid target "Makefile") |
1389 |
miho |
7 |
|
|
|
8 |
## User Settings |
1399 |
miho |
9 |
# Frequencies are in Hz, Callibration is usualy not needed |
1389 |
miho |
10 |
FREQUENCIES = 30000 32000 34000 36000 38000 40000 56000 |
|
|
11 |
CALIBRATION = 0 |
|
|
12 |
|
|
|
13 |
## Project |
1399 |
miho |
14 |
# Main source file name, target platform, destination directory |
1389 |
miho |
15 |
PROJECT = Tykadlo |
|
|
16 |
MCU = attiny13 |
|
|
17 |
TARGETDIR = BIN |
|
|
18 |
|
|
|
19 |
## Variants - all supported frequences |
1399 |
miho |
20 |
# Combine project name with all required frequencies |
1389 |
miho |
21 |
VARIANTS = $(foreach FREQ, $(FREQUENCIES), $(PROJECT)_$(FREQ)) |
|
|
22 |
|
|
|
23 |
## General Flags |
|
|
24 |
CC = avr-gcc |
|
|
25 |
|
|
|
26 |
## Options common to compile, link and assembly rules |
1399 |
miho |
27 |
COMMON = -mmcu=$(MCU) |
1389 |
miho |
28 |
|
|
|
29 |
## Compile options common for all C compilation units. |
1399 |
miho |
30 |
CFLAGS = $(COMMON) |
|
|
31 |
CFLAGS += -Wall -gdwarf-2 -std=gnu99 -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums |
|
|
32 |
CFLAGS += -MD -MP -MT $(*F).o -MF dep/$(@F).d |
1389 |
miho |
33 |
|
|
|
34 |
## Linker flags |
1399 |
miho |
35 |
LDFLAGS = $(COMMON) |
|
|
36 |
LDFLAGS += -Wl |
1389 |
miho |
37 |
|
|
|
38 |
## Intel Hex file production flags |
|
|
39 |
HEX_FLASH_FLAGS = -R .fuse -R .lock -R .signature |
|
|
40 |
|
|
|
41 |
## Build |
1399 |
miho |
42 |
|
|
|
43 |
# Tag targets that are not / do not require files |
|
|
44 |
.PHONY: all allhex alllss clean Makefile |
|
|
45 |
|
|
|
46 |
# Main target |
1389 |
miho |
47 |
all: allhex |
|
|
48 |
|
1399 |
miho |
49 |
# Subtarget - all variants hex files |
1389 |
miho |
50 |
allhex: $(foreach VAR, $(VARIANTS), $(VAR).hex) |
|
|
51 |
|
1399 |
miho |
52 |
# Subtarget - all variants lss files |
1389 |
miho |
53 |
alllss: $(foreach VAR, $(VARIANTS), $(VAR).lss) |
|
|
54 |
|
1399 |
miho |
55 |
# How to translate .o file - from .c with all possible frequencies |
1389 |
miho |
56 |
%.o: $(PROJECT).c |
|
|
57 |
$(CC) $(INCLUDES) $(CFLAGS) -c $< -D CALIBRATION=$(CALIBRATION) -D IR_FREQUENCY=$(subst $(PROJECT)_,,$(@:.o=))UL -o $@ |
|
|
58 |
|
1399 |
miho |
59 |
# How to link .elf - from .o |
1389 |
miho |
60 |
%.elf: %.o |
|
|
61 |
$(CC) $(LDFLAGS) $< $(LIBDIRS) $(LIBS) -o $@ |
|
|
62 |
rm $< |
|
|
63 |
|
1399 |
miho |
64 |
# How to generate .hex file - from .elf |
1389 |
miho |
65 |
%.hex: %.elf |
|
|
66 |
avr-objcopy -O ihex $(HEX_FLASH_FLAGS) $< $(TARGETDIR)/$@ |
|
|
67 |
|
1399 |
miho |
68 |
# How to generate .lss file - from .elf |
1389 |
miho |
69 |
%.lss: %.elf |
|
|
70 |
avr-objdump -h -S $< > $(TARGETDIR)/$@ |
|
|
71 |
|
|
|
72 |
## Clean target |
|
|
73 |
clean: |
|
|
74 |
-rm -rf $(PROJECT)*.o $(PROJECT)*.elf dep/* $(TARGETDIR)/$(PROJECT)*.hex $(TARGETDIR)/$(PROJECT)*.lss |
|
|
75 |
-rmdir dep |
|
|
76 |
-rmdir $(TARGETDIR) |
|
|
77 |
|
|
|
78 |
## Other dependencies |
|
|
79 |
-include $(shell mkdir dep 2>/dev/null) $(wildcard dep/*) |
|
|
80 |
-include $(shell mkdir $(TARGETDIR) 2>/dev/null) |