#!/bin/sh
# $URL: http://subversion:8080/svn/gsc/trunk/drivers/LINUX/SIO4%20and%20SIO8/SIO4_Linux_2.x.x_GSC_DN/make_all $
# $Rev: 56360 $
# $Date: 2025-04-15 08:17:25 -0500 (Tue, 15 Apr 2025) $

# SIO4: Overall make script



#==============================================================================
_process_sources() {
	# 1 = name of "sources" script to process
	# 2 = build target

	SRC=${1}
	DST=_sources

	if [ -e ${SRC} ]
	then
		# The above named file is present at GSC for development purposes only
		# and is not distributed in driver archives.

		D2U=`which dos2unix 2>/dev/null | wc -l`

		if [ "${D2U}" != "1" ]
		then

			D2U=~/c/gsc/gsc_common/utils/linux/d2u

		else

			D2U=dos2unix

		fi

		rm -f ${DST}

		chmod +w ${SRC}
		${D2U} ${SRC}	 2>/dev/null  1>/dev/null
		chmod +x ${SRC}
		${SRC}

		make -f ${DST} ${2}

		rm -f ${DST}

	fi
}



#==============================================================================
_process() {
	# 1 = directory name
	# 2 = build target

	if [ -d ./${1} ]
	then

		echo -e "======================================================================\r${1} "

		CWD=`pwd`

		cd ./${1}

		_process_sources ./sources ${2}

		if [ -e ./makefile ]
		then

			make -f ./makefile ${2}

		elif [ -e ./Makefile ]
		then

			make -f ./Makefile ${2}

		fi

		cd ${CWD}

	fi
}



#==============================================================================

_process driver						${1}

if [ ! "${1}" != "" ]
then
./driver/start
fi

_process include					${1}
_process api						${1}
_process docsrc						${1}
_process utils						${1}

_process async/api					${1}
_process fasync/api					${1}
_process hdlc/api					${1}
_process isoc/api					${1}
_process sync/api					${1}

_process async/utils				${1}
_process fasync/utils				${1}
_process hdlc/utils					${1}
_process isoc/utils					${1}
_process sync/utils					${1}

_process lib						${1}

_process samples/id					${1}
_process samples/irq				${1}
_process samples/led				${1}
_process samples/regs				${1}
_process samples/services			${1}
_process samples/txrate				${1}

_process async/samples/asyncc2c		${1}
_process async/samples/rxasync		${1}
_process async/samples/stream		${1}
_process async/samples/txasync		${1}

_process fasync/samples/din			${1}
_process fasync/samples/dout		${1}
_process fasync/samples/fasyncc2c	${1}
_process fasync/samples/gpio		${1}

_process hdlc/samples/hdlcc2c		${1}

_process isoc/samples/isocc2c		${1}

_process sync/samples/gpio			${1}
_process sync/samples/syncc2c		${1}

# Protocol Library API test applications ==================

if [ -d ./samples/apitest ]
then
echo -n
_process ./samples/apitest			${1}
fi

if [ -d ./async/samples/apitest ]
then
echo -n
_process ./async/samples/apitest	${1}
fi

if [ -d ./fasync/samples/apitest ]
then
echo -n
_process ./fasync/samples/apitest	${1}
fi

if [ -d ./hdlc/samples/apitest ]
then
echo -n
_process ./hdlc/samples/apitest		${1}
fi

if [ -d ./isoc/samples/apitest ]
then
echo -n
_process ./isoc/samples/apitest		${1}
fi

if [ -d ./sync/samples/apitest ]
then
echo -n
_process ./sync/samples/apitest		${1}
fi

# Internal test applications ==============================

if [ -d ./samples/bar2 ]
then
echo -n
_process ./samples/bar2				${1}
fi

if [ -d ./samples/dma_test ]
then
echo -n
_process ./samples/dma_test			${1}
fi

if [ -d ./samples/fifo_lvl ]
then
echo -n
_process ./samples/fifo_lvl			${1}
fi

if [ -d ./samples/irq2 ]
then
echo -n
_process ./samples/irq2				${1}
fi

if [ -d ./samples/metrics ]
then
echo -n
_process ./samples/metrics			${1}
fi

if [ -d ./samples/read_call_time ]
then
echo -n
_process ./samples/read_call_time	${1}
fi

if [ -d ./samples/sbtest ]
then
echo -n
_process ./samples/sbtest			${1}
fi

if [ -d ./samples/sio4flash ]
then
echo -n
_process ./samples/sio4flash		${1}
fi

if [ -d ./samples/throughput ]
then
echo -n
_process ./samples/throughput		${1}
fi

if [ -d ./samples/tx_fifo_time ]
then
echo -n
_process ./samples/tx_fifo_time		${1}
fi

# Async test applications =================================

if [ -d ./async/samples/test ]
then
echo -n
_process ./async/samples/test		${1}
fi

# HDLC test applications ==================================

if [ -d ./hdlc/samples/decode_pico ]
then
echo -n
_process ./hdlc/samples/decode_pico	${1}
fi

if [ -d ./hdlc/samples/test ]
then
echo -n
_process ./hdlc/samples/test		${1}
fi

if [ -d ./hdlc/samples/rx_test ]
then
echo -n
_process ./hdlc/samples/rx_test		${1}
fi

if [ -d ./hdlc/samples/rxc_calc ]
then
echo -n
_process ./hdlc/samples/rxc_calc	${1}
fi

if [ -d ./hdlc/samples/rxdata ]
then
echo -n
_process ./hdlc/samples/rxdata		${1}
fi

if [ -d ./hdlc/samples/tx_test ]
then
echo -n
_process ./hdlc/samples/tx_test		${1}
fi

if [ -d ./hdlc/samples/txdata ]
then
echo -n
_process ./hdlc/samples/txdata		${1}
fi
