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