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