#!/bin/csh
#*---------------------------------------------------------------------*/
#*    serrano/prgm/project/bigloo/distribution/boot ...                */
#*                                                                     */
#*    Author      :  Manuel Serrano                                    */
#*    Creation    :  Mon Mar  1 08:32:22 1993                          */
#*    Last change :  Wed Jun 30 09:25:54 1993  (serrano)               */
#*                                                                     */
#*    Le fichier qui se charge de booter Bigloo sur un site.           */
#*    -------------------------------------------------------------    */
#*    !!! WARNING !!! WARNING !!! WARNING !!! WARNING !!! WARNING !!!  */
#*    Don't edit this file.                                            */
#*---------------------------------------------------------------------*/

#*---------------------------------------------------------------------*/
#*    Les variables utilisateurs                                       */
#*---------------------------------------------------------------------*/
set cc      = $1
set version = "1.3"

#*---------------------------------------------------------------------*/
#*    Le site                                                          */
#*---------------------------------------------------------------------*/
set site = `pwd`

set vcc = `which $cc`

if( ! -f "$vcc" ) then
	echo "Can't find $cc compiler (see Makefile)"
	exit( -2 )
endif

if( ! -d "$site/runtime$version" ) then
	echo "Can't find $site/runtime$version directory"
	exit( -3 )
endif

if( ! -d "$site/comptime$version" ) then
	echo "Can't find $site/comptime$version directory"
	exit( -4 )
endif

\rm -f distribution/SITE
echo $site > distribution/SITE

#*---------------------------------------------------------------------*/
#*    Quelques autres variables                                        */
#*---------------------------------------------------------------------*/
set cflags       = "-O -I$site/lib/$version -w"
set runtime_dir  = "$site/runtime$version"
set comptime_dir = "$site/comptime$version"
set lib_dir      = "$site/lib/$version"
set bin_dir      = "$site/bin"
set dirname      = "$site/public/dirname"

#*---------------------------------------------------------------------*/
#*    La recherche du type de machine                                  */
#*---------------------------------------------------------------------*/
( cd public; $cc -o arch arch.c )

set arch = `public/arch`

switch( "$arch" )
	case "sun4" :
		breaksw
	case "sun3" :
		breaksw
	case "mips" :
		breaksw
	case "ds3100" :
		breaksw
	case "hp-ux" :
		breaksw

	default :
		echo "*** ERROR: "
		echo "don't known how to make Bigloo on $arch architecture"
		exit( -1 )
endsw

#*---------------------------------------------------------------------*/
#*    Il faut faire `bigloo.h'                                         */
#*---------------------------------------------------------------------*/
\rm -f $site/lib/$version/bigloo.h

cat distribution/bigloo.h.head >! $site/lib/$version/bigloo.h
echo \#define LIBRARY_DIR"()" \"$site/lib/$version\" >> $site/lib/$version/bigloo.h
echo \#define INCLUDE_DIR"()" \"$site/lib/$version\" >> $site/lib/$version/bigloo.h
cat distribution/bigloo.h.tail >> $site/lib/$version/bigloo.h

#*---------------------------------------------------------------------*/
#*    On commence par faire dirname pour avoir la paix                 */
#*---------------------------------------------------------------------*/
( cd public; $cc dirname.c -o dirname )

#*---------------------------------------------------------------------*/
#*    Il faut modifier les makes pour changer `gcc' en `$cc'           */
#*---------------------------------------------------------------------*/
if( "gcc" != "$cc" ) then
	mv $runtime_dir/Makefile $runtime_dir/m
	cat $runtime_dir/m | sed -e s,"gcc",$cc, > $runtime_dir/Makefile
	\rm -f $runtime_dir/m

	mv $comptime_dir/Makefile $comptime_dir/m
	cat $comptime_dir/m | sed -e s,"gcc",$cc, > $comptime_dir/Makefile
	\rm -f $comptime_dir/m

	( cd distribution;                       \
	  mv install i;                          \
	  cat i | sed -e s,"gcc",$cc, > install; \
	  \rm -f i )

endif
	                   
#*---------------------------------------------------------------------*/
#*    C'est bon, on va compiler les deux librairies:                   */
#*---------------------------------------------------------------------*/
cd $runtime_dir

switch( "$arch" )
	case "mips"
		( echo "mips_mach_dep.s:";                     \
		  cd Gc;                                       \
		  as mips_mach_dep.s -o mips_mach_dep.o;       \
		  cp mips_mach_dep.o ../.Olib/Gc/mach_dep.o;   \
		  mv mips_mach_dep.o ../.Olib_u/Gc/mach_dep.o; \
		  \rm -f mach_dep.c )
		breaksw
		
	case "ds3100" :
		( echo "mips_mach_dep.s:";                     \
		  cd Gc;                                       \
		  as mips_mach_dep.s -o mips_mach_dep.o;       \
		  cp mips_mach_dep.o ../.Olib/Gc/mach_dep.o;   \
		  mv mips_mach_dep.o ../.Olib_u/Gc/mach_dep.o; \
		  \rm -f mach_dep.c )
		breaksw
		
	case "AIX" :
		( echo "rs6000_mach_dep.s:";                     \
		  cd Gc;                                         \
		  as rs6000_mach_dep.s -o rs6000_mach_dep.o;     \
		  cp rs6000_mach_dep.o ../.Olib/Gc/mach_dep.o;   \
		  mv rs6000_mach_dep.o ../.Olib_u/Gc/mach_dep.o; \
		  \rm -f mach_dep.c )
		breaksw
		
        default :	
		breaksw
endsw		

foreach p (.Olib*/Llib/*.c)
	echo "$p":
	( cd `$dirname $p`; $cc $cflags -c `basename $p`; \
	  if( $status != 0 ) echo "*** $cc error:$p" ) 
end	

foreach p ({Clib,Gc}/*.c)
	echo "$p":
	( cd .Olib/`$dirname $p`; $cc $cflags -c $runtime_dir/$p; \
	  if( $status != 0 ) echo "*** $cc error:$p" )
end

cp .Olib/Clib/* .Olib_u/Clib
cp .Olib/Gc/* .Olib_u/Gc

ar rcv $lib_dir/libbigloo.a .Olib/{Clib,Llib,Gc}/*.o
ar rcv $lib_dir/libbigloo_u.a .Olib_u/{Clib,Llib,Gc}/*.o

ranlib $lib_dir/libbigloo.a
ranlib $lib_dir/libbigloo_u.a

echo "Libraries done"

#*---------------------------------------------------------------------*/
#*    On va compiler `comptime'                                        */
#*---------------------------------------------------------------------*/
cd $comptime_dir

foreach p (*/*.c)
	echo "$p":
	( cd `$dirname $p`; $cc $cflags -c `basename $p` )
end

$cc $cflags -o $bin_dir/bigloo$version */*.o -L$lib_dir -lbigloo -lm
strip $bin_dir/bigloo$version > & /dev/null

echo "Bigloo done"
	
