# Name: Makefile
# Project: 3D_mouse; 3D_accelerator to HID mouse converter
# Author: Alex Badea
# Creation Date: 2007-01-14
# Tabsize: 8
# Copyright: (c) 2007 Alex Badea <vamposdecampos@gmail.com>
# License: Proprietary, free under certain conditions. See Documentation.

COMPILE = avr-gcc -Wall -Os -Iusbdrv -I. -mmcu=atmega8 #-DDEBUG_LEVEL=3
OBJECTS = usbdrv/usbdrv.o usbdrv/usbdrvasm.o usbdrv/oddebug.o 3D_mouse.o


# symbolic targets:
all:	3D_mouse.hex

.c.o:
	$(COMPILE) -c $< -o $@

.S.o:
	$(COMPILE) -x assembler-with-cpp -c $< -o $@
# "-x assembler-with-cpp" should not be necessary since this is the default
# file type for the .S (with capital S) extension. However, upper case
# characters are not always preserved on Windows. To ensure WinAVR
# compatibility define the file type manually.

.c.s:
	$(COMPILE) -S $< -o $@

# Fuse high byte:
# 0xc9 = 1 1 0 0   1 0 0 1 <-- BOOTRST (boot reset vector at 0x0000)
#        ^ ^ ^ ^   ^ ^ ^------ BOOTSZ0
#        | | | |   | +-------- BOOTSZ1
#        | | | |   + --------- EESAVE (don't preserve EEPROM over chip erase)
#        | | | +-------------- CKOPT (full output swing)
#        | | +---------------- SPIEN (allow serial programming)
#        | +------------------ WDTON (WDT not always on)
#        +-------------------- RSTDISBL (reset pin is enabled)
# Fuse low byte:
# 0x9f = 1 0 0 1   1 1 1 1
#        ^ ^ \ /   \--+--/
#        | |  |       +------- CKSEL 3..0 (external >8M crystal)
#        | |  +--------------- SUT 1..0 (crystal osc, BOD enabled)
#        | +------------------ BODEN (BrownOut Detector enabled)
#        +-------------------- BODLEVEL (2.7V)

clean:
	rm -f 3D_mouse.hex 3D_mouse.lst 3D_mouse.obj 3D_mouse.cof 3D_mouse.list 3D_mouse.map 3D_mouse.eep.hex 3D_mouse.bin *.o usbdrv/*.o 3D_mouse.s usbdrv/oddebug.s usbdrv/usbdrv.s

# file targets:
3D_mouse.bin:	$(OBJECTS)
	$(COMPILE) -o 3D_mouse.bin $(OBJECTS)

3D_mouse.hex:	3D_mouse.bin
	rm -f 3D_mouse.hex 3D_mouse.eep.hex
	avr-objcopy -j .text -j .data -O ihex 3D_mouse.bin 3D_mouse.hex
	avr-size 3D_mouse.bin
	#./checksize 3D_mouse.bin 8192 960

disasm:	3D_mouse.bin
	avr-objdump -d 3D_mouse.bin

cpp:
	$(COMPILE) -E 3D_mouse.c
