#! /bin/sh
# Copyright 1998-1999, University of Notre Dame.
# Authors: Jeffrey M. Squyres, Kinis L. Meyer, with M. D. McNally 
#          and Andrew Lumsdaine
#
# This file is part of the Notre Dame LAM implementation of MPI.
#
# You should have received a copy of the License Agreement for the
# Notre Dame LAM implementation of MPI along with the software; see
# the file LICENSE.  If not, contact Office of Research, University of
# Notre Dame, Notre Dame, IN 46556.
#
# Permission to modify the code and to distribute modified code is
# granted, provided the text of this NOTICE is retained, a notice that
# the code was modified is included with the above COPYRIGHT NOTICE and
# with the COPYRIGHT NOTICE in the LICENSE file, and that the LICENSE
# file is distributed with the modified code.
#
# LICENSOR MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED.
# By way of example, but not limitation, Licensor MAKES NO
# REPRESENTATIONS OR WARRANTIES OF MERCHANTABILITY OR FITNESS FOR ANY
# PARTICULAR PURPOSE OR THAT THE USE OF THE LICENSED SOFTWARE COMPONENTS
# OR DOCUMENTATION WILL NOT INFRINGE ANY PATENTS, COPYRIGHTS, TRADEMARKS
# OR OTHER RIGHTS.
#
# Additional copyrights may follow.
#

oarch=obj

if test -n "$1"
then
     oarch=$1
fi

make_dep_links () {
    echo '##' > $1/Depends
    echo '## automatic dependencies and rules' >> $1/Depends
    echo '##' >> $1/Depends
    rm -f Depends Makefile
    ln -s $1/Depends Depends
    ln -s $1/Makefile Makefile
}

init_t () {
    ln -s ../../otb/t/Makefile Makefile
    for d in etc freq kreq nreq tools; do
	( mkdir $d; cd $d; make_dep_links ../../../otb/t/$d )
    done
}

init_lib () {
    ln -s ../otb/Makefile Makefile
    for d in args impi trillium tstdio mpi; do
	( mkdir $d; cd $d; make_dep_links ../../otb/$d )
    done
    ( mkdir pmpi; cd pmpi; rm -f Makefile Depends; \
	ln -s ../../otb/pmpi/Makefile Makefile; ln -s ../../otb/mpi/Depends Depends)
    ( mkdir t; cd t; init_t )
}

init_sys () {
    ln -s ../../otb/sys/Makefile Makefile
    for d in bforward bufferd dli_inet dlo_inet echod filed flatd impid iod \
	    kenyad kernel lamd loadd router traced; do
	( mkdir $d; cd $d; make_dep_links ../../../otb/sys/$d )
    done
}

init_otb () {
    ln -s ../otb/Makefile Makefile
    for d in bfctl bfstate doom fctl fstate lamclean lamexec lamgrow \
	    lamshrink lamtrace loadgo mpimsg mpirun mpitask state tping; do
	( mkdir $d; cd $d; make_dep_links ../../otb/$d )
    done
    ( mkdir sys; cd sys; init_sys )
}

init_tools () {
    ln -s ../tools/Makefile Makefile
    for d in hboot hcc hf77 lamboot recon tkill wipe; do
	( mkdir $d; cd $d; make_dep_links ../../tools/$d )
    done
}

( mkdir lib/otb-$oarch; cd lib/otb-$oarch; init_lib )
( mkdir otb-$oarch; cd otb-$oarch; init_otb )
( mkdir tools-$oarch; cd tools-$oarch; init_tools )

exit 0
