#!/bin/csh
# $Id: mkmfPI,v 1.1.1.1 1999-11-26 16:37:08 ansari Exp $

set makefname = 'GNUmakefile'

cd ../$1

if ( ! -f exclude_dpc ) touch exclude_dpc
if ( ! $?TMPDIR ) set TMPDIR = /tmp
sort exclude_dpc >! $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'

rm -f $makefname

echo "MODULECXXREPNAME := PI" >>  $makefname

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



# 04/98: le fichier X11/Xlib.h contient des declarations de fonctions sans type  
# Cela genere un grand nombre de warning avec cxx V6 
# On specifie donc -msg_quiet pour PI, ProgPI, ...
echo 'MODULEDECCXXFLAGS := -msg_quiet' >> $makefname
echo 'include ../Mgr/Makefile.h' >> $makefname

echo " " >> $makefname

set ccfiles  = `ls *.cc  | comm -3 -1 $TMPDIR/exclude.sort -`
set objfiles = `ls *.cc  | comm -3 -1 $TMPDIR/exclude.sort - | sed -e 's/\.cc/.o/g' | sed -e 's/^/$(OBJ)/'`

rm -f $TMPDIR/exclude.sort

echo 'all:' $libf >> $makefname 

echo $libf ':' $objfiles  >> $makefname
echo '	$(AR) $(ARFLAGS)  $@ $? ' >> $makefname
echo 'ifeq ($(CXX),cxx)' >> $makefname
echo '	$(CXX) $? $(CPPFLAGS) $(CXXFLAGS)' $hfcxxlibs '-o $(OBJ)xx.x -Hf' >> $makefname
echo 'endif ' >> $makefname

echo " " >> $makefname

echo 'clean:' >> $makefname 
echo '	rm -f '$objfiles >> $makefname
echo 'ifeq ($(CXX),cxx)' >> $makefname
echo '	cd $(REPM); rm -f *.o'  >> $makefname
echo 'endif ' >> $makefname

echo " " >> $makefname

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

foreach f ( $ccfiles )
  gcc -MM -I$inc -I$incxx $f  \
       | sed -e 's/.*\.o/\$(OBJ)&/'  \
       | sed -e 's?'$incxx/'?$(CXI)?g' \
       | sed -e 's?'$inc/'?$(INC)?g' >> $makefname
end






