#!/bin/csh
#----------------------------------------------- (c) 1994 Apic Systemes
#
# usage   : Appel /make/ apres avoir  positionne les variables d'environnement
#           selon la ligne de commande.
#
# syntaxe : asmka [-m machine ] [-p projet ] [-d dev ] [--] other-args ...
#

    set nonomatch
    set p=$0
    set pn=$p:t
    set suffix="incl"
#
#   --- -m
    if ( $#argv >= 1 ) then
        if ( "$1" == '-m' ) then
             if ( $#argv >= 2 ) then
                 if ( -e $MAKE_INCL_DIR/machine/$2.$suffix ) then
                     set file=$MAKE_INCL_DIR/machine/$2.$suffix
                 else
                     set file=$MAKE_INCL_DIR/machine/$2*.$suffix
                 endif
                 if (($#file == 1) && (-e $file[1]))  then
#                    --- Un seul fichier, ok
                         setenv MAKE_INCL_MACHINE $file:t
                         shift
                         shift
                 else if ($#file > 1) then
#                    --- Ambiguite
                     echo "$pn : too many matches for -m option"
                     goto error_file
                 else
#                    --- Pas de fichier
                     echo "$pn : no matching file for -m option"
                     goto error_no_file
                 endif
             else
                 goto error_arg
             endif
        endif
    endif
#
#   --- -p
    if ( $#argv >= 1 ) then
        if ( "$1" == '-p' ) then
             if ( $#argv >= 2 ) then
                 if ( -e $MAKE_INCL_DIR/generique/$2.$suffix ) then
                     set file=$MAKE_INCL_DIR/generique/$2.$suffix
                 else
                     set file=$MAKE_INCL_DIR/generique/$2*.$suffix
                 endif
                 if (($#file == 1) && (-e $file[1]))  then
#                    --- Un seul fichier, ok
                         setenv MAKE_INCL_GENERIQUE $file:t
                         shift
                         shift
                 else if ($#file > 1) then
#                    --- Ambiguite
                     echo "$pn : too many matches for -p option"
                     goto error_file
                 else
#                    --- Pas de fichier
                     echo "$pn : no matching file for -p option"
                     goto error_no_file
                 endif
             else
                 goto error_arg
             endif
        endif
    endif
#
#   --- -d
    if ( $#argv >= 1 ) then
        if ("$1" == '-d' ) then
             if ( $#argv >= 2 ) then
                 if ( -e $MAKE_INCL_DIR/dev/$2.$suffix ) then
                     set file=$MAKE_INCL_DIR/dev/$2.$suffix
                 else
                     set file=$MAKE_INCL_DIR/dev/$2*.$suffix
                 endif
                 if (($#file == 1) && (-e $file[1]))  then
#                    --- Un seul fichier, ok
                         setenv MAKE_INCL_DEV $file:t
                         shift
                         shift
                 else if ($#file > 1) then
#                    --- Ambiguite
                     echo "$pn : too many matches for -d option"
                     goto error_file
                 else
#                    --- Pas de fichier
                     echo "$pn : no matching file for -d option"
                     goto error_no_file
                 endif
             else
                 goto error_arg
             endif
        endif
    endif
#
#   --- --
    if ( $#argv >= 1 ) then
        if ( "$1" == '--' ) then
             shift
        endif
    endif

ok:
echo "********* : $0"
echo "home      : $MAKE_INCL_DIR"
echo "machine   : $MAKE_INCL_MACHINE"
echo "dev       : $MAKE_INCL_DEV"
    make $*
    exit 0

error_arg:
echo "syntaxe : $pn [-m machine ] [-p projet ] [-d dev ] [--] other-args ..."
    goto error

error_file:
    echo -n "$pn : "
    foreach f ($file)
        echo -n "$f:t "
    end
    echo
    goto error

error_no_file:
    echo "$pn : $file"
    goto error

error:
    exit 1


