blob: 8e17d0944c86c28febe8e25f1e919873f0062e3d [file]
#!/bin/sh
t=makemake.targets
T=makemake.TARGETS
S=makemake.SOURCES
trap 'rm -fv *.tmp.$$ $T $S; rm -r $t' EXIT
rm -rf $t $T $S
mkdir -p $t
rm -f `cat TARGETS`
c() {
echo "$*" >&2;
}
error() {
echo "$0: Error: $*" >&2;
}
dependon() {
for dep in $*; do
echo "$dep" >&3
target $dep
done
}
formake() {
echo " $*" >&4
}
nosuchtarget() {
if [ -e "$target" ]; then
echo "$target" >>$S
else
error "No such target: $target"
fi
}
directtarget() {
# What is this supposed to do?
:
}
dependcc() {
dependon $1
for file in $(sed -e '/^#include "/!d;s/"$//;s/^.*"//' $1 2>/dev/null);
do
dependcc $file
done
}
depend() {
# What is this supposed to do?
# Invoked as: depend -ezmlm-warn.o=m
:
}
target() {
target=$1
if [ -e $target -a ! -e ${target}.do ]; then
echo $target >>$S
return
fi
if [ -e $t/$target.deps ]; then
return
fi
#c target: $target
starget=`echo $target | tr / :`
tmp=$starget.tmp.$$
(
ext=${target##*.}
base=${target%%.*}
if [ -f $target.do ]; then
. ./$target.do
elif [ -f default.$ext.do ]; then
. ./default.$ext.do $target $base $tmp
else
. ./default.do $target $base $tmp
fi
) 3>$t/$starget.deps 4>$t/$starget.cmds
# if [ -s $tmp ]; then
# mv -f $tmp $target
# else
# rm -f $tmp
# fi
}
echo "Calculating targets..."
target clean
target targets
rm -f $t/targets
echo "Building Makefile..."
(
cat <<EOF
# This file is automatically generated, do not edit.
SHELL=/bin/sh
default: it
EOF
cd $t
for deps in *.deps; do
target=${deps%.deps}
cmds=$target.cmds
target=`echo $target | tr : /`
if [ -s $deps -o -s $cmds ]; then
echo
echo "$target: \\"
echo `uniq $deps`
cat $cmds
echo $target >&2
fi
rm -f $deps $cmds
done
) >Makefile 2>$T
echo SOURCES >>$S
echo Makefile >>$S
sort -u $S >SOURCES
sort -u $T | fgrep -vxf SOURCES >TARGETS
rm -f $S $T
echo "done."