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