#!/bin/csh
# $Id: mkmflib,v 1.2 1999-10-20 10:25:12 ansari Exp $

cd ../$1

if ( ! -f exclude ) touch exclude
if ( ! $?TMPDIR ) set TMPDIR = /tmp
sort exclude >! $TMPDIR/exclude.sort

##############################################
########### fichier de la liste des .o #######
##############################################

set liblist = $1.o.list
rm -f $liblist
ls *.{c,cc} | comm -3 -1 $TMPDIR/exclude.sort - | sed -e 's/\.cc/.o/' | sed -e 's/\.c/.o/' >> $liblist
unset liblist

##############################################
########### Creation de GNUmakefile ##########
##############################################

set libf='$(LIB)lib'$1'.a'

set hfcxxlibs = '-L$(LIB)' 
set i = 1
while ($i <= $#argv)
  set hfcxxlibs = "$hfcxxlibs -l$argv[$i]"
  @ i++
end


rm -f GNUmakefile

echo 'include ../Mgr/Makefile.h' >> GNUmakefile 

echo " " >> GNUmakefile
echo 'all:' $libf  >> GNUmakefile 

echo 'clean:' >> GNUmakefile
set toto='rm -f'
foreach f (*.cc *.c) 
  set toto= ( $toto '$(OBJ)'$f:r.o )
end
echo '	'$toto >> GNUmakefile
echo '	rm '$libf >> GNUmakefile

echo $libf ':' \
 `ls *.{c,cc} | comm -3 -1 $TMPDIR/exclude.sort - | sed -e 's/\.cc/.o/' | sed -e 's/\.c/.o/' | sed -e 's/^/$(OBJ)/'` >> GNUmakefile
echo '	$(ARCXX) $(ARCXXFLAGS) $@ $?' >> GNUmakefile
#  Pour faire compiler les instantiations automatique de cxx (DEC)
echo 'ifeq ($(CXX),cxx)' >> GNUmakefile
echo '	$(CXX) $? $(CPPFLAGS) $(CXXFLAGS)' $hfcxxlibs '-o $(OBJ)xx.x -Hf' >> GNUmakefile
echo 'endif ' >> GNUmakefile

rm -f $TMPDIR/exclude.sort

echo " " >> GNUmakefile

set inc = $DPCDEVREP/Include
set incxx = $inc/CxxInc

foreach f ( *.cc )
  grep -q '^'$f'$' exclude && continue
  gcc -MM -I$inc -I$incxx $f  \
       | sed -e 's/.*\.o/\$(OBJ)&/'  \
       | sed -e 's?'$incxx/'?$(CXI)?g' \
       | sed -e 's?'$inc/'?$(INC)?g' >> GNUmakefile
end

foreach f ( *.c )
  grep -q '^'$f'$' exclude && continue
  gcc -MM -I$inc -I$incxx $f  \
       | sed -e 's/.*\.o/\$(OBJ)&/'  \
       | sed -e 's?'$incxx/'?$(CXI)?g' \
       | sed -e 's?'$inc/'?$(INC)?g' >> GNUmakefile
end 




