#! /bin/bash
sourcebase=$1
if [ -z ${sourcebase} ]
then
	echo "Need an input"
	exit
fi

if [ ! -d ${sourcebase} ]
then
	echo "${sourcebase} not a directory"
	exit
fi

findcmd=$QNX_HOST/usr/bin/find
if [ ! -e ${findcmd} ]
then
	findcmd=find
fi

#directory rename hack.
if [ ! -d 'QNX Neutrino']
then
	echo "Creating QNX Neutrino dir"
	mkdir QNX_Neutrino
else
	echo "Renaming QNX Neutrino dir to maintain compatibility"
	mv QNX\ Neutrino QNX_Neutrino
fi

echo "Locating GNUmakefile's in ${sourcebase}"
list=`${findcmd} ${sourcebase} -name GNUmakefile`
for f in ${list}
do
	dir=`dirname ${f}`
	echo "Touching ${dir}/Makefile.dnm"
	touch ${dir}/Makefile.dnm
done

#end of directory rename hack.
if [ -e "QNX_Neutrino" ]
then
	echo "Renaming QNX_Neutrino dir back to QNX Neutrino"
	mv QNX_Neutrino QNX\ Neutrino
else
	echo "The system encountered an error, please check for the existence of a QNX_Neutrino"
	echo "directory, or a QNX Neutrino directory."
	exit
fi
