#!/bin/sh

# Copyright distributed.net 1998 - All Rights Reserved
# For use in distributed.net projects only.
# Any other distribution or use of this source violates copyright.

# $Log: configure,v $
# Revision 1.113.2.4  1998/11/11 19:16:48  remi
# Synced with :
#   Revision 1.122  1998/11/11 19:08:19  remi
#   Simplified $OPTS_GCC272
#
#   Revision 1.121  1998/11/11 16:39:02  remi
#   Sorted out x86-linux entries.
#   Created new $OPTS_GCC272 as I don't think -fno-exceptions is a gcc
#   2.7.2.x valid option.
#
#   Revision 1.120  1998/11/11 05:26:55  cramer
#   Various minor fixes...
#
# Revision 1.113.2.3  1998/11/11 03:03:44  remi
# Oops, forget a " and a # !
#
# Revision 1.113.2.2  1998/11/11 01:04:07  remi
# Synced with :
#   Revision 1.119  1998/11/10 10:35:31  jlawson
#   moved location of the parisc rc5 core files into the rc5 directory
#
#   Revision 1.118  1998/11/10 09:18:09  silby
#   Added alpha-linux target, should use axp-bmeyer core.
#
#   Revision 1.116  1998/11/08 21:35:42  silby
#   Removed second processor source from freebsd-elf nonmt build.
#
# Revision 1.113.2.1  1998/11/08 11:01:59  remi
# Initial (re)import of the public code.
#
#
# Synchonized with official 1.113

echo ""
echo "RC5DES client makefile generator"
echo "originally by Jeff Lawson for distributed.net"
echo "see http://www.distributed.net/"
echo ""

if [ -z "$1" ]; then
  echo "No platform specified on command line.";
  echo "Run with 'list' as an argument to see available platforms."
  exit 1
fi


# Note to people making changes..  Do not put spaces around the '='
# signs in the variable definitions below.  Some sh implementations
# will interpret such lines as statements rather than assignments.


#
# Common compiler options
#
OPTS_GCC='-fcaller-saves -fcse-follow-jumps -fcse-skip-blocks \
    -fexpensive-optimizations -fomit-frame-pointer \
    -frerun-cse-after-loop -fstrength-reduce -fthread-jumps \
    -funroll-loops -Wall -Icommon -Irc5 -Ides -Iplatforms \
    -fno-inline-functions -fno-exceptions '

OPTS_GCC272='-fomit-frame-pointer -fno-inline-functions -fno-handle-exceptions \
    -fno-rtti -Wall -Icommon -Irc5 -Ides -Iplatforms '

OPTS_XLC3='-O3 -qansialias -qlibansi'

OPTS_EGCS='-O2 -fno-exceptions -fomit-frame-pointer -Wall -Icommon -Ides \
    -Irc5 -Iplatforms'

#
# Common platform compiler options
#
OPTS_CC_SPARC='-fast -xO4 -xtarget=ultra1/140 -DASM_SPARC'
OPTS_GCC_SPARC="$OPTS_GCC -O6 -msupersparc -DASM_SPARC"
OPTS_GCC_ULTRA="$OPTS_GCC -O6 -msupersparc -DASM_SPARC"
OPTS_GAS_ULTRA=-Av9a
OPTS_GCC_NONULTRA_SPARC="$OPTS_GCC -O6 -DASM_SPARC"
OPTS_EGCS_NONULTRA_SPARC="$OPTS_EGCS -O6 -mtune=supersparc -DASM_SPARC"

#--

OPTS_GCC_SUN68K="$OPTS_GCC -O2 -DASM_68K -D_SUN68K_"

#--

OPTS_CC_MIPS='-O2 -xansi -DASM_MIPS -Icommon -Ides -Irc5'
OPTS_GCC_MIPS="$OPTS_GCC -O6 -DASM_MIPS"

#--

OPTS_CC_ALPHA_EV4='-O4 -tune ev4 -inline all'
OPTS_CC_ALPHA_EV5='-O4 -tune ev5 -inline all'
OPTS_CC_ALPHA='-O4 -fast -arch ev56 -tune ev56 -inline all -Icommon -Ides -Irc5'
OPTS_GCC_ALPHA="$OPTS_GCC -O6 -DASM_ALPHA"

#--

LDFLAGS_CC_HPUX='+A +DA2.0'
OPTS_CC_HPUX="$LDFLAGS_CC_HPUX +a1 +O3 -D_HPUX -DASM_HPPA -Icommon -Ides -Irc5"
OPTS_GCC_HPUX="$OPTS_GCC -O6 -DASM_HPPA"
OPTS_GCC_HPUX_M68K="$OPTS_GCC -D_HPUX_M68K"

#--

OPTS_GCC_DGUX="$OPTS_GCC -O6 -D_DGUX -DPIPELINE_COUNT=2 \
        -DCPU_ID=CPU_88K -DOS_ID=OS_DGUX"

#--

OPTS_GCC_PPC601="$OPTS_GCC -O6 -DASM_PPC -mcpu=601"
OPTS_GCC_PPC="$OPTS_GCC -O6 -DASM_PPC -mcpu=604"
OPTS_GCC_POWER="$OPTS_GCC -O6 -DASM_POWER"

OPTS_XLC_PPC601="$OPTS_XLC -qarch=ppc -qtune=601 -D_AIX -D_ARCH_PPC -Icommon"
OPTS_XLC_PPC="$OPTS_XLC -qarch=ppc -qtune=604 -D_AIX -D_ARCH_PPC -Icommon"
OPTS_XLC_POWER="$OPTS_XLC -qarch=pwr -qtune=pwr -D_AIX -D_ARCH_PWR"
OPTS_XLC_POWER2="$OPTS_XLC -qarch=pwr2 -qtune=pwr2 -D_AIX"

OPTS_XLC3_PPC601="$OPTS_XLC3 -qarch=ppc -qtune=601 -D_AIX -D_ARCH_PPC"
OPTS_XLC3_POWER="$OPTS_XLC3 -qarch=pwr -qtune=pwr -D_AIX -D_ARCH_PWR"

OPTS_GCC_AIX="$OPTS_GCC -O6 -D_ARCH_PPC -D_AIX"

#--

OPTS_GCC_X86="$OPTS_GCC -O6 -m486 -DASM_X86 -DPIPELINE_COUNT=2"
OPTS_GCC272_X86="$OPTS_GCC272 -O6 -m486 -DASM_X86 -DPIPELINE_COUNT=2"
OPTS_EGCS_X86="$OPTS_EGCS -mcpu=pentium -DASM_X86 -DPIPELINE_COUNT=2"

#--

OPTS_EPC_DYNIX="-relax -D_SEQUENT_ -Icommon -Ides -Irc5"
OPTS_GCC_DYNIX="-D_SEQUENT_ -Icommon -Ides -Irc5"

#--

OPTS_GCC_M68K="$OPTS_GCC -m68040 -DASM_68K"
OPTS_GAS_M68K="-v -V --register-prefix-optional -m68040"
OPTS_GCC_M68030K="$OPTS_GCC -m68030 -DASM_68K"
OPTS_GAS_M68030K="-v -V --register-prefix-optional -m68030"

OPTS_NEXT_M68K="$OPTS_GCC -O6 -m68040 -DASM_68K"
OPTS_NEXT_SPARC="$OPTS_GCC -O6 -DASM_SPARC -D_OLD_NEXT_"
OPTS_NEXT_HPPA="$OPTS_GCC -O6 -DASM_HPPA -D_OLD_NEXT_"

#--

OPTS_GCC_ARM="$OPTS_GCC $OPT_FLAGS -DARM"

#--

#-D__STRING_CODE_SET__="ISO8859-1"
OPTS_OS390="-D_ALL_SOURCE -I./common -I./rc5 -I./des"

#--
# look in platforms/ultrasparc/s_paramaters.h for the meaning of all these defines
OPTS_DES_ULTRA_C="-DDES_ULTRA -DINLINE=' ' -DIN_DCTI_CLIENT \
-DLOW_WORD_VALID -DMANUAL_REGISTER_ALLOCATION -DBIT_32 \
-DKWAN_LOOP_SLICE='unsigned long' -Iplatforms/ultrasparc"
# a bit hairy, isn't it ? ;-)
OPTS_DES_ULTRA_ASM="-DINTSIZES=442 -fstrength-reduce -Wall -Icommon \
-Irc5 -Ides -Iplatforms -O6 -mv8 -mepilogue -Wa,-xarch=v8plusa -mno-flat \
-funroll-loops -DASM_SPARC -DIN_DCTI_CLIENT -DDES_ULTRA -DINLINE=inline \
-DFULL_64_BIT_VALID -DASM -DMANUAL_REGISTER_ALLOCATION -DDO_FLOAT_PIPE \
-DUSE_IDENTICAL_FLOAT_REGISTERS -DUSE_64_BIT_SENTINEL -DBIT_64 \
-DKWAN_LOOP_SLICE='unsigned long' -Iplatforms/ultrasparc"

#--
OPTS_DES_MMX="-DMMX_BITSLICER -DKWAN -DMEGGS -DBIT_64"

#
# Source C++ files making up the base client code
#
COMMON_SRCS="common/cliconfig.cpp common/client.cpp common/problem.cpp
    common/convdes.cpp common/clicdata.cpp common/clirate.cpp
    common/clisrate.cpp common/clitime.cpp
    common/cpucheck.cpp
    common/logstuff.cpp common/disphelp.cpp
    common/triggers.cpp common/selcore.cpp
    common/cmdline.cpp common/selftest.cpp
    common/bench.cpp common/probman.cpp
    common/console.cpp common/modereq.cpp"
#KWAN_SLICE_SRCS="des/deseval.cpp des/des-slice.cpp des/sboxes-kwan.cpp"
#KWAN_SLICE_SRCS2="des/deseval.cpp des/des-slice.cpp des/sboxes-kwan2.cpp"
KWAN_SLICE_SRCS3="des/deseval.cpp des/des-slice.cpp des/sboxes-kwan3.cpp"
KWAN_SLICE_SRCS4="des/deseval.cpp des/des-slice.cpp des/sboxes-kwan4.cpp"
OLDER_MEGGS_SLICE_SRCS="des/deseval-meggs2.cpp des/des-slice-meggs.cpp"
MEGGS_SLICE_SRCS="des/deseval-meggs3.cpp des/des-slice-meggs.cpp"
XLC_LINTILLA_ASMS="rc5/crunch_lintilla.ppcxlc.s rc5/crunch_allitnil_552.ppcxlc.s"
RC5X86_SRCS="rc5/rc5-486-rg.cpp rc5/rc5-6x86-rg.cpp rc5/rc5p5brf.cpp rc5/rc5-p6-rg.cpp rc5/rc5-k5-rg.cpp rc5/rc5-k6-rg.cpp"
DESX86_SRCS="des/des-x86.cpp"
DESMMX_SRCS="des/deseval-meggs3-mmx.cpp des/sboxes-mmx.cpp des/des-slice-meggs.cpp"
DESULTRA_SRCS_C="platforms/ultrasparc/des-slice-ultrasparc.cpp platforms/ultrasparc/simple.c platforms/ultrasparc/des_ultra_crunch.c platforms/ultrasparc/kwan_from_to.c platforms/ultrasparc/do_all.c platforms/ultrasparc/do_all_fancy.c platforms/ultrasparc/do_s1.c platforms/ultrasparc/do_s1_s3.c platforms/ultrasparc/do_s2.c platforms/ultrasparc/do_s3.c platforms/ultrasparc/do_s4.c platforms/ultrasparc/do_s5.c platforms/ultrasparc/do_s6.c platforms/ultrasparc/do_s7.c platforms/ultrasparc/do_s8.c"
DESULTRA_SRCS_ASM="platforms/ultrasparc/des-slice-ultrasparc.cpp platforms/ultrasparc/des_ultra_crunch.c"

#
# Define the default compilation options
#
TARGET_CC="g++"
TARGET_CCFLAGS="$OPTS_GCC"
TARGET_LDFLAGS=""
TARGET_LIBS=""
TARGET_AS="gas"
TARGET_NASM="nasm"
TARGET_NASMFLAGS="-i rc5/nasm/ -f elf"
TARGET_ASFLAGS=""

TARGET_ADDSRCS=""
TARGET_ADDASMS=""
TARGET_ADDNASMS=""
TARGET_ADDOBJS=""
EXENAME="rc5des"


#
# Determine the platform specific options for this target
#
case "$1" in

###### MIPS based platforms
    *mips-sni-gcc)           #For MIPS SINIX
	RC5CORECOPY="rc5/mips-crunch.cpp"
	TARGET_CCFLAGS="$OPTS_GCC_MIPS -DPIPELINE_COUNT=2 -DMIPS_CRUNCH=1 -Dsinix"
	TARGET_LIBS="-lsocket -lnsl -lc -L/usr/ucblib -lucb"
	;;

    *mips-cc-64)             # For 64bit MIPS processors
	#  mips-crunch.cpp doesn't yet compile with CC
	RC5CORECOPY="rc5/rc5ansi2-rg2.cpp"
	TARGET_CC="CC"
	TARGET_CCFLAGS="$OPTS_CC_MIPS -O3 -static -r5000 -IPA -64 -mips4 -DPIPELINE_COUNT=2 -DBIT_64 -DMEGGS -DKWAN"
	TARGET_LDFLAGS="-64 -IPA -mips4"
	TARGET_ADDSRCS="$MEGGS_SLICE_SRCS"
	;;

    *mips5-cc)                # IRIX CC is slower than mips-gcc targets
        #  mips-crunch.cpp doesn't compile with CC
	RC5CORECOPY="rc5/rc5ansi2-rg2.cpp"
	TARGET_CC="CC"
	TARGET_LDFLAGS="-n32"
	TARGET_CCFLAGS="$OPTS_CC_MIPS -n32 -DPIPELINE_COUNT=2 -DBIT_32 -DMEGGS -DKWAN"
	TARGET_ADDSRCS="$MEGGS_SLICE_SRCS"
	;;

    *mips-cc)                # IRIX CC is slower than mips-gcc targets
        #  mips-crunch.cpp doesn't compile with CC
	RC5CORECOPY="rc5/rc5ansi2-rg2.cpp"
	TARGET_CC="CC"
	TARGET_CCFLAGS="$OPTS_CC_MIPS -DPIPELINE_COUNT=2 -DBIT_32 -DMEGGS -DKWAN"
	TARGET_ADDSRCS="$MEGGS_SLICE_SRCS"
	;;

    *mips-gcc-irix5-crunch)        # faster than mips-gcc for IRIX
        RC5CORECOPY="rc5/mips-crunch.cpp"
        TARGET_CCFLAGS="$OPTS_GCC_MIPS -DPIPELINE_COUNT=2 -D_irix5_ -DMIPS_CRUNCH=1 -DBIT_32 -DKWAN -DMEGGS"
        TARGET_ADDSRCS="$MEGGS_SLICE_SRCS"
        ;;


    *mips-gcc-crunch)        # faster than mips-gcc for IRIX
        RC5CORECOPY="rc5/mips-crunch.cpp"
        TARGET_CCFLAGS="$OPTS_GCC_MIPS -DPIPELINE_COUNT=2 -DMIPS_CRUNCH=1 -DBIT_32 -DKWAN -DMEGGS"
        TARGET_ADDSRCS="$MEGGS_SLICE_SRCS"
        ;;

    *mips-gcc)               # faster than mips-cc for IRIX
        RC5CORECOPY="rc5/rc5ansi2-rg.cpp"
        TARGET_CCFLAGS="$OPTS_GCC_MIPS -DBIT_32 -DPIPELINE_COUNT=2 -DKWAN"
        TARGET_ADDSRCS="$KWAN_SLICE_SRCS3"
        ;;

    *mips-gcc-ultrix)        # For mips based DEC Ultrix machines
	RC5CORECOPY="rc5/rc5ansi2-rg.cpp"
        TARGET_CCFLAGS="$OPTS_GCC_MIPS -DBIT_32 -DPIPELINE_COUNT=2 -DKWAN -DMEGGS"
	TARGET_ADDSRCS="$MEGGS_SLICE_SRCS"
	;;


###### HPUX

    *hpux-CC)
	RC5CORECOPY="rc5/parisc.cpp"
	TARGET_CC="CC"
	TARGET_CCFLAGS="$OPTS_CC_HPUX -DPIPELINE_COUNT=2 -DBIT_32 -DMEGGS -DKWAN"
	TARGET_ADDSRCS="rc5/parisc.s $MEGGS_SLICE_SRCS"
	TARGET_LDFLAGS="$LDFLAGS_CC_HPUX"
	;;

    *hpux-gcc)
	RC5CORECOPY="rc5/parisc.cpp"
	TARGET_CCFLAGS="$OPTS_GCC_HPUX -DPIPELINE_COUNT=2 -DBIT_32 -DMEGGS -DKWAN"
	TARGET_ADDSRCS="rc5/parisc.s $MEGGS_SLICE_SRCS"
	;;


    *hpux-gcc-m68k)
	RC5CORECOPY="rc5/rc5ansi1-b2.cpp"
	TARGET_CCFLAGS="$OPTS_GCC_HPUX_M68K -DPIPELINE_COUNT=1 -DBIT_32 -DKWAN"
	TARGET_AFLAGS="$OPTS_GAS_M68030K"
	TARGET_ADDASMS="rc5/crunch.68k.gcc.s"
	TARGET_ADDSRCS="$SLICE_SRCS3"
	echo $TARGET_CCFLAGS
	;;

###### DGUX (Data General Unix)
    *dgux-gcc)
	RC5CORECOPY="rc5/rc5ansi2-rg.cpp"
	TARGET_CC="/usr/local/bin/g++"
	TARGET_CCFLAGS="$OPTS_GCC_DGUX"
	;;

###### Sparc/UltraSparc or Sun/SunOS/Solaris

    *sparc-openbsd)
	RC5CORECOPY="rc5/rc5ansi2-rg2.cpp"
	TARGET_CCFLAGS="$OPTS_GCC_NONULTRA_SPARC -DPIPELINE_COUNT=2 -DBIT_32 -DKWAN"
	TARGET_ADDSRCS="$SLICE_SRCS4"
	;;

    *sparc-linux)
	RC5CORECOPY="rc5/rc5ansi2-rg.cpp"
	TARGET_CCFLAGS="$OPTS_GCC_NONULTRA_SPARC -DPIPELINE_COUNT=2 -DKWAN -DBIT_32"
	TARGET_ADDSRCS="$KWAN_SLICE_SRCS3"
	TARGET_LIBS="-ldl"
	;;

    *sparc-linux-egcs)
	RC5CORECOPY="rc5/rc5ansi2-rg.cpp"
	TARGET_CCFLAGS="$OPTS_EGCS_NONULTRA_SPARC -fno-inline-functions -DPIPELINE_COUNT=2 -DKWAN -DMEGGS -DBIT_32"
	TARGET_ADDSRCS="$MEGGS_SLICE_SRCS"
	;;

    *sparc-cc)
	RC5CORECOPY="rc5/rc5-ultra-crunch.cpp"
	TARGET_CC="cc"
	TARGET_CCFLAGS="$OPTS_CC_SPARC -DPIPELINE_COUNT=1"
	TARGET_LIBS="-lnsl -lsocket"
	;;

    *sunos-gcc)	
	RC5CORECOPY="rc5/rc5ansi2-rg.cpp"
	TARGET_CCFLAGS="$OPTS_GCC_SPARC -DPIPELINE_COUNT=2"
	;;

    *sun3-gcc)
	TARGET_CCFLAGS="$OPTS_GCC_SUN68K -DPIPELINE_COUNT=1 -DBIT_32 -DMEGGS -DKWAN"
	TARGET_ADDSRCS="$MEGGS_SLICE_SRCS crunch.sun68k.gcc.s"
	;;

    *sun2-sunos3-gcc)
	TARGET_CCFLAGS="$OPTS_GCC_SUN68K -D_SUNOS3_ -DPIPELINE_COUNT=1 -DBIT_32 -DMEGGS -DKWAN"
	TARGET_ADDSRCS="$MEGGS_SLICE_SRCS crunch.sun68k.gcc.s"
	;;
    *m68k-linux-gcc)
        TARGET_CFLAGS="$(OPTS_GCC_M68K) -DPIPELINE_COUNT=1 -DBIT_32 -DKWAN"
	TARGET_AFLAGS="$OPTS_GAS_M68K"
 	TARGET_ADDSRCS="$KWAN_SLICE_SRCS3"
 	TARGET_ADDASMS="crunch.68k.gcc.s"
	;;
    #####

    *sparc-solaris-gcc)           # slower rc5, slower des
	RC5CORECOPY="rc5/rc5ansi2-rg.cpp"
	TARGET_CCFLAGS="$OPTS_GCC_SPARC -Dsolaris -DBIT_32 -DPIPELINE_COUNT=2 -DULTRA_CRUNCH=1 -DKWAN"
	TARGET_ADDSRCS="$KWAN_SLICE_SRCS3"
	TARGET_LIBS="-lnsl -lsocket -ldl"
	;;

    *sparc-solaris-gcc-crunch)       # fastest rc5, slower des
	RC5CORECOPY="rc5/rc5-ultra-crunch.cpp"
	TARGET_CCFLAGS="$OPTS_GCC_SPARC -Dsolaris -DBIT_32 -DPIPELINE_COUNT=2 -DULTRA_CRUNCH=1 -DKWAN"
	TARGET_ADDSRCS="$KWAN_SLICE_SRCS3"
	TARGET_LIBS="-lnsl -lsocket -ldl"
	;;

    *sparc-solaris-gcc-crunch-slice)      # fastest rc5 & des for ultra
	RC5CORECOPY="rc5/rc5-ultra-crunch.cpp"
	TARGET_CCFLAGS="$OPTS_GCC_SPARC -Dsolaris -DBIT_32 -DMEGGS -DKWAN -DPIPELINE_COUNT=2 -DULTRA_CRUNCH=1"
	TARGET_ADDSRCS="$MEGGS_SLICE_SRCS"
	TARGET_LIBS="-lnsl -lsocket -ldl"
	;;

    *sparc-solaris-gcc-crunch-asmslice)      # fastest rc5 & VIS DES
	RC5CORECOPY="rc5/rc5-ultra-crunch.cpp"
	TARGET_CCFLAGS="$OPTS_DES_ULTRA_ASM -Dsolaris -DPIPELINE_COUNT=2 -DULTRA_CRUNCH=1"
	TARGET_ADDSRCS="$DESULTRA_SRCS_ASM"
 	TARGET_ADDASMS="platforms/ultrasparc/simple.handopt.s"
	TARGET_ASFLAGS="$OPTS_GAS_ULTRA"
	TARGET_CC="gcc"
	TARGET_LIBS="-lnsl -lsocket -ldl"
	;;

    #####

    *x86-solaris)
	TARGET_CCFLAGS="$OPTS_GCC_X86 $OPTS_DES_MMX -DMMX_RC5 -Dsolaris -DPIPELINE_COUNT=2"
	TARGET_ADDSRCS="$RC5X86_SRCS $DESX86_SRCS $DESMMX_SRCS"
	TARGET_ADDASMS="output/bdeslow.S output/x86ident.S des/p1bdespro.S"
        TARGET_ADDNASMS="rc5/nasm/rc5mmx.asm"
	TARGET_LIBS="-lnsl -lsocket -ldl"
	;;

###### Alpha
    *alpha-cc-ev5)
	RC5CORECOPY="rc5/rc5ansi2-bo2.cpp"
	TARGET_CC="cxx"
	TARGET_CCFLAGS="$OPTS_CC_ALPHA_EV5 -DPIPELINE_COUNT=2 -DBIT_64 -DMEGGS -DKWAN"
	TARGET_ADDSRCS="$MEGGS_SLICE_SRCS"
	;;

    *alpha-cc-ev4)
	RC5CORECOPY="rc5/rc5ansi2-bo2.cpp"
	TARGET_CC="cxx"
	TARGET_CCFLAGS="$OPTS_CC_ALPHA_EV4 -DPIPELINE_COUNT=2 -DBIT_64 -DMEGGS -DKWAN"
	TARGET_ADDSRCS="$MEGGS_SLICE_SRCS"
	;;

    *alpha-cc)
	RC5CORECOPY="rc5/rc5ansi2-bo2.cpp"
	TARGET_CC="cxx"
	TARGET_CCFLAGS="$OPTS_CC_ALPHA -DPIPELINE_COUNT=2 -DBIT_64 -DMEGGS -DKWAN"
	TARGET_ADDSRCS="$MEGGS_SLICE_SRCS"
	;;

    *alpha-gcc)
	RC5CORECOPY="rc5/rc5ansi1-b2.cpp"
	TARGET_CC="g++"
	TARGET_CCFLAGS="$OPTS_GCC_ALPHA -DPIPELINE_COUNT=1 -DBIT_64 -DMEGGS -DKWAN"
	TARGET_ADDSRCS="$MEGGS_SLICE_SRCS"
	;;

    *alpha-netbsd)
	RC5CORECOPY="rc5/rc5ansi1-b2.cpp"
	TARGET_CC="g++"
	TARGET_CCFLAGS="$OPTS_GCC_ALPHA -DPIPELINE_COUNT=1 -DBIT_64 -DMEGGS -DKWAN"
	TARGET_ADDSRCS="$MEGGS_SLICE_SRCS"
	TARGET_LIBS="-ltermcap"
	;;

    *alpha-linux)
	TARGET_AS="g++ -c"
	TARGET_CC="g++"
	TARGET_CCFLAGS="$OPTS_GCC_ALPHA -DPIPELINE_COUNT=2 -DBIT_64 -DMEGGS -DKWAN"
	TARGET_ADDSRCS="$MEGGS_SLICE_SRCS rc5/alphaasm/axp-bmeyer.cpp rc5/alphaasm/axp-bmeyer.s"
	;;

###### PowerPC/POWER

    *ppc-gcc)
	TARGET_CCFLAGS="$OPTS_GCC_PPC -DPIPELINE_COUNT=1 -DBIT_32 -DMEGGS -DKWAN"
	TARGET_ADDSRCS="$MEGGS_SLICE_SRCS rc5/crunch_allitnil_552.ppc.s rc5/crunch_lintilla_296.ppc.s"
	;;

    *power-gcc)
	TARGET_CCFLAGS="$OPTS_GCC_POWER -DPIPELINE_COUNT=1 -DBIT_32 -DMEGGS -DKWAN"
	TARGET_ADDSRCS="$MEGGS_SLICE_SRCS"
	;;

    *aix-ppc)       # This is the fastest build for AIX 4.x PPC machines
	TARGET_CC="xlC"
	TARGET_CCFLAGS="$OPTS_XLC_PPC -DPIPELINE_COUNT=1 -DBIT_32 -DMEGGS -DKWAN"
	TARGET_ADDASMS="$XLC_LINTILLA_ASMS"
	TARGET_ADDSRCS="$MEGGS_SLICE_SRCS"
	TARGET_LIBS="-lCns"
	;;

    *aix-ppc601)    # AIX 4.x PPC, 601 chip
	TARGET_CC="xlC"
	TARGET_CCFLAGS="$OPTS_XLC_PPC601 -DPIPELINE_COUNT=1 -DBIT_32 -DMEGGS -DKWAN"
	TARGET_ADDASMS="$XLC_LINTILLA_ASMS"
	TARGET_ADDSRCS="$MEGGS_SLICE_SRCS"
	TARGET_LIBS="-lCns"
	;;

    *aix32-ppc)     # AIX 3.2.x PPC
	TARGET_CC="xlC"
	TARGET_CCFLAGS="$OPTS_XLC3_PPC601 -DPIPELINE_COUNT=1 -DBIT_32 -DMEGGS -DKWAN -DNO_STRCASECMP"
	TARGET_ADDASMS="$XLC_LINTILLA_ASMS"
	TARGET_ADDSRCS="$MEGGS_SLICE_SRCS"
	TARGET_LIBS="-lCns"
	;;

    *aix-gcc)      # possibly useful for POWER machines
	RC5CORECOPY="rc5/rc5ansi1-rg.cpp"
	TARGET_CCFLAGS="$OPTS_GCC_AIX -DPIPELINE_COUNT=1 -DBIT_32 -DMEGGS -DKWAN"
	TARGET_ADDSRCS="$MEGGS_SLICE_SRCS"
	;;

    *aix-gcc2)     # possibly useful for POWER machines
	RC5CORECOPY="rc5/rc5ansi2-rg.cpp"
	TARGET_CCFLAGS="$OPTS_GCC_AIX -DPIPELINE_COUNT=2 -DBIT_32 -DMEGGS -DKWAN"
	TARGET_ADDSRCS="$MEGGS_SLICE_SRCS"
	;;

###### Intel X86 Linux platforms
    *x86-linux-egcs)              # uses EGCS options
	TARGET_AS="g++ -c"
	TARGET_CC="g++"
	TARGET_CCFLAGS="$OPTS_EGCS_X86 $OPTS_DES_MMX -DMMX_RC5"
	TARGET_ADDSRCS="$RC5X86_SRCS $DESX86_SRCS $DESMMX_SRCS"
	TARGET_ADDASMS="des/bdeslow.S platforms/x86ident.S des/p1bdespro.S"
        TARGET_ADDNASMS="rc5/nasm/rc5mmx.asm"
	;;

    *x86-linux-gcc)               # uses standard GCC options plus '-pipe'
	TARGET_AS="gcc -c"
	TARGET_CCFLAGS="-pipe $OPTS_GCC272_X86 $OPTS_DES_MMX -DMMX_RC5"
	TARGET_ADDSRCS="$RC5X86_SRCS $DESX86_SRCS $DESMMX_SRCS"
	TARGET_ADDASMS="des/bdeslow.S platforms/x86ident.S des/p1bdespro.S"
        TARGET_ADDNASMS="rc5/nasm/rc5mmx.asm"
	;;

###### Intel X86 FreeBSD/NetBSD/OpenBSD

    *x86-freebsd)
	TARGET_AS="gcc -c"
	TARGET_CCFLAGS="$OPTS_GCC_X86 $OPTS_DES_MMX -DMMX_RC5 -DPIPELINE_COUNT=2"
	TARGET_ADDSRCS="$RC5X86_SRCS $DESX86_SRCS $DESMMX_SRCS"
	TARGET_ADDASMS="des/bdeslow.S platforms/x86ident.S des/p1bdespro.S"
        TARGET_LIBS="-lc_r"
        TARGET_ADDNASMS="rc5/nasm/rc5mmx.asm"
        TARGET_NASMFLAGS="-i rc5/nasm/ -f aoutb"
	;;

    *x86-freebsd-elf)
        TARGET_AS="gcc -c"
        TARGET_CCFLAGS="$OPTS_GCC_X86 $OPTS_DES_MMX -DMMX_RC5 -static -DPIPELINE_COUNT=2 -D__ELF__"
        TARGET_ADDSRCS="$RC5X86_SRCS $DESX86_SRCS $DESMMX_SRCS"
        TARGET_ADDASMS="des/bdeslow.S platforms/x86ident.S des/p1bdespro.S"
        TARGET_ADDNASMS="rc5/nasm/rc5mmx.asm"
	TARGET_NASMFLAGS="-i rc5/nasm/ -f elf"
        TARGET_LIBS="-lc_r"
        ;;

    *x86-netbsd)
	TARGET_AS="g++ -c -DNO_BALIGN"
	TARGET_CCFLAGS="$OPTS_GCC_X86 $OPTS_DES_MMX -DMMX_RC5 -DPIPELINE_COUNT=2"
	TARGET_ADDSRCS="$RC5X86_SRCS $DESX86_SRCS $DESMMX_SRCS"
	TARGET_ADDASMS="des/bdeslow.S platforms/x86ident.S des/p1bdespro.S"
        TARGET_ADDNASMS="rc5/nasm/rc5mmx.asm"
	;;

    *x86-openbsd)
	TARGET_AS="g++ -c"
	TARGET_CCFLAGS="$OPTS_GCC_X86 $OPTS_DES_MMX -DMMX_RC5 -DPIPELINE_COUNT=2"
	TARGET_ADDSRCS="$RC5X86_SRCS $DESX86_SRCS $DESMMX_SRCS"
	TARGET_ADDASMS="des/bdeslow.S platforms/x86ident.S des/p1bdespro.S"
        TARGET_ADDNASMS="rc5/nasm/rc5mmx.asm"
	;;

    *x86-bsdi)
	TARGET_AS="g++ -c -DNO_BALIGN"
	TARGET_CCFLAGS="$OPTS_GCC_X86 -DPIPELINE_COUNT=2"
	TARGET_ADDSRCS="$RC5X86_SRCS $DESX86_SRCS"
	TARGET_ADDASMS="des/bdeslow.S platforms/x86ident.S des/p1bdespro.S"
       ;;

####### BSD/OS 4.0 with ELF format
    *x86-bsdi4)
	TARGET_AS="g++ -c -DNO_BALIGN"
	TARGET_CCFLAGS="$OPTS_GCC_X86 $OPTS_DES_MMX -DMMX_RC5 -DPIPELINE_COUNT=2  -D__ELF__"
	TARGET_ADDSRCS="$RC5X86_SRCS $DESX86_SRCS $DESMMX_SRCS"
	TARGET_ADDASMS="des/bdeslow.S platforms/x86ident.S des/p1bdespro.S"
	TARGET_ADDNASMS="rc5/nasm/rc5mmx.asm"
       ;;

####### Intel X86 SCO5

    *x86-sco5)
	TARGET_AS="g++ -c"
	TARGET_CCFLAGS="$OPTS_GCC_X86 $OPTS_DES_MMX -DMMX_RC5 -DPIPELINE_COUNT=2 -belf -Dsco5"
	TARGET_ADDSRCS="$RC5X86_SRCS $DESX86_SRCS $DESMMX_SRCS"
	TARGET_ADDASMS="des/bdeslow.S platforms/x86ident.S des/p1bdespro.S"
        TARGET_ADDNASMS="rc5/nasm/rc5mmx.asm"
	TARGET_LIBS="-lsocket"
	;;

####### Intel x86 DYNIX

    *x86-dynix4)
	RC5CORECOPY="rc5/rc5ansi2-rg2.cpp"
	TARGET_CC="ec++"
	TARGET_CCFLAGS="$OPTS_EPC_DYNIX -DMMX_RC5 -DBIT_32 -DMEGGS -DKWAN -DPIPELINE_COUNT=2"
	TARGET_ADDSRCS="$OLDER_MEGGS_SLICE_SRCS"
        TARGET_ADDNASMS="rc5/nasm/rc5mmx.asm"
	TARGET_LIBS="-lsocket -lnsl -lseq -L/opt/epc/ec++/lib -lec++"
	;;

    *x86-dynix2)
	RC5CORECOPY="rc5/rc5ansi2-rg2.cpp"
	TARGET_CCFLAGS="$OPTS_GCC_DYNIX -DMMX_RC5 -DBIT_32 -DMEGGS -DKWAN -DPIPELINE_COUNT=2"
	TARGET_ADDSRCS="$MEGGS_SLICE_SRCS"
        TARGET_ADDNASMS="rc5/nasm/rc5mmx.asm"
	TARGET_LDFLAGS="-L."
	# Don't panic; -lXbsd is for gettimeofday()
	TARGET_LIBS="-lsocket -linet -lnsl -lXbsd -lseq"
	;;

###### NeXT (x86, m68k, sparc, hppa)

    *x86-next)
	TARGET_AS="gcc -c"
	TARGET_CC="gcc"
	TARGET_CCFLAGS="$OPTS_GCC_X86 $OPTS_DES_MMX -DMMX_RC5 -D_NeXT_ -DPIPELINE_COUNT=2 -DBIT_32"
	TARGET_ADDSRCS="$RC5X86_SRCS $DESX86_SRCS $DESMMX_SRCS"
	TARGET_ADDASMS="des/bdeslow.S platforms/x86ident.S des/p1bdespro.S"
        TARGET_ADDNASMS="rc5/nasm/rc5mmx.asm"
	;;

    *m68k-next-gcc)
	TARGET_CC="gcc"
	TARGET_CCFLAGS="$OPTS_NEXT_M68K -D_NeXT_ -DPIPELINE_COUNT=1 -DBIT_32 -DKWAN"
	TARGET_ADDSRCS="rc5/crunch.68k.gcc.s $KWAN_SLICE_SRCS4"
	;;

    *m68k-next)
	RC5CORECOPY="rc5/rc5ansi1-b2.cpp"
	TARGET_CC="cc++"
	TARGET_CCLAGS="$OPTS_NEXT_M68K -arch m68k -D_NeXT_ -DPIPELINE_COUNT=1"
	;;

    *sparc-next)
	RC5CORECOPY="rc5/rc5ansi2-rg.cpp"
	TARGET_CC="cc++"
	TARGET_CCFLAGS="$OPTS_NEXT_SPARC -arch sparc -D_NeXT_ -DPIPELINE_COUNT=2 -DBIT_32"
	TARGET_ADDSRCS="des/des-slice.cpp des/deseval.cpp"
	;;

    *hppa-next)
	RC5CORECOPY="rc5/rc5ansi2-b2.cpp"
	TARGET_CC="cc++"
	TARGET_CCFLAGS="$OPTS_NEXT_HPPA -arch hppa -D_NeXT_ -DPIPELINE_COUNT=2 -DBIT_32"
	TARGET_ADDSRCS="des/des-slice.cpp des/deseval.cpp"
	;;

###### ARM

    *riscos)
	TARGET_CC="armcpp -aif -nodebug -littleend -apcs 3/26bit/swst/hardfp/fpe2 -zps1 -nounusedareas -l/home/cberry/play/riscoslib/CLib/stubs.o"
	TARGET_AS="armasm -apcs 3/26bit"
	TARGET_CCFLAGS="-Icommon -Irc5 -Ides -Iplatforms -J/home/cberry/play/riscoslib/CLib -I/home/cberry/play/riscoslib/OSLib -I/home/cberry/play/riscoslib/TCPIPLibs -DCOMPAT_INET4 -D__riscos -DPIPELINE_COUNT=2 -DBIT_32 -DKWAN  -DOLDRESOLVE"
	TARGET_ADDSRCS="platforms/riscos/riscos.cpp"
	TARGET_ADDASMS="platforms/riscos/riscosasm.s rc5/rc5-arm-1.s rc5/rc5-arm-2.s rc5/rc5-arm-3.s des/des-slice-arm.s des/des-slice-sa.s"
	TARGET_LIBS="-lcpplib /home/cberry/play/riscoslib/TCPIPLibs/unixlib.o /home/cberry/play/riscoslib/TCPIPLibs/inetlib.o /home/cberry/play/riscoslib/TCPIPLibs/socklib.o"
	EXENAME=rc5des,ff8
	;;

    *arm-linux)
	TARGET_CC="gcc"
	TARGET_AS="as"
	TARGET_CCFLAGS="$OPTS_GCC_ARM -DPIPELINE_COUNT=2 -DBIT_32 -Dlinux -DKWAN"
	TARGET_ADDSRCS=""
	TARGET_ADDASMS="rc5/rc5-sa-gnu.s rc5/rc5-arm-gnu.s des/des-slice-sa-gnu.s des/des-slice-arm-gnu.s"
	TARGET_LIBS="-lm"
	;;

    *arm-netbsd)
	TARGET_CC="gcc"
	TARGET_AS="as"
	TARGET_CCFLAGS="$OPTS_GCC_ARM -DPIPELINE_COUNT=2 -DBIT_32 -DKWAN"
	TARGET_ADDSRCS=""
	TARGET_ADDASMS="rc5/rc5-sa-gnu.s rc5/rc5-arm-gnu.s des/des-slice-sa-gnu.s des/des-slice-arm-gnu.s"
	TARGET_LIBS="-lm"
	;;

###### OS390
    *os390)
	RC5CORECOPY="rc5/rc5ansi2-rg2.cpp"
	TARGET_CC="gcc"
	TARGET_AS=""
	TARGET_CCFLAGS="$OPTS_OS390 -DPIPELINE_COUNT=2 -DBIT_32 -DKWAN -DMEGGS"
	TARGET_ADDSRCS="$MEGGS_SLICE_SRCS"
	TARGET_ADDASMS=""
	TARGET_LIBS="$SOCKS_LIBS"
	;;

###### Unknown
    *list)
	egrep "^[ ]*\*" $0 | more
	echo ""
	exit 1
	;;
    *)
        echo "Unknown target platform \"$1\" specified."
	echo "Run with 'list' as an argument to see available platforms."
	echo ""
	exit 1
esac
echo "Platform target for \"$1\" recognized."


#
# Generate the list of output objects, making note of what
# source file it was derrived from.
#

TARGET_ALLCCOBJS=
TARGET_ALLASOBJS=
TARGET_ALLNASMOBJS=

echo "Scanning output C++ dependencies..."
for target in ${COMMON_SRCS} ${TARGET_ADDSRCS}; do
    TARGETOBJECT=output/`basename $target .cpp`.o
    SAFENAME=`echo ${TARGETOBJECT} | tr -d '/.\$\-'`
    echo "  ${target} -> ${TARGETOBJECT} (${SAFENAME})"
    eval "DEPEND_${SAFENAME}=${target}"
    TARGET_ALLCCOBJS="${TARGET_ALLCCOBJS} ${TARGETOBJECT}"
done

echo "Scanning output AS dependencies..."
for target in ${TARGET_ADDASMS}; do
    TARGETOBJECT=output/`basename $target`.o
    SAFENAME=`echo ${TARGETOBJECT} | tr -d '/.\$\-'`
    echo "  $target -> $TARGETOBJECT ($SAFENAME)"
    eval "DEPEND_${SAFENAME}=$target"
    TARGET_ALLASOBJS="${TARGET_ALLASOBJS} ${TARGETOBJECT}"
done

echo "Scanning output NASM dependencies..."
for target in ${TARGET_ADDNASMS}; do
    TARGETOBJECT=output/`basename $target`.o
    SAFENAME=`echo ${TARGETOBJECT} | tr -d '/.\$\-'`
    echo "  $target -> $TARGETOBJECT ($SAFENAME)"
    eval "DEPEND_${SAFENAME}=$target"
    TARGET_ALLNASMOBJS="${TARGET_ALLNASMOBJS} ${TARGETOBJECT}"
done


#
# Build the test program
#
echo "Building test program..."
sh -c "${TARGET_CC} ${TARGET_CCFLAGS} common/testplat.cpp ${TARGET_LDFLAGS} ${TARGET_LIBS} -o testplat"
if [ $? -ne 0 ]; then
   echo "Compilation failed.  Check your target options."
   exit
fi


#
# Look up the platform and os types
#
if [ $1 = riscos ]; then
CLIENTCPU=11
CLIENTOS=34
INTSIZES=442
else
CLIENTCPU=`./testplat cpu`
CLIENTOS=`./testplat os`
INTSIZES=`./testplat intsizes`
fi
CLIENTOSNAME=`grep "#define OS_.*\<$CLIENTOS\>" common/cputypes.h | head -1 | cut -d' ' -f2`
CLIENTCPUNAME=`grep "#define CPU_.*\<$CLIENTCPU\>" common/cputypes.h | head -1 | cut -d' ' -f2`
echo "CLIENT_CPU = $CLIENTCPUNAME ($CLIENTCPU)"
echo "CLIENT_OS = $CLIENTOSNAME ($CLIENTOS)"
echo "INTSIZES = $INTSIZES"
TARGET_CCFLAGS="-DINTSIZES=${INTSIZES} ${TARGET_CCFLAGS}"


#
# Start building the output makefile
#
echo "Generating output Makefile prologue code..."
rm -f Makefile

echo "# Autogenerated RC5DES client makefile ($1)" > Makefile
echo "#   target cpu --> $CLIENTCPUNAME ($CLIENTCPU)" >> Makefile
echo "#    target os --> $CLIENTOSNAME ($CLIENTOS)" >> Makefile
echo "#     intsizes --> $INTSIZES" >> Makefile
echo "# see http://www.distributed.net/ for details." >> Makefile
echo "" >> Makefile

echo "CC = ${TARGET_CC}" >> Makefile
echo "CCFLAGS = ${TARGET_CCFLAGS}" >> Makefile
echo "LDFLAGS = ${TARGET_LDFLAGS}" >> Makefile
echo "LIBS = ${TARGET_LIBS}" >> Makefile
echo "AS = ${TARGET_AS}" >> Makefile
echo "ASFLAGS = ${TARGET_ASFLAGS}" >> Makefile
echo "NASM = ${TARGET_NASM}" >> Makefile
echo "NASMFLAGS = ${TARGET_NASMFLAGS}" >> Makefile
echo "ALLOBJS = ${TARGET_ALLCCOBJS} ${TARGET_ALLASOBJS} ${TARGET_ALLNASMOBJS}" >> Makefile
echo "ADDOBJS = ${TARGET_ADDOBJS}" >> Makefile
echo "BUILDNAME = $1" >> Makefile
echo "" >> Makefile


#
# Generate the main production targets in the makefile
#
echo "Generating Makefile production targets..."
echo "# Regular targets follow" >> Makefile

echo "${EXENAME}:	\${ALLOBJS} \${ADDOBJS}" >> Makefile
echo "	\${CC} \${LDFLAGS} \${ALLOBJS} \${ADDOBJS} \${LIBS} -o ${EXENAME}" >> Makefile
echo "" >> Makefile

echo "clean:" >> Makefile
echo "	rm -f \${ALLOBJS} ${EXENAME}" >> Makefile
#echo "	sh $0 \${BUILDNAME}" >> Makefile
echo "" >> Makefile

echo "superclean:" >> Makefile
echo "	rm -f \${ALLOBJS} ${EXENAME} Makefile buff-in.* buff-out.* *.ini testplat" >> Makefile
echo "	find . -name '*~' -exec rm {} \\;" >> Makefile
echo "" >> Makefile

echo "ident:	${EXENAME}" >> Makefile
echo "	ident ${EXENAME} | awk '{ printf(\"%-30s %10s %s %s %s %s%c\", \$\$2,\$\$3,\$\$4,\$\$5,\$\$6,\$\$7,10)}'" >> Makefile
echo "" >> Makefile

#
# Generate the dependency targets in the makefile
#
echo "Generating Makefile C++ dependency targets..."
echo "# Dependency targets follow" >> Makefile
for target in ${TARGET_ALLCCOBJS}; do
  SAFENAME=`echo $target | tr -d '/.\$\-'`
  eval TARGETSRC=$`echo DEPEND_$SAFENAME`
  if [ -n "${RC5CORECOPY}" -a `basename ${TARGETSRC}` = problem.cpp ]; then
    echo "$target:	${TARGETSRC} ${RC5CORECOPY}" >> Makefile
    echo "	rm -f rc5/rc5stub.cpp" >> Makefile
    echo "	cp ${RC5CORECOPY} rc5/rc5stub.cpp" >> Makefile
    echo "	\${CC} -c \${CCFLAGS} ${TARGETSRC} -o $target" >> Makefile
    echo "	rm -f rc5/rc5stub.cpp" >> Makefile
  else
    TARGET_HDEPS=`./testplat build_dependancies ${TARGETSRC}`
    echo "$target:	${TARGETSRC} ${TARGET_HDEPS}" >> Makefile
    echo "	\${CC} -c \${CCFLAGS} ${TARGETSRC} -o $target" >> Makefile
  fi
  echo "" >> Makefile
done
echo "Generating Makefile AS dependency targets..."
for target in ${TARGET_ALLASOBJS}; do
  SAFENAME=`echo $target | tr -d '/.\$\-'`
  eval TARGETSRC=$`echo DEPEND_$SAFENAME`
  echo "$target:	${TARGETSRC}" >> Makefile
  echo "	\${AS} \${ASFLAGS} ${TARGETSRC} -o $target" >> Makefile
  echo "" >> Makefile
done
echo "Generating Makefile NASM dependency targets..."
for target in ${TARGET_ALLNASMOBJS}; do
  SAFENAME=`echo $target | tr -d '/.\$\-'`
  eval TARGETSRC=$`echo DEPEND_$SAFENAME`
  echo "$target:	${TARGETSRC}" >> Makefile
  echo "	\${NASM} \${NASMFLAGS} ${TARGETSRC} -o $target" >> Makefile
  echo "" >> Makefile
done
echo "Makefile auto-generation complete!"
echo ""
