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