#!/bin/csh -f
#
#  MKARCH - Reset the platform architecture.  Assumes source-only tree and
#  that it's safe to just manually change links.


set aarch	= `unix/hlib/irafarch.csh -actual`

if (-e $iraf/unix/bin.$aarch/mkpkg.e) then
    # Assume we've got a system with binaries and can use MKPKG.
    set use_mkpkg	= 1
else
    if ($?IRAFARCH && -e $iraf/unix/bin.$IRAFARCH/mkpkg.e) then
        set use_mkpkg	= 1
    else
        # Change the links manually, but strip all binaries first.
        set use_mkpkg	= 0
    endif
endif


if ($#argv == 1) then
    set arch = $1

loop_:
    echo "Making architecture: "$arch

    if ($use_mkpkg == 1) then
        mkpkg $arch
        (chdir noao ; mkpkg -p noao $arch)
        (chdir vo   ; mkpkg -p vo $arch)
    else
	$iraf/util/mkclean
        /bin/rm -rf bin noao/bin unix/bin unix/as vo/bin

        ln -s bin.$arch bin
        (chdir vo   ; ln -s bin.$arch bin)
        (chdir noao ; ln -s bin.$arch bin)
        (chdir unix ; ln -s bin.$arch bin)
        (chdir unix ; ln -s as.$arch as)
    endif

    if ("$arch" == "macintel" || "$arch" == "linux64") then
        (chdir unix/hlib ; \
	     rm -f iraf.h mach.h ; \
	     ln -s iraf64.h iraf.h ; \
	     ln -s mach64.h mach.h)
    else
        (chdir unix/hlib ; \
	     rm -f iraf.h mach.h ; \
	     ln -s iraf32.h iraf.h ; \
	     ln -s mach32.h mach.h)
    endif

else
    set arch = $aarch
    goto loop_
endif
