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