Makefile.common 2.25 KB
Newer Older
Anders Blomdell's avatar
Anders Blomdell committed
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
#
# Define the following in your makefile and then include this file
#   TARGETS=<list of targets to be built>
#
#   <TARGET>.ARCH=<architecture for target (avr)>
#   <TARGET>.CHIP=<chip used for target>
#   <TARGET>.FUSE=<fuse settings for target>
#   <TARGET>.C=<.c files for target>
#   <TARGET>.H=<.h file for target>

# Factory defaults for various chips
# factory_mega16.FUSE=--wr_fuse_l=0xe1 --wr_fuse_h=0x99 --wr_fuse_e=0xff

ifeq ($(TARGET),)

all:	$(TARGETS:%=%.LINK)


%.LINK:
	@mkdir -p compiled/$*
	make --no-print-directory TARGET=$* $*.LINK

%.VERIFY: 
	@mkdir -p compiled/$*
	make --no-print-directory TARGET=$* $*.VERIFY

%.LOAD: 
	@mkdir -p compiled/$*
	make --no-print-directory TARGET=$* $*.LOAD 

%.FUSE:
	make --no-print-directory TARGET=$* $*.FUSE



else

avr-CC=avr-gcc
39
avr-CCFLAGS=-mmcu=$(CHIP) -g -Wall -Werror -O3 -I. -I../../lib/avr
Anders Blomdell's avatar
Anders Blomdell committed
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
avr-OBJCOPY=avr-objcopy

ARCH=$($(TARGET).ARCH)
CHIP=$($(TARGET).CHIP)

CC=$($(ARCH)-CC)
CCFLAGS=$($(ARCH)-CCFLAGS) $($(TARGET).CCFLAGS)
OBJCOPY=$($(ARCH)-OBJCOPY)

SOURCES=$($(1).C:%=%.c) $($(1).H:%=%.h)
OBJECTS=$($(1).C:%=compiled/$(1)/%.o) 


%.LINK: compiled/$(TARGET)/%.exe
	echo $@

%.LOAD_uisp: compiled/$(TARGET)/%.sr
	uisp \
		-dprog=stk200 \
		--erase \
		--upload if=compiled/$(TARGET)/$*.sr

%.VERIFY: compiled/$(TARGET)/%.sr
	avrdude -P usb -c avrisp2 -p $(CHIP) \
	        -U flash:v:compiled/$(TARGET)/$*.sr:s

%.LOAD: compiled/$(TARGET)/%.sr
	avrdude -P usb -c avrisp2 -p $(CHIP) \
	        -U flash:w:compiled/$(TARGET)/$*.sr:s

%.FUSE:
71
72
73
74
75
76
77
78
79
	[ -n "$($(TARGET).FUSE_L)" ] && avrdude -P usb -c avrisp2 -p $(CHIP) \
	        -U lfuse:w:$($(TARGET).FUSE_L):m || true
	[ -n "$($(TARGET).FUSE_H)" ] && avrdude -P usb -c avrisp2 -p $(CHIP) \
	        -U hfuse:w:$($(TARGET).FUSE_H):m || true
	[ -n "$($(TARGET).FUSE_E)" ] && avrdude -P usb -c avrisp2 -p $(CHIP) \
	        -U efuse:w:$($(TARGET).FUSE_E):m || true

%.FUSE_uisp:
	exit 1
Anders Blomdell's avatar
Anders Blomdell committed
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
	uisp \
		-dprog=stk200 \
		$($(TARGET).FUSE)

compiled/$(TARGET)/%.o: $(call SOURCES,$(TARGET))
	$(CC) $(CCFLAGS) -o $@ -c $*.c

compiled/$(TARGET)/%.exe: $(call OBJECTS,$(TARGET))
	$(CC) $(CCFLAGS) -o $@ $(call OBJECTS,$*)

compiled/$(TARGET)/%.sr: compiled/$(TARGET)/%.exe
	$(OBJCOPY) -O srec $< $@

.PRECIOUS: compiled/$(TARGET)/%.o \
	   compiled/$(TARGET)/%.exe \
	   compiled/$(TARGET)/%.sr

97
endif