# -----------------------------------------------------------------------------
#  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)

# Auto-build script
AUTOBUILD      = ${HOME}/git/fw_development_tools/logic_memory_mapper/gen_elhal.py

# Define the C++ compiler
#C++            = /home/jenkins_user/jenkins_slave/workspace/1.10000_GMA_EL_syn/a/ver/modelsim_ase/gcc-4.7.4-linux/bin/g++
C++            = g++

# Define the options
COPTS          =-m32 -static -fPIC -std=c++11 -I. -Iauto -I../src/testvp/vproc/usercode -I../src/testvp/vproc/code -DDEBUG -DHDL_SIM

# List the targets
TARGET         = libHAL_SOM_core_sim.a
SRCFILES       = CSwim.cpp main.cpp

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

# Define the common source code 
INCLUDES = ../src/testvp/vproc/usercode/hps_0.h $(wildcard *.h) $(wildcard auto/*.h) 

# make directory command
MKDIR_P        = mkdir -p

# Python command
PYTHON         = python3

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

all: ${AUTODIR} ${TARGET}

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

${TARGET}: ${SRCFILES:%.cpp=%.o} 
	@ar rcs $@ $^ 
	@#${C++} -m32 -shared -fPIC $^ -o $@

${SRCFILES:%.cpp=%.o} : ${INCLUDES}

%.o : %.cpp
	@${C++} -c ${COPTS} $<

autogen :
	@${MKDIR_P} ${AUTODIR}
	@${PYTHON} ${AUTOBUILD} -r ${REPOTOP} -b csr seq -o ${AUTODIR}

clean:
	@rm -rf ${TARGET} *.o ${AUTODIR}
