#
#  makefile for OpenGPS
#
#  creates library libopengps.a 
#  and moves it to ${BINDIR}
#

#  which machine are we running on?

host-name := $(shell hostname)


#  program version

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

# compiler & linker

CC     := gcc
LD     := ld
AR     := ar
RANLIB := ranlib


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

#LINUX_HDR := /usr/src/linux/include
#RTAI_HDR  := /usr/src/rtai/include
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

# include directories

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

CFLAGS     := -g ${INCLUDE} ${WARN} \
 -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 \
# ${OGR_HDR}/ogru_structs.h ${OGR_HDR}/ogru_globals.h ${OGR_HDR}/ogru_prototypes.h \
# ${OGR_HDR}/og_library.h


# object files

USR_OBJ := oglib_ipc.o oglib_channels.o


# rules

all: ${LIBDIR}/libopengps.a

SRC := $(wildcard *.c)

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

.PHONY: clean

include .depend

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

${LIBDIR}/libopengps.a: $(objects)
	${AR} rvu ${LIBDIR}/libopengps.a $(objects)
	${RANLIB} ${LIBDIR}/libopengps.a

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

# end of makefile
