#
#  makefile for OpenGPS receiver
#
#  - creates module ogrt_module.o (RT process} and 
#    executable ogrcvr (user process} 
#  - moves both files to ${BINDIR}
#

# The current directory is passed to sub-makes as argument
PWD := $(shell pwd)

#  which machine are we running on?

host-name := $(shell hostname)

OGR_DEF := -DPCIBOARD=$(is_pci_board) -DCHECK_CORR_OUTPUT=$(check_corr_output) \
    -DPROGRAMVERSION=\"$(OPENGPSRELEASE)\"

# compiler & linker

CC := gcc
LD := ld


# it is assumed that these directories exist 
# and point to the correct set of header files ...

LINUX_HDR := /usr/src/kernel-headers-`uname -r`/include
RTAI_HDR  := /usr/realtime/include

OGR_HDR   := ../include

BINDIR    := ../../bin
LIBDIR    := ../../lib

# compiler flags
# (-Wuninitialized not supported without -O)

WARN       := -W -Wall -Wstrict-prototypes -Wmissing-prototypes \
   -Wno-trigraphs -Wunused

#  WARNMOD    := -W -Wstrict-prototypes -Wmissing-prototypes \
#   -Wno-trigraphs -Wunused-variable

# include directories

INCLUDE    := -I${RTAI_HDR} -I${LINUX_HDR} -I${OGR_HDR} 

#  INCLUDEMOD := -isystem ${RTAI_HDR} -isystem ${LINUX_HDR} -I${OGR_HDR}

CFLAGS       := -g ${INCLUDE} ${WARN} -fomit-frame-pointer \
    -fno-strict-aliasing -fno-common -pipe ${OGR_DEF}

#  EXTRA_CFLAGS := -I/usr/realtime/include -I/usr/include/ -ffast-math -mhard-float

LDFLAGS      := -L${LIBDIR}


# rules

all: ${BINDIR}/ogrcvr

SRC := $(wildcard *.c)

.depend: $(SRC)
	  $(RM) $@
	  gcc -MM $(CFLAGS) $(SRC) > $@

.PHONY: clean

include .depend

objects := $(patsubst %.c,%.o,$(wildcard *.c))
     
${BINDIR}/ogrcvr : $(objects) ${LIBDIR}/libopengps.a
	${CC} ${CFLAGS} ${LDFLAGS} -o ${BINDIR}/ogrcvr $(objects) -lm -lopengps

clean:
	  $(RM) -r *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions
	  $(RM) ${BINDIR}/ogrcvr

# end of makefile

