1 |
# ====================================================================== |
1 |
# ====================================================================== |
2 |
# Common Makefile for USBtiny applications |
2 |
# Common Makefile for USBtiny applications |
3 |
# |
3 |
# |
4 |
# Macros to be defined before including this file: |
4 |
# Macros to be defined before including this file: |
5 |
# |
5 |
# |
6 |
# USBTINY - the location of this directory |
6 |
# USBTINY - the location of this directory |
7 |
# TARGET_ARCH - gcc -mmcu= option with AVR device type |
7 |
# TARGET_ARCH - gcc -mmcu= option with AVR device type |
8 |
# OBJECTS - the objects in addition to the USBtiny objects |
8 |
# OBJECTS - the objects in addition to the USBtiny objects |
9 |
# FLASH_CMD - command to upload main.hex to flash |
9 |
# FLASH_CMD - command to upload main.hex to flash |
- |
|
10 |
# FUSES_CMD - command to program the fuse bytes |
10 |
# STACK - maximum stack size (optional) |
11 |
# STACK - maximum stack size (optional) |
11 |
# FLASH - flash size (optional) |
12 |
# FLASH - flash size (optional) |
12 |
# SRAM - SRAM size (optional) |
13 |
# SRAM - SRAM size (optional) |
13 |
# SCHEM - Postscript version of the schematic to be generated |
14 |
# SCHEM - Postscript version of the schematic to be generated |
14 |
# |
15 |
# |
15 |
# Copyright (C) 2006 Dick Streefland |
16 |
# Copyright 2006-2010 Dick Streefland |
16 |
# |
17 |
# |
17 |
# This is free software, licensed under the terms of the GNU General |
18 |
# This is free software, licensed under the terms of the GNU General |
18 |
# Public License as published by the Free Software Foundation. |
19 |
# Public License as published by the Free Software Foundation. |
19 |
# ====================================================================== |
20 |
# ====================================================================== |
20 |
|
21 |
|
- |
|
22 |
check = $(shell $(CC) $1 -c -xc /dev/null -o/dev/null 2>/dev/null && echo $1) |
- |
|
23 |
|
21 |
CC = avr-gcc |
24 |
CC = avr-gcc |
22 |
CFLAGS = -Os -g -Wall -I. -I$(USBTINY) |
25 |
OPTIM = -Os -ffunction-sections $(call check,-fno-split-wide-types) |
23 |
ASFLAGS = -Os -g -Wall -I. |
26 |
CFLAGS = -g -Wall -Wattributes -I. -I$(USBTINY) $(OPTIM) |
24 |
LDFLAGS = -g |
27 |
LDFLAGS = -g -Wl,--relax,--gc-sections |
25 |
MODULES = crc.o int.o usb.o $(OBJECTS) |
28 |
MODULES = crc.o int.o usb.o $(OBJECTS) |
26 |
UTIL = $(USBTINY)/../util |
29 |
UTIL = $(USBTINY)/../util |
27 |
|
30 |
|
28 |
main.hex: |
31 |
main.hex: |
29 |
|
32 |
|
30 |
all: main.hex $(SCHEM) |
33 |
all: main.hex $(SCHEM) |
31 |
|
34 |
|
32 |
clean: |
35 |
clean: |
33 |
rm -f main.elf *.o tags *.sch~ gschem.log |
36 |
rm -f main.elf *.o tags *.sch~ gschem.log |
34 |
|
37 |
|
35 |
clobber: clean |
38 |
clobber: clean |
36 |
rm -f main.hex $(SCHEM) |
39 |
rm -f main.hex $(SCHEM) |
37 |
|
40 |
|
38 |
main.elf: $(MODULES) |
41 |
main.elf: $(MODULES) |
39 |
$(LINK.o) -o $@ $(MODULES) |
42 |
$(LINK.o) -o $@ $(MODULES) |
40 |
|
43 |
|
41 |
main.hex: main.elf $(UTIL)/check.py |
44 |
main.hex: main.elf $(UTIL)/check.py |
42 |
@python $(UTIL)/check.py main.elf $(STACK) $(FLASH) $(SRAM) |
45 |
@python $(UTIL)/check.py main.elf $(STACK) $(FLASH) $(SRAM) |
43 |
avr-objcopy -j .text -j .data -O ihex main.elf main.hex |
46 |
avr-objcopy -j .text -j .data -O ihex main.elf main.hex |
44 |
|
47 |
|
- |
|
48 |
check: main.elf $(UTIL)/check.py |
- |
|
49 |
@python $(UTIL)/check.py main.elf $(STACK) $(FLASH) $(SRAM) |
- |
|
50 |
|
45 |
disasm: main.elf |
51 |
disasm: main.elf |
46 |
avr-objdump -S main.elf |
52 |
avr-objdump -S main.elf |
47 |
|
53 |
|
48 |
flash: main.hex |
54 |
flash: main.hex |
49 |
$(FLASH_CMD) |
55 |
$(FLASH_CMD) |
50 |
|
56 |
|
- |
|
57 |
fuses: |
- |
|
58 |
$(FUSES_CMD) |
- |
|
59 |
|
51 |
crc.o: $(USBTINY)/crc.S $(USBTINY)/def.h usbtiny.h |
60 |
crc.o: $(USBTINY)/crc.S $(USBTINY)/def.h usbtiny.h |
52 |
$(COMPILE.c) $(USBTINY)/crc.S |
61 |
$(COMPILE.c) $(USBTINY)/crc.S |
53 |
int.o: $(USBTINY)/int.S $(USBTINY)/def.h usbtiny.h |
62 |
int.o: $(USBTINY)/int.S $(USBTINY)/def.h usbtiny.h |
54 |
$(COMPILE.c) $(USBTINY)/int.S |
63 |
$(COMPILE.c) $(USBTINY)/int.S |
55 |
usb.o: $(USBTINY)/usb.c $(USBTINY)/def.h $(USBTINY)/usb.h usbtiny.h |
64 |
usb.o: $(USBTINY)/usb.c $(USBTINY)/def.h $(USBTINY)/usb.h usbtiny.h |
56 |
$(COMPILE.c) $(USBTINY)/usb.c |
65 |
$(COMPILE.c) $(USBTINY)/usb.c |
57 |
|
66 |
|
58 |
main.o: $(USBTINY)/usb.h |
67 |
main.o: $(USBTINY)/usb.h |
59 |
|
68 |
|
60 |
%.ps: %.sch $(UTIL)/sch2ps |
69 |
%.ps: %.sch $(UTIL)/sch2ps |
61 |
$(UTIL)/sch2ps $< |
70 |
$(UTIL)/sch2ps $< |