Set the 386 flag automatically when building on i386.
[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             10.*)
86                 echo "${MACHINE}-hp-hpux10."; exit 0
87                 ;;
88             *)
89                 echo "${MACHINE}-hp-hpux"; exit 0
90                 ;;
91         esac
92         ;;
93
94     IRIX:*)
95         echo "${MACHINE}-sgi-irix"; exit 0
96         ;;
97
98     IRIX64:*)
99         echo "${MACHINE}-sgi-irix64"; exit 0
100         ;;
101
102     Linux:[2-9].*)
103         echo "${MACHINE}-whatever-linux2"; exit 0
104         ;;
105
106     Linux:1.*)
107         echo "${MACHINE}-whatever-linux1"; exit 0
108         ;;
109
110     LynxOS:*)
111         echo "${MACHINE}-lynx-lynxos"; exit 0
112         ;;
113
114     BSD/386:*:*:*486*|BSD/OS:*:*:*:*486*)
115         echo "i486-whatever-bsdi"; exit 0
116         ;;
117
118     BSD/386:*|BSD/OS:*)
119         echo "${MACHINE}-whatever-bsdi"; exit 0
120         ;;
121
122     FreeBSD:3*:*:*)
123         echo "${MACHINE}-whatever-freebsd3"; exit 0
124         ;;
125
126     FreeBSD:*:*:*486*)
127         echo "i486-whatever-freebsd"; exit 0
128         ;;
129
130     FreeBSD:*)
131         echo "${MACHINE}-whatever-freebsd"; exit 0
132         ;;
133
134     NetBSD:*:*:*486*)
135         echo "i486-whatever-netbsd"; exit 0
136         ;;
137
138     NetBSD:*)
139         echo "${MACHINE}-whatever-netbsd"; exit 0
140         ;;
141
142     OpenBSD:*)
143         echo "${MACHINE}-whatever-openbsd"; exit 0
144         ;;
145
146     OSF1:*:*:*alpha*)
147         echo "${MACHINE}-dec-osf"; exit 0
148         ;;
149
150     QNX:*)
151         case "$VERSION" in
152             423)
153                 echo "${MACHINE}-qssl-qnx32"
154                 ;;
155             *)
156                 echo "${MACHINE}-qssl-qnx"
157                 ;;
158         esac
159         exit 0
160         ;;
161
162     Paragon*:*:*:*)
163         echo "i860-intel-osf1"; exit 0
164         ;;
165
166     SunOS:5.*)
167         echo "${MACHINE}-sun-solaris2"; exit 0
168         ;;
169
170     SunOS:*)
171         echo "${MACHINE}-sun-sunos4"; exit 0
172         ;;
173
174     UNIX_System_V:4.*:*)
175         echo "${MACHINE}-whatever-sysv4"; exit 0
176         ;;
177
178     *:4*:R4*:m88k)
179         echo "${MACHINE}-whatever-sysv4"; exit 0
180         ;;
181
182     DYNIX/ptx:4*:*)
183         echo "${MACHINE}-whatever-sysv4"; exit 0
184         ;;
185
186     *:4.0:3.0:3[34]?? | *:4.0:3.0:3[34]??,*)
187         echo "i486-ncr-sysv4"; exit 0
188         ;;
189
190     ULTRIX:*)
191         echo "${MACHINE}-unknown-ultrix"; exit 0
192         ;;
193
194     SINIX*)
195         echo "${MACHINE}-sni-sysv4"; exit 0
196         ;;
197
198     machten:*)
199        echo "${MACHINE}-tenon-${SYSTEM}"; exit 0;
200        ;;
201
202     library:*)
203         echo "${MACHINE}-ncr-sysv4"; exit 0
204         ;;
205
206     ConvexOS:*:11.0:*)
207         echo "${MACHINE}-v11-${SYSTEM}"; exit 0;
208         ;;
209
210 esac
211
212 #
213 # Ugg. These are all we can determine by what we know about
214 # the output of uname. Be more creative:
215 #
216
217 # Do the Apollo stuff first. Here, we just simply assume
218 # that the existance of the /usr/apollo directory is proof
219 # enough
220 if [ -d /usr/apollo ]; then
221     echo "whatever-apollo-whatever"
222     exit 0
223 fi
224
225 # Now NeXT
226 ISNEXT=`hostinfo 2>/dev/null`
227 case "$ISNEXT" in
228     *NeXT*)
229         echo "whatever-next-nextstep"; exit 0
230         ;;
231 esac
232
233 # At this point we gone through all the one's
234 # we know of: Punt
235
236 echo "${MACHINE}-whatever-${SYSTEM}|${RELEASE}|${VERSION}" 
237 exit 0
238 ) 2>/dev/null | (
239
240 # ---------------------------------------------------------------------------
241 # this is where the translation occurs into SSLeay terms
242 # ---------------------------------------------------------------------------
243
244 PREFIX=""
245 SUFFIX=""
246 VERBOSE="false"
247 TEST="false"
248
249 # pick up any command line args to config
250 for i
251 do
252 case "$i" in 
253 -d*) PREFIX="debug-";;
254 -v*) VERBOSE="true";;
255 -t*) TEST="true";;
256 -h*) TEST="true"; cat <<EOF
257 Usage: config [options]
258  -d     Add a debug- prefix to machine choice.
259  -v     Verbose mode.
260  -t     Test mode, do not run the Configure perl script.
261  -h     This help.
262
263 Any other text will be passed to the Configure perl script.
264 Useful options include
265  no-asm Build with no assember code.
266  -Dxxx  Add xxx define to compilation.
267  -Lxxx  Add xxx library include path to build.
268  -lxxx  Add xxx library to build.
269
270 EOF
271 ;;
272 *) options=$options" $i" ;;
273 esac
274 done
275
276 # figure out if gcc is available and if so we use it otherwise
277 # we fallback to whatever cc does on the system
278 GCCVER=`(gcc -v) 2>&1`
279 if [ $? = "0" ]; then
280   CC=gcc
281 else
282   CC=cc
283 fi
284
285 # read the output of the embedded GuessOS 
286 read GUESSOS
287
288 if [ "$VERBOSE" = "true" ]; then
289   echo GUESSOS $GUESSOS
290 fi
291
292 # now map the output into SSLeay terms ... really should hack into the
293 # script above so we end up with values in vars but that would take
294 # more time that I want to waste at the moment
295 case "$GUESSOS" in
296   alpha-*-linux2) OUT="alpha-gcc" ;;
297   ppc-*-linux2) OUT="linux-ppc" ;;
298   *-*-linux2) OUT="linux-elf" ;;
299   *-*-linux1) OUT="linux-aout" ;;
300   sun4*-sun-solaris2) OUT="solaris-sparc-$CC" ;;
301   *86*-sun-solaris2) OUT="solaris-x86-$CC" ;;
302   *-*-sunos4) OUT="sunos-$CC" ;;
303   *-freebsd3) OUT="FreeBSD-elf" ;;
304   *-freebsd) OUT="FreeBSD" ;;
305   *86*-*-netbsd) OUT="NetBSD-x86" ;;
306   sun3*-*-netbsd) OUT="NetBSD-m68" ;;
307   *-*-netbsd) OUT="NetBSD-sparc" ;;
308   *86*-*-openbsd) OUT="OpenBSD-x86" ;;
309   alpha*-*-openbsd) OUT="OpenBSD-alpha" ;;
310   pmax*-*-openbsd) OUT="OpenBSD-mips" ;;
311   *-*-openbsd) OUT="OpenBSD" ;;
312   *-*-osf) OUT="alpha-cc" ;;
313   *-*-unixware*) OUT="unixware-2.0" ;;
314   *-sni-sysv4) OUT="SINIX" ;;
315   *-hpux*) OUT="hpux-$CC" ;;
316   # these are all covered by the catchall below
317   # *-aix) OUT="aix-$CC" ;;
318   # *-dgux) OUT="dgux" ;;
319   *) OUT=`echo $GUESSOS | awk -F- '{print $3}'`;;
320 esac
321
322 case "$GUESSOS" in
323   i386-*) options="$options 386" ;;
324 esac
325
326 if [ -z "$OUT" ]; then
327   OUT="$CC"
328 fi
329
330 if [ ".$PERL" = . ] ; then
331         for i in . `echo $PATH | sed 's/:/ /g'`; do
332                 if [ -f "$i/perl5" ] ; then
333                         PERL="$i/perl5"
334                         break;
335                 fi;
336         done
337 fi
338
339 if [ ".$PERL" = . ] ; then
340         for i in . `echo $PATH | sed 's/:/ /g'`; do
341                 if [ -f "$i/perl" ] ; then
342                         if "$i/perl" -e 'exit($]<5.0)'; then
343                                 PERL="$i/perl"
344                                 break;
345                         fi;
346                 fi;
347         done
348 fi
349
350 if [ ".$PERL" = . ] ; then
351         echo "You need Perl 5."
352         exit 1
353 fi
354
355 # run Configure to check to see if we need to specify the 
356 # compiler for the platform ... in which case we add it on
357 # the end ... otherwise we leave it off
358
359 $PERL ./Configure 2>&1 | grep "$OUT-$CC" > /dev/null
360 if [ $? = "0" ]; then
361   OUT="$OUT-$CC"
362 fi
363
364 OUT="$PREFIX$OUT"
365
366 # at this point we have the answer ... which we could check again
367 # and then fallback to a vanilla SSLeay build but then this script
368 # wouldn't get updated
369 echo Configuring for $OUT
370
371 if [ "$TEST" = "true" ]; then
372   echo $PERL ./Configure $OUT $options
373 else
374   $PERL ./Configure $OUT $options
375 fi
376
377 )
378