# -----------------------------------------------------------------------------
#  Title      : makefile for EL HAL
#  Project    : UNKNOWN
# -----------------------------------------------------------------------------
#  File       : makefile
#  Author     : Simon SOuthwell
#  Company    : Global Inkjet Systems
#  Created    : 2018-03-20
# -----------------------------------------------------------------------------
#  Description:
#  This file is the makefile for the embedded logic HAL. Currently only 
#  support Cygwin builds
# -----------------------------------------------------------------------------
#  Copyright (c) 2017, 2018 Global Inkjet Systems
# -----------------------------------------------------------------------------

##########################################################
# Definitions
##########################################################

OSTYPE:=$(shell uname -o)

ifeq (${OSTYPE}, Cygwin)
  # Define path to gcc ARM cross-compiler bin for CYGWIN
  GCCBIN       = /cygdrive/c/ArmDs5/17.1/embedded/ds-5/sw/gcc/bin/
endif

# Auto-build script
AUTOBUILD      = /cygdrive/e/git/fw_development_tools/logic_memory_mapper/gen_elhal.py

# Define the C++ compiler
C++            = ${GCCBIN}/arm-linux-gnueabihf-g++

# Define the options
COPTS          = -std=c++11 -I. -Iauto -I../build -DDEBUG
COPTS_SO       = -fPIC -shared ${COPTS}

# List the targets
TARGETS        = libHAL_SOM_core.so

AUTODIR        = auto
REPOTOP        = ../../../

# Define the common source code 
COMMONINCLUDES = ../build/hps_0.h
COMMONSRC      = CSwim.cpp
COMMONDEP      = ${COMMONINCLUDES} ${COMMONSRC}

# make directory command
MKDIR_P        = mkdir -p

# Python command
PYTHON         = python3

##########################################################
# Compilation rules
##########################################################

all: ${AUTODIR} ${TARGETS}

.PHONY: ${AUTODIR}
${AUTODIR}:
ifeq ($(wildcard ${AUTODIR}),)
	@${MKDIR_P} ${AUTODIR}
	@${PYTHON} ${AUTOBUILD} -r ${REPOTOP} -b csr seq -o ${AUTODIR}
endif

libHAL_SOM_core.so: ${COMMONDEP} main.cpp
	@${C++} ${COPTS_SO} ${COMMONSRC} main.cpp -o $@

clean:
	@rm -rf ${TARGETS} ${AUTODIR}
