#!/bin/sh
# $URL: http://subversion:8080/svn/gsc/trunk/drivers/LINUX/SIO4%20and%20SIO8/SIO4_Linux_1.x.x_GSC_DN/make_all $
# $Rev: 47447 $
# $Date: 2020-06-04 15:01:41 -0500 (Thu, 04 Jun 2020) $

# SIO4: Overall make script



#==============================================================================
_process() {
	# 1 = directory name
	# 2 = command line specified target

	CWD=`pwd`

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

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

		cd ./${1}

		if [ -e ./sources ]
		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

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

			if [ "${2}" != "sources" ]
			then

				make -f _sources ${2}

			else

				make -f _sources

			fi

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

				make -s -f _sources os_makefile.inc

			fi

			rm -f _sources

		fi

		if [ "${2}" != "sources" ]
		then

			if [ -e ./makefile ]
			then

				make -f ./makefile ${2}

			elif [ -e ./Makefile ]
			then

				make -f ./Makefile ${2}

			fi
		fi

		cd ${CWD}

	fi
}



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

_process driver						${1}

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

_process include					${1}
_process docsrc						${1}
_process utils						${1}
_process async/lib					${1}
_process sync/lib					${1}
_process sync/docsrc				${1}
_process lib						${1}

_process samples/id					${1}
_process samples/irq				${1}
_process samples/regs				${1}
_process samples/sbtest				${1}

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

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

if [ -d sync/samples/test ]
then
_process sync/samples/test			${1}
fi
