#!/bin/sh

# Copyright distributed.net 1998-1999 - 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.22  1999/01/30 15:41:47  remi
# - Deleted ${BUILDNAME}, not needed in the public configure / makefile
# - Added TARGET_AS="gcc -c" in the x86-solaris entry
#
# Revision 1.113.2.21  1999/01/23 14:22:57  remi
# Fixed alpha-* entries for the public code.
#
# Revision 1.113.2.20  1999/01/23 14:19:17  remi
# Synced with :
#
#  Revision 1.175  1999/01/21 05:02:41  pct
#  Minor updates for Digital Unix clients.
#
#  Revision 1.174  1999/01/18 18:49:35  remi
#  Integration of Christoph Dworzak's alpha bitslicer.
#  Currently only on alpha-linux.
#
# Revision 1.113.2.19  1999/01/17 12:14:00  remi
# Synced with :
#
#  Revision 1.173  1999/01/14 23:02:11  pct
#  Updates for Digital Unix alpha client and ev5 related code.  This also
#  includes inital code for autodetection of CPU type and SMP.
#
#  Revision 1.172  1999/01/14 19:30:21  patrick
#  If caluses still buggy because of missing quotes (some shells might work without them)
#
#  Revision 1.171  1999/01/13 23:03:58  friedbait
#  fixed bug in OS2 conditional path. A syntax error caused OS2 specific
#  stuff being put in the Makefile even if there was no OS2 target selected.
#  The bug was an 'if' statement with the condition written like:
#
#  if [ $target=OS2 ]; then
#
#  the correct syntax is
#
#  if [ $target = OS2 ]; then
#
# Revision 1.113.2.18  1999/01/17 12:11:13  remi
# Synced with :
#
#  Revision 1.170  1999/01/13 21:28:29  patrick
#  new target for OS2: x86-os2-gcc
#
#  Revision 1.169  1999/01/13 11:57:19  snake
#  fixed sparc-openbsd target
#
#  Revision 1.168  1999/01/12 21:48:23  remi
#  Little fix for linux-aout.
#
#  Revision 1.167  1999/01/12 21:03:00  remi
#  - Added conditional $Id tags in NASM files
#  - Added -d __showids__ to NASM_FLAGS in targets where __showids_ was
#    already defined in CFLAGS
#
#  Revision 1.166  1999/01/12 09:39:41  chrisb
#  small fixes to the x86-solaris config
#
#  Revision 1.165  1999/01/12 08:51:33  silby
#  Changes for ELF deseval-mmx builds.
#
#  Revision 1.164  1999/01/12 08:31:00  silby
#  Added mmx-bitslice include path for nasm.
#
#  Revision 1.163  1999/01/12 08:23:15  silby
#  Changes to use new des mmx core.
#
#  Revision 1.162  1999/01/11 20:50:00  patrick
#  modified aix-pwer-gcc
#  CHANGE of DELETECHARS broke AIX compile (only changed POWER targets)
#
#  Revision 1.161  1999/01/11 11:44:13  cramer
#  added -pipe to some solaris targets
#
# Revision 1.113.2.17  1999/01/17 11:58:54  remi
# Synced with :
#
#  Revision 1.160  1999/01/11 05:45:09  pct
#  Ultrix modifications for updated client.
#
#  Revision 1.159  1999/01/10 11:00:53  cramer
#  Added targets for 601/604/860 linux-PPC builds (mt and non-mt.)  Only the
#  604 build appears to work on my 7200/75 (601) machine.
#  ${BUILDNAME} is no long striped, but ${EXENAME} (rc5des) is.
#
#  Revision 1.158  1999/01/08 10:02:24  chrisb
#  removed OLDRESOLVE from riscos
#
#  Revision 1.157  1999/01/08 08:07:12  myshkin
#  Added support for PPC 821/860 target. Thanks to Cort Dougan
#    (cort@persephone.cs.nmt.edu) for the gcc command-line arguments.
#
#  Revision 1.156  1999/01/08 07:25:08  cramer
#  Added Solaris/Sparc/non-mt target
#
#  Revision 1.155  1999/01/06 21:37:24  cramer
#  Changes sparc-solaris targets to TARGET_CC="gcc" to avoid g++ stupidly
#  linking in libs that it doesn't need.
#
#  Revision 1.154  1999/01/06 07:32:02  cramer
#  Fixed configure for sparc-linux (oops)
#
# Revision 1.113.2.16  1999/01/17 11:51:37  remi
# Synced with :
#
#  Revision 1.153  1999/01/05 08:18:06  cramer
#  A pack of wild dogs rampaged through configure... I cleaned up after them :)
#  (If anything is borked, it's my fault.  There may be a few oops' in there
#   but it shouldn't be anything major... missing or misplaced '\'...)
#
# Revision 1.113.2.15  1999/01/04 03:54:46  remi
# Synced with :
#
#  Revision 1.152  1999/01/02 09:49:24  cramer
#  Updated sparc-linux target (uses gcc)
#
#  Revision 1.151  1999/01/01 02:45:14  cramer
#  Part 1 of 1999 Copyright updates...
#
#  Revision 1.150  1999/01/01 01:16:45  silby
#  Added dctistrg.cpp
#
#  Revision 1.149  1998/12/30 07:46:57  cramer
#  removed a redundant 'rm' from distclean
#
#  Revision 1.148  1998/12/29 20:59:01  silby
#  Removed guistuff.cpp
#
# Revision 1.113.2.14  1998/12/29 19:41:21  remi
# Synced with :
#
#  Revision 1.147  1998/12/28 23:09:48  cramer
#  More tweaks to configure (ok, so I'm bored)
#
#  Revision 1.146  1998/12/28 21:37:53  cramer
#  Misc. cleanups for the disappearing RC5CORECOPY junk and minor stuff to
#  get a solaris client to build.
#
#  Revision 1.145  1998/12/28 18:17:39  cyp
#  added clievent.cpp
#
# Revision 1.113.2.13  1998/12/28 16:54:10  remi
# Fixed the previous comment.
#
# Revision 1.113.2.12  1998/12/28 16:53:19  remi
# Added common/pollsys.cpp to COMMON_SRCS (needed by sleepdefs.cpp).
#
# Revision 1.113.2.11  1998/12/28 16:00:24  remi
# Synced with :
#
#  Revision 1.144  1998/12/23 10:54:37  myshkin
#  Added code to _GetRawPPCIdentification to read /proc/cpuinfo on linux-ppc.
#  Added *ppc-gcc272 entry to configure (until I successfully upgrade to egcs).
#
#  Revision 1.143  1998/12/21 16:18:23  jcmichot
#  Add qnx4 support.
#
#  Revision 1.142  1998/12/22 02:38:39  snake
#  EPROTO doesn't exist on some systems
#
# Revision 1.113.2.10  1998/12/15 23:37:51  remi
# Synced with (!) :
#
#  Revision 1.141  1998/12/14 23:24:39  remi
#  Minor fixes in the x86 linux entries.
#
#  Revision 1.140  1998/12/14 12:55:36  cyp
#  Added kwan4/slice to serve as the third integer DES core on x86 platforms
#  to take up the slack for >2 threads. Slice is slower than Bryd, but better
#  than nothing.
#
#  Revision 1.139  1998/12/14 10:26:56  snake
#  fixes for OpenBSD sparc
#
#  Revision 1.138  1998/12/14 09:38:58  snake
#  Re-integrated non-nasm x86 cores, cause nasm doesn't support all x86
#  platforms. Sorry, no bye-bye to .cpp cores. Moved RC5X86_SRCS to
#  NASM_RC5X86_SRCS and corrected other targets.
#
#  Revision 1.136  1998/12/10 00:24:57  silby
#  Here are the nasm x86 cores, folks.  Bye bye .cpp!
#
#  Revision 1.135  1998/12/09 09:43:33  chrisb
#  Various mods to help RISC OS building. Changed definition of DELETECHARS.
#
#  Revision 1.134  1998/12/09 02:55:32  foxyloxy
#  More irix tweaks/clean up. Nothing worth specifically noting here.
#
#  Revision 1.133  1998/12/05 19:45:21  daa
#  fic for sun3 - rc5/   added to path to crunch_sun68k
#
#  Revision 1.133  1998/11/29 14:40:19  cyp
#  Added SMC support to x86-linux-gcc
#
#  Revision 1.132  1998/11/28 17:49:32  remi
#  Integration of the 386/486 self-modifying core.
#  To use this core on your platform :
#  * add -DSMC to TARGET_CFLAGS
#  * change TARGET_LDFLAGS to let the program write to its own text
#    segment.
#  * add rc5/rc5-486-smc-rg.cpp to TARGET_ADDSRCS
#
#  Revision 1.130  1998/11/25 05:53:21  dicamillo
#  Update for BeOS R4 for Intel.  Added x86-beos target.  Also added the
#  variable DELETECHARS for the argument of "tr", since since the argument
#  needs to be changed for the BeOS.
#
# Revision 1.113.2.9  1998/11/16 23:34:43  remi
# Synced with :
#  Revision 1.128  1998/11/16 20:09:49  foxyloxy
#  egcs now allows the existence of a mips-gcc-64 target! Whee!
#
# Revision 1.113.2.8  1998/11/16 16:36:34  remi
# Synced with :
#  Revision 1.127  1998/11/16 16:21:48  remi
#  sparc-linux-mt-egcs now use deseval-meggs2-2.cpp instead of deseval-meggs3.cpp.
#
# Revision 1.113.2.7  1998/11/15 17:30:41  remi
# A bunch of -D__showids__
#
# Revision 1.113.2.6  1998/11/15 11:15:38  remi
# Synced with :
#  Revision 1.126  1998/11/15 06:31:28  remi
#  Added the missing RC5CORECOPY to power-gcc target.
#
# Revision 1.113.2.5  1998/11/12 23:05:40  remi
# Synced with :
#  Revision 1.124  1998/11/12 22:58:34  remi
#  Reworked a bit AIX ppc & power defines, based on Patrick Hildenbrand
#  advice.
#
# 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 -fno-inline-functions -fno-handle-exceptions \
	  -Wall -Icommon -Irc5 -Ides -Iplatforms -D__showids__'

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

OPTS_XLC3='-O3 -qansialias -qlibansi -D__showids__'

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

#
# Common platform compiler options
#

#-- Sparc

OPTS_CC_SPARC='-fast -xO4 -xtarget=ultra1/140 -DASM_SPARC'

# (sparc/v7 [SS1/2/IPX] gcc)
OPTS_GCC_SPARC1="$OPTS_GCC -O6 -mcypress -DASM_SPARC"
OPTS_GCC272_SPARC1="$OPTS_GCC272 -O6 -mcypress -DASM_SPARC"

# (sparc/v8 [SS5+]      gcc)
OPTS_GCC_SPARC="$OPTS_GCC -O6 -msupersparc -DASM_SPARC"
OPTS_GCC272_SPARC="$OPTS_GCC272 -O6 -msupersparc -DASM_SPARC"

# (sparc/v9 [Ultra]     gcc)
OPTS_GCC_ULTRA="$OPTS_GCC -O6 -msupersparc -DASM_SPARC"
OPTS_GCC272_ULTRA="$OPTS_GCC272 -O6 -msupersparc -DASM_SPARC"
OPTS_GAS_ULTRA="-Av9a"

# (sparc/v8 [SS5+]     egcs)
OPTS_EGCS_NONULTRA_SPARC="$OPTS_EGCS -O6 -mtune=supersparc -DASM_SPARC"

#-- SUN 68k

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

#-- MIPS

OPTS_CC_MIPS='-O2 -xansi -DASM_MIPS -Icommon -Ides -Irc5 -D__showids__'
OPTS_GCC_MIPS="$OPTS_GCC -O6 -DASM_MIPS"
OPTS_EGCS_MIPS="$OPTS_EGCS -Os -DASM_MIPS" 

#-- Alpha

OPTS_CC_ALPHA_EV4='-O4 -tune ev4 -inline all -D__showids__'
OPTS_CC_ALPHA_EV5='-O4 -tune ev5 -inline all -D__showids__'
OPTS_CC_ALPHA='-O4 -fast -arch ev56 -tune ev56 -inline all -Icommon -Ides -Irc5 -D__showids__'

OPTS_GCC_ALPHA="$OPTS_GCC -O6 -DASM_ALPHA -D__showids__"

#-- HPUX

LDFLAGS_CC_HPUX='+A +DA2.0'
OPTS_CC_HPUX="$LDFLAGS_CC_HPUX +a1 +O3 -D_HPUX -DASM_HPPA -Icommon -Ides -Irc5 -D__showids__"

OPTS_GCC_HPUX="$OPTS_GCC -O6 -DASM_HPPA"
OPTS_GCC_HPUX_M68K="$OPTS_GCC -D_HPUX_M68K"

#-- DGUX

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

#-- PPC

OPTS_GCC_PPC601="$OPTS_GCC -O6 -DASM_PPC -mcpu=601"
OPTS_GCC_PPC="$OPTS_GCC -O6 -DASM_PPC -mcpu=604"
OPTS_GCC_PPC860="$OPTS_GCC -O6 -DASM_PPC -mcpu=860 -msoft-float"
OPTS_GCC272_PPC="$OPTS_GCC272 -O6 -DASM_PPC -mcpu=604"
OPTS_GCC272_PPC860="$OPTS_GCC272 -O6 -DASM_PPC -mcpu=860 -msoft-float"
OPTS_GCC_POWER="$OPTS_GCC -O6 -DASM_POWER -mcpu=power"

OPTS_EGCS_PPC601="$OPTS_EGCS -O6 -DASM_PPC -mcpu=601"
OPTS_EGCS_PPC604="$OPTS_EGCS -O6 -DASM_PPC -mcpu=604"
OPTS_EGCS_PPC860="$OPTS_EGCS -O6 -DASM_PPC -mcpu=860 -msoft-float"
OPTS_EGCS_POWER="$OPTS_EGCS -O6 -DASM_POWER -mcpu=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 -D_ARCH_PWR2"

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"

#-- X86

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"

#-- DYNIX

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

OPTS_GCC_DYNIX="-D_SEQUENT_ -Icommon -Ides -Irc5 -D__showids__"

#-- NeXT

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_"

#-- ARM

OPTS_GCC_ARM="$OPTS_GCC $OPT_FLAGS -DARM"

#-- OS/390

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

#-- UltraSparc
#
# See Also: platforms/ultrasparc/s_paramaters.h
#
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 -DASM_SPARC -DIN_DCTI_CLIENT \
		    -DDES_ULTRA -DINLINE=inline -DFULL_64_BIT_VALID -DASM \
		    -DMANUAL_REGISTER_ALLOCATION -DDO_FLOAT_PIPE -DBIT_64 \
		    -DUSE_IDENTICAL_FLOAT_REGISTERS -DUSE_64_BIT_SENTINEL \
		    -DKWAN_LOOP_SLICE='unsigned long' -Iplatforms/ultrasparc \
		    -fstrength-reduce -funroll-loops \
		    -Wall -Icommon -Irc5 -Ides -Iplatforms \
		    -O6 -mv8 -mepilogue -Wa,-xarch=v8plusa -mno-flat"

#-- MMX/DES

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/pollsys.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 \
	     common/clievent.cpp \
	     common/dctistrg.cpp"

#
# Source files making up the RC5 core code
#
XLC_LINTILLA_ASMS="rc5/crunch_lintilla.ppcxlc.s \
		   rc5/crunch_allitnil_552.ppcxlc.s"

NASM_RC5X86_SRCS="rc5/nasm/rg486.asm \
		  rc5/nasm/rc5-rgk5.asm \
		  rc5/nasm/brfp5.asm \
		  rc5/nasm/rc5-rgk6.asm \
		  rc5/nasm/rc5-rgp6.asm \
		  rc5/nasm/rg6x86.asm \
		  rc5/nasm/rc5mmx.asm"

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"

#
# Source files making up the DES core code
#
KWAN_SLICE_SRCS1="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"

MEGGS_SLICE_SRCS1="des/deseval-meggs2.cpp des/des-slice-meggs.cpp"
MEGGS_SLICE_SRCS2="des/deseval-meggs3.cpp des/des-slice-meggs.cpp"

DESX86_SRCS="des/des-x86.cpp"

DESMMX_SRCS="des/des-slice-meggs.cpp"
NASM_DESMMX_SRCS="des/mmx-bitslice/deseval-mmx.asm"


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/ -i des/mmx-bitslice/ -d__ELF__ -f elf"
TARGET_ASFLAGS=""
TARGET_STRIP="touch"
TARGET_CP="cp"

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

#
# Define characters to delete to form a safe name
#     [WARNING: this is a GNU-ism]
DELETECHARS="'[:punct:]'"

#
# 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 -Dsinix \
			-DPIPELINE_COUNT=2 -DMIPS_CRUNCH=1"
	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 -r5000 -IPA -64 -mips4 \
			-DPIPELINE_COUNT=2 -DBIT_64 -DKWAN -DMEGGS"
	TARGET_LDFLAGS="-64 -IPA -mips4"
	TARGET_ADDSRCS="$MEGGS_SLICE_SRCS2"
	;;

    *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_CCFLAGS="$OPTS_CC_MIPS -D_irix5_ \
			-DPIPELINE_COUNT=2 -DBIT_32 -DKWAN -DMEGGS"
	TARGET_ADDSRCS="$MEGGS_SLICE_SRCS2"
	;;

    *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_LDFLAGS="-n32"
	TARGET_CCFLAGS="$OPTS_CC_MIPS -n32 \
			-DPIPELINE_COUNT=2 \
			-DBIT_32 -DKWAN -DMEGGS "
	TARGET_ADDSRCS="$MEGGS_SLICE_SRCS2"
	TARGET_LIBS="-lpthread"
	;;

    *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_SRCS2"
	;;

    *mips-egcs-crunch-64)     #needs very recent egcs
	RC5CORECOPY="rc5/mips-crunch.cpp"
	TARGET_CCFLAGS="$OPTS_EGCS_MIPS -mabi=64 \
			-DPIPELINE_COUNT=2 \
			-DMIPS_CRUNCH=1 -DBIT_64 -DKWAN -DMEGGS"
	TARGET_ADDSRCS="$MEGGS_SLICE_SRCS2"
	TARGET_LIBS="-lpthread"
	;;

    *mips-egcs-crunch)	# faster than mips-gcc for IRIX
	RC5CORECOPY="rc5/mips-crunch.cpp"
	TARGET_CCFLAGS="$OPTS_EGCS_MIPS -mab=n32 \
			-DPIPELINE_COUNT=2 \
			-DMIPS_CRUNCH=1 -DBIT_32 -DKWAN -DMEGGS"
	TARGET_ADDSRCS="$MEGGS_SLICE_SRCS2"
	TARGET_LIBS="-lpthread"
	;;

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


###### HPUX

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

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


    *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-rg.cpp"
	TARGET_CCFLAGS="$OPTS_GCC272_SPARC1 \
			-DPIPELINE_COUNT=2 -DBIT_32 -DKWAN -DMEGGS"
	#TARGET_ADDSRCS="$KWAN_SLICE_SRCS3"
	TARGET_ADDSRCS="des/deseval-meggs2-2.cpp des/des-slice-meggs.cpp"
	;;

    *sparc-linux)
	RC5CORECOPY="rc5/rc5ansi2-rg.cpp"
	TARGET_CCFLAGS="$OPTS_GCC_SPARC \
			-DPIPELINE_COUNT=2 \
			-DBIT_32 -DKWAN -DMEGGS"
	TARGET_ADDSRCS="des/deseval-meggs2-2.cpp des/des-slice-meggs.cpp"
	TARGET_LIBS="-ldl"
	;;

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

    *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)	
	# FIX THIS
	DELETECHARS="'[:punct:]'"
	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 -DKWAN -DMEGGS"
	TARGET_ADDSRCS="$MEGGS_SLICE_SRCS2 rc5/crunch.sun68k.gcc.s"
	;;

    *sun2-sunos3-gcc)
	TARGET_CCFLAGS="$OPTS_GCC_SUN68K -D_SUNOS3_ \
			-DPIPELINE_COUNT=1 -DBIT_32 -DKWAN -DMEGGS"
	TARGET_ADDSRCS="$MEGGS_SLICE_SRCS2 rc5/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_CC="gcc"
	TARGET_CCFLAGS="$OPTS_GCC_SPARC -Dsolaris \
			-DPIPELINE_COUNT=2 \
			-DULTRA_CRUNCH=1 -DBIT_32 -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_CC="gcc"
	TARGET_CCFLAGS="$OPTS_GCC_SPARC -Dsolaris \
			-DPIPELINE_COUNT=2 \
			-DULTRA_CRUNCH=1 -DBIT_32 -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_CC="gcc -pipe"
	TARGET_CCFLAGS="$OPTS_GCC_SPARC -Dsolaris \
			-DPIPELINE_COUNT=2 \
			-DULTRA_CRUNCH=1 -DBIT_32 -DKWAN -DMEGGS"
	TARGET_ADDSRCS="$MEGGS_SLICE_SRCS2"
	TARGET_LIBS="-lnsl -lsocket -ldl"
	;;

    *sparc-solaris-gcc-crunch-asmslice)      # fastest rc5 & VIS DES
	RC5CORECOPY="rc5/rc5-ultra-crunch.cpp"
	TARGET_CC="gcc -pipe"
	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_LIBS="-lnsl -lsocket -ldl"
	;;

    #####

    *x86-solaris)    # gcc, nomt, dynamic
	TARGET_CCFLAGS="$OPTS_GCC_X86 -Dsolaris $OPTS_DES_MMX -DMMX_RC5 \
			-DPIPELINE_COUNT=2"
	TARGET_AS="gcc -c"
	TARGET_ADDSRCS="$DESX86_SRCS $DESMMX_SRCS $KWAN_SLICE_SRCS4"
	TARGET_ADDASMS="des/bdeslow.S platforms/x86ident.S des/p1bdespro.S"
	TARGET_ADDNASMS="$NASM_RC5X86_SRCS $NASM_DESMMX_SRCS"
	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 -DKWAN -DMEGGS"
	TARGET_ADDSRCS="$MEGGS_SLICE_SRCS2"
	TARGET_LIBS="-non_shared"
	;;

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

    *alpha-gcc-ev5-digital_unix)
	RC5CORECOPY="rc5/rc5-alpha-osf.cpp"
	TARGET_CC="g++"
	TARGET_CCFLAGS="-Wa,-02 -mcpu=ev5 $OPTS_GCC -O6 -DPIPELINE_COUNT=2 -DBIT_64 -DMEGGS -DKWAN -DALPHA_EV5_CORE"
	TARGET_ADDSRCS="$MEGGS_SLICE_SRCS2"
	TARGET_LIBS=""
	;;

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

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

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

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

    *alpha-linux)
	TARGET_AS="gcc -c"
	TARGET_CC="gcc"
	TARGET_CCFLAGS="-O2 -fno-schedule-insns -fno-handle-exceptions -fno-rtti \
	                -Wall -Icommon -Irc5 -Ides -Iplatforms -DASM_ALPHA -static \
                        -DPIPELINE_COUNT=2 -DBIT_64 -DKWAN -DMEGGS"
	TARGET_ADDSRCS="des/deseval-dworz2.c des/des-slice-dworz.cpp \
			rc5/alphaasm/axp-bmeyer.cpp \
			rc5/alphaasm/axp-bmeyer.s"
	;;

###### PowerPC/POWER

  ### generic targets

    *ppc-601-linux-egcs)		# [cramer] PPC 601 target
	TARGET_CC="gcc -pipe -g"
	TARGET_CCFLAGS="$OPTS_EGCS_PPC601 -DPIPELINE_COUNT=1 \
			-DBIT_32 -DMEGGS -DKWAN"
	TARGET_ADDSRCS="$MEGGS_SLICE_SRCS2 \
			rc5/crunch_allitnil_552.ppc.s \
			rc5/crunch_lintilla_296.ppc.s"
	;;

    *ppc-604-linux-egcs)		# [cramer] PPC 604 target
	TARGET_CC="gcc -pipe -g"
	TARGET_CCFLAGS="$OPTS_EGCS_PPC604 -DPIPELINE_COUNT=1 \
			-DBIT_32 -DMEGGS -DKWAN"
	TARGET_ADDSRCS="$MEGGS_SLICE_SRCS2 \
			rc5/crunch_allitnil_552.ppc.s \
			rc5/crunch_lintilla_296.ppc.s"
	;;

    *ppc-860-linux-egcs)		# [cramer] PPC 860 target
	TARGET_CC="gcc -pipe -g"
	TARGET_CCFLAGS="$OPTS_EGCS_PPC860 -DPIPELINE_COUNT=1 \
			-DBIT_32 -DMEGGS -DKWAN"
	TARGET_ADDSRCS="$MEGGS_SLICE_SRCS2 \
			rc5/crunch_allitnil_552.ppc.s \
			rc5/crunch_lintilla_296.ppc.s"
	;;

    *ppc-gcc)		# generic PPC target
	TARGET_CCFLAGS="$OPTS_GCC_PPC -DPIPELINE_COUNT=1 \
			-DBIT_32 -DMEGGS -DKWAN"
	TARGET_ADDSRCS="$MEGGS_SLICE_SRCS2 \
			rc5/crunch_allitnil_552.ppc.s \
			rc5/crunch_lintilla_296.ppc.s"
	;;

    *ppc860-gcc)	# PPC 821/860 target
	TARGET_CCFLAGS="$OPTS_GCC_PPC -DPIPELINE_COUNT=1 \
			-DBIT_32 -DMEGGS -DKWAN"
	TARGET_ADDSRCS="$MEGGS_SLICE_SRCS2 \
			rc5/crunch_allitnil_552.ppc.s \
			rc5/crunch_lintilla_296.ppc.s"
	;;

    *ppc-gcc272)	# generic PPC target, gcc 2.7.2
	TARGET_CCFLAGS="$OPTS_GCC272_PPC -DPIPELINE_COUNT=1 \
			-DBIT_32 -DMEGGS -DKWAN"
	TARGET_ADDSRCS="$MEGGS_SLICE_SRCS2 \
			rc5/crunch_allitnil_552.ppc.s \
			rc5/crunch_lintilla_296.ppc.s"
	;;

    *ppc860-gcc272)	# PPC 821/860 target, gcc 2.7.2
	TARGET_CCFLAGS="$OPTS_GCC272_PPC860 -DPIPELINE_COUNT=1 \
			-DBIT_32 -DMEGGS -DKWAN"
	TARGET_ADDSRCS="$MEGGS_SLICE_SRCS2 \
			rc5/crunch_allitnil_552.ppc.s \
			rc5/crunch_lintilla_296.ppc.s"
	;;

    *power-gcc)	    # generic POWER target
	RC5CORECOPY="rc5/rc5ansi1-rg.cpp"
	TARGET_CCFLAGS="$OPTS_GCC_POWER -DPIPELINE_COUNT=1 \
			-DBIT_32 -DMEGGS -DKWAN"
	TARGET_ADDSRCS="$MEGGS_SLICE_SRCS2"
	;;

  ### AIX PPC targets

    *aix4-ppc-xlc)	 # 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_SRCS2"
	TARGET_LIBS="-lCns"
	;;

    *aix4-ppc601-xlc)      # 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_SRCS2"
	TARGET_LIBS="-lCns"
	;;

    *aix32-ppc-xlc)	# 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_SRCS2"
	TARGET_LIBS="-lCns"
	;;

  ### AIX POWER targets
	# classes are buggy with AIX !

    *aix-power-gcc-pipe1)  # AIX POWER with PIPELINE_COUNT=1 (do not use)
        DELETECHARS="'/.\$\-'"
	RC5CORECOPY="rc5/rc5ansi1-rg.cpp"
	TARGET_CCFLAGS="$OPTS_GCC_POWER -D_AIX -DPIPELINE_COUNT=1 \
			-DBIT_32 -DMEGGS -DKWAN"
	TARGET_ADDSRCS="$MEGGS_SLICE_SRCS2"
	;;

    *aix-power-gcc-pipe2)  # AIX POWER with PIPELINE_COUNT=2 (preferred)
        DELETECHARS="'/.\$\-'"
	RC5CORECOPY="rc5/rc5ansi2-rg.cpp"
	TARGET_CCFLAGS="$OPTS_GCC_POWER -D_AIX -DPIPELINE_COUNT=2 \
			-DBIT_32 -DMEGGS -DKWAN"
	TARGET_ADDSRCS="$MEGGS_SLICE_SRCS2"
	;;

###### Intel X86 Linux platforms

    *x86-linux-gcc)			# nomt, static, gcc/pipe
	TARGET_AS="gcc -c"
	TARGET_CC="gcc"
	TARGET_CCFLAGS="$OPTS_GCC_X86 $OPTS_DES_MMX -DMMX_RC5 -pipe -DSMC"
	TARGET_LDFLAGS="-static -Xlinker -omagic"
	TARGET_ADDSRCS="rc5/rc5-486-smc-rg.cpp \
			$DESX86_SRCS $DESMMX_SRCS $KWAN_SLICE_SRCS4"
	TARGET_ADDASMS="des/bdeslow.S platforms/x86ident.S des/p1bdespro.S"
	TARGET_ADDNASMS="$NASM_RC5X86_SRCS $NASM_DESMMX_SRCS"
	TARGET_NASMFLAGS="-i rc5/nasm/ -i des/mmx-bitslice/ \
			  -d__ELF__ \
			  -f elf"
	TARGET_LIBS=""
	;;

    *x86-linux-egcs)		   # nomt, static, egcs
	TARGET_AS="g++ -c"
	TARGET_CC="g++"
	TARGET_CCFLAGS="$OPTS_EGCS_X86 $OPTS_DES_MMX -DMMX_RC5 -DSMC"
	TARGET_LDFLAGS="-static -Xlinker -omagic"
	TARGET_ADDSRCS="rc5/rc5-486-smc-rg.cpp \
			$DESX86_SRCS $DESMMX_SRCS $KWAN_SLICE_SRCS4"
	TARGET_ADDASMS="des/bdeslow.S platforms/x86ident.S des/p1bdespro.S"
	TARGET_ADDNASMS="$NASM_RC5X86_SRCS $NASM_DESMMX_SRCS"
	TARGET_NASMFLAGS="-i rc5/nasm/ -i des/mmx-bitslice/ \
			  -d__ELF__ \
			  -f elf"
	TARGET_LIBS=""
	;;

###### 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="$DESX86_SRCS $DESMMX_SRCS $KWAN_SLICE_SRCS4"
	TARGET_ADDASMS="des/bdeslow.S platforms/x86ident.S des/p1bdespro.S"
	TARGET_LIBS="-lc_r"
	TARGET_ADDNASMS="$NASM_RC5X86_SRCS $NASM_DESMMX_SRCS"
	TARGET_NASMFLAGS="-i rc5/nasm/ -i des/mmx-bitslice/ -f aoutb"
	;;

    *x86-freebsd-elf)
	TARGET_AS="gcc -c"
	TARGET_CCFLAGS="$OPTS_GCC_X86 $OPTS_DES_MMX -DMMX_RC5 \
			-DPIPELINE_COUNT=2 -D__ELF__"
	TARGET_ADDSRCS="$DESX86_SRCS $DESMMX_SRCS $KWAN_SLICE_SRCS4"
	TARGET_ADDASMS="des/bdeslow.S platforms/x86ident.S des/p1bdespro.S"
	TARGET_ADDNASMS="$NASM_RC5X86_SRCS $NASM_DESMMX_SRCS"
	TARGET_NASM="/usr/local/bin/nasm"
	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="$DESX86_SRCS $DESMMX_SRCS $KWAN_SLICE_SRCS4"
	TARGET_ADDASMS="des/bdeslow.S platforms/x86ident.S des/p1bdespro.S"
	TARGET_ADDNASMS="$NASM_RC5X86_SRCS $NASM_DESMMX_SRCS"
	;;

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

    *x86-openbsd)
	TARGET_AS="g++ -c"
	TARGET_CCFLAGS="$OPTS_GCC_X86 $OPTS_DES_MMX -DMMX_RC5 \
			-DPIPELINE_COUNT=2"
	TARGET_ADDSRCS="$DESX86_SRCS $DESMMX_SRCS $KWAN_SLICE_SRCS4"
	TARGET_ADDASMS="des/bdeslow.S platforms/x86ident.S des/p1bdespro.S"
	TARGET_ADDNASMS="$NASM_RC5X86_SRCS $NASM_DESMMX_SRCS"
	;;

    *x86-bsdi)
	TARGET_AS="g++ -c -DNO_BALIGN"
	TARGET_CCFLAGS="$OPTS_GCC272_X86 -DPIPELINE_COUNT=2 -DKWAN"
	TARGET_ADDSRCS="$RC5X86_SRCS $DESX86_SRCS $KWAN_SLICE_SRCS4"
	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="$DESX86_SRCS $DESMMX_SRCS $KWAN_SLICE_SRCS4"
	TARGET_ADDASMS="des/bdeslow.S platforms/x86ident.S des/p1bdespro.S"
	TARGET_ADDNASMS="$NASM_RC5X86_SRCS $NASM_DESMMX_SRCS"
	TARGET_NASMFLAGS="-i rc5/nasm/ -i des/mmx-bitslice/ \
			  -d__showids__ -d__ELF__ \
			  -f elf"
       ;;

####### 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="$DESX86_SRCS $DESMMX_SRCS $KWAN_SLICE_SRCS4"
	TARGET_ADDASMS="des/bdeslow.S platforms/x86ident.S des/p1bdespro.S"
	TARGET_ADDNASMS="$NASM_RC5X86_SRCS $NASM_DESMMX_SRCS"
	TARGET_LIBS="-lsocket"
	;;

####### Intel x86 DYNIX

    *x86-dynix4)
	RC5CORECOPY="rc5/rc5ansi2-rg2.cpp"
	TARGET_CC="ec++"
	TARGET_CCFLAGS="$OPTS_EPC_DYNIX -DMMX_RC5 -DPIPELINE_COUNT=2 \
			-DBIT_32 -DMEGGS -DKWAN"
	TARGET_ADDSRCS="$MEGGS_SLICE_SRCS1"
	TARGET_ADDNASMS="$NASM_RC5X86_SRCS $NASM_DESMMX_SRCS"
	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 -DPIPELINE_COUNT=2 \
			-DBIT_32 -DMEGGS -DKWAN"
	TARGET_ADDSRCS="$MEGGS_SLICE_SRCS2"
	TARGET_ADDNASMS="$NASM_RC5X86_SRCS $NASM_DESMMX_SRCS"
	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="$DESX86_SRCS $DESMMX_SRCS $KWAN_SLICE_SRCS4"
	TARGET_ADDASMS="des/bdeslow.S platforms/x86ident.S des/p1bdespro.S"
	TARGET_ADDNASMS="$RC5X86_SRCS $NASM_DESMMX_SRCS"
	;;

    *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 \
			-I/home/cberry/play/riscoslib/OSLib \
			-I/home/cberry/play/riscoslib/TCPIPLibs \
			-J/home/cberry/play/riscoslib/CLib \
			-D__showids__ \
			-DCOMPAT_INET4 -D__riscos \
			-DPIPELINE_COUNT=2 -DBIT_32 -DKWAN"
	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"
	TARGET_STRIP=touch
	EXENAME=rc5des,ff8
	;;

    *arm-linux)
	TARGET_CC="gcc"
	TARGET_AS="as"
	TARGET_CCFLAGS="$OPTS_GCC_ARM -Dlinux \
			-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"
	;;

    *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_SRCS2"
	TARGET_ADDASMS=""
	TARGET_LIBS="$SOCKS_LIBS"
	;;

###### Be OS (x86, PPC)
    *x86-beos)
	TARGET_AS="gcc -c"
	TARGET_CC="gcc"
	TARGET_CCFLAGS="$OPTS_EGCS_X86 $OPTS_DES_MMX -DMMX_RC5"
	TARGET_ADDSRCS="$DESX86_SRCS $DESMMX_SRCS $KWAN_SLICE_SRCS4"
	TARGET_ADDASMS="des/bdeslow.S des/bbdeslow.S \
			platforms/x86ident.S \
			des/p1bdespro.S des/p2bdespro.S"
	TARGET_ADDNASMS="$NASM_RC5X86_SRCS $NASM_DESMMX_SRCS"
	TARGET_NASMFLAGS="-i rc5/nasm/ -i des/mmx-bitslice/ \
			  -d__showids__ -d__ELF__ \
			  -f elf"
	TARGET_LIBS=""
	;;

####### OS/2 (x86, emx)
    # requires EMX, gcc 2.72 
    # if you don't have a basename command, you can use the following script:
    # just copy it to basename.cmd
        #@echo off
        #ksh -c "parm=%1 ; echo ${parm##*[\\/]}"
       
    *x86-os2-gcc)      
        basename ()
        {
        export parm=$1
        ksh -c 'echo ${parm##*/}'
        }
	TARGET_AS="gcc -c"
        TARGET_CC="gcc"
	TARGET_CCFLAGS="-Zmts -pipe $OPTS_GCC_X86 $OPTS_DES_MMX -DMMX_RC5 -I. -I${C_INCLUDE_PATH} -DMULTITHREAD -D__showids__"
	TARGET_LDFLAGS="-Zmts"
	TARGET_ADDSRCS="rc5/rc5-486-smc-rg.cpp $RC5X86_SRCS $DESX86_SRCS $DESMMX_SRCS $KWAN_SLICE_SRCS4 platforms/os2cli/os2inst.cpp"
	TARGET_ADDASMS="des/bdeslow.S des/bbdeslow.S platforms/x86ident.S des/p1bdespro.S des/p2bdespro.S"
	TARGET_ADDNASMS="rc5/nasm/rc5mmx.asm $NASM_DESMMX_SRCS"
        TARGET_NASMFLAGS="-i rc5/nasm/ -f aout"
        TARGET_LIBS="-lsocket"
        TARGET_OS=OS2
        ;;


###### 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=

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

if [ -n "${TARGET_ADDASMS}" ]; then
  echo "Scanning output AS dependencies..."
  for target in ${TARGET_ADDASMS}; do
      TARGETOBJECT=output/`basename $target`.o
      SAFENAME=`echo ${TARGETOBJECT} | tr -d ${DELETECHARS}`
      echo "  $target -> $TARGETOBJECT ($SAFENAME)"
      eval "DEPEND_${SAFENAME}=$target"
      TARGET_ALLASOBJS="${TARGET_ALLASOBJS} ${TARGETOBJECT}"
  done
fi

if [ -n "${TARGET_ADDNASMS}" ]; then
  echo "Scanning output NASM dependencies..."
  for target in ${TARGET_ADDNASMS}; do
      TARGETOBJECT=output/`basename $target`.o
      SAFENAME=`echo ${TARGETOBJECT} | tr -d ${DELETECHARS}`
      echo "  $target -> $TARGETOBJECT ($SAFENAME)"
      eval "DEPEND_${SAFENAME}=$target"
      TARGET_ALLNASMOBJS="${TARGET_ALLNASMOBJS} ${TARGETOBJECT}"
  done
fi


#
# Build the test program
#
echo "Building test program..."
if [ $1 = riscos ]; then
  #tum-te-tum
  rsh starman "cd rc5/src/client; gcc common/testplat.cpp -o testplat"
else
    echo "${TARGET_CC} ${TARGET_CCFLAGS} common/testplat.cpp ${TARGET_LDFLAGS} ${TARGET_LIBS} -o testplat"
  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."
    echo " ---------------------------------------------"
    echo "${TARGET_CC} ${TARGET_CCFLAGS} common/testplat.cpp ${TARGET_LDFLAGS} ${TARGET_LIBS} -o testplat"
    echo " ---------------------------------------------"
    exit
  fi
  if [ "$TARGET_OS" = "OS2" ]; then
     emxbind testplat
  else
     ${TARGET_STRIP} testplat
  fi
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} -DBUILDNAME=\${BUILDNAME} ${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 "CP = ${TARGET_CP}" >> 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

if [ "$TARGET_OS" = "OS2" ]; then

echo "${EXENAME}.exe:	\${ALLOBJS} \${ADDOBJS} output/${EXENAME}.res" >> Makefile
echo "	\${CC} \${LDFLAGS} \${ALLOBJS} \${ADDOBJS} \${LIBS} -o ${EXENAME}" >> Makefile
echo "	emxbind -b -r output/${EXENAME}.res ${EXENAME}" >> Makefile
echo "" >> Makefile

echo "output/${EXENAME}.res: platforms/os2cli/rc5des.rc" >> Makefile
echo "	 platforms\\os2cli\\gcc_rc.cmd ${EXENAME}.res" >> Makefile
echo "" >> Makefile

else

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

fi

echo "clean:" >> Makefile
echo "	rm -f \${ALLOBJS}  ${EXENAME}" >> Makefile
if [ "$TARGET_OS" = "OS2" ]; then
echo "	rm -f output/\${BUILDNAME}.res" >> Makefile
fi
echo "" >> Makefile

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

echo "distclean: superclean $0" >> Makefile
echo "	find . -name '.#*' -exec rm {} \\;" >> Makefile
echo "	rm -f \`egrep \"^[ ]*\\*\" $0 | sed -e 's/\(^.*\*\)\(.*\)\().*\$\$\)/\2/'\`" >> 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 "# Dependency targets follow" >> Makefile

if [ -n "${TARGET_ALLCCOBJS}" ]; then
  echo "Generating Makefile C++ dependency targets..."
  for target in ${TARGET_ALLCCOBJS}; do
    SAFENAME=`echo $target | tr -d ${DELETECHARS}`
    eval TARGETSRC=$`echo DEPEND_$SAFENAME`
    if [ -n "${RC5CORECOPY}" -a `basename ${TARGETSRC}` = problem.cpp ]; then
      TARGET_HDEPS1=`./testplat build_dependancies ${TARGETSRC}`
      TARGET_HDEPS2=`./testplat build_dependancies ${RC5CORECOPY}`
      echo "$target:	${TARGETSRC} ${TARGET_HDEPS1} ${RC5CORECOPY} ${TARGET_HDEPS2}" >> Makefile
      echo "	\${CC} -c \${CCFLAGS} -include ${RC5CORECOPY} ${TARGETSRC} -o $target" >> 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
fi

if [ -n "${TARGET_ALLASOBJS}" ]; then
  echo "Generating Makefile AS dependency targets..."
  for target in ${TARGET_ALLASOBJS}; do
    SAFENAME=`echo $target | tr -d ${DELETECHARS}`
    eval TARGETSRC=$`echo DEPEND_$SAFENAME`
    echo "$target:	${TARGETSRC}" >> Makefile
    echo "	\${AS} \${ASFLAGS} ${TARGETSRC} -o $target" >> Makefile
    echo "" >> Makefile
  done
fi

if [ -n "${TARGET_ALLNASMOBJS}" ]; then
  echo "Generating Makefile NASM dependency targets..."
  for target in ${TARGET_ALLNASMOBJS}; do
    SAFENAME=`echo $target | tr -d ${DELETECHARS}`
    eval TARGETSRC=$`echo DEPEND_$SAFENAME`
    echo "$target:	${TARGETSRC}" >> Makefile
    echo "	\${NASM} \${NASMFLAGS} ${TARGETSRC} -o $target" >> Makefile
    echo "" >> Makefile
  done
fi

echo "Makefile auto-generation complete!"
echo ""

