Next step in tidying up the LHASH code.
[openssl.git] / config
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
25 MACHINE=`(uname -m) 2>/dev/null` || MACHINE="unknown"
26 RELEASE=`(uname -r) 2>/dev/null` || RELEASE="unknown"
27 SYSTEM=`(uname -s) 2>/dev/null`  || SYSTEM="unknown"
28 VERSION=`(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 (
35 XREL=`uname -X 2>/dev/null | grep "^Release" | awk '{print $3}'`
36 if [ "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
70 fi
71 # Now we simply scan though... In most cases, the SYSTEM info is enough
72 #
73 case "${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     Darwin:*)
207         echo "ppc-apple-darwin"; exit 0
208         ;;
209
210     SunOS:5.*)
211         echo "${MACHINE}-whatever-solaris2"; exit 0
212         ;;
213
214     SunOS:*)
215         echo "${MACHINE}-sun-sunos4"; exit 0
216         ;;
217
218     UNIX_System_V:4.*:*)
219         echo "${MACHINE}-whatever-sysv4"; exit 0
220         ;;
221
222     *:4*:R4*:m88k)
223         echo "${MACHINE}-whatever-sysv4"; exit 0
224         ;;
225
226     DYNIX/ptx:4*:*)
227         echo "${MACHINE}-whatever-sysv4"; exit 0
228         ;;
229
230     *:4.0:3.0:3[34]?? | *:4.0:3.0:3[34]??,*)
231         echo "i486-ncr-sysv4"; exit 0
232         ;;
233
234     ULTRIX:*)
235         echo "${MACHINE}-unknown-ultrix"; exit 0
236         ;;
237
238     SINIX*|ReliantUNIX*)
239         echo "${MACHINE}-siemens-sysv4"; exit 0
240         ;;
241
242     POSIX-BC*)
243         echo "${MACHINE}-siemens-sysv4"; exit 0   # Here, $MACHINE == "BS2000"
244         ;;
245
246     machten:*)
247        echo "${MACHINE}-tenon-${SYSTEM}"; exit 0;
248        ;;
249
250     library:*)
251         echo "${MACHINE}-ncr-sysv4"; exit 0
252         ;;
253
254     ConvexOS:*:11.0:*)
255         echo "${MACHINE}-v11-${SYSTEM}"; exit 0;
256         ;;
257
258     NEWS-OS:4.*)
259         echo "mips-sony-newsos4"; exit 0;
260         ;;
261
262 esac
263
264 #
265 # Ugg. These are all we can determine by what we know about
266 # the output of uname. Be more creative:
267 #
268
269 # Do the Apollo stuff first. Here, we just simply assume
270 # that the existance of the /usr/apollo directory is proof
271 # enough
272 if [ -d /usr/apollo ]; then
273     echo "whatever-apollo-whatever"
274     exit 0
275 fi
276
277 # Now NeXT
278 ISNEXT=`hostinfo 2>/dev/null`
279 case "$ISNEXT" in
280     *'NeXT Mach 3.3'*)
281         echo "whatever-next-nextstep3.3"; exit 0
282         ;;
283     *NeXT*)
284         echo "whatever-next-nextstep"; exit 0
285         ;;
286 esac
287
288 # At this point we gone through all the one's
289 # we know of: Punt
290
291 echo "${MACHINE}-whatever-${SYSTEM}" 
292 exit 0
293 ) 2>/dev/null | (
294
295 # ---------------------------------------------------------------------------
296 # this is where the translation occurs into SSLeay terms
297 # ---------------------------------------------------------------------------
298
299 PREFIX=""
300 SUFFIX=""
301 TEST="false"
302
303 # pick up any command line args to config
304 for i
305 do
306 case "$i" in 
307 -d*) PREFIX="debug-";;
308 -t*) TEST="true";;
309 -h*) TEST="true"; cat <<EOF
310 Usage: config [options]
311  -d     Add a debug- prefix to machine choice.
312  -t     Test mode, do not run the Configure perl script.
313  -h     This help.
314
315 Any other text will be passed to the Configure perl script.
316 See INSTALL for instructions.
317
318 EOF
319 ;;
320 *) options=$options" $i" ;;
321 esac
322 done
323
324 # figure out if gcc is available and if so we use it otherwise
325 # we fallback to whatever cc does on the system
326 GCCVER=`(gcc --version) 2>/dev/null`
327 if [ "$GCCVER" != "" ]; then
328   CC=gcc
329   # then strip off whatever prefix Cygnus prepends the number with...
330   GCCVER=`echo $GCCVER | sed 's/^[a-z]*\-//'`
331   # peak single digit before and after first dot, e.g. 2.95.1 gives 29
332   GCCVER=`echo $GCCVER | sed 's/\([0-9]\)\.\([0-9]\).*/\1\2/'`
333 else
334   CC=cc
335 fi
336
337 if [ "$SYSTEM" = "SunOS" ]; then
338   # check for WorkShop C, expected output is "cc: blah-blah C x.x"
339   CCVER=`(cc -V 2>&1) 2>/dev/null | \
340         egrep -e '^cc: .* C [0-9]\.[0-9]' | \
341         sed 's/.* C \([0-9]\)\.\([0-9]\).*/\1\2/'`
342   CCVER=${CCVER:-0}
343   if [ $CCVER -gt 40 ]; then
344     CC=cc       # overrides gcc!!!
345     if [ $CCVER -eq 50 ]; then
346       echo "WARNING! Detected WorkShop C 5.0. Do make sure you have"
347       echo "         patch #107357-01 or later applied."
348       sleep 5
349     fi
350   elif [ "$CC" = "cc" -a $CCVER -gt 0 ]; then
351     CC=sc3
352   fi
353 fi
354
355 if [ "${SYSTEM}-${MACHINE}" = "Linux-alpha" ]; then
356   # check for Compaq C, expected output is "blah-blah C Vx.x"
357   CCCVER=`(ccc -V 2>&1) 2>/dev/null | \
358         egrep -e '.* C V[0-9]\.[0-9]' | \
359         sed 's/.* C V\([0-9]\)\.\([0-9]\).*/\1\2/'`
360   CCCVER=${CCCVER:-0}
361   if [ $CCCVER -gt 60 ]; then
362     CC=ccc      # overrides gcc!!! well, ccc outperforms inoticeably
363                 # only on hash routines and des, otherwise gcc (2.95)
364                 # keeps along rather tight...
365   fi
366 fi
367
368 GCCVER=${GCCVER:-0}
369 CCVER=${CCVER:-0}
370
371 # read the output of the embedded GuessOS 
372 read GUESSOS
373
374 echo Operating system: $GUESSOS
375
376 # now map the output into SSLeay terms ... really should hack into the
377 # script above so we end up with values in vars but that would take
378 # more time that I want to waste at the moment
379 case "$GUESSOS" in
380   mips2-sgi-irix)
381         CPU=`(hinv -t cpu) 2>/dev/null | sed 's/^CPU:[^R]*R\([0-9]*\).*/\1/'`
382         CPU=${CPU:-0}
383         if [ $CPU -ge 4000 ]; then
384                 options="$options -mips2"
385         fi
386         OUT="irix-$CC"
387         ;;
388   mips3-sgi-irix)
389         CPU=`(hinv -t cpu) 2>/dev/null | sed 's/^CPU:[^R]*R\([0-9]*\).*/\1/'`
390         CPU=${CPU:-0}
391         if [ $CPU -ge 5000 ]; then
392                 options="$options -mips4"
393         else
394                 options="$options -mips3"
395         fi
396         OUT="irix-mips3-$CC"
397         ;;
398   mips4-sgi-irix64)
399         echo "WARNING! If you wish to build 64-bit library, then you have to"
400         echo "         invoke './Configre irix64-mips4-$CC' *manually*."
401         echo "         Type Ctrl-C if you don't want to continue."
402         read waste < /dev/tty
403         options="$options -mips4"
404         OUT="irix-mips3-$CC"
405         ;;
406   alpha-*-linux2)
407         ISA=`awk '/cpu model/{print$4}' /proc/cpuinfo`
408         case ${ISA:-generic} in
409         *[67])  OUT="linux-alpha+bwx-$CC" ;;
410         *)      OUT="linux-alpha-$CC" ;;
411         esac
412         if [ "$CC" = "gcc" ]; then
413             case ${ISA:-generic} in
414             EV5|EV45)           options="$options -mcpu=ev5";;
415             EV56|PCA56)         options="$options -mcpu=ev56";;
416             EV6|EV67|PCA57)     options="$options -mcpu=ev6";;
417             esac
418         fi
419         ;;
420   mips-*-linux?)
421           cat >dummy.c <<EOF
422 #include <stdio.h>  /* for printf() prototype */
423         int main (argc, argv) int argc; char *argv[]; {
424 #ifdef __MIPSEB__
425   printf ("linux-%s\n", argv[1]);
426 #endif
427 #ifdef __MIPSEL__
428   printf ("linux-%sel\n", argv[1]);
429 #endif
430   return 0;
431 }
432 EOF
433         ${CC} -o dummy dummy.c && OUT=`./dummy ${MACHINE}`
434         rm dummy dummy.c
435         ;;
436   ppc-*-linux2) OUT="linux-ppc" ;;
437   m68k-*-linux*) OUT="linux-m68k" ;;
438   ia64-*-linux?) OUT="linux-ia64" ;;
439   ppc-apple-rhapsody) OUT="rhapsody-ppc-cc" ;;
440   ppc-apple-darwin) OUT="darwin-ppc-cc" ;;
441   sparc64-*-linux2)
442         #Before we can uncomment following lines we have to wait at least
443         #till 64-bit glibc for SPARC is operational:-(
444         #echo "WARNING! If you wish to build 64-bit library, then you have to"
445         #echo "         invoke './Configure linux64-sparcv9' *manually*."
446         #echo "         Type Ctrl-C if you don't want to continue."
447         #read waste < /dev/tty
448         OUT="linux-sparcv9" ;;
449   sparc-*-linux2)
450         KARCH=`awk '/^type/{print$3}' /proc/cpuinfo`
451         case ${KARCH:-sun4} in
452         sun4u*) OUT="linux-sparcv9" ;;
453         sun4m)  OUT="linux-sparcv8" ;;
454         sun4d)  OUT="linux-sparcv8" ;;
455         *)      OUT="linux-sparcv7" ;;
456         esac ;;
457   arm*-*-linux2) OUT="linux-elf-arm" ;;
458   *-*-linux2) OUT="linux-elf" ;;
459   *-*-linux1) OUT="linux-aout" ;;
460   sun4u*-*-solaris2)
461         ISA64=`(isalist) 2>/dev/null | grep sparcv9`
462         if [ "$ISA64" != "" -a "$CC" = "cc" -a $CCVER -ge 50 ]; then
463                 echo "WARNING! If you wish to build 64-bit library, then you have to"
464                 echo "         invoke './Configure solaris64-sparcv9-cc' *manually*."
465                 echo "         Type Ctrl-C if you don't want to continue."
466                 read waste < /dev/tty
467         fi
468         OUT="solaris-sparcv9-$CC" ;;
469   sun4m-*-solaris2)     OUT="solaris-sparcv8-$CC" ;;
470   sun4d-*-solaris2)     OUT="solaris-sparcv8-$CC" ;;
471   sun4*-*-solaris2)     OUT="solaris-sparcv7-$CC" ;;
472   *86*-*-solaris2) OUT="solaris-x86-$CC" ;;
473   *-*-sunos4) OUT="sunos-$CC" ;;
474   alpha*-*-freebsd*) OUT="FreeBSD-alpha" ;;
475   *-freebsd[3-9]*) OUT="FreeBSD-elf" ;;
476   *-freebsd[1-2]*) OUT="FreeBSD" ;;
477   *86*-*-netbsd) OUT="NetBSD-x86" ;;
478   sun3*-*-netbsd) OUT="NetBSD-m68" ;;
479   *-*-netbsd) OUT="NetBSD-sparc" ;;
480   *86*-*-openbsd) OUT="OpenBSD-x86" ;;
481   alpha*-*-openbsd) OUT="OpenBSD-alpha" ;;
482   pmax*-*-openbsd) OUT="OpenBSD-mips" ;;
483   *-*-openbsd) OUT="OpenBSD" ;;
484   *86*-*-bsdi4) OUT="bsdi-elf-gcc" ;;
485   *-*-osf) OUT="alpha-cc" ;;
486   *-*-unixware7) OUT="unixware-7" ;;
487   *-*-UnixWare7) OUT="unixware-7" ;;
488   *-*-Unixware7) OUT="unixware-7" ;;
489   *-*-unixware[1-2]*) OUT="unixware-2.0" ;;
490   *-*-UnixWare[1-2]*) OUT="unixware-2.0" ;;
491   *-*-Unixware[1-2]*) OUT="unixware-2.0" ;;
492   BS2000-siemens-sysv4) OUT="BS2000-OSD" ;;
493   RM*-siemens-sysv4) OUT="ReliantUNIX" ;;
494   *-siemens-sysv4) OUT="SINIX" ;;
495   *-hpux1*)     OUT="hpux-parisc-$CC"
496                 options="$options -D_REENTRANT" ;;
497   *-hpux)       OUT="hpux-parisc-$CC" ;;
498   # these are all covered by the catchall below
499   # *-aix) OUT="aix-$CC" ;;
500   # *-dgux) OUT="dgux" ;;
501   mips-sony-newsos4) OUT="newsos4-gcc" ;;
502   *) OUT=`echo $GUESSOS | awk -F- '{print $3}'`;;
503 esac
504
505 # NB: This atalla support has been superceded by the ENGINE support
506 # That contains its own header and definitions anyway. Support can
507 # be enabled or disabled on any supported platform without external
508 # headers, eg. by adding the "hw-atalla" switch to ./config or
509 # perl Configure
510 #
511 # See whether we can compile Atalla support
512 #if [ -f /usr/include/atasi.h ]
513 #then
514 #  options="$options -DATALLA"
515 #fi
516
517 # gcc < 2.8 does not support -mcpu=ultrasparc
518 if [ "$OUT" = solaris-sparcv9-gcc -a $GCCVER -lt 28 ]
519 then
520   echo "WARNING! Do consider upgrading to gcc-2.8 or later."
521   sleep 5
522   OUT=solaris-sparcv9-gcc27
523 fi
524 if [ "$OUT" = "linux-sparcv9" -a $GCCVER -lt 28 ]
525 then
526   echo "WARNING! Falling down to 'linux-sparcv8'."
527   echo "         Upgrade to gcc-2.8 or later."
528   sleep 5
529   OUT=linux-sparcv8
530 fi
531
532 case "$GUESSOS" in
533   i386-*) options="$options 386" ;;
534 esac
535
536 for i in bf cast des dh dsa hmac md2 md5 mdc2 rc2 rc4 rc5 ripemd rsa sha
537 do
538   if [ ! -d crypto/$i ]
539   then
540     options="$options no-$i"
541   fi
542 done
543
544 # Discover Kerberos 5 (since it's still a prototype, we don't
545 # do any guesses yet, that's why this section is commented away.
546 #if [ -d /usr/kerberos ]; then
547 #    krb5_dir=/usr/kerberos
548 #    if [ \( -f $krb5_dir/lib/libgssapi_krb5.a -o -f $krb5_dir/lib/libgssapi_krb5.so* \)\
549 #       -a \( -f $krb5_dir/lib/libkrb5.a -o -f $krb5_dir/lib/libkrb5.so* \)\
550 #       -a \( -f $krb5_dir/lib/libcom_err.a -o -f $krb5_dir/lib/libcom_err.so* \)\
551 #       -a \( -f $krb5_dir/lib/libk5crypto.a -o -f $krb5_dir/lib/libk5crypto.so* \)\
552 #       -a \( -f $krb5_dir/include/krb5.h \) ]; then
553 #       options="$options --with-krb5-flavor=MIT"
554 #    fi
555 #elif [ -d /usr/heimdal ]; then
556 #    krb5_dir=/usr/heimdal
557 #    if [ \( -f $krb5_dir/lib/libgssapi.a -o -f $krb5_dir/lib/libgssapi.so* \)\
558 #       -a \( -f $krb5_dir/lib/libkrb5.a -o -f $krb5_dir/lib/libkrb5.so* \)\
559 #       -a \( -f $krb5_dir/lib/libcom_err.a -o -f $krb5_dir/lib/libcom_err.so* \)\
560 #       -a \( -f $krb5_dir/include/krb5.h \) ]; then
561 #       options="$options --with-krb5-flavor=Heimdal"
562 #    fi
563 #fi
564
565 if [ -z "$OUT" ]; then
566   OUT="$CC"
567 fi
568
569 if [ ".$PERL" = . ] ; then
570         for i in . `echo $PATH | sed 's/:/ /g'`; do
571                 if [ -f "$i/perl5" ] ; then
572                         PERL="$i/perl5"
573                         break;
574                 fi;
575         done
576 fi
577
578 if [ ".$PERL" = . ] ; then
579         for i in . `echo $PATH | sed 's/:/ /g'`; do
580                 if [ -f "$i/perl" ] ; then
581                         if "$i/perl" -e 'exit($]<5.0)'; then
582                                 PERL="$i/perl"
583                                 break;
584                         fi;
585                 fi;
586         done
587 fi
588
589 if [ ".$PERL" = . ] ; then
590         echo "You need Perl 5."
591         exit 1
592 fi
593
594 # run Configure to check to see if we need to specify the 
595 # compiler for the platform ... in which case we add it on
596 # the end ... otherwise we leave it off
597
598 $PERL ./Configure LIST | grep "$OUT-$CC" > /dev/null
599 if [ $? = "0" ]; then
600   OUT="$OUT-$CC"
601 fi
602
603 OUT="$PREFIX$OUT"
604
605 $PERL ./Configure LIST | grep "$OUT" > /dev/null
606 if [ $? = "0" ]; then
607   echo Configuring for $OUT
608
609   if [ "$TEST" = "true" ]; then
610     echo $PERL ./Configure $OUT $options
611   else
612     $PERL ./Configure $OUT $options
613   fi
614 else
615   echo "This system ($OUT) is not supported. See file INSTALL for details."
616 fi
617 )