#!/bin/sh
#
# make-process.o.sh
#  Try to make process.o various ways.
#
#  $Id: make-process.o.sh.in,v 1.22 2000/07/28 12:17:46 lha Exp $
#

srcdir=@srcdir@

CC=${CC-"@CC@"}
GCC=${GCC-"@GCC@"}
CPP=${CPP-"@CPP@"}
AS=${AS-"@AS@"}
RM=rm
HOST_CPU="@host_cpu@"
HOST_OS="@host_os@"
LN_S="@LN_S@"
LWP_O="@LWP_O@"

#
# Here is a test to check if we manage to build process.o
#  (use this because some sh doesn't have functions)
#
# $CC -o testprocess testprocess.o process.o preempt.o ${LWP_O} && exit 0
# $RM -f process.o

#
# Options that you may need to override for your CPU/OS
#

PROCESS_S="undefined_you_loose"
USE_AS="no"
MYDEF=""


#
# Clean out the process.o
#

$RM -f process.o process.S foo.c

# 
# Add PROCESS_S you need
#

case "$HOST_CPU" in
    sparc*)  PROCESS_S="process.sparc.S" ;;
    i*86*)   PROCESS_S="process.i386.S" ;;
    m68k)    PROCESS_S="process.m68k.S" ;;
    mips*)   PROCESS_S="process.mips.S" ;;
    alpha*)  PROCESS_S="process.alpha.S" ;;
    hppa*)   PROCESS_S="process.hpux.S" ;;
    powerpc) PROCESS_S="process.ppc.S" ;;
    rs6000)  PROCESS_S="process.rios.S" ;;
    f301) ;;
    *)  echo "Unknown host_cpu, good luck" ;;
esac 

#
# Add OSDEF your OS need
#

case "$HOST_OS" in 
    *bsd*) OSDEF="-DHAVE_PIC -DAFS_BSD_ENV" ;; 
    *linux*) OSDEF="-DAFS_LINUX_ENV" ;; 
    *dux* | *osf*) OSDEF="-DAFS_OSF_ENV" ;; 
    *solaris*) OSDEF="-DAFS_SUN5_ENV -D_ASM" USE_AS="yes" ;; 
    *irix*) OSDEF="-Dsgi -n32 -DHAVE_PIC"; ASDEF="-n32" ;; 
    *hpux*) OSDEF="-DAFS_HPUX_ENV" ;; 
    rhapsody*) OSDEF="-DAFS_BSD_ENV" ;; 
    aix*) CPUDEF=""; OSDEF="" ;; 
    uxpv*) 
	$CPP -P ${srcdir}/process-vpp.s > foo.s
	$AS -o process.o foo.s && $RM -f foo.s && exit 0
	$RM -f foo.s
	exit 1
	;;
    *) ;; 
esac 

#
# Now try to do the magic stuff.
#

$LN_S ${srcdir}/${PROCESS_S} process.S

#
# Can we use $CC to do the asm for us ? (GCC)
#   

if test "X$GCC" = "Xyes" -a "X$USE_AS" = "Xno"; then 
    ${CC} -I../include -I$srcdir -DASSEMBLER $MYDEF $CPUDEF $OSDEF -c process.S

# process.o there ?
    $CC -o testprocess testprocess.o process.o preempt.o ${LWP_O} && exit 0
    $RM -f process.o
fi

#
# Try to use $AS -P for assably 
#

$AS -P -I../include -I$srcdir -DASSEMBLER $MYDEF $CPUDEF $OSDEF process.S -o process.o

# process.o there ?
$CC -o testprocess testprocess.o process.o preempt.o ${LWP_O} && exit 0
$RM -f process.o


#
# Some $AS does "intresting" things, like ignorings the -o flag
# and creats a .i file that is preprocessed. (Digital Unix)
#

if test -s process.i ; then
    $AS $ASDEF process.i -o process.o
    $RM -f process.i

    # process.o there ?
    $CC -o testprocess testprocess.o process.o preempt.o ${LWP_O} && exit 0
    $RM -f process.o
fi

#
# Try to use $AS (without -P) for assably 
#

$AS -I../include -I$srcdir -DASSEMBLER $MYDEF $CPUDEF $OSDEF process.S -o process.o

# process.o there ?
$CC -o testprocess testprocess.o process.o preempt.o ${LWP_O} && exit 0
$RM -f process.o


#
# Some $AS does "intresting" things, like ignorings the -o flag
# and creats a .i file that is preprocessed. (Digital Unix)
#

if test -s process.i ; then
    $AS process.i -o process.o
    $RM -f process.i

    # process.o there ?
    $CC -o testprocess testprocess.o process.o preempt.o ${LWP_O} && exit 0
    $RM -f process.o
fi

#
# Try to fool $CC by adding a .c extension. 
#

$LN_S process.S foo.c 
$CPP -I../include -I$srcdir $MYDEF $CPUDEF $OSDEF foo.c > process.ss 
$RM -f foo.c
$AS process.ss -o process.o 
$RM -f process.ss

# process.o there ?
$CC -o testprocess testprocess.o process.o preempt.o ${LWP_O} && exit 0
$RM -f process.o

echo "WE HAVE NO process.o !"
exit 1
