#!/bin/sh

# set -x

srcdir=$1

./mk-stubs -t files < header.aux | sort | uniq | comm -12 - $srcdir/stubs/written-stubs > tmp-stubs

# Complete the file.
echo s-assert-__eprintf.o >> tmp-stubs

if grep dirent-readdir.o tmp-stubs > /dev/null; then
echo s-dirent-chkr_func.o  >> tmp-stubs
fi

if grep grp-getgrent.o tmp-stubs > /dev/null; then
echo s-grp-chkr_func.o  >> tmp-stubs
fi

if grep sys_socket-bind.o tmp-stubs > /dev/null; then
echo s-sys_socket-chkr_func.o  >> tmp-stubs
fi

if grep sys_socket-bind.o tmp-stubs > /dev/null; then
echo s-sys_socket-chkr_func.o  >> tmp-stubs
fi

if grep sys_stat-stat.o tmp-stubs > /dev/null; then
echo s-sys_stat-chkr_func.o  >> tmp-stubs
fi

if grep sys_time-gettimeofday.o tmp-stubs > /dev/null; then
echo s-sys_time-chkr_func.o  >> tmp-stubs
fi

echo stubs-malloc.o >> tmp-stubs
echo check-printf.o >> tmp-stubs

#
echo "STUB_OBJS= \\" > Makefile-stubs
sed -e "s/\.o/.o \\\\/" < tmp-stubs >> Makefile-stubs
echo >> Makefile-stubs
cat $srcdir/stubs/SubMakefile >> Makefile-stubs
rm -f tmp-stubs
