#!/bin/sh
# mkdep - create dependencies
# usage: mkdep source output compiler flags
# e.g. mkdep foo/bar.c foo/bar.d gcc -g -O2 -DFOOBAR

set -e

source_file=$1
base_name=${source_file%%.c}
base_base_name=`basename $base_name`
output_file=$2
compiler=$3
shift 3

"$compiler" -M "$@" "$source_file" >"$output_file".tmp

sed "s!$base_base_name.o *:!$base_name.o $base_name.d:!g" <"$output_file".tmp >"$output_file"

rm -f "$output_file".tmp
