CROSS_COMPILE=/usr/local/wince/bin/arm-wince-pe-

CC=$(CROSS_COMPILE)gcc
STRIP=$(CROSS_COMPILE)strip
CFLAGS=-Wall

CFLAGS+=-O2

LDLIBS=-lc -lgcc -lcoredll -lwinsock

TARGETS=boot.exe boot.s blue.exe readregs.exe changes.exe touch.exe \
	dumpresume.exe hackresume.exe

all: $(TARGETS)

boot.o: winhack.h build.h

boot.exe: asm.o

dumpresume: dumpresume.exe
	pcp dumpresume.exe ':/My Documents/dumpresume.exe'
#	pls '/My Documents/'
#	prun '/My Documents/dumpresume.exe'
#	pls '/My Documents/'

hackresume: hackresume.exe resumedump.bin
	pcp hackresume.exe ':/My Documents/hackresume.exe'
	pcp resumedump.bin ':/My Documents/hackresume.bin'
	prun '/My Documents/hackresume.exe'

copy: all
	#pcp boot.exe ":\\My Documents\\boot.exe"
	pcp changes.exe ":\\My Documents\\changes.exe"
	#pcp readregs.exe ":\\My Documents\\readregs.exe"
	#pcp touch.exe ":\\My Documents\\touch.exe"

run: all
	pcp default.txt ":\\SD-MMC Card\\default.txt"
	pcp boot.exe ":\\My Documents\\boot.exe"
	prun "\\My Documents\\boot"

build:
	echo `expr \`cat BUILD\` + 1` >BUILD-
	mv BUILD- BUILD

BUILD:
	make build

build.h: BUILD
	echo "#define BUILD \"$(USER)-`cat BUILD` `date`\"" >build.h

zip:
	make build
	make
	zip boot-$(USER)-`cat BUILD`.zip \
		BUILD ChangeLog COPYING Makefile \
		winhack.h \
		boot.c asm.S setup.h boot.exe \
		default.txt \
		blue.c \
		readregs.c showregs.py \
		changes.c changes.exe

%.exe: %.o
	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $+ $(LDLIBS)
	$(STRIP) $@

%.s: %.c
	$(CC) $(CFLAGS) -S -o $@ $+

%.o: %.S
	/opt/crosstool/gcc-3.4.1-glibc-2.3.3/arm-9tdmi-linux-gnu/bin/arm-9tdmi-linux-gnu-gcc -D__ASSEMBLY__ -c $+

%.bin: %.o
	/opt/crosstool/gcc-3.4.1-glibc-2.3.3/arm-9tdmi-linux-gnu/bin/arm-9tdmi-linux-gnu-objcopy $< -O binary $@

clean:
	rm -f *.exe *.zip *.o *.s *~ *.pyc boot.h
