#!/bin/sh

gencommon () {
	dep="build/${s%.*}${1}.d"
	obj="build/${s%.*}${1}"
	
	mkdir -p $(dirname ${dep})

	echo "${dep}:"		>> deps.mk
	echo "include ${dep}"	>> deps.mk
	echo "${obj}: ${s}"		>> deps.mk

}

genlink () {
	gencommon ".ld"
	echo "	\$(GENLINK) $< | \$(STRIPLINK) | \$(KERN_INFO) > \$@"\
		>> deps.mk;
}

genrule () {
	gencommon "${1}"
	echo "	\$(COMPILE)  -c \$< -o \$@"	>> deps.mk
}

case "${1}" in
	--compile)
		suffix=.o
		func=genrule
		;;
	--link)
		suffix=.ld
		func=genlink
esac

for s in ${2}
do
	${func} ${suffix}
	echo ${obj}
done
