# NOTE!>>> The linker needs the lib paths to be defined with -L the same way it is done after main.bin: (-Lf:\usr\gcc\sh-1-coff\lib)!
CC =		gcc
CFLAGS =	-O2 -m1 -fomit-frame-pointer -Dprintf=(+_printf_+) -D__DPRINTF__
CPPFLAGS =
LD =		ld

MAIN_OBJS =	abcpad.o \
		actor.o \
		anakey.o \
		anascale.o \
		anasense.o \
		audio.o \
		beeper.o \
		beepkey.o \
		boardkey.o \
		can.o \
		cicfs.o \
		cicmath.o \
		cicmisc.o \
		clock.o \
		datalog.o \
		defhtml.o \
		dialog.o \
		drawable.o \
		dsactor.o \
		dsview.o \
		eggtimer.o \
		eventmgr.o \
		exit.o \
		fastfont.o \
		filereq.o \
		flash.o \
		flashlog.o \
		flashmem.o \
		font.o \
		fvolamem.o \
		gdevice.o \
		gseri.o \
		gsms.o \
		gtxrx.o \
		gudp.o \
		gpsscan.o \
		graphics.o \
		gsm.o \
		htwindow.o \
		htmlwind.o \
		i2c.o \
		icondata.o \
		icons.o \
		ignlogic.o \
		init.o \
		keyboard.o \
		keysense.o \
		label.o \
		list.o \
		main.o \
		memarea.o \
		memory.o \
		menu.o \
		named.o \
		ne.o \
		nvolamem.o \
		nvolamgr.o \
		outkey.o \
		outport.o \
		pattern.o \
		poster.o \
		post256.o \
		pppproto.o \
		rammem.o \
		rdssense.o \
		registry.o \
		router.o \
		rtmain.o \
		screen.o \
		scrkey.o \
		segfont.o \
		sensor.o \
		shutdown.o \
		smain.o \
		smsrec.o \
		smssense.o \
		sovieimp.o \
		statlog.o \
		strhdr.o \
		taipmgr.o \
		testact.o \
		ticker.o \
		timer.o \
		ttalarm.o \
		ttdsuite.o \
		ttglobal.o \
		tthibar.o \
		tthlight.o \
		ttlobar.o \
		ttmanual.o \
		ttmap.o \
		ttpage.o \
		ttpage1.o \
		ttpage2.o \
		ttphone.o \
		ttphone1.o \
		ttphone2.o \
		ttphpan.o \
		ttradio.o \
		ttrevcam.o \
		ttsetobj.o \
		ttsetup.o \
		ttsetup1.o \
		ttsetup2.o \
		ttsetup3.o \
		ttsetup4.o \
		ttsetup5.o \
		ttsetup6.o \
		tttv.o \
		tttv1.o \
		tuner.o \
		udpip.o \
		udprece.o \
		udpsend.o \
		udpsense.o \
		udpsock.o \
		udpswupd.o \
		userkey.o \
		vaaka.o \
		video.o \
		watchdog.o \
		wscanf.o \
		wsprintf.o

MAIN_LIBS =	-lm \
		-lc \
		-lgcc \
		-lgxx \
		-lc

.PHONY:		all clean

all:		main.bin

net: SW
	loadsw 172.16.1.51

SW: main.bin
	addcrc32 main.bin SW

main.bin:	$(MAIN_OBJS)
	$(LD) sys/start.o syscalls/glue.o syscalls/iobyte.o $(MAIN_OBJS) \
	$(MAIN_LIBS) -Tmain.lnk -o main.sr -Map main.map -Lf:\usr\gcc\sh-1-coff\lib
	objcopy -I srec -O binary main.sr main.bin

editable.txt: strtable.txt
	rchar u 9 59 strtable.txt editable.txt

strhdr.ch: editable.txt strlist.h
	rchar d 59 9 editable.txt strtable.txt
	textconv -s=strlist.h -it=strtable.txt -ot=strtable.txt -od=strhdr.dat
	rchar u 9 59 strtable.txt editable.txt
	file2str strhdr.ch strhdr.dat strdatafile
%.o : %.cpp
	$(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
%.o : %.c
	$(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@

%.d : %.cpp
	$(CC) -MM $(CPPFLAGS) $< > $@
%.d : %.c
	$(CC) -MM $(CPPFLAGS) $< > $@

.PHONY : clean
clean:
	-rm *.o
	-rm SW
	-rm main.bin

depend:
	-rm *.d
	-touch exit.d
	
include $(MAIN_OBJS:.o=.d)
