#!/bin/sh
if [ x$1 = x ]
then echo fixincludes: no output directory specified
exit 1
fi
LIB=${1?"fixincludes: output directory not specified"}
if [ ! -d $LIB ]; then
mkdir $LIB || exit 1
fi
ORIG_DIR=`${PWDCMD-pwd}`
case $LIB in
/*)
;;
*)
cd $LIB; LIB=`${PWDCMD-pwd}`
;;
esac
echo 'Building fixincludes in ' ${LIB}
if ln -s X $LIB/ShouldNotExist 2>/dev/null; then
rm -f $LIB/ShouldNotExist
LINKS=true
else
LINKS=false
fi
echo 'Making directories:'
shift
if [ $ set /usr/include
fi
INLIST="$@"
for INPUT in ${INLIST} ; do
cd ${ORIG_DIR}
cd ${INPUT}
if $LINKS; then
files=`ls -LR | sed -n s/:$//p`
else
files=`find . -type d -print | sed '/^.$/d'`
fi
for file in $files; do
rm -rf $LIB/$file
if [ ! -d $LIB/$file ]
then mkdir $LIB/$file
fi
done
treetops="${INPUT} ${LIB}"
if $LINKS; then
echo 'Making internal symbolic directory links'
for file in $files; do
dest=`ls -ld $file | sed -n 's/.*-> //p'`
if [ "$dest" ]; then
cwd=`pwd`
cd ${INPUT}
cd `echo ./$file | sed -n 's&[^/]*$&&p'`
(cd $dest) > /dev/null 2>&1
if [ $? = 0 ]; then
cd $dest
x=`pwd`
if expr $x : "${INPUT}/.*" > /dev/null; then
y=`echo $x | sed -n "s&${INPUT}/&&p"`
dots=`echo "$file" |
sed -e 's@^./@@' -e 's@/./@/@g' -e 's@[^/][^/]*@..@g' -e 's@..$@@'`
echo $file '->' $dots$y ': Making link'
rm -fr ${LIB}/$file > /dev/null 2>&1
ln -s $dots$y ${LIB}/$file > /dev/null 2>&1
else
treetops="$treetops $x ${LIB}/$file"
fi
fi
cd $cwd
fi
done
fi
file=_int_varargs.h
if [ -r ${INPUT}/$file ]; then
echo Replacing $file
cat > ${LIB}/$file << EOF
/* This file was generated by fixinc.dgux. */
typedef struct
{
int __va_arg; /* argument number */
int *__va_stk; /* start of args passed on stack */
int *__va_reg; /* start of args passed in regs */
} __gnuc_va_list;
typedef __gnuc_va_list va_list;
EOF
chmod a+r ${LIB}/$file
fi
echo 'Removing unneeded directories:'
cd $LIB
files=`find . -type d -print | sort -r`
for file in $files; do
rmdir $LIB/$file > /dev/null 2>&1
done
if $LINKS; then
echo 'Making internal symbolic non-directory links'
cd ${INPUT}
files=`find . -type l -print`
for file in $files; do
dest=`ls -ld $file | sed -n 's/.*-> //p'`
if expr "$dest" : '[^/].*' > /dev/null; then
target=${LIB}/`echo file | sed "s|[^/]*\$|$dest|"`
if [ -f $target ]; then
ln -s $dest ${LIB}/$file >/dev/null 2>&1
fi
fi
done
fi
done
if [ x${INSTALL_ASSERT_H} != x ]
then
cd ${ORIG_DIR}
rm -f include/assert.h
cp ${srcdir}/assert.h include/assert.h || exit 1
chmod a+r include/assert.h
fi
exit 0