
#########################################################################
#
#  $Id: Makefile 1.9 2017/04/12 08:49:33 martin TEST $
#
#  Description:
#    Makefile for gpsxmple for Unix-like systems.
#    Currently supported OSs: Linux, QNX 6.x
#
# -----------------------------------------------------------------------
#  $Log: Makefile $
#  Revision 1.9  2017/04/12 08:49:33  martin
#  Changed CFLAGS to CPPFLAGS.
#  Revision 1.8  2017/04/05 16:08:53  martin
#  Added some library modules.
#  Revision 1.7  2014/10/30 13:50:04  martin
#  Added module mbgerror.o.
#  Revision 1.6  2013/02/01 16:11:27  martin
#  Added extiohlp module to the list of object files.
#  Revision 1.5  2011/08/19 07:26:40  martin
#  Modified the way to define targets etc.
#  Revision 1.4  2011/04/18 08:08:41  martin
#  Modified DEBUG handling.
#  Revision 1.3  2009/10/01 14:09:19  martin
#  Added mbgserio.c source module.
#  Revision 1.2  2006/08/22 15:49:27  martin
#  Moved this makefile for Unix-like systems to folder unix.
#  This build environment now supports Linux and QNX 6.x.
#  Network socket I/O is supported for both Linux and QNX.
#  Serial I/O is not yet supprted for QNX, but for Linux.
#  Account for mbglib files having been moved to subdirectory mbglib.
#  Build with debug if make is called with DEBUG=1.
#  Added library modules mbgextio.c and aes128.c.
#  Revision 1.1  2004/06/01 14:55:27  martin
#
#########################################################################

TARGET = gpsxmple

MBGLIB = ../mbglib
MBGLIB_DIRS += common

VPATH += ..
VPATH += $(foreach dir,$(MBGLIB_DIRS),$(MBGLIB)/$(dir))

OBJS = $(TARGET).o
OBJS += extiohlp.o
OBJS += xtiocomm.o
OBJS += cfg_hlp.o
OBJS += mbgextio.o
OBJS += mbgserio.o
OBJS += gpsserio.o
OBJS += gpsutils.o
OBJS += aes128.o
OBJS += mbgerror.o
OBJS += str_util.o
OBJS += lan_util.o
OBJS += xdevfeat.o

# Try to determine whether the OS is QNX
OS_IS_QNX := $(shell uname | grep -i QNX && echo "QNX" )


# set up the compiler flags

CPPFLAGS += -Wall

ifdef DEBUG
  # build with debugging enabled
  CPPFLAGS += -g -DDEBUG=$(DEBUG)
else
  # build with specified optimization level
  CPPFLAGS += -O2
endif

CPPFLAGS += -D_USE_SOCKET_IO=1

CPPFLAGS += -I.
CPPFLAGS += $(foreach dir,$(MBGLIB_DIRS),-I$(MBGLIB)/$(dir))

ifneq ($(OS_IS_QNX),)
  # for QNX we must link the socket library explicitely
  LDFLAGS += -lsocket
  # we don't yet support serial I/O under QNX
  CPPFLAGS += -D_USE_SERIAL_IO=0
else
  CPPFLAGS += -D_USE_SERIAL_IO=1
endif


LD = $(CC)

.PHONY: all
all: $(TARGET)

$(TARGET): $(OBJS)
	$(LD) $(LDFLAGS) -o $@ $(OBJS)


.PHONY: clean
clean:
	rm -f *.o *~ core
	rm -f $(TARGET)

.PHONY: distclean
distclean: clean

