# makefile for OpenGPS

CC=gcc
LD=ld

LINUX_HDR=/usr/src/linux/include
RTAI_HDR=/usr/realtime/include
OGR_HDR=../../include

# adjust include directories accordingly

CFLAGS=-O2 -g -I$(RTAI_HDR) -I$(LINUX_HDR) -I$(OGR_HDR) -Wall \
 -Wstrict-prototypes -Wno-trigraphs -fomit-frame-pointer \
 -fno-strict-aliasing -fno-common -pipe

DEP=$(OGR_HDR)/ogr_structs.h

DEPR=$(OGR_HDR)/ogrt_defines.h \
 $(OGR_HDR)/ogr_structs.h $(OGR_HDR)/ogrt_globals.h

all: clean ogrt_module.o user acqlist utcdate install

rtproc.o: rtproc.c $(DEP) $(DEPR)
	$(CC) $(CFLAGS) -c -D__KERNEL__ -DMODULE rtproc.c

carrier.o: carrier.c $(DEP) $(DEPR)
	$(CC) $(CFLAGS) -c -D__KERNEL__ -DMODULE carrier.c

code.o: code.c $(DEP) $(DEPR)
	$(CC) $(CFLAGS) -c -D__KERNEL__ -DMODULE code.c

commandTasks.o: commandTasks.c $(DEP) $(DEPR)
	$(CC) $(CFLAGS) -c -D__KERNEL__ -DMODULE commandTasks.c

error.o: error.c $(DEP) $(DEPR)
	$(CC) $(CFLAGS) -c -D__KERNEL__ -DMODULE error.c

frameDecode.o: frameDecode.c $(DEP) $(DEPR)
	$(CC) $(CFLAGS) -c -D__KERNEL__ -DMODULE frameDecode.c

gp2021.o: gp2021.c $(DEP) $(DEPR)
	$(CC) $(CFLAGS) -c -D__KERNEL__ -DMODULE gp2021.c

houseKeepingTask.o: houseKeepingTask.c $(DEP) $(DEPR)
	$(CC) $(CFLAGS) -c -D__KERNEL__ -DMODULE houseKeepingTask.c

list.o: list.c $(DEP) $(DEPR)
	$(CC) $(CFLAGS) -c -D__KERNEL__ -DMODULE list.c

list_survey.o: list_survey.c $(DEP) $(DEPR)
	$(CC) $(CFLAGS) -c -D__KERNEL__ -DMODULE list_survey.c

messages.o: messages.c $(DEP) $(DEPR)
	$(CC) $(CFLAGS) -c -D__KERNEL__ -DMODULE messages.c

readTask.o: readTask.c $(DEP) $(DEPR)
	$(CC) $(CFLAGS) -c -D__KERNEL__ -DMODULE readTask.c

survey.o: survey.c $(DEP) $(DEPR)
	$(CC) $(CFLAGS) -c -D__KERNEL__ -DMODULE survey.c

ogrt_maths.o: ogrt_maths.c $(DEP) $(DEPR)
	$(CC) $(CFLAGS) -c -D__KERNEL__ -DMODULE ogrt_maths.c

ogrt_module.o: rtproc.o carrier.o code.o commandTasks.o error.o frameDecode.o \
 gp2021.o houseKeepingTask.o list.o list_survey.o messages.o readTask.o \
 survey.o ogrt_maths.o 
	$(LD) -r  ogrt_maths.o rtproc.o carrier.o code.o commandTasks.o error.o \
 frameDecode.o gp2021.o houseKeepingTask.o list.o list_survey.o messages.o \
 readTask.o survey.o -o ogrt_module.o

kbhit.o: kbhit.c ../../include/kbhit.h
	$(CC) $(CFLAGS) -c kbhit.c

user: user.c kbhit.o 
	$(CC) $(CFLAGS) -o ogr user.c kbhit.o -lncurses -lm 

acqlist: acqlist.c
	$(CC) -g -Wall acqlist.c -o acqlist

utcdate: utcdate.c
	$(CC) -g -Wall utcdate.c -o utcdate -lm

clean: 
	rm -f *.o ogr acqlist utcdate

install:
	cp ogr /usr/local/bin/
	chmod u+s /usr/local/bin/ogr
	cp ogrt_module.o /lib/modules/`uname -r`/ogr/
	depmod -a
