don't use shell functions
[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         echo "${MACHINE}-dec-osf"; exit 0
200         ;;
201
202     QNX:*)
203         case "$VERSION" in
204             4*)
205                 echo "${MACHINE}-whatever-qnx4"
206                 ;;
207             *)
208                 echo "${MACHINE}-whatever-qnx"
209                 ;;
210         esac
211         exit 0
212         ;;
213
214     Paragon*:*:*:*)
215         echo "i860-intel-osf1"; exit 0
216         ;;
217
218     Rhapsody:*)
219         echo "ppc-apple-rhapsody"; exit 0
220         ;;
221
222     SunOS:5.*)
223         echo "${MACHINE}-whatever-solaris2"; exit 0
224         ;;
225
226     SunOS:*)
227         echo "${MACHINE}-sun-sunos4"; exit 0
228         ;;
229
230     UNIX_System_V:4.*:*)
231         echo "${MACHINE}-whatever-sysv4"; exit 0
232         ;;
233
234     *:4*:R4*:m88k)
235         echo "${MACHINE}-whatever-sysv4"; exit 0
236         ;;
237
238     DYNIX/ptx:4*:*)
239         echo "${MACHINE}-whatever-sysv4"; exit 0
240         ;;
241
242     *:4.0:3.0:3[34]?? | *:4.0:3.0:3[34]??,*)
243         echo "i486-ncr-sysv4"; exit 0
244         ;;
245
246     ULTRIX:*)
247         echo "${MACHINE}-unknown-ultrix"; exit 0
248         ;;
249
250     SINIX*|ReliantUNIX*)
251         echo "${MACHINE}-siemens-sysv4"; exit 0
252         ;;
253
254     POSIX-BC*)
255         echo "${MACHINE}-siemens-sysv4"; exit 0   # Here, $MACHINE == "BS2000"
256         ;;
257
258     machten:*)
259        echo "${MACHINE}-tenon-${SYSTEM}"; exit 0;
260        ;;
261
262     library:*)
263         echo "${MACHINE}-ncr-sysv4"; exit 0
264         ;;
265
266     ConvexOS:*:11.0:*)
267         echo "${MACHINE}-v11-${SYSTEM}"; exit 0;
268         ;;
269
270     NEWS-OS:4.*)
271         echo "mips-sony-newsos4"; exit 0;
272         ;;
273
274 esac
275
276 #
277 # Ugg. These are all we can determine by what we know about
278 # the output of uname. Be more creative:
279 #
280
281 # Do the Apollo stuff first. Here, we just simply assume
282 # that the existance of the /usr/apollo directory is proof
283 # enough
284 if [ -d /usr/apollo ]; then
285     echo "whatever-apollo-whatever"
286     exit 0
287 fi
288
289 # Now NeXT
290 ISNEXT=`hostinfo 2>/dev/null`
291 case "$ISNEXT" in
292     *'NeXT Mach 3.3'*)
293         echo "whatever-next-nextstep3.3"; exit 0
294         ;;
295     *NeXT*)
296         echo "whatever-next-nextstep"; exit 0
297         ;;
298 esac
299
300 # At this point we gone through all the one's
301 # we know of: Punt
302
303 echo "${MACHINE}-whatever-${SYSTEM}" 
304 exit 0
305 ) 2>/dev/null | (
306
307 # ---------------------------------------------------------------------------
308 # this is where the translation occurs into SSLeay terms
309 # ---------------------------------------------------------------------------
310
311 PREFIX=""
312 SUFFIX=""
313 TEST="false"
314
315 # pick up any command line args to config
316 for i
317 do
318 case "$i" in 
319 -d*) PREFIX="debug-";;
320 -t*) TEST="true";;
321 -h*) TEST="true"; cat <<EOF
322 Usage: config [options]
323  -d     Add a debug- prefix to machine choice.
324  -t     Test mode, do not run the Configure perl script.
325  -h     This help.
326
327 Any other text will be passed to the Configure perl script.
328 See INSTALL for instructions.
329
330 EOF
331 ;;
332 *) options=$options" $i" ;;
333 esac
334 done
335
336 # figure out if gcc is available and if so we use it otherwise
337 # we fallback to whatever cc does on the system
338 GCCVER=`(gcc --version) 2>/dev/null`
339 if [ "$GCCVER" != "" ]; then
340   CC=gcc
341   # then strip off whatever prefix Cygnus prepends the number with...
342   GCCVER=`echo $GCCVER | sed 's/^[a-z]*\-//'`
343   # peak single digit before and after first dot, e.g. 2.95.1 gives 29
344   GCCVER=`echo $GCCVER | sed 's/\([0-9]\)\.\([0-9]\).*/\1\2/'`
345 else
346   CC=cc
347 fi
348
349 if [ "$SYSTEM" = "SunOS" ]; then
350   # check for WorkShop C, expected output is "cc: blah-blah C x.x"
351   CCVER=`(cc -V 2>&1) 2>/dev/null | \
352         egrep -e '^cc: .* C [0-9]\.[0-9]' | \
353         sed 's/.* C \([0-9]\)\.\([0-9]\).*/\1\2/'`
354   CCVER=${CCVER:-0}
355   if [ $CCVER -gt 40 ]; then
356     CC=cc       # overrides gcc!!!
357     if [ $CCVER -eq 50 ]; then
358       echo "WARNING! Detected WorkShop C 5.0. Do make sure you have"
359       echo "         patch #107357-01 or later applied."
360       sleep 5
361     fi
362   elif [ "$CC" = "cc" -a $CCVER -gt 0 ]; then
363     CC=sc3
364   fi
365 fi
366
367 if [ "${SYSTEM}-${MACHINE}" = "Linux-alpha" ]; then
368   # check for Compaq C, expected output is "blah-blah C Vx.x"
369   CCCVER=`(ccc -V 2>&1) 2>/dev/null | \
370         egrep -e '.* C V[0-9]\.[0-9]' | \
371         sed 's/.* C V\([0-9]\)\.\([0-9]\).*/\1\2/'`
372   CCCVER=${CCCVER:-0}
373   if [ $CCCVER -gt 60 ]; then
374     CC=ccc      # overrides gcc!!! well, ccc outperforms inoticeably
375                 # only on hash routines and des, otherwise gcc (2.95)
376                 # keeps along rather tight...
377   fi
378 fi
379
380 GCCVER=${GCCVER:-0}
381 CCVER=${CCVER:-0}
382
383 # read the output of the embedded GuessOS 
384 read GUESSOS
385
386 echo Operating system: $GUESSOS
387
388 # now map the output into SSLeay terms ... really should hack into the
389 # script above so we end up with values in vars but that would take
390 # more time that I want to waste at the moment
391 case "$GUESSOS" in
392   mips2-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 4000 ]; then
396                 options="$options -mips2"
397         fi
398         OUT="irix-$CC"
399         ;;
400   mips3-sgi-irix)
401         CPU=`(hinv -t cpu) 2>/dev/null | sed 's/^CPU:[^R]*R\([0-9]*\).*/\1/'`
402         CPU=${CPU:-0}
403         if [ $CPU -ge 5000 ]; then
404                 options="$options -mips4"
405         else
406                 options="$options -mips3"
407         fi
408         OUT="irix-mips3-$CC"
409         ;;
410   mips4-sgi-irix64)
411         echo "WARNING! If you wish to build 64-bit library, then you have to"
412         echo "         invoke './Configure irix64-mips4-$CC' *manually*."
413         echo "         Type return if you want to continue, Ctrl-C to abort."
414         read waste < /dev/tty
415         CPU=`(hinv -t cpu) 2>/dev/null | sed 's/^CPU:[^R]*R\([0-9]*\).*/\1/'`
416         CPU=${CPU:-0}
417         if [ $CPU -ge 5000 ]; then
418                 options="$options -mips4"
419         else
420                 options="$options -mips3"
421         fi
422         OUT="irix-mips3-$CC"
423         ;;
424   alpha-*-linux2)
425         ISA=`awk '/cpu model/{print$4}' /proc/cpuinfo`
426         case ${ISA:-generic} in
427         *[67])  OUT="linux-alpha+bwx-$CC" ;;
428         *)      OUT="linux-alpha-$CC" ;;
429         esac
430         if [ "$CC" = "gcc" ]; then
431             case ${ISA:-generic} in
432             EV5|EV45)           options="$options -mcpu=ev5";;
433             EV56|PCA56)         options="$options -mcpu=ev56";;
434             EV6|EV67|PCA57)     options="$options -mcpu=ev6";;
435             esac
436         fi
437         ;;
438   mips-*-linux?) OUT="linux-mips" ;;
439   ppc-*-linux2) OUT="linux-ppc" ;;
440   m68k-*-linux*) OUT="linux-m68k" ;;
441   ia64-*-linux?) OUT="linux-ia64" ;;
442   ppc-apple-rhapsody) OUT="rhapsody-ppc-cc" ;;
443   sparc64-*-linux2)
444         #Before we can uncomment following lines we have to wait at least
445         #till 64-bit glibc for SPARC is operational:-(
446         #echo "WARNING! If you wish to build 64-bit library, then you have to"
447         #echo "         invoke './Configure linux64-sparcv9' *manually*."
448         #echo "         Type return if you want to continue, Ctrl-C to abort."
449         #read waste < /dev/tty
450         OUT="linux-sparcv9" ;;
451   sparc-*-linux2)
452         KARCH=`awk '/^type/{print$3}' /proc/cpuinfo`
453         case ${KARCH:-sun4} in
454         sun4u*) OUT="linux-sparcv9" ;;
455         sun4m)  OUT="linux-sparcv8" ;;
456         sun4d)  OUT="linux-sparcv8" ;;
457         *)      OUT="linux-sparcv7" ;;
458         esac ;;
459   arm*-*-linux2) OUT="linux-elf-arm" ;;
460   s390-*-linux2) OUT="linux-s390" ;;
461   *-*-linux2) OUT="linux-elf" ;;
462   *-*-linux1) OUT="linux-aout" ;;
463   sun4u*-*-solaris2)
464         ISA64=`(isalist) 2>/dev/null | grep sparcv9`
465         if [ "$ISA64" != "" -a "$CC" = "cc" -a $CCVER -ge 50 ]; then
466                 echo "WARNING! If you wish to build 64-bit library, then you have to"
467                 echo "         invoke './Configure solaris64-sparcv9-cc' *manually*."
468                 echo "         Type return if you want to continue, Ctrl-C to abort."
469                 read waste < /dev/tty
470         fi
471         OUT="solaris-sparcv9-$CC" ;;
472   sun4m-*-solaris2)     OUT="solaris-sparcv8-$CC" ;;
473   sun4d-*-solaris2)     OUT="solaris-sparcv8-$CC" ;;
474   sun4*-*-solaris2)     OUT="solaris-sparcv7-$CC" ;;
475   *86*-*-solaris2) OUT="solaris-x86-$CC" ;;
476   *-*-sunos4) OUT="sunos-$CC" ;;
477   alpha*-*-freebsd*) OUT="FreeBSD-alpha" ;;
478   *-freebsd[3-9]*) OUT="FreeBSD-elf" ;;
479   *-freebsd[1-2]*) OUT="FreeBSD" ;;
480   *86*-*-netbsd) OUT="NetBSD-x86" ;;
481   sun3*-*-netbsd) OUT="NetBSD-m68" ;;
482   *-*-netbsd) OUT="NetBSD-sparc" ;;
483   *86*-*-openbsd) OUT="OpenBSD-x86" ;;
484   alpha*-*-openbsd) OUT="OpenBSD-alpha" ;;
485   pmax*-*-openbsd) OUT="OpenBSD-mips" ;;
486   *-*-openbsd) OUT="OpenBSD" ;;
487   *86*-*-bsdi4) OUT="bsdi-elf-gcc" ;;
488   *-*-osf) OUT="alpha-cc" ;;
489   *-*-unixware7) OUT="unixware-7" ;;
490   *-*-UnixWare7) OUT="unixware-7" ;;
491   *-*-Unixware7) OUT="unixware-7" ;;
492   *-*-unixware20*) OUT="unixware-2.0" ;;
493   *-*-unixware21*) OUT="unixware-2.1" ;;
494   *-*-UnixWare20*) OUT="unixware-2.0" ;;
495   *-*-UnixWare21*) OUT="unixware-2.1" ;;
496   *-*-Unixware20*) OUT="unixware-2.0" ;;
497   *-*-Unixware21*) OUT="unixware-2.1" ;;
498   BS2000-siemens-sysv4) OUT="BS2000-OSD" ;;
499   RM*-siemens-sysv4) OUT="ReliantUNIX" ;;
500   *-siemens-sysv4) OUT="SINIX" ;;
501   *-hpux1*)     OUT="hpux-parisc-$CC"
502                 options="$options -D_REENTRANT" ;;
503   *-hpux)       OUT="hpux-parisc-$CC" ;;
504   # these are all covered by the catchall below
505   # *-aix) OUT="aix-$CC" ;;
506   # *-dgux) OUT="dgux" ;;
507   mips-sony-newsos4) OUT="newsos4-gcc" ;;
508   *) OUT=`echo $GUESSOS | awk -F- '{print $3}'`;;
509 esac
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 if [ -z "$OUT" ]; then
545   OUT="$CC"
546 fi
547
548 if [ ".$PERL" = . ] ; then
549         for i in . `echo $PATH | sed 's/:/ /g'`; do
550                 if [ -f "$i/perl5" ] ; then
551                         PERL="$i/perl5"
552                         break;
553                 fi;
554         done
555 fi
556
557 if [ ".$PERL" = . ] ; then
558         for i in . `echo $PATH | sed 's/:/ /g'`; do
559                 if [ -f "$i/perl" ] ; then
560                         if "$i/perl" -e 'exit($]<5.0)'; then
561                                 PERL="$i/perl"
562                                 break;
563                         fi;
564                 fi;
565         done
566 fi
567
568 if [ ".$PERL" = . ] ; then
569         echo "You need Perl 5."
570         exit 1
571 fi
572
573 # run Configure to check to see if we need to specify the 
574 # compiler for the platform ... in which case we add it on
575 # the end ... otherwise we leave it off
576
577 $PERL ./Configure LIST | grep "$OUT-$CC" > /dev/null
578 if [ $? = "0" ]; then
579   OUT="$OUT-$CC"
580 fi
581
582 OUT="$PREFIX$OUT"
583
584 $PERL ./Configure LIST | grep "$OUT" > /dev/null
585 if [ $? = "0" ]; then
586   echo Configuring for $OUT
587
588   if [ "$TEST" = "true" ]; then
589     echo $PERL ./Configure $OUT $options
590   else
591     $PERL ./Configure $OUT $options
592   fi
593 else
594   echo "This system ($OUT) is not supported. See file INSTALL for details."
595 fi
596 )