##########################################################################
# Copyright 2020 MBARI                                             
##########################################################################
# Summary  : Top-level Makefile for VN100 compass driver
# Filename : Makefile
# Author   : Laughlin Barker
# Project  : 
# Version  : Version 1.0.0
# Created  : 05/05/2020
# Archived :
##########################################################################

# Nominally, this should be set by git tag, like the following but since we 
# don't have Git on QNX, we manually update for now.
# Based on Makefile code written by Phillip Johnston, Embedded Artistry
# https://embeddedartistry.com/blog/2016/12/21/giving-your-firmware-build-a-version/

# version:="$(shell git describe --tags --long --dirty)"
version := $(subst -, ,v0.2.2-0)

COMMIT := $(strip $(word 3, $(version)))
COMMITS_PAST := $(strip $(word 2, $(version)))
DIRTY := $(strip $(word 4, $(version)))
ifneq ($(COMMITS_PAST), 0)
	BUILD_INFO_COMMITS := "."$(COMMITS_PAST)
endif
ifneq ($(DIRTY),)
	BUILD_INFO_DIRTY :="+"
endif

export BUILD_TAG :=$(strip $(word 1, $(version)))
export BUILD_INFO := $(COMMIT)$(BUILD_INFO_COMMITS)$(BUILD_INFO_DIRTY)

# MAKEFILE = Makefile
.PHONY: all tests clean vnc_driver src

ALL:	all

# NOTE
# 'tests' are left out of 'all' because the testframework and test source
# do not compile under QNX.
all: vnc_driver src

clean: clean_vnc_driver clean_src

clean_src:
	@echo "Cleaning vn100/src..."
	cd src; make clean

clean_tests:
	@echo "Cleaning vn100/tests..."
	cd tests; make clean

clean_vnc_driver:
	@echo "Cleaning vnc_driver..."
	cd vnc_driver; make clean

src:
	@echo "Making vn100/src..."
	cd src; make all

tests: vnc_driver
	@echo "Making vn100/tests..."
	cd tests; make all_no_tests; ./vn100_compass_tests -c

vnc_driver:
	@echo "Making vnc_driver..."
	cd vnc_driver; make all
	
install: src
	@echo "Installing vn100 driver..."
	cd src; make install $(AUV_BIN_DIR)/. 

format:
	@echo "Running clang-format..."
	clang-format-9 -style=file -i src/*.cc src/*.h
