all: sched_toggle.o rtc_toggle.o rectangle.o

MYCFLAGS = -O2 -Wall
include rtl.mk

sched_toggle.o: sched_toggle.c common.h
	$(CC) ${INCLUDE} ${CFLAGS} -c sched_toggle.c

rtc_toggle.o: rtc_toggle.c common.h
	$(CC) ${INCLUDE} ${CFLAGS} -c rtc_toggle.c

rtc_toggle_fifo.o: rtc_toggle_fifo.c common.h
	$(CC) ${INCLUDE} ${CFLAGS} -c -o rtc_toggle_fifo.o rtc_toggle_fifo.c

sine_wave.o: sine_wave.c common.h
	$(CC) ${INCLUDE} ${CFLAGS} -c -o sine_wave.o sine_wave.c
	ld -r  -static -o sine_wave sine_wave.o -L/usr/lib -lm 
rectangle.o: rectangle.c
	$(CC) ${INCLUDE} ${CFLAGS} -c -o rectangle.o  rectangle.c 
monitor: monitor.c
	$(CC) ${INCLUDE} ${MYCFLAGS} -o monitor monitor.c

#test, remove any modules, load new ones and run app
test_sched: 
	@echo "Type <return> to continue"
	@read junk
	@make stop_test
	@echo "First we remove any existing rtl-modules"
	@echo "You may see error warnings from \"make\" - ignore them"
	@echo "Type <return> to continue"
	@read junk
	-rmmod frank_module 
	(cd $(RTL_DIR); ./rmrtl)
	@echo "Now insert the fifo and the scheduler"
	@echo "Type <return> to continue"
	@read junk
	(cd $(RTL_DIR); ./insrtl)
	@echo "Now start the real-time tasks  module"
	@echo "Type <return> to continue"
	@read junk
	@insmod sched_toggle.o

test_rectangle: 
	@echo "Type <return> to continue"
	@read junk
	@make stop_test.o
	@echo "First we remove any existing rtl-modules"
	@echo "You may see error warnings from \"make\" - ignore them"
	@echo "Type <return> to continue"
	@read junk
	-rmmod frank_module 
	(cd $(RTL_DIR); ./rmrtl)
	@echo "Now insert the fifo and the scheduler"
	@echo "Type <return> to continue"
	@read junk
	(cd $(RTL_DIR); ./insrtl)
	@echo "Now start the real-time tasks  module"
	@echo "Type <return> to continue"
	@read junk
	@insmod rectangle.o

test_rtc: 
	@make stop_test
	@insmod rtc_toggle

#This should be done with modeprobe to clear all rt modules
# but it works this brute force way too.
stop_test:
	-rmmod frank_module
	-rmmod rtc_toggle
	-rmmod rectangle
	-rmmod sched_toggle
	-rmmod rt_process
	-rmmod rtl_fifo
	-rmmod rtl_sched
	-rmmod rtl_fpsched

clean:
	rm -f *.o
