#!/bin/sh

mk=Makefile
depth=${depth:-..}

SRCS="\
${depth}/aspell/rclaspell.cpp \
${depth}/common/rclconfig.cpp \
${depth}/common/rclinit.cpp \
${depth}/common/textsplit.cpp \
${depth}/common/unacpp.cpp \
${depth}/index/csguess.cpp \
${depth}/index/indexer.cpp \
${depth}/index/mimetype.cpp \
${depth}/internfile/htmlparse.cpp \
${depth}/internfile/myhtmlparse.cpp \
${depth}/internfile/mimehandler.cpp \
${depth}/internfile/internfile.cpp \
${depth}/internfile/mh_exec.cpp \
${depth}/internfile/mh_html.cpp \
${depth}/internfile/mh_mail.cpp \
${depth}/internfile/mh_mbox.cpp \
${depth}/internfile/mh_text.cpp \
${depth}/query/docseq.cpp \
${depth}/query/docseqdb.cpp \
${depth}/query/docseqhist.cpp \
${depth}/query/history.cpp \
${depth}/query/sortseq.cpp \
${depth}/query/wasastringtoquery.cpp \
${depth}/query/wasatorcl.cpp \
${depth}/rcldb/pathhash.cpp \
${depth}/rcldb/rcldb.cpp \
${depth}/rcldb/searchdata.cpp \
${depth}/rcldb/stemdb.cpp \
${depth}/rcldb/stoplist.cpp \
${depth}/utils/base64.cpp \
${depth}/utils/conftree.cpp \
${depth}/utils/copyfile.cpp \
${depth}/utils/debuglog.cpp \
${depth}/utils/execmd.cpp \
${depth}/utils/fstreewalk.cpp \
${depth}/utils/idfile.cpp \
${depth}/utils/md5.cpp \
${depth}/utils/mimeparse.cpp \
${depth}/utils/pathut.cpp \
${depth}/utils/readfile.cpp \
${depth}/utils/smallut.cpp \
${depth}/utils/transcode.cpp \
${depth}/utils/wipedir.cpp \
${depth}/utils/x11mon.cpp \
"


for c in $SRCS;do
    o=`basename $c .cpp`.o
    OBJS="$OBJS $o"
    d=`basename $c .cpp`.dep
    cp /dev/null $d
    s=`basename $c .cpp`.dep.stamp
    DEPS="$DEPS $s"
done

test -f $mk && chmod +w $mk

cat > $mk <<EOF
# DONT EDIT BY HAND: created by script mkMake
depth = ${depth}
include \$(depth)/mk/sysconf

UNACCFLAGS = \$(CFLAGS) -g -I. -I\$(depth)/unac \$(INCICONV) -DUNAC_VERSION=\\"1.0.7\\"

LIBS = librcl.a

all: \$(LIBS)

OBJS = $OBJS
DEPS = $DEPS

librcl.a : \$(DEPS) \$(OBJS) unac.o
	ar ru librcl.a \$(OBJS) unac.o
	\$(RANLIB) librcl.a

unac.o : \$(depth)/unac/unac.c \$(depth)/unac/unac.h
	\$(CC) \$(UNACCFLAGS) -c \$(depth)/unac/unac.c
EOF

for c in $SRCS;do
    o=`basename $c .cpp`.o
    echo "$o : $c" >> $mk
    echo "	\$(CXX) \$(ALL_CXXFLAGS) -c $c" >> $mk
done

cat >> $mk <<EOF
depend: \$(DEPS)
clean:
	rm -f \$(OBJS) \$(LIBS) \$(DEPS) unac.o
	for i in *.dep;do test -f \$\$i && cp /dev/null \$\$i;done
distclean: clean
	rm -f *.dep   
EOF

for c in $SRCS;do
    d=`basename $c .cpp`.dep
    s=`basename $c .cpp`.dep.stamp
    echo "$s : $c" >> $mk
    echo "	\$(CXX) -M \$(ALL_CXXFLAGS) $c > $d" >> $mk
    echo "	touch $s" >> $mk
done
for c in $SRCS;do
    d=`basename $c .cpp`.dep
    echo "include $d" >> $mk
done
