SPIN    = TV_Half_Height
LIBNAME = ../Tv2Text.a

OBJECTS = Tv2Text.o $(SPIN)_firmware.o
SOURCES = $(OBJECTS:.o=.c)

all:	$(OBJECTS) $(LIBNAME) $(SPIN).dat Makefile

$(LIBNAME):
	$(AR) $(OBJECTS)

LIBINCS=-I../../include

# The compiler/linker
CC=$(TOOLPATH)zpu-elf-gcc
AR=$(TOOLPATH)zpu-elf-ar -r $(LIBNAME)

# Compiler flags. Compile only, debug info, all warnings, optimize for size
CFLAGS=-c -g -Wall -Os -I/usr/include $(LIBINCS)

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

# Extract DAT section (PASM code for COG) from Spin module into .dat file (-0x enables #defines)
$(SPIN).dat: $(SPIN).spin Makefile
	bstc.linux -Ox -c $(SPIN).spin 

# Convert binary .dat file into an elf object file for zpu-elf-gcc target
# N.B. the zpu-elf-objcopy has no reverse-bytes option, use the host objcopy.
$(SPIN)_firmware.o: $(SPIN).dat Makefile
	objcopy -I binary -O binary --reverse-bytes=4  $(SPIN).dat
	$(TOOLPATH)zpu-elf-objcopy -I binary -B zpu -O zpu-elf-gcc $(SPIN).dat $(SPIN)_firmware.o

clean: FORCE
	rm -f *.o *.dat $(LIBNAME)
FORCE:
