5 kx #!/bin/sh
5 kx # mkdep - create dependencies.
5 kx #
5 kx # Copyright (c) 1998, 2001 Joseph Samuel Myers.
5 kx # All rights reserved.
5 kx #
5 kx # Redistribution and use in source and binary forms, with or without
5 kx # modification, are permitted provided that the following conditions
5 kx # are met:
5 kx # 1. Redistributions of source code must retain the above copyright
5 kx # notice, this list of conditions and the following disclaimer.
5 kx # 2. Redistributions in binary form must reproduce the above copyright
5 kx # notice, this list of conditions and the following disclaimer in the
5 kx # documentation and/or other materials provided with the distribution.
5 kx # 3. The name of the author may not be used to endorse or promote products
5 kx # derived from this software without specific prior written permission.
5 kx #
5 kx # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
5 kx # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
5 kx # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
5 kx # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
5 kx # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
5 kx # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
5 kx # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
5 kx # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
5 kx # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
5 kx # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
5 kx # SUCH DAMAGE.
5 kx
5 kx # usage: mkdep source output compiler flags
5 kx # e.g. mkdep foo/bar.c foo/bar.d gcc -g -O2 -DFOOBAR
5 kx
5 kx set -e
5 kx
5 kx source_file=$1
5 kx base_name=${source_file%%.c}
5 kx base_base_name=`basename $base_name`
5 kx output_file=$2
5 kx compiler=$3
5 kx shift 3
5 kx
5 kx if test "`echo $compiler | grep ccache`" != "" ; then
5 kx compiler=$1
5 kx shift 1
5 kx fi
5 kx
5 kx "$compiler" -M "$@" "$source_file" >"$output_file".tmp
5 kx
5 kx sed "s!^$base_base_name.o *:!$base_name.o :!g
5 kx s!$base_name.o *:!$base_name.o $base_name.d:!g" <"$output_file".tmp >"$output_file"
5 kx
5 kx rm -f "$output_file".tmp