summaryrefslogtreecommitdiff
path: root/include.mk
blob: 2efc96eb30bf67e5c14124cb197c66c073d7228b (plain) (blame)
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
##
##  spreadspace teensy utils
##
##
##  Copyright (C) 2011 Christian Pointner <equinox@spreadspace.org>
##                         
##  This file is part of spreadspace teensy utils.
##
##  spreadspace teensy utils is free software: you can redistribute it and/or modify
##  it under the terms of the GNU General Public License as published by
##  the Free Software Foundation, either version 3 of the License, or
##  any later version.
##
##  spreadspace teensy utils is distributed in the hope that it will be useful,
##  but WITHOUT ANY WARRANTY; without even the implied warranty of
##  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
##  GNU General Public License for more details.
##
##  You should have received a copy of the GNU General Public License
##  along with spreadspace teensy utils. If not, see <http://www.gnu.org/licenses/>.
##

#NAME := 
#OBJ := 
#BOARD_TYPE := 

ifeq ($(BOARD_TYPE),teensy1)
MCU := at90usb162
endif
ifeq ($(BOARD_TYPE),teensy2)
MCU := atmega32u4
endif
ifeq ($(BOARD_TYPE),teensypp1)
MCU := at90usb646
endif
ifeq ($(BOARD_TYPE),teensypp2)
MCU := at90usb1286
endif
FORMAT := ihex

CC = avr-gcc
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
SIZE = avr-size
AR = avr-ar rcs
NM = avr-nm
COPY = cp


SRC := $(OBJ:%.o=%.c)

.PHONY: clean cleanall distclean program

ELFFILE := $(NAME).elf

all: $(ELFFILE)

%.d: %.c
	@set -e; rm -f $@; \
  $(CC) -MM $(CFLAGS) $< > $@.$$$$; \
  sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
  rm -f $@.$$$$; echo '(re)building $@'

ifneq ($(MAKECMDGOALS),distclean)
-include $(SRC:%.c=%.d)
endif

$(ELFFILE): $(OBJ)
	$(CC) $(OBJ) -o $@ $(LDFLAGS)

%.o: %.c
	$(CC) $(CFLAGS) -c $<


strip: $(ELFFILE)
	$(STRIP) -s $(ELFFILE)

distclean: cleanall
	find . -name *.o -exec rm -f {} \;
	find . -name "*.\~*" -exec rm -rf {} \;
	rm -f include.mk
	rm -f version.h
	rm -f tun.c

clean:
	rm -f *.o
	rm -f *.d
	rm -f *.d.*
	rm -f $(ELFFILE)

program: $(ELFFILE)
  $(OBJCOPY) -O $(FORMAT) -R .eeprom -R .fuse -R .lock -R .signature $< $(ELFFILE:%.elf=%.hex)
  teensy_loader_cli -mmcu=$(MCU) -w -v $@