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