#!/bin/sh
#
#       dnsutl - utilities to make DNS easier to configure
#       Copyright (C) 1995, 1999, 2004, 2007 Peter Miller
#
#       This program is free software; you can redistribute it and/or modify
#       it under the terms of the GNU General Public License as published by
#       the Free Software Foundation; either version 3 of the License, or
#       (at your option) any later version.
#
#       This program is distributed in the hope that it will be useful,
#       but WITHOUT ANY WARRANTY; without even the implied warranty of
#       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#       GNU General Public License for more details.
#
#       You should have received a copy of the GNU General Public License
#       along with this program. If not, see
#       <http://www.gnu.org/licenses/>.
#
case $# in
2 | 3)
        ;;
*)
        echo "usage: $0 filename resolved-filename" 1>&2
        exit 1
        ;;
esac
file="$1"
rfn="$2"
depfile="$3"
TAB=`awk 'BEGIN{printf("%c",9)}' /dev/null`

case $file in

*/*.y)
        root=`basename $file .y`
        stem=`echo $file | sed 's/\.y$//'`
        dir=`echo $file | sed 's|/.*||'`

        case $file in
        cook/parse.y)
                numconf="1 shift/reduce"
                ;;
        cooktime/date.y)
                numconf="8 shift/reduce"
                ;;
        make2cook/gram.y)
                numconf="1 shift/reduce"
                ;;
        *)
                numconf="no"
                ;;
        esac

        yy=`echo $stem | sed -e 's|^[^/]*/||' -e 's|[^a-zA-Z0-9]|_|g'`
        echo ""
        echo "${stem}.gen.c ${stem}.gen.h: $file"
        echo "${TAB}@echo Expect $numconf conflicts:"
        echo "${TAB}\$(YACC) -d $file"
        echo "${TAB}sed -e 's/[yY][yY]/${yy}_/g'" \
                "-e '/#include.<stdio.h>/d'" \
                "-e '/#include.<stddef.h>/d'" \
                "-e '/#include.<stdlib.h>/d'" \
                "y.tab.c > ${stem}.gen.c"
        echo "${TAB}sed -e 's/[yY][yY]/${yy}_/g' y.tab.h > ${stem}.gen.h"
        echo "${TAB}rm y.tab.c y.tab.h"

        if [ -n "$depfile" -a -r "$depfile" ]; then
                dep=`cat $depfile`
        fi

        echo ""
        echo "${stem}.gen.\$(OBJEXT): ${stem}.gen.c" $dep
        echo "${TAB}\$(CC) \$(CPPFLAGS) \$(CFLAGS) -I$dir" \
            "-Icommon -c ${stem}.gen.c"
        echo "${TAB}mv ${root}.gen.\$(OBJEXT) \$@"
        ;;

*/*.c)
        root=`basename $file .c`
        stem=`echo $file | sed 's/\.c$//'`
        dir=`echo $file | sed 's|/.*||'`

        if [ -n "$depfile" -a -r "$depfile" ]; then
                dep=`cat $depfile`
        fi

        if [ ${root} = option ]
        then
                libdir="-D'LIBDIR=\"\$(libdir)\"'"
        fi

        echo ""
        echo "${stem}.\$(OBJEXT): $file" $dep
        echo "${TAB}\$(CC) \$(CPPFLAGS) \$(CFLAGS)" $libdir \
            "-I$dir -Icommon -c $file"
        echo "${TAB}mv ${root}.\$(OBJEXT) \$@"
        ;;

man1/*.1)
        root=`basename $file .1`
        echo ""
        echo "man1/$root.h: $file etc/txt2c.awk"
        echo "${TAB}awk -f etc/txt2c.awk $file > \$@"

        echo ""
        echo "\$(mandir)/man1/$root.1: $file man1/.mandir"
        echo "${TAB}\$(SOELIM) -Iman1 $file > tmp"
        echo "${TAB}\$(INSTALL_DATA) tmp \$@"
        echo "${TAB}@rm tmp"
        ;;

man1/*.so)
        root=`basename $file .so`
        echo ""
        echo "man1/$root.h: $file etc/txt2c.awk"
        echo "${TAB}awk -f etc/txt2c.awk $file > \$@"
        ;;

test/*/*)
        root=`basename $file .sh`
        echo ""
        echo "$root: $file all"
        echo "${TAB}\$(SH) $file"
        ;;

*)
        ;;
esac
exit 0


syntax highlighted by Code2HTML, v. 0.9.1