#! /bin/sh
# ======================================================================
#  $Id: makecommondependencies,v 1.4 2003/10/10 10:16:26 goiwai Exp $
#  $Name: CLDAQ-1-11-00 $
#  $Log: makecommondependencies,v $
#  Revision 1.4  2003/10/10 10:16:26  goiwai
#  ちょとだけ変更しました.
#
#  Revision 1.3  2003/10/06 13:31:43  goiwai
#  cldaq-config
#
#  Revision 1.2  2003/07/30 16:12:50  goiwai
#  ファイルにコミットログをつけることにしました.
#
# ======================================================================
dep=""
tmpdir=$1
shift
gmk="commondep.gmk"
gmk="$tmpdir/$gmk"
echo="echo -e"
if [ ! -d $tmpdir ]; then
  mkdir -p $tmpdir;
fi
if [ -e $gmk ]; then
  rm -f $gmk
fi
touch $gmk


for obj in $*; do
cat >> $gmk << EOF
\$(CLDAQ_CATEGORY_TMP_DIR)/$obj.o: $obj.cc
	@\$(ECHO) Compiling $obj.cc ...
	@\$(CXX) \$(CXXFLAGS) \$(CPPFLAGS) -c \$(OUT_OBJ)\$(CLDAQ_CATEGORY_TMP_DIR)/$obj.o $obj.cc


EOF
done


cat >> $gmk << EOF
.PHONY: all obj lib clean
obj: \$(CLDAQ_CATEGORY_TMP_DIR)/obj.last
\$(CLDAQ_CATEGORY_TMP_DIR)/obj.last: \$(objects)
	@touch \$@


EOF


for obj in $*; do
cat >> $gmk << EOF
\$(CLDAQ_CATEGORY_TMP_DIR)/$obj.d: $obj.cc
	@\$(ECHO) Making dependency for file \$< ...
	@if [ ! -d \$(CLDAQ_CATEGORY_TMP_DIR) ]; then mkdir -p \$(CLDAQ_CATEGORY_TMP_DIR); fi
	@(\$(ECHO) \$(CLDAQ_TARGET_TMP_DIR)/\\\\c; \$(CXX) \$(GPPFLAGS) \$(CPPFLAGS) \$< ) | sed 's!\$(CLDAQ_TARGET_TMP_DIR)/\$*.o!& \$@!' > \$@


EOF
done

cat >> $gmk << EOF
-include \$(dependencies)
EOF

exit 0
