# makefile for ogplot
# (graphical output for ogrcvr)

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


#  which machine are we running on?
host-name := $(shell hostname)

#  program version

#  PRGVER = ${VERSION}.${PATCHLEVEL}.${SUBLEVEL}

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}
CFLAGS       := -g ${INCLUDE} ${WARN} ${OGR_DEF}

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

LDFLAGS      := -L${LIBDIR}


## module requires compilation with flag O2
#
#  CFLAGSMOD  := -O2 -D__KERNEL__ -DMODULE ${INCLUDEMOD} ${WARNMOD} \
#   -fomit-frame-pointer -fno-strict-aliasing -fno-common -pipe ${OGR_DEF}


# dependencies

DEP  := ${OGR_HDR}/ogr_defines.h ${OGR_HDR}/ogr_structs.h ${OGR_HDR}/port.h

DEPU := ${OGR_HDR}/ogru_structs.h ${OGR_HDR}/ogru_globals.h ${OGR_HDR}/ogru_prototypes.h

#  DEPR := ${OGR_HDR}/ogrt_defines.h ${OGR_HDR}/ogrt_globals.h ${OGR_HDR}/ogrt_prototypes.h


# object files

#  MOD_OBJ    := ogrt_fifos.o ogrt_gp2021.o ogrt_maths.o \
#   ogrt_preamble.o ogrt_modfun.o ogrt_navbit.o \
#   ogrt_procfs.o ogrt_track.o \

SRC = ogplot_main.c opengl_functions.c plot2d.c rtai_functions.c

USR_OBJ := ogplot_main.o 


# rules

all: ${BINDIR}/ogplot

SRC := $(wildcard *.c)

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

.PHONY: clean

include .depend

objects := $(patsubst %.c,%.o,$(wildcard *.c))
     
${BINDIR}/ogplot: $(objects) ${LIBDIR}/libopengps.a
	${CC} ${CFLAGS} ${LDFLAGS} -o ${BINDIR}/ogplot $(objects) -lm \
  -L/usr/X11R6/lib -lX11 -lXi -lXmu -lglut -lGL -lGLU  ${LDFLAGS} -lm


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

# end of makefile

