#!/bin/csh 
# $Id: mkmf,v 1.1.1.1 1999-04-09 17:55:32 ansari Exp $

# creation de MakefileUser.h a partir de Makefile.h
echo 'mkmf: Creation de MakefileUser.h'
cat Makefile.h | awk -f makefileuser.awk >! MakefileUser.h

# creation des liens pour les includes
echo 'mkmf: Creation des liens (appel mkmflien)'
./mkmflien

echo 'mkmf: Creation makefile global :'
rm -f GNUmakefile

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

echo 'LIBF = ' `sed -e 's/.*/$(LIB)lib&.a/' libdirs` >> GNUmakefile
echo 'LIBS = -L$(LIB)' `sed -e 's/.*/-l&/' libdirs` '-lm' >> GNUmakefile
echo 'LIBG = -L$(GLB) -lstdc++' >> GNUmakefile

cat >> GNUmakefile <<EOF

defaut: libs

all: libs PI


libs: cxxlibs
# Dans cet ordre pour les templates de cxx, a cause des dependances
# pour instantiation automatique/manuels

cxxlibs: Blitz SysTools NTools 

EOF


#  Attention, ne pas changer l'ordre de libnames dependances cxx
set libnames = (Blitz SysTools NTools)
set i = 1
set j = $#libnames ; @ j--
while ($i <= $#libnames)
  set f = $libnames[$i]
  set k = $i ; @ k++
  if ( -d ../$f ) then 
    set cmd = "./mkmflib $f $libnames[$k-$j]"
    echo "mkmf: Creation makefile lib $f"
    echo "   execution $cmd"
    $cmd
  endif
  echo '.PHONY: ' $f >> GNUmakefile
  echo $f':' >> GNUmakefile
  echo '	if [ -d '$f' ] ; then cd ' $f '; $(MAKE) ; fi' >> GNUmakefile
  echo ' ' >> GNUmakefile
  @ i++
end


if ( -d ../PI ) then 
  set cmd = './mkmfPI PI SysTools'
  echo "mkmf: Creation makefile lib PI"
  echo "   execution $cmd"
  $cmd
endif
if ( -d ../PIext ) then 
  set cmd = './mkmfPI PIext SysTools NTools PI'
  echo "mkmf: Creation makefile lib PIext"
  echo "   execution $cmd"
  $cmd
endif
echo '.PHONY: PI' >> GNUmakefile
echo 'PI:' >> GNUmakefile
echo '	if [ -d PI ] ; then cd PI ; $(MAKE) ; fi' >> GNUmakefile
echo '	if [ -d PIext ] ; then cd PIext ; $(MAKE) ; fi' >> GNUmakefile

cat Makefile.slb >> GNUmakefile

cat >> GNUmakefile << __END__

clean:
	if [ -d \$(LIB) ] ; then cd \$(LIB)/. ; rm -f *.a  ; fi
	if [ -d \$(SLB) ] ; then cd \$(SLB)/. ; rm -f *.so ; fi
	if [ -d \$(OBJ) ] ; then cd \$(OBJ)/. ; rm -f *.o  ; fi
	if [ -d \$(OBJ)/cxxrep ] ; then cd \$(OBJ)/cxxrep/. ; rm -f *.o  ; fi
	if [ -d PI ]     ; then cd PI/.     ; \$(MAKE) clean ; fi

__END__

mv GNUmakefile ../GNUmakefile

echo '*** mkmf done ***'

