#! /bin/csh -f
if ($#argv < 3) then
    echo "Usage: $BINTAR <release> <dist-type> <machine-type1> <machine-type2> ..."
    exit(1)
endif
set release = $argv[1]
if (!(-d $release)) then
    echo Release $release does not exist or is not a directory
    exit(1)
endif

switch ($argv[2])
    case tar.gz:
        if (!($?tarfile)) set tarfile = "$release"
        foreach x ($argv[3-])
            set tarfile = "$tarfile"-$x
        end
        set tarfile = "$tarfile".tar.gz
        alias command 'tar -chf - \!* | gzip -c >' $tarfile
        breaksw
    default
        echo Unknown target $argv[2]
        exit(1)
endsw

set files = ()
set files = ($files $release/{Notice,ReadMe})
set files = ($files $release/License)
set files = ($files $release/examples/*)
set files = ($files $release/custom/{ReadMe,custom.c})
set files = ($files $release/custom/{crepl.c,sample.c,sample.ss})

foreach m ($argv[3-])
    set files = ($files $release/boot/$m/scheme.h)
    set files = ($files $release/boot/$m/petite.boot)
    set files = ($files $release/boot/$m/scheme.boot)
    switch ($m)
        case a6nt:
        case ta6nt:
        case ti3nt:
        case i3nt:
            set files = ($files $release/bin/$m/scheme.exe)
            set files = ($files $release/bin/$m/csv941.dll)
            set files = ($files $release/bin/$m/csv941.lib)
            set files = ($files $release/bin/$m/vcruntime140.dll)
            set files = ($files $release/boot/$m/csv941md.lib)
            set files = ($files $release/boot/$m/csv941mt.lib)
            set files = ($files $release/boot/$m/custommd.obj)
            set files = ($files $release/boot/$m/custommt.obj)
            set files = ($files $release/boot/$m/scheme.res)
            set files = ($files $release/custom/Makefile.$m)
            breaksw
        default:
            set files = ($files $release/bin/$m/scheme)
            set files = ($files $release/boot/$m/custom.o)
            set files = ($files $release/boot/$m/kernel.o)
            set files = ($files $release/custom/Mf-$m)
            if (! $?custom_make) then
                set files = ($files $release/custom/{configure,Makefile.in,Mf-none,Mf-install.in,installsh})
                set files = ($files $release/custom/scheme.1.in)
                set custom_make
            endif
            breaksw
    endsw
end

if ($?INTERACTIVE) then
  ls -lL $files | more -10
  askokay:
    echo -n "Okay? (y/n) [y]: "
    set ans = $<
    if ("$ans" == "n") exit(1)
    if ("$ans" != "" && "$ans" != "y") goto askokay

  again:
    echo "Command Alias:"
    alias command
    echo -n "Okay? (y/n) [y]: "
    set ans = $<
    if ("$ans" != "" && "$ans" != "y") then
      if ("$ans" == "n") then
        echo -n "Enter appropriate command: "
        alias command "$<"
      endif
      goto again
    endif
endif

command $files
