config revision 89837
1#!/bin/sh
2#
3# OpenSSL config: determine the operating system and run ./Configure
4#
5# "config -h" for usage information.
6#
7#          this is a merge of minarch and GuessOS from the Apache Group.
8#          Originally written by Tim Hudson <tjh@cryptsoft.com>.
9
10# Original Apache Group comments on GuessOS
11
12# Simple OS/Platform guesser. Similar to config.guess but
13# much, much smaller. Since it was developed for use with
14# Apache, it follows under Apache's regular licensing
15# with one specific addition: Any changes or additions
16# to this script should be Emailed to the Apache
17# group (apache@apache.org) in general and to
18# Jim Jagielski (jim@jaguNET.com) in specific.
19#
20# Be as similar to the output of config.guess/config.sub
21# as possible.
22
23# First get uname entries that we use below
24
25MACHINE=`(uname -m) 2>/dev/null` || MACHINE="unknown"
26RELEASE=`(uname -r) 2>/dev/null` || RELEASE="unknown"
27SYSTEM=`(uname -s) 2>/dev/null`  || SYSTEM="unknown"
28VERSION=`(uname -v) 2>/dev/null` || VERSION="unknown"
29
30
31# Now test for ISC and SCO, since it is has a braindamaged uname.
32#
33# We need to work around FreeBSD 1.1.5.1 
34(
35XREL=`uname -X 2>/dev/null | grep "^Release" | awk '{print $3}'`
36if [ "x$XREL" != "x" ]; then
37    if [ -f /etc/kconfig ]; then
38	case "$XREL" in
39	    4.0|4.1)
40		    echo "${MACHINE}-whatever-isc4"; exit 0
41		;;
42	esac
43    else
44	case "$XREL" in
45	    3.2v4.2)
46		echo "whatever-whatever-sco3"; exit 0
47		;;
48	    3.2v5.0*)
49		echo "whatever-whatever-sco5"; exit 0
50		;;
51	    4.2MP)
52		if [ "x$VERSION" = "x2.01" ]; then
53		    echo "${MACHINE}-whatever-unixware201"; exit 0
54		elif [ "x$VERSION" = "x2.02" ]; then
55		    echo "${MACHINE}-whatever-unixware202"; exit 0
56		elif [ "x$VERSION" = "x2.03" ]; then
57		    echo "${MACHINE}-whatever-unixware203"; exit 0
58		elif [ "x$VERSION" = "x2.1.1" ]; then
59		    echo "${MACHINE}-whatever-unixware211"; exit 0
60		elif [ "x$VERSION" = "x2.1.2" ]; then
61		    echo "${MACHINE}-whatever-unixware212"; exit 0
62		elif [ "x$VERSION" = "x2.1.3" ]; then
63		    echo "${MACHINE}-whatever-unixware213"; exit 0
64		else
65		    echo "${MACHINE}-whatever-unixware2"; exit 0
66		fi
67		;;
68	    4.2)
69		echo "whatever-whatever-unixware1"; exit 0
70		;;
71     OpenUNIX)
72		if [ "`echo x$VERSION | sed -e 's/\..*//'`" = "x8" ]; then
73		    echo "${MACHINE}-unknown-OpenUNIX${VERSION}"; exit 0
74		fi
75		;;
76	    5)
77		if [ "`echo x$VERSION | sed -e 's/\..*//'`" = "x7" ]; then
78		    echo "${MACHINE}-sco-unixware7"; exit 0
79		fi
80		;;
81	esac
82    fi
83fi
84# Now we simply scan though... In most cases, the SYSTEM info is enough
85#
86case "${SYSTEM}:${RELEASE}:${VERSION}:${MACHINE}" in
87    MPE/iX:*)
88	MACHINE=`echo "$MACHINE" | sed -e 's/-/_/g'`
89	echo "parisc-hp-MPE/iX"; exit 0
90	;;
91    A/UX:*)
92	echo "m68k-apple-aux3"; exit 0
93	;;
94
95    AIX:[3456789]:4:*)
96	echo "${MACHINE}-ibm-aix43"; exit 0
97	;;
98
99    AIX:*:[56789]:*)
100	echo "${MACHINE}-ibm-aix43"; exit 0
101	;;
102
103    AIX:*)
104	echo "${MACHINE}-ibm-aix"; exit 0
105	;;
106
107    dgux:*)
108	echo "${MACHINE}-dg-dgux"; exit 0
109	;;
110
111    HI-UX:*)
112	echo "${MACHINE}-hi-hiux"; exit 0
113	;;
114
115    HP-UX:*)
116	HPUXVER=`echo ${RELEASE}|sed -e 's/[^.]*.[0B]*//'`
117	case "$HPUXVER" in
118	    11.*)
119		echo "${MACHINE}-hp-hpux11"; exit 0
120		;;
121	    10.*)
122		echo "${MACHINE}-hp-hpux10"; exit 0
123		;;
124	    *)
125		echo "${MACHINE}-hp-hpux"; exit 0
126		;;
127	esac
128	;;
129
130    IRIX:5.*)
131	echo "mips2-sgi-irix"; exit 0
132	;;
133
134    IRIX:6.*)
135	echo "mips3-sgi-irix"; exit 0
136	;;
137
138    IRIX64:*)
139	echo "mips4-sgi-irix64"; exit 0
140	;;
141
142    Linux:[2-9].*)
143	echo "${MACHINE}-whatever-linux2"; exit 0
144	;;
145
146    Linux:1.*)
147	echo "${MACHINE}-whatever-linux1"; exit 0
148	;;
149
150    LynxOS:*)
151	echo "${MACHINE}-lynx-lynxos"; exit 0
152	;;
153
154    BSD/OS:4.*)  # BSD/OS always says 386
155	echo "i486-whatever-bsdi4"; exit 0
156	;;
157
158    BSD/386:*:*:*486*|BSD/OS:*:*:*:*486*)
159        case `/sbin/sysctl -n hw.model` in
160	    Pentium*)
161                echo "i586-whatever-bsdi"; exit 0
162                ;;
163            *)
164                echo "i386-whatever-bsdi"; exit 0
165                ;;
166            esac;
167	;;
168
169    BSD/386:*|BSD/OS:*)
170	echo "${MACHINE}-whatever-bsdi"; exit 0
171	;;
172
173    FreeBSD:*)
174        VERS=`echo ${RELEASE} | sed -e 's/[-(].*//'`
175        MACH=`sysctl -n hw.model`
176        ARCH='whatever'
177        case ${MACH} in
178           *386*       ) MACH="i386"     ;;
179           *486*       ) MACH="i486"     ;;
180           Pentium\ II*) MACH="i686"     ;;
181           Pentium*    ) MACH="i586"     ;;
182           Alpha*      ) MACH="alpha"    ;;
183           *           ) MACH="$MACHINE" ;;
184        esac
185        case ${MACH} in
186           i[0-9]86 ) ARCH="pc" ;;
187        esac
188        echo "${MACH}-${ARCH}-freebsd${VERS}"; exit 0
189        ;;
190
191    NetBSD:*:*:*386*)
192        echo "`(/usr/sbin/sysctl -n hw.model || /sbin/sysctl -n hw.model) | sed 's,.*\(.\)86-class.*,i\186,'`-whatever-netbsd"; exit 0
193	;;
194
195    NetBSD:*)
196	echo "${MACHINE}-whatever-netbsd"; exit 0
197	;;
198
199    OpenBSD:*)
200	echo "${MACHINE}-whatever-openbsd"; exit 0
201	;;
202
203    OpenUNIX:*)
204	echo "${MACHINE}-unknown-OpenUNIX${VERSION}"; exit 0
205	;;
206
207    OSF1:*:*:*alpha*)
208	OSFMAJOR=`echo ${RELEASE}| sed -e 's/^V\([0-9]*\)\..*$/\1/'`
209	case "$OSFMAJOR" in
210	    4|5)
211		echo "${MACHINE}-dec-tru64"; exit 0
212		;;
213	    1|2|3)
214		echo "${MACHINE}-dec-osf"; exit 0
215		;;
216	    *)
217		echo "${MACHINE}-dec-osf"; exit 0
218		;;
219	esac
220	;;
221
222    QNX:*)
223	case "$RELEASE" in
224	    4*)
225		echo "${MACHINE}-whatever-qnx4"
226		;;
227	    6*)
228		echo "${MACHINE}-whatever-qnx6"
229		;;
230	    *)
231		echo "${MACHINE}-whatever-qnx"
232		;;
233	esac
234	exit 0
235	;;
236
237    Paragon*:*:*:*)
238	echo "i860-intel-osf1"; exit 0
239	;;
240
241    Rhapsody:*)
242	echo "ppc-apple-rhapsody"; exit 0
243	;;
244
245    Darwin:*)
246	echo "ppc-apple-darwin"; exit 0
247	;;
248
249    SunOS:5.*)
250	echo "${MACHINE}-whatever-solaris2"; exit 0
251	;;
252
253    SunOS:*)
254	echo "${MACHINE}-sun-sunos4"; exit 0
255	;;
256
257    UNIX_System_V:4.*:*)
258	echo "${MACHINE}-whatever-sysv4"; exit 0
259	;;
260
261    *:4*:R4*:m88k)
262	echo "${MACHINE}-whatever-sysv4"; exit 0
263	;;
264
265    DYNIX/ptx:4*:*)
266	echo "${MACHINE}-whatever-sysv4"; exit 0
267	;;
268
269    *:4.0:3.0:3[34]?? | *:4.0:3.0:3[34]??,*)
270	echo "i486-ncr-sysv4"; exit 0
271	;;
272
273    ULTRIX:*)
274	echo "${MACHINE}-unknown-ultrix"; exit 0
275	;;
276
277    SINIX*|ReliantUNIX*)
278	echo "${MACHINE}-siemens-sysv4"; exit 0
279	;;
280
281    POSIX-BC*)
282	echo "${MACHINE}-siemens-sysv4"; exit 0   # Here, $MACHINE == "BS2000"
283	;;
284
285    machten:*)
286       echo "${MACHINE}-tenon-${SYSTEM}"; exit 0;
287       ;;
288
289    library:*)
290	echo "${MACHINE}-ncr-sysv4"; exit 0
291	;;
292
293    ConvexOS:*:11.0:*)
294	echo "${MACHINE}-v11-${SYSTEM}"; exit 0;
295	;;
296
297    NEWS-OS:4.*)
298	echo "mips-sony-newsos4"; exit 0;
299	;;
300
301    CYGWIN*)
302	echo "${MACHINE}-whatever-cygwin32"; exit 0
303	;;
304
305esac
306
307#
308# Ugg. These are all we can determine by what we know about
309# the output of uname. Be more creative:
310#
311
312# Do the Apollo stuff first. Here, we just simply assume
313# that the existance of the /usr/apollo directory is proof
314# enough
315if [ -d /usr/apollo ]; then
316    echo "whatever-apollo-whatever"
317    exit 0
318fi
319
320# Now NeXT
321ISNEXT=`hostinfo 2>/dev/null`
322case "$ISNEXT" in
323    *'NeXT Mach 3.3'*)
324	echo "whatever-next-nextstep3.3"; exit 0
325	;;
326    *NeXT*)
327	echo "whatever-next-nextstep"; exit 0
328	;;
329esac
330
331# At this point we gone through all the one's
332# we know of: Punt
333
334echo "${MACHINE}-whatever-${SYSTEM}" 
335exit 0
336) 2>/dev/null | (
337
338# ---------------------------------------------------------------------------
339# this is where the translation occurs into SSLeay terms
340# ---------------------------------------------------------------------------
341
342PREFIX=""
343SUFFIX=""
344TEST="false"
345
346# pick up any command line args to config
347for i
348do
349case "$i" in 
350-d*) PREFIX="debug-";;
351-t*) TEST="true";;
352-h*) TEST="true"; cat <<EOF
353Usage: config [options]
354 -d	Add a debug- prefix to machine choice.
355 -t	Test mode, do not run the Configure perl script.
356 -h	This help.
357
358Any other text will be passed to the Configure perl script.
359See INSTALL for instructions.
360
361EOF
362;;
363*) options=$options" $i" ;;
364esac
365done
366
367# figure out if gcc is available and if so we use it otherwise
368# we fallback to whatever cc does on the system
369GCCVER=`(gcc --version) 2>/dev/null`
370if [ "$GCCVER" != "" ]; then
371  CC=gcc
372  # then strip off whatever prefix Cygnus prepends the number with...
373  GCCVER=`echo $GCCVER | sed 's/^[a-z]*\-//'`
374  # peak single digit before and after first dot, e.g. 2.95.1 gives 29
375  GCCVER=`echo $GCCVER | sed 's/\([0-9]\)\.\([0-9]\).*/\1\2/'`
376else
377  CC=cc
378fi
379
380if [ "$SYSTEM" = "SunOS" ]; then
381  # check for WorkShop C, expected output is "cc: blah-blah C x.x"
382  CCVER=`(cc -V 2>&1) 2>/dev/null | \
383  	egrep -e '^cc: .* C [0-9]\.[0-9]' | \
384	sed 's/.* C \([0-9]\)\.\([0-9]\).*/\1\2/'`
385  CCVER=${CCVER:-0}
386  if [ $CCVER -gt 40 ]; then
387    CC=cc	# overrides gcc!!!
388    if [ $CCVER -eq 50 ]; then
389      echo "WARNING! Detected WorkShop C 5.0. Do make sure you have"
390      echo "         patch #107357-01 or later applied."
391      sleep 5
392    fi
393  elif [ "$CC" = "cc" -a $CCVER -gt 0 ]; then
394    CC=sc3
395  fi
396fi
397
398if [ "${SYSTEM}-${MACHINE}" = "Linux-alpha" ]; then
399  # check for Compaq C, expected output is "blah-blah C Vx.x"
400  CCCVER=`(ccc -V 2>&1) 2>/dev/null | \
401	egrep -e '.* C V[0-9]\.[0-9]' | \
402	sed 's/.* C V\([0-9]\)\.\([0-9]\).*/\1\2/'`
403  CCCVER=${CCCVER:-0}
404  if [ $CCCVER -gt 60 ]; then
405    CC=ccc	# overrides gcc!!! well, ccc outperforms inoticeably
406		# only on hash routines and des, otherwise gcc (2.95)
407		# keeps along rather tight...
408  fi
409fi
410
411GCCVER=${GCCVER:-0}
412CCVER=${CCVER:-0}
413
414# read the output of the embedded GuessOS 
415read GUESSOS
416
417echo Operating system: $GUESSOS
418
419# now map the output into SSLeay terms ... really should hack into the
420# script above so we end up with values in vars but that would take
421# more time that I want to waste at the moment
422case "$GUESSOS" in
423  mips2-sgi-irix)
424	CPU=`(hinv -t cpu) 2>/dev/null | sed 's/^CPU:[^R]*R\([0-9]*\).*/\1/'`
425	CPU=${CPU:-0}
426	if [ $CPU -ge 4000 ]; then
427		options="$options -mips2"
428	fi
429	OUT="irix-$CC"
430	;;
431  mips3-sgi-irix)
432	CPU=`(hinv -t cpu) 2>/dev/null | sed 's/^CPU:[^R]*R\([0-9]*\).*/\1/'`
433	CPU=${CPU:-0}
434	if [ $CPU -ge 5000 ]; then
435		options="$options -mips4"
436	else
437		options="$options -mips3"
438	fi
439	OUT="irix-mips3-$CC"
440	;;
441  mips4-sgi-irix64)
442	echo "WARNING! If you wish to build 64-bit library, then you have to"
443	echo "         invoke './Configure irix64-mips4-$CC' *manually*."
444	echo "         Type return if you want to continue, Ctrl-C to abort."
445	read waste < /dev/tty
446        CPU=`(hinv -t cpu) 2>/dev/null | sed 's/^CPU:[^R]*R\([0-9]*\).*/\1/'`
447        CPU=${CPU:-0}
448        if [ $CPU -ge 5000 ]; then
449                options="$options -mips4"
450        else
451                options="$options -mips3"
452        fi
453	OUT="irix-mips3-$CC"
454	;;
455  alpha-*-linux2)
456        ISA=`awk '/cpu model/{print$4}' /proc/cpuinfo`
457	case ${ISA:-generic} in
458	*[67])	OUT="linux-alpha+bwx-$CC" ;;
459	*)	OUT="linux-alpha-$CC" ;;
460	esac
461	if [ "$CC" = "gcc" ]; then
462	    case ${ISA:-generic} in
463	    EV5|EV45)		options="$options -mcpu=ev5";;
464	    EV56|PCA56)		options="$options -mcpu=ev56";;
465	    EV6|EV67|PCA57)	options="$options -mcpu=ev6";;
466	    esac
467	fi
468	;;
469  mips-*-linux?)
470          cat >dummy.c <<EOF
471#include <stdio.h>  /* for printf() prototype */
472        int main (argc, argv) int argc; char *argv[]; {
473#ifdef __MIPSEB__
474  printf ("linux-%s\n", argv[1]);
475#endif
476#ifdef __MIPSEL__
477  printf ("linux-%sel\n", argv[1]);
478#endif
479  return 0;
480}
481EOF
482	${CC} -o dummy dummy.c && OUT=`./dummy ${MACHINE}`
483	rm dummy dummy.c
484	;;
485  ppc-*-linux2) OUT="linux-ppc" ;;
486  m68k-*-linux*) OUT="linux-m68k" ;;
487  ia64-*-linux?) OUT="linux-ia64" ;;
488  ppc-apple-rhapsody) OUT="rhapsody-ppc-cc" ;;
489  ppc-apple-darwin) OUT="darwin-ppc-cc" ;;
490  sparc64-*-linux2)
491	#Before we can uncomment following lines we have to wait at least
492	#till 64-bit glibc for SPARC is operational:-(
493	#echo "WARNING! If you wish to build 64-bit library, then you have to"
494	#echo "         invoke './Configure linux64-sparcv9' *manually*."
495	#echo "         Type return if you want to continue, Ctrl-C to abort."
496	#read waste < /dev/tty
497	OUT="linux-sparcv9" ;;
498  sparc-*-linux2)
499	KARCH=`awk '/^type/{print$3}' /proc/cpuinfo`
500	case ${KARCH:-sun4} in
501	sun4u*)	OUT="linux-sparcv9" ;;
502	sun4m)	OUT="linux-sparcv8" ;;
503	sun4d)	OUT="linux-sparcv8" ;;
504	*)	OUT="linux-sparcv7" ;;
505	esac ;;
506  arm*-*-linux2) OUT="linux-elf-arm" ;;
507  s390-*-linux2) OUT="linux-s390" ;;
508  *-*-linux2) OUT="linux-elf" ;;
509  *-*-linux1) OUT="linux-aout" ;;
510  sun4u*-*-solaris2)
511	ISA64=`(isalist) 2>/dev/null | grep sparcv9`
512	if [ "$ISA64" != "" -a "$CC" = "cc" -a $CCVER -ge 50 ]; then
513		echo "WARNING! If you wish to build 64-bit library, then you have to"
514		echo "         invoke './Configure solaris64-sparcv9-cc' *manually*."
515		echo "         Type return if you want to continue, Ctrl-C to abort."
516		read waste < /dev/tty
517	fi
518	OUT="solaris-sparcv9-$CC" ;;
519  sun4m-*-solaris2)	OUT="solaris-sparcv8-$CC" ;;
520  sun4d-*-solaris2)	OUT="solaris-sparcv8-$CC" ;;
521  sun4*-*-solaris2)	OUT="solaris-sparcv7-$CC" ;;
522  *86*-*-solaris2) OUT="solaris-x86-$CC" ;;
523  *-*-sunos4) OUT="sunos-$CC" ;;
524  alpha*-*-freebsd*) OUT="FreeBSD-alpha" ;;
525  *-freebsd[3-9]*) OUT="FreeBSD-elf" ;;
526  *-freebsd[1-2]*) OUT="FreeBSD" ;;
527  *86*-*-netbsd) OUT="NetBSD-x86" ;;
528  sun3*-*-netbsd) OUT="NetBSD-m68" ;;
529  *-*-netbsd) OUT="NetBSD-sparc" ;;
530  *86*-*-openbsd) OUT="OpenBSD-x86" ;;
531  alpha*-*-openbsd) OUT="OpenBSD-alpha" ;;
532  pmax*-*-openbsd) OUT="OpenBSD-mips" ;;
533  *-*-openbsd) OUT="OpenBSD" ;;
534  *86*-*-bsdi4) OUT="bsdi-elf-gcc" ;;
535  *-*-osf) OUT="alphaold-cc" ;;
536  *-*-tru64) OUT="alpha-cc" ;;
537  *-*-OpenUNIX*)
538	if [ "$CC" = "gcc" ]; then
539	  OUT="OpenUNIX-8-gcc" 
540	else    
541	  OUT="OpenUNIX-8" 
542	fi
543	;;
544  *-*-unixware7) OUT="unixware-7" ;;
545  *-*-UnixWare7) OUT="unixware-7" ;;
546  *-*-Unixware7) OUT="unixware-7" ;;
547  *-*-unixware20*) OUT="unixware-2.0" ;;
548  *-*-unixware21*) OUT="unixware-2.1" ;;
549  *-*-UnixWare20*) OUT="unixware-2.0" ;;
550  *-*-UnixWare21*) OUT="unixware-2.1" ;;
551  *-*-Unixware20*) OUT="unixware-2.0" ;;
552  *-*-Unixware21*) OUT="unixware-2.1" ;;
553  BS2000-siemens-sysv4) OUT="BS2000-OSD" ;;
554  RM*-siemens-sysv4) OUT="ReliantUNIX" ;;
555  *-siemens-sysv4) OUT="SINIX" ;;
556  *-hpux1*)	OUT="hpux-parisc-$CC"
557		options="$options -D_REENTRANT" ;;
558  *-hpux)	OUT="hpux-parisc-$CC" ;;
559  # these are all covered by the catchall below
560  # *-aix) OUT="aix-$CC" ;;
561  # *-dgux) OUT="dgux" ;;
562  mips-sony-newsos4) OUT="newsos4-gcc" ;;
563  *-*-cygwin32) OUT="CygWin32"
564		options="$options no-threads no-asm" ;;
565  *) OUT=`echo $GUESSOS | awk -F- '{print $3}'`;;
566esac
567
568# See whether we can compile Atalla support
569if [ -f /usr/include/atasi.h ]
570then
571  options="$options -DATALLA"
572fi
573
574# gcc < 2.8 does not support -mcpu=ultrasparc
575if [ "$OUT" = solaris-sparcv9-gcc -a $GCCVER -lt 28 ]
576then
577  echo "WARNING! Do consider upgrading to gcc-2.8 or later."
578  sleep 5
579  OUT=solaris-sparcv9-gcc27
580fi
581if [ "$OUT" = "linux-sparcv9" -a $GCCVER -lt 28 ]
582then
583  echo "WARNING! Falling down to 'linux-sparcv8'."
584  echo "         Upgrade to gcc-2.8 or later."
585  sleep 5
586  OUT=linux-sparcv8
587fi
588
589case "$GUESSOS" in
590  i386-*) options="$options 386" ;;
591esac
592
593for i in bf cast des dh dsa hmac idea md2 md5 mdc2 rc2 rc4 rc5 ripemd rsa sha
594do
595  if [ ! -d crypto/$i ]
596  then
597    options="$options no-$i"
598  fi
599done
600
601if [ -z "$OUT" ]; then
602  OUT="$CC"
603fi
604
605if [ ".$PERL" = . ] ; then
606	for i in . `echo $PATH | sed 's/:/ /g'`; do
607		if [ -f "$i/perl5" ] ; then
608			PERL="$i/perl5"
609			break;
610		fi;
611	done
612fi
613
614if [ ".$PERL" = . ] ; then
615	for i in . `echo $PATH | sed 's/:/ /g'`; do
616		if [ -f "$i/perl" ] ; then
617			if "$i/perl" -e 'exit($]<5.0)'; then
618				PERL="$i/perl"
619				break;
620			fi;
621		fi;
622	done
623fi
624
625if [ ".$PERL" = . ] ; then
626	echo "You need Perl 5."
627	exit 1
628fi
629
630# run Configure to check to see if we need to specify the 
631# compiler for the platform ... in which case we add it on
632# the end ... otherwise we leave it off
633
634$PERL ./Configure LIST | grep "$OUT-$CC" > /dev/null
635if [ $? = "0" ]; then
636  OUT="$OUT-$CC"
637fi
638
639OUT="$PREFIX$OUT"
640
641$PERL ./Configure LIST | grep "$OUT" > /dev/null
642if [ $? = "0" ]; then
643  echo Configuring for $OUT
644
645  if [ "$TEST" = "true" ]; then
646    echo $PERL ./Configure $OUT $options
647  else
648    $PERL ./Configure $OUT $options
649  fi
650else
651  echo "This system ($OUT) is not supported. See file INSTALL for details."
652fi
653)
654