##########################################################################
# Copyright 2020 MBARI                                             
##########################################################################
# Summary  : Makefile for VN100 MEMS Compass
# Filename : Makefile
# Author   : Laughlin Barker
# Project  : 
# Version  : Version 1.1
# Created  : 03/22/20
# Modified : 06/08/20
# Archived :
##########################################################################

CC 			= cc
CCPP 		= cc
LD			= cc
AR 			= wlib
DEPEND_TOOL = makedepend

AUV_BIN_DIR = $(AUV)/bin
LIBDIR = ../vnc_driver
BINDIR = build
OBJDIR = $(BINDIR)/obj

DEBUG 	    		= -g
EXCEPTION_HANDLING 	= -WC,-xs

CFLAGS	    += -c $(DEBUG) $(MAP_OUTPUT) $(OPTIMIZE) -D_QNX -DUNIX -Wc,-ei
CPPFLAGS    += -c $(DEBUG) $(MAP_OUTPUT) $(OPTIMIZE) -D_QNX -DUNIX \
	         $(EXCEPTION_HANDLING) -WC,-ei

CPPFLAGS += -D VERSION_BUILD_DATE=\""$(shell date +%Y_%m_%dT%T%Z)"\"
CPPFLAGS += -D VERSION_BUILD_TAG=\"$(BUILD_TAG)\"
CPPFLAGS += -D VERSION_BUILD_INFO=\"$(BUILD_INFO)\"

INCLUDES = 	-I.  \
		-I$(AUV) \
		-I$(AUV)/utils \
		-I$(AUV)/framework \
		-I$(AUV)/taskIF \
	  -I/usr/include \
		-I/usr/local/include \
		-I$(AUV)/DataLog \
		-I$(AUV)/Simulator \
		-I$(AUV)/LayeredControl \
		-I$(LIBDIR)/include 


LDFLAGS 	= 	-g -lmqueue
LIBPATH	    = 	/usr/lib:$(AUV)/lib:$(AUV)

LIBS        =   $(AUV)/utils/utils.lib \
		$(AUV)/framework/auvFramework.lib \
		$(AUV)/taskIF/taskInterfaces.lib \
		$(AUV)/DataLog/dataLog.lib \
		$(AUV)/vn100/vnc_driver/build/libvnc.a

OBJS	=	VN100.o \
			VN100Server.o \
			VN100Output.o \
			VN100RawMeasOutput.o \
			VN100Log.o \
			VN100RawMeasLog.o \
			VN100IronCalibrationLog.o \
			VN100Sensor.o \
			VN100UartSensor.o \
			VN100SpiSensor.o

TARGETS =	vn100Server \
			vn100 \
			vn100Test \
			vn100IronCalibration

-include $(AUV)/autonomy.make # this file contains the general
                       # modifications we want to apply to
                       # all the modules

# all: dirs vn_lib $(TARGETS)
all: $(TARGETS)

vn100Server: _VN100Server.o vn_lib $(OBJS) $(LIBS)
	$(LD) $(LDFLAGS) _VN100Server.o $(OBJS) $(LIBS) -o $@

vn100: _VN100.o vn_lib $(OBJS) $(LIBS)
	$(LD) $(LDFLAGS) _VN100.o $(OBJS) $(LIBS) -o $@

vn100Test: _VN100Test.o vn_lib $(OBJS) $(LIBS)
	$(LD) $(LDFLAGS) _VN100Test.o $(OBJS) $(LIBS) -o $@

vn100IronCalibration: _VN100HSI_Control.o vn_lib $(OBJS) $(LIBS)
	$(LD) $(LDFLAGS) _VN100HSI_Control.o $(OBJS) $(LIBS) -o $@

vn_lib:
	cd $(LIBDIR) && make lib

install:
	cp -f $(TARGETS) $(AUV_BIN_DIR)/.

# Create the directories used in the build
.PHONY: dirs
dirs:
	@mkdir -p $(BINDIR)
	@mkdir -p $(OBJDIR)

clean:
	rm -f *.o $(OBJS:.o=.d) *.yy *.tab.* $(TARGETS) *.err
	cd $(LIBDIR) && make clean

##########################################################################
# Do not modify anything below this line unless absolutely necessary

.SUFFIXES:
.SUFFIXES:	.o .c .cc .d .idl

%.d: %.c
	@echo Generating dependencies for $?
	@$(DEPEND_TOOL) $(CFLAGS) $(INCLUDES) $? -f $@

%.d: %.cc
	@echo Generating dependencies for $?
	@$(DEPEND_TOOL) $(CPPFLAGS) $(INCLUDES) $? -f $@ 

%.o: %.c 
	$(CC) $(CFLAGS) $(INCLUDES) $< -o $@	

%.o: %.cc
	$(CCPP) $(CPPFLAGS) $(INCLUDES) $< -o $@


DEST	    = .

MAKEFILE    = Makefile

include       $(OBJS:.o=.d)

depend:	

update:
	cvs update $(CC_SRCS) $MAKEFILE

commit:
	cvs commit $(CC_SRCS) $MAKEFILE

##########################################################################
