#!/bin/csh 
# $Id: mkmfprog,v 1.3 2000-04-10 17:37:51 ansari Exp $

# $1 : nom du repertoire
# dans le repertoire, programs : liste des programs
#                     usedlibs : liste des -L -l utilises
#                     usedslibs : idem pour shlibs

cd ../$1

rm -f GNUmakefile


echo 'MODULECXXREPNAME := ' $1  >> GNUmakefile
# 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 ProgPI
if ($1 == 'ProgPI')  then
  echo 'MODULEDECCXXFLAGS := -msg_quiet' >> GNUmakefile 
endif
echo 'include ../Mgr/Makefile.h' >> GNUmakefile

echo ' ' >> GNUmakefile

echo 'ifdef NOSHLIB'                                        >> GNUmakefile
echo 'LIBF = ' `sed -e 's/.*/$(LIB)lib&.a/' usedlibs`       >> GNUmakefile
echo 'LIBS = -L$(LIB)' `sed -e 's/.*/-l&/' usedlibs` ' -lm' >> GNUmakefile
echo 'ifeq ($(CXX),cxx)'                                    >> GNUmakefile
echo '# librairie des instances de templates cxx'           >> GNUmakefile
echo 'LIBS := $(LIBS) -lertcxx'                             >> GNUmakefile
echo 'endif' >> GNUmakefile 
echo 'else'                                                 >> GNUmakefile
echo 'LIBF = ' `sed -e 's/.*/$(SLB)lib&.so/' usedslibs`     >> GNUmakefile
echo 'LIBS = -L$(SLB)' `sed -e 's/.*/-l&/' usedslibs` ' -lm'>> GNUmakefile
echo 'endif'                                                >> GNUmakefile

echo 'LIBSORA := $(LIBS)' >> GNUmakefile
echo 'ifdef ORACLE_HOME' >> GNUmakefile
echo 'LIBSORA := -L$(LIB) -lDb++ $(LIBS) -lErosDb -L$(ORACLE_HOME)/lib -lclntsh' >> GNUmakefile
echo 'endif' >> GNUmakefile

echo 'LDLIBS := $(LIBS) $(LDLIBS)' >> GNUmakefile

set progaexe = programs
if( -e programs_exe ) set progaexe = programs_exe
echo 'PROGS = '`cut -d \  -f1 $progaexe | awk '{if(length($1)>0) print $1}' | sed -e 's/^/\$(EXE)/'` >> GNUmakefile
unset progaexe

echo " " >> GNUmakefile
echo 'all: $(PROGS)' >> GNUmakefile 

set cxxrepname = cxxrep_$1

cat >> GNUmakefile << __END__

clean:
	rm -f \$(PROGS)
	if [ -d \$(OBJ)$cxxrepname ] ; then cd \$(OBJ)$cxxrepname ; rm -f *.o ; fi

__END__

awk -f ../Mgr/mkmfprog.awk programs >> GNUmakefile

#foreach f (`cat programs`)
#  echo $f ': $(EXE)'$f >> GNUmakefile
#  echo '	' >> GNUmakefile
#  echo '$(EXE)'$f ':' '$(OBJ)'$f.o '$(LIBF)' >> GNUmakefile
#  echo '	g++ $(LDFLAGS) -o $@ $< $(LIBS)' >> GNUmakefile
#  echo " ">> GNUmakefile
#end

#foreach f (`cat ../Mgr/programs_db`)
#  echo $f ': $(EXE)'$f >> GNUmakefile
#  echo '	' >> GNUmakefile
#  echo '$(EXE)'$f ':' '$(OBJ)'$f.o '$(LIBF)' >> GNUmakefile
#  echo '	g++ $(LDFLAGS) -o $@ $< $(LIBSORA)' >> GNUmakefile
#  echo " ">> GNUmakefile
#end

set inc = $DPCDEVREP/Include
set incext = $EXTLIBDIR/Include


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




