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