#!/bin/csh
# $Id: mkmflib,v 1.10 2001-11-27 21:19:36 aubourg Exp $

cd ../$1

if ( ! -f exclude ) touch exclude
if ( ! -f flags_compil ) touch flags_compil
if ( ! -f extlib_list ) touch extlib_list
if ( ! -f extslb_list ) touch extslb_list

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

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

set liblist = $1.o.list
rm -f $liblist
touch $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

set extlib_list = `cat extlib_list`
set hfcxxlibs = ($hfcxxlibs '-L$(EXTLIBPATH)' $extlib_list)

rm -f GNUmakefile
touch GNUmakefile

cat flags_compil >> 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 -f '$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) $@ $($(ARARGS))' >> 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 '	$(CXX) $? $(CPPFLAGS) $(CXXFLAGS) -o $(OBJ)xx.x -Hf' >> GNUmakefile
echo 'endif ' >> GNUmakefile

rm -f $TMPDIR/exclude.sort

echo " " >> GNUmakefile

set inc = $DPCDEVREP/Include
# set incxx = $inc/CxxInc
set incext = $EXTLIBDIR/Include
set nomsys = `uname`

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

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




