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