Improve struct tm population
[openssl.git] / config
1 #!/bin/sh
2 # Copyright 1998-2017 The OpenSSL Project Authors. All Rights Reserved.
3 #
4 # Licensed under the OpenSSL license (the "License").  You may not use
5 # this file except in compliance with the License.  You can obtain a copy
6 # in the file LICENSE in the source distribution or at
7 # https://www.openssl.org/source/license.html
8
9 # OpenSSL config: determine the operating system and run ./Configure
10 # Derived from minarch and GuessOS from Apache.
11 #
12 # Do "config -h" for usage information.
13 SUFFIX=""
14 DRYRUN="false"
15 VERBOSE="false"
16 EXE=""
17 THERE=`dirname $0`
18
19 # pick up any command line args to config
20 for i
21 do
22 case "$i" in 
23 -d*) options=$options" --debug";;
24 -t*) DRYRUN="true" VERBOSE="true";;
25 -v*) VERBOSE="true";;
26 -h*) DRYRUN="true"; cat <<EOF
27 Usage: config [options]
28  -d     Build with debugging when possible.
29  -t     Test mode, do not run the Configure perl script.
30  -v     Verbose mode, show the exact Configure call that is being made.
31  -h     This help.
32
33 Any other text will be passed to the Configure perl script.
34 See INSTALL for instructions.
35
36 EOF
37 ;;
38 *) options=$options" $i" ;;
39 esac
40 done
41
42 # First get uname entries that we use below
43
44 [ "$MACHINE" ] || MACHINE=`(uname -m) 2>/dev/null` || MACHINE="unknown"
45 [ "$RELEASE" ] || RELEASE=`(uname -r) 2>/dev/null` || RELEASE="unknown"
46 [ "$SYSTEM" ] || SYSTEM=`(uname -s) 2>/dev/null`  || SYSTEM="unknown"
47 [ "$BUILD" ] || VERSION=`(uname -v) 2>/dev/null` || VERSION="unknown"
48
49
50 # Now test for ISC and SCO, since it is has a braindamaged uname.
51 #
52 # We need to work around FreeBSD 1.1.5.1 
53 (
54 XREL=`uname -X 2>/dev/null | grep "^Release" | awk '{print $3}'`
55 if [ "x$XREL" != "x" ]; then
56     if [ -f /etc/kconfig ]; then
57         case "$XREL" in
58             4.0|4.1)
59                     echo "${MACHINE}-whatever-isc4"; exit 0
60                 ;;
61         esac
62     else
63         case "$XREL" in
64             3.2v4.2)
65                 echo "whatever-whatever-sco3"; exit 0
66                 ;;
67             3.2v5.0*)
68                 echo "whatever-whatever-sco5"; exit 0
69                 ;;
70             4.2MP)
71                 case "x${VERSION}" in
72                     x2.0*) echo "whatever-whatever-unixware20"; exit 0 ;;
73                     x2.1*) echo "whatever-whatever-unixware21"; exit 0 ;;
74                     x2*)   echo "whatever-whatever-unixware2";  exit 0 ;;
75                 esac
76                 ;;
77             4.2)
78                 echo "whatever-whatever-unixware1"; exit 0
79                 ;;
80             5*)
81                 case "x${VERSION}" in
82                     # We hardcode i586 in place of ${MACHINE} for the
83                     # following reason. The catch is that even though Pentium
84                     # is minimum requirement for platforms in question,
85                     # ${MACHINE} gets always assigned to i386. Now, problem
86                     # with i386 is that it makes ./config pass 386 to
87                     # ./Configure, which in turn makes make generate
88                     # inefficient SHA-1 (for this moment) code.
89                     x[678]*)  echo "i586-sco-unixware7"; exit 0 ;;
90                 esac
91                 ;;
92         esac
93     fi
94 fi
95 # Now we simply scan though... In most cases, the SYSTEM info is enough
96 #
97 case "${SYSTEM}:${RELEASE}:${VERSION}:${MACHINE}" in
98     A/UX:*)
99         echo "m68k-apple-aux3"; exit 0
100         ;;
101
102     AIX:[3-9]:4:*)
103         echo "${MACHINE}-ibm-aix"; exit 0
104         ;;
105
106     AIX:*:[5-9]:*)
107         echo "${MACHINE}-ibm-aix"; exit 0
108         ;;
109
110     AIX:*)
111         echo "${MACHINE}-ibm-aix3"; exit 0
112         ;;
113
114     HI-UX:*)
115         echo "${MACHINE}-hi-hiux"; exit 0
116         ;;
117
118     HP-UX:*)
119         HPUXVER=`echo ${RELEASE}|sed -e 's/[^.]*.[0B]*//'`
120         case "$HPUXVER" in
121             1[0-9].*)   # HPUX 10 and 11 targets are unified
122                 echo "${MACHINE}-hp-hpux1x"; exit 0
123                 ;;
124             *)
125                 echo "${MACHINE}-hp-hpux"; exit 0
126                 ;;
127         esac
128         ;;
129
130     IRIX:6.*)
131         echo "mips3-sgi-irix"; exit 0
132         ;;
133
134     IRIX64:*)
135         echo "mips4-sgi-irix64"; exit 0
136         ;;
137
138     Linux:[2-9].*)
139         echo "${MACHINE}-whatever-linux2"; exit 0
140         ;;
141
142     Linux:1.*)
143         echo "${MACHINE}-whatever-linux1"; exit 0
144         ;;
145
146     GNU*)
147         echo "hurd-x86"; exit 0;
148         ;;
149
150     LynxOS:*)
151         echo "${MACHINE}-lynx-lynxos"; exit 0
152         ;;
153
154     BSD/OS:4.*)  # BSD/OS always says 386
155         echo "i486-whatever-bsdi4"; exit 0
156         ;;
157
158     BSD/386:*:*:*486*|BSD/OS:*:*:*:*486*)
159         case `/sbin/sysctl -n hw.model` in
160             Pentium*)
161                 echo "i586-whatever-bsdi"; exit 0
162                 ;;
163             *)
164                 echo "i386-whatever-bsdi"; exit 0
165                 ;;
166             esac;
167         ;;
168
169     BSD/386:*|BSD/OS:*)
170         echo "${MACHINE}-whatever-bsdi"; exit 0
171         ;;
172
173     FreeBSD:*:*:*386*)
174         VERS=`echo ${RELEASE} | sed -e 's/[-(].*//'`
175         MACH=`sysctl -n hw.model`
176         ARCH='whatever'
177         case ${MACH} in
178            *386*       ) MACH="i386"     ;;
179            *486*       ) MACH="i486"     ;;
180            Pentium\ II*) MACH="i686"     ;;
181            Pentium*    ) MACH="i586"     ;;
182            *           ) MACH="$MACHINE" ;;
183         esac
184         case ${MACH} in
185            i[0-9]86 ) ARCH="pc" ;;
186         esac
187         echo "${MACH}-${ARCH}-freebsd${VERS}"; exit 0
188         ;;
189
190     DragonFly:*)
191         echo "${MACHINE}-whatever-dragonfly"; exit 0
192         ;;
193
194     FreeBSD:*)
195         echo "${MACHINE}-whatever-freebsd"; exit 0
196         ;;
197
198     Haiku:*)
199         echo "${MACHINE}-whatever-haiku"; exit 0
200         ;;
201
202     NetBSD:*:*:*386*)
203         echo "`(/usr/sbin/sysctl -n hw.model || /sbin/sysctl -n hw.model) | sed 's,.*\(.\)86-class.*,i\186,'`-whatever-netbsd"; exit 0
204         ;;
205
206     NetBSD:*)
207         echo "${MACHINE}-whatever-netbsd"; exit 0
208         ;;
209
210     OpenBSD:*)
211         echo "${MACHINE}-whatever-openbsd"; exit 0
212         ;;
213
214     OpenUNIX:*)
215         echo "${MACHINE}-unknown-OpenUNIX${VERSION}"; exit 0
216         ;;
217
218     OSF1:*:*:*alpha*)
219         OSFMAJOR=`echo ${RELEASE}| sed -e 's/^V\([0-9]*\)\..*$/\1/'`
220         case "$OSFMAJOR" in
221             4|5)
222                 echo "${MACHINE}-dec-tru64"; exit 0
223                 ;;
224             1|2|3)
225                 echo "${MACHINE}-dec-osf"; exit 0
226                 ;;
227             *)
228                 echo "${MACHINE}-dec-osf"; exit 0
229                 ;;
230         esac
231         ;;
232
233     QNX:*)
234         case "$RELEASE" in
235             4*)
236                 echo "${MACHINE}-whatever-qnx4"
237                 ;;
238             6*)
239                 echo "${MACHINE}-whatever-qnx6"
240                 ;;
241             *)
242                 echo "${MACHINE}-whatever-qnx"
243                 ;;
244         esac
245         exit 0
246         ;;
247
248     Paragon*:*:*:*)
249         echo "i860-intel-osf1"; exit 0
250         ;;
251
252     Rhapsody:*)
253         echo "ppc-apple-rhapsody"; exit 0
254         ;;
255
256     Darwin:*)
257         case "$MACHINE" in
258             Power*)
259                 echo "ppc-apple-darwin${VERSION}"
260                 ;;
261             x86_64)
262                 echo "x86_64-apple-darwin${VERSION}"
263                 ;;
264             *)
265                 echo "i686-apple-darwin${VERSION}"
266                 ;;
267         esac
268         exit 0
269         ;;
270
271     SunOS:5.*)
272         echo "${MACHINE}-whatever-solaris2"; exit 0
273         ;;
274
275     SunOS:*)
276         echo "${MACHINE}-sun-sunos4"; exit 0
277         ;;
278
279     UNIX_System_V:4.*:*)
280         echo "${MACHINE}-whatever-sysv4"; exit 0
281         ;;
282
283     VOS:*:*:i786)
284      echo "i386-stratus-vos"; exit 0
285      ;;
286
287     VOS:*:*:*)
288      echo "hppa1.1-stratus-vos"; exit 0
289      ;;
290
291     *:4*:R4*:m88k)
292         echo "${MACHINE}-whatever-sysv4"; exit 0
293         ;;
294
295     DYNIX/ptx:4*:*)
296         echo "${MACHINE}-whatever-sysv4"; exit 0
297         ;;
298
299     *:4.0:3.0:3[34]?? | *:4.0:3.0:3[34]??,*)
300         echo "i486-ncr-sysv4"; exit 0
301         ;;
302
303     ULTRIX:*)
304         echo "${MACHINE}-unknown-ultrix"; exit 0
305         ;;
306
307     POSIX-BC*)
308         echo "${MACHINE}-siemens-sysv4"; exit 0   # Here, $MACHINE == "BS2000"
309         ;;
310
311     machten:*)
312        echo "${MACHINE}-tenon-${SYSTEM}"; exit 0;
313        ;;
314
315     library:*)
316         echo "${MACHINE}-ncr-sysv4"; exit 0
317         ;;
318
319     ConvexOS:*:11.0:*)
320         echo "${MACHINE}-v11-${SYSTEM}"; exit 0;
321         ;;
322
323     # The following combinations are supported
324     # MINGW64* on x86_64 => mingw64
325     # MINGW32* on x86_64 => mingw
326     # MINGW32* on i?86 => mingw
327     #
328     # MINGW64* on i?86 isn't expected to work...
329     MINGW64*:*:*:x86_64)
330         echo "${MACHINE}-whatever-mingw64"; exit 0;
331         ;;
332     MINGW*)
333         echo "${MACHINE}-whatever-mingw"; exit 0;
334         ;;
335     CYGWIN*)
336         echo "${MACHINE}-pc-cygwin"; exit 0
337         ;;
338
339     vxworks*)
340        echo "${MACHINE}-whatever-vxworks"; exit 0;
341        ;;
342 esac
343
344 #
345 # Ugg. These are all we can determine by what we know about
346 # the output of uname. Be more creative:
347 #
348
349 # Do the Apollo stuff first. Here, we just simply assume
350 # that the existence of the /usr/apollo directory is proof
351 # enough
352 if [ -d /usr/apollo ]; then
353     echo "whatever-apollo-whatever"
354     exit 0
355 fi
356
357 # Now NeXT
358 ISNEXT=`hostinfo 2>/dev/null`
359 case "$ISNEXT" in
360     *'NeXT Mach 3.3'*)
361         echo "whatever-next-nextstep3.3"; exit 0
362         ;;
363     *NeXT*)
364         echo "whatever-next-nextstep"; exit 0
365         ;;
366 esac
367
368 # At this point we gone through all the one's
369 # we know of: Punt
370
371 echo "${MACHINE}-whatever-${SYSTEM}" 
372 exit 0
373 ) 2>/dev/null | (
374
375 # ---------------------------------------------------------------------------
376 # this is where the translation occurs into SSLeay terms
377 # ---------------------------------------------------------------------------
378
379 # Only set CC if not supplied already
380 if [ -z "$CROSS_COMPILE$CC" ]; then
381   GCCVER=`sh -c "gcc -dumpversion" 2>/dev/null`
382   if [ "$GCCVER" != "" ]; then
383     # then strip off whatever prefix egcs prepends the number with...
384     # Hopefully, this will work for any future prefixes as well.
385     GCCVER=`echo $GCCVER | LC_ALL=C sed 's/^[a-zA-Z]*\-//'`
386     # Since gcc 3.1 gcc --version behaviour has changed.  gcc -dumpversion
387     # does give us what we want though, so we use that.  We just just the
388     # major and minor version numbers.
389     # peak single digit before and after first dot, e.g. 2.95.1 gives 29
390     GCCVER=`echo $GCCVER | sed 's/\([0-9]\)\.\([0-9]\).*/\1\2/'`
391     CC=gcc
392   else
393     CC=cc
394   fi
395 fi
396 GCCVER=${GCCVER:-0}
397 if [ "$SYSTEM" = "HP-UX" ];then
398   # By default gcc is a ILP32 compiler (with long long == 64).
399   GCC_BITS="32"
400   if [ $GCCVER -ge 30 ]; then
401     # PA64 support only came in with gcc 3.0.x.
402     # We check if the preprocessor symbol __LP64__ is defined...
403     if echo "__LP64__" | gcc -v -E -x c - 2>/dev/null | grep "^__LP64__" 2>&1 > /dev/null; then
404       : # __LP64__ has slipped through, it therefore is not defined
405     else
406       GCC_BITS="64"
407     fi
408   fi
409 fi
410 if [ "$SYSTEM" = "SunOS" ]; then
411   if [ $GCCVER -ge 30 ]; then
412     # 64-bit ABI isn't officially supported in gcc 3.0, but it appears
413     # to be working, at the very least 'make test' passes...
414     if gcc -v -E -x c /dev/null 2>&1 | grep __arch64__ > /dev/null; then
415       GCC_ARCH="-m64"
416     else
417       GCC_ARCH="-m32"
418     fi
419   fi
420   # check for WorkShop C, expected output is "cc: blah-blah C x.x"
421   CCVER=`(cc -V 2>&1) 2>/dev/null | \
422         egrep -e '^cc: .* C [0-9]\.[0-9]' | \
423         sed 's/.* C \([0-9]\)\.\([0-9]\).*/\1\2/'`
424   CCVER=${CCVER:-0}
425   if [ $MACHINE != i86pc -a $CCVER -gt 40 ]; then
426     CC=cc       # overrides gcc!!!
427     if [ $CCVER -eq 50 ]; then
428       echo "WARNING! Detected WorkShop C 5.0. Do make sure you have"
429       echo "         patch #107357-01 or later applied."
430       sleep 5
431     fi
432   fi
433 fi
434
435 if [ "${SYSTEM}" = "AIX" ]; then        # favor vendor cc over gcc
436     (cc) 2>&1 | grep -iv "not found" > /dev/null && CC=cc
437 fi
438
439 CCVER=${CCVER:-0}
440
441 # read the output of the embedded GuessOS 
442 read GUESSOS
443
444 echo Operating system: $GUESSOS
445
446 # now map the output into SSLeay terms ... really should hack into the
447 # script above so we end up with values in vars but that would take
448 # more time that I want to waste at the moment
449 case "$GUESSOS" in
450   uClinux*64*)
451     OUT=uClinux-dist64
452         ;;
453   uClinux*)
454     OUT=uClinux-dist
455         ;;
456   mips3-sgi-irix)
457         #CPU=`(hinv -t cpu) 2>/dev/null | head -1 | sed 's/^CPU:[^R]*R\([0-9]*\).*/\1/'`
458         #CPU=${CPU:-0}
459         #if [ $CPU -ge 5000 ]; then
460         #       options="$options -mips4"
461         #else
462         #       options="$options -mips3"
463         #fi
464         OUT="irix-mips3-$CC"
465         ;;
466   mips4-sgi-irix64)
467         echo "WARNING! If you wish to build 64-bit library, then you have to"
468         echo "         invoke '$THERE/Configure irix64-mips4-$CC' *manually*."
469         if [ "$DRYRUN" = "false" -a -t 1 ]; then
470           echo "         You have about 5 seconds to press Ctrl-C to abort."
471           (trap "stty `stty -g`; exit 0" 2 0; stty -icanon min 0 time 50; read waste) <&1
472         fi
473         #CPU=`(hinv -t cpu) 2>/dev/null | head -1 | sed 's/^CPU:[^R]*R\([0-9]*\).*/\1/'`
474         #CPU=${CPU:-0}
475         #if [ $CPU -ge 5000 ]; then
476         #        options="$options -mips4"
477         #else
478         #        options="$options -mips3"
479         #fi
480         OUT="irix-mips3-$CC"
481         ;;
482   ppc-apple-rhapsody) OUT="rhapsody-ppc-cc" ;;
483   ppc-apple-darwin*)
484         ISA64=`(sysctl -n hw.optional.64bitops) 2>/dev/null`
485         if [ "$ISA64" = "1" -a -z "$KERNEL_BITS" ]; then
486             echo "WARNING! If you wish to build 64-bit library, then you have to"
487             echo "         invoke '$THERE/Configure darwin64-ppc-cc' *manually*."
488             if [ "$DRYRUN" = "false" -a -t 1 ]; then
489               echo "         You have about 5 seconds to press Ctrl-C to abort."
490               (trap "stty `stty -g`; exit 0" 2 0; stty -icanon min 0 time 50; read waste) <&1
491             fi
492         fi
493         if [ "$ISA64" = "1" -a "$KERNEL_BITS" = "64" ]; then
494             OUT="darwin64-ppc-cc"
495         else
496             OUT="darwin-ppc-cc"
497         fi ;;
498   i?86-apple-darwin*)
499         ISA64=`(sysctl -n hw.optional.x86_64) 2>/dev/null`
500         if [ "$ISA64" = "1" -a -z "$KERNEL_BITS" ]; then
501             echo "WARNING! If you wish to build 64-bit library, then you have to"
502             echo "         invoke 'KERNEL_BITS=64 $THERE/config $options'."
503             if [ "$DRYRUN" = "false" -a -t 1 ]; then
504               echo "         You have about 5 seconds to press Ctrl-C to abort."
505               # The stty technique used elsewhere doesn't work on
506               # MacOS. At least, right now on this Mac.
507               sleep 5
508             fi
509         fi
510         if [ "$ISA64" = "1" -a "$KERNEL_BITS" = "64" ]; then
511             OUT="darwin64-x86_64-cc"
512         else
513             OUT="darwin-i386-cc"
514         fi ;;
515   x86_64-apple-darwin*)
516         if [ "$KERNEL_BITS" = "32" ]; then
517             OUT="darwin-i386-cc"
518         else
519             OUT="darwin64-x86_64-cc"
520         fi ;;
521   armv6+7-*-iphoneos)
522         options="$options -arch%20armv6 -arch%20armv7"
523         OUT="iphoneos-cross" ;;
524   *-*-iphoneos)
525         options="$options -arch%20${MACHINE}"
526         OUT="iphoneos-cross" ;;
527   arm64-*-iphoneos|*-*-ios64)
528         OUT="ios64-cross" ;;
529   alpha-*-linux2)
530         ISA=`awk '/cpu model/{print$4;exit(0);}' /proc/cpuinfo`
531         case ${ISA:-generic} in
532         *[678]) OUT="linux-alpha+bwx-$CC" ;;
533         *)      OUT="linux-alpha-$CC" ;;
534         esac
535         if [ "$CC" = "gcc" ]; then
536             case ${ISA:-generic} in
537             EV5|EV45)           options="$options -mcpu=ev5";;
538             EV56|PCA56)         options="$options -mcpu=ev56";;
539             *)                  options="$options -mcpu=ev6";;
540             esac
541         fi
542         ;;
543   ppc64-*-linux2)
544         if [ -z "$KERNEL_BITS" ]; then
545             echo "WARNING! If you wish to build 64-bit library, then you have to"
546             echo "         invoke '$THERE/Configure linux-ppc64' *manually*."
547             if [ "$DRYRUN" = "false" -a -t 1 ]; then
548                 echo "         You have about 5 seconds to press Ctrl-C to abort."
549                 (trap "stty `stty -g`; exit 0" 2 0; stty -icanon min 0 time 50; read waste) <&1
550             fi
551         fi
552         if [ "$KERNEL_BITS" = "64" ]; then
553             OUT="linux-ppc64"
554         else
555             OUT="linux-ppc"
556             (echo "__LP64__" | gcc -E -x c - 2>/dev/null | grep "^__LP64__" 2>&1 > /dev/null) || options="$options -m32"
557         fi
558         ;;
559   ppc64le-*-linux2) OUT="linux-ppc64le" ;;
560   ppc-*-linux2) OUT="linux-ppc" ;;
561   mips64*-*-linux2)
562         echo "WARNING! If you wish to build 64-bit library, then you have to"
563         echo "         invoke '$THERE/Configure linux64-mips64' *manually*."
564         if [ "$DRYRUN" = "false" -a -t 1 ]; then
565             echo "         You have about 5 seconds to press Ctrl-C to abort."
566             (trap "stty `stty -g`; exit 0" 2 0; stty -icanon min 0 time 50; read waste) <&1
567         fi
568         OUT="linux-mips64"
569         ;;
570   mips*-*-linux2) OUT="linux-mips32" ;;
571   ppc60x-*-vxworks*) OUT="vxworks-ppc60x" ;;
572   ppcgen-*-vxworks*) OUT="vxworks-ppcgen" ;;
573   pentium-*-vxworks*) OUT="vxworks-pentium" ;;
574   simlinux-*-vxworks*) OUT="vxworks-simlinux" ;;
575   mips-*-vxworks*) OUT="vxworks-mips";;
576   ia64-*-linux?) OUT="linux-ia64" ;;
577   sparc64-*-linux2)
578         echo "WARNING! If you *know* that your GNU C supports 64-bit/V9 ABI"
579         echo "         and wish to build 64-bit library, then you have to"
580         echo "         invoke '$THERE/Configure linux64-sparcv9' *manually*."
581         if [ "$DRYRUN" = "false" -a -t 1 ]; then
582           echo "          You have about 5 seconds to press Ctrl-C to abort."
583           (trap "stty `stty -g`; exit 0" 2 0; stty -icanon min 0 time 50; read waste) <&1
584         fi
585         OUT="linux-sparcv9" ;;
586   sparc-*-linux2)
587         KARCH=`awk '/^type/{print$3;exit(0);}' /proc/cpuinfo`
588         case ${KARCH:-sun4} in
589         sun4u*) OUT="linux-sparcv9" ;;
590         sun4m)  OUT="linux-sparcv8" ;;
591         sun4d)  OUT="linux-sparcv8" ;;
592         *)      OUT="linux-generic32"; options="$options -DB_ENDIAN" ;;
593         esac ;;
594   parisc*-*-linux2)
595         # 64-bit builds under parisc64 linux are not supported and
596         # compiler is expected to generate 32-bit objects...
597         CPUARCH=`awk '/cpu family/{print substr($5,1,3); exit(0);}' /proc/cpuinfo`
598         CPUSCHEDULE=`awk '/^cpu.[       ]*: PA/{print substr($3,3); exit(0);}' /proc/cpuinfo`
599
600         # ??TODO ??  Model transformations
601         # 0. CPU Architecture for the 1.1 processor has letter suffixes. We strip that off
602         #    assuming no further arch. identification will ever be used by GCC.
603         # 1. I'm most concerned about whether is a 7300LC is closer to a 7100 versus a 7100LC.
604         # 2. The variant 64-bit processors cause concern should GCC support explicit schedulers
605         #    for these chips in the future.
606         #         PA7300LC -> 7100LC (1.1)
607         #         PA8200   -> 8000   (2.0)
608         #         PA8500   -> 8000   (2.0)
609         #         PA8600   -> 8000   (2.0)
610
611         CPUSCHEDULE=`echo $CPUSCHEDULE|sed -e 's/7300LC/7100LC/' -e 's/8.00/8000/'`
612         # Finish Model transformations
613
614         options="$options -DB_ENDIAN -mschedule=$CPUSCHEDULE -march=$CPUARCH"
615         OUT="linux-generic32" ;;
616   armv[1-3]*-*-linux2) OUT="linux-generic32" ;;
617   armv[7-9]*-*-linux2) OUT="linux-armv4"; options="$options -march=armv7-a" ;;
618   arm*-*-linux2) OUT="linux-armv4" ;;
619   aarch64-*-linux2) OUT="linux-aarch64" ;;
620   sh*b-*-linux2) OUT="linux-generic32"; options="$options -DB_ENDIAN" ;;
621   sh*-*-linux2)  OUT="linux-generic32"; options="$options -DL_ENDIAN" ;;
622   m68k*-*-linux2) OUT="linux-generic32"; options="$options -DB_ENDIAN" ;;
623   s390-*-linux2) OUT="linux-generic32"; options="$options -DB_ENDIAN" ;;
624   s390x-*-linux2)
625         # To be uncommented when glibc bug is fixed, see Configure...
626         #if egrep -e '^features.* highgprs' /proc/cpuinfo >/dev/null ; then
627         #  echo "WARNING! If you wish to build \"highgprs\" 32-bit library, then you"
628         #  echo "         have to invoke './Configure linux32-s390x' *manually*."
629         #  if [ "$DRYRUN" = "false" -a -t -1 ]; then
630         #    echo "         You have about 5 seconds to press Ctrl-C to abort."
631         #    (trap "stty `stty -g`; exit 0" 2 0; stty -icanon min 0 time 50; read waste) <&1
632         #  fi
633         #fi
634         OUT="linux64-s390x"
635         ;;
636   x86_64-*-linux?)
637         if $CC -dM -E -x c /dev/null 2>&1 | grep -q ILP32 > /dev/null; then
638             OUT="linux-x32"
639         else
640             OUT="linux-x86_64"
641         fi ;;
642   *86-*-linux2)
643         # On machines where the compiler understands -m32, prefer a
644         # config target that uses it
645         if $CC -m32 -E -x c /dev/null > /dev/null 2>&1; then
646             OUT="linux-x86"
647         else
648             OUT="linux-elf"
649         fi ;;
650   *86-*-linux1) OUT="linux-aout" ;;
651   *-*-linux?) OUT="linux-generic32" ;;
652   sun4[uv]*-*-solaris2)
653         OUT="solaris-sparcv9-$CC"
654         ISA64=`(isainfo) 2>/dev/null | grep sparcv9`
655         if [ "$ISA64" != "" -a "$KERNEL_BITS" = "" ]; then
656             if [ "$CC" = "cc" -a $CCVER -ge 50 ]; then
657                 echo "WARNING! If you wish to build 64-bit library, then you have to"
658                 echo "         invoke '$THERE/Configure solaris64-sparcv9-cc' *manually*."
659                 if [ "$DRYRUN" = "false" -a -t 1 ]; then
660                   echo "         You have about 5 seconds to press Ctrl-C to abort."
661                   (trap "stty `stty -g`; exit 0" 2 0; stty -icanon min 0 time 50; read waste) <&1
662                 fi
663             elif [ "$CC" = "gcc" -a "$GCC_ARCH" = "-m64" ]; then
664                 # $GCC_ARCH denotes default ABI chosen by compiler driver
665                 # (first one found on the $PATH). I assume that user
666                 # expects certain consistency with the rest of his builds
667                 # and therefore switch over to 64-bit. <appro>
668                 OUT="solaris64-sparcv9-gcc"
669                 echo "WARNING! If you wish to build 32-bit library, then you have to"
670                 echo "         invoke '$THERE/Configure solaris-sparcv9-gcc' *manually*."
671                 if [ "$DRYRUN" = "false" -a -t 1 ]; then
672                   echo "         You have about 5 seconds to press Ctrl-C to abort."
673                   (trap "stty `stty -g`; exit 0" 2 0; stty -icanon min 0 time 50; read waste) <&1
674                 fi
675             elif [ "$GCC_ARCH" = "-m32" ]; then
676                 echo "NOTICE! If you *know* that your GNU C supports 64-bit/V9 ABI"
677                 echo "        and wish to build 64-bit library, then you have to"
678                 echo "        invoke '$THERE/Configure solaris64-sparcv9-gcc' *manually*."
679                 if [ "$DRYRUN" = "false" -a -t 1 ]; then
680                   echo "         You have about 5 seconds to press Ctrl-C to abort."
681                   (trap "stty `stty -g`; exit 0" 2 0; stty -icanon min 0 time 50; read waste) <&1
682                 fi
683             fi
684         fi
685         if [ "$ISA64" != "" -a "$KERNEL_BITS" = "64" ]; then
686             OUT="solaris64-sparcv9-$CC"
687         fi
688         ;;
689   sun4m-*-solaris2)     OUT="solaris-sparcv8-$CC" ;;
690   sun4d-*-solaris2)     OUT="solaris-sparcv8-$CC" ;;
691   sun4*-*-solaris2)     OUT="solaris-sparcv7-$CC" ;;
692   *86*-*-solaris2)
693         ISA64=`(isainfo) 2>/dev/null | grep amd64`
694         if [ "$ISA64" != "" -a ${KERNEL_BITS:-64} -eq 64 ]; then
695             OUT="solaris64-x86_64-$CC"
696         else
697             OUT="solaris-x86-$CC"
698             if [ `uname -r | sed -e 's/5\.//'` -lt 10 ]; then
699                 options="$options no-sse2"
700             fi
701         fi
702         ;;
703   *-*-sunos4)           OUT="sunos-$CC" ;;
704
705   *86*-*-bsdi4)         OUT="BSD-x86-elf"; options="$options no-sse2 -ldl" ;;
706   alpha*-*-*bsd*)       OUT="BSD-generic64"; options="$options -DL_ENDIAN" ;;
707   powerpc64-*-*bsd*)    OUT="BSD-generic64"; options="$options -DB_ENDIAN" ;;
708   sparc64-*-*bsd*)      OUT="BSD-sparc64" ;;
709   ia64-*-*bsd*)         OUT="BSD-ia64" ;;
710   x86_64-*-dragonfly*)  OUT="BSD-x86_64" ;;
711   amd64-*-*bsd*)        OUT="BSD-x86_64" ;;
712   *86*-*-*bsd*)         # mimic ld behaviour when it's looking for libc...
713                         if [ -L /usr/lib/libc.so ]; then        # [Free|Net]BSD
714                             libc=/usr/lib/libc.so
715                         else                                    # OpenBSD
716                             # ld searches for highest libc.so.* and so do we
717                             libc=`(ls /usr/lib/libc.so.* /lib/libc.so.* | tail -1) 2>/dev/null`
718                         fi
719                         case "`(file -L $libc) 2>/dev/null`" in
720                         *ELF*)  OUT="BSD-x86-elf" ;;
721                         *)      OUT="BSD-x86"; options="$options no-sse2" ;;
722                         esac ;;
723   *-*-*bsd*)            OUT="BSD-generic32" ;;
724
725   x86_64-*-haiku)       OUT="haiku-x86_64" ;;
726   *-*-haiku)            OUT="haiku-x86" ;;
727
728   *-*-osf)              OUT="osf1-alpha-cc" ;;
729   *-*-tru64)            OUT="tru64-alpha-cc" ;;
730   *-*-[Uu]nix[Ww]are7)
731         if [ "$CC" = "gcc" ]; then
732           OUT="unixware-7-gcc" ; options="$options no-sse2"
733         else    
734           OUT="unixware-7" ; options="$options no-sse2 -D__i386__"
735         fi
736         ;;
737   *-*-[Uu]nix[Ww]are20*) OUT="unixware-2.0"; options="$options no-sse2 no-sha512" ;;
738   *-*-[Uu]nix[Ww]are21*) OUT="unixware-2.1"; options="$options no-sse2 no-sha512" ;;
739   *-*-vos)
740         options="$options no-threads no-shared no-asm no-dso"
741         EXE=".pm"
742         OUT="vos-$CC" ;;
743   BS2000-siemens-sysv4) OUT="BS2000-OSD" ;;
744   *-hpux1*)
745         if [ $CC = "gcc" -a $GCC_BITS = "64" ]; then
746             OUT="hpux64-parisc2-gcc"
747         fi
748         [ "$KERNEL_BITS" ] || KERNEL_BITS=`(getconf KERNEL_BITS) 2>/dev/null`
749         KERNEL_BITS=${KERNEL_BITS:-32}
750         CPU_VERSION=`(getconf CPU_VERSION) 2>/dev/null`
751         CPU_VERSION=${CPU_VERSION:-0}
752         # See <sys/unistd.h> for further info on CPU_VERSION.
753         if   [ $CPU_VERSION -ge 768 ]; then     # IA-64 CPU
754              if [ $KERNEL_BITS -eq 64 -a "$CC" = "cc" ]; then
755                 OUT="hpux64-ia64-cc"
756              else
757                 OUT="hpux-ia64-cc"
758              fi
759         elif [ $CPU_VERSION -ge 532 ]; then     # PA-RISC 2.x CPU
760              OUT=${OUT:-"hpux-parisc2-${CC}"}
761              if [ $KERNEL_BITS -eq 64 -a "$CC" = "cc" ]; then
762                 echo "WARNING! If you wish to build 64-bit library then you have to"
763                 echo "         invoke '$THERE/Configure hpux64-parisc2-cc' *manually*."
764                 if [ "$DRYRUN" = "false" -a -t 1 ]; then
765                   echo "         You have about 5 seconds to press Ctrl-C to abort."
766                   (trap "stty `stty -g`; exit 0" 2 0; stty -icanon min 0 time 50; read waste) <&1
767                 fi
768              fi
769              # PA-RISC 2.0 is no longer supported as separate 32-bit
770              # target. This is compensated for by run-time detection
771              # in most critical assembly modules and taking advantage
772              # of 2.0 architecture in PA-RISC 1.1 build.
773              OUT="hpux-parisc1_1-${CC}"
774         elif [ $CPU_VERSION -ge 528 ]; then     # PA-RISC 1.1+ CPU
775              OUT="hpux-parisc1_1-${CC}"
776         elif [ $CPU_VERSION -ge 523 ]; then     # PA-RISC 1.0 CPU
777              OUT="hpux-parisc-${CC}"
778         else                                    # Motorola(?) CPU
779              OUT="hpux-$CC"
780         fi
781         options="$options -D_REENTRANT" ;;
782   *-hpux)       OUT="hpux-parisc-$CC" ;;
783   *-aix)
784         [ "$KERNEL_BITS" ] || KERNEL_BITS=`(getconf KERNEL_BITMODE) 2>/dev/null`
785         KERNEL_BITS=${KERNEL_BITS:-32}
786         OBJECT_MODE=${OBJECT_MODE:-32}
787         if [ "$CC" = "gcc" ]; then
788             OUT="aix-gcc"
789           if [ $OBJECT_MODE -eq 64 ]; then
790             echo 'Your $OBJECT_MODE was found to be set to 64'
791             OUT="aix64-gcc"
792           fi
793         elif [ $OBJECT_MODE -eq 64 ]; then
794             echo 'Your $OBJECT_MODE was found to be set to 64' 
795             OUT="aix64-cc"
796         else
797             OUT="aix-cc"
798             if [ $KERNEL_BITS -eq 64 ]; then
799                 echo "WARNING! If you wish to build 64-bit kit, then you have to"
800                 echo "         invoke '$THERE/Configure aix64-cc' *manually*."
801                 if [ "$DRYRUN" = "false" -a -t 1 ]; then
802                     echo "         You have ~5 seconds to press Ctrl-C to abort."
803                     (trap "stty `stty -g`; exit 0" 2 0; stty -icanon min 0 time 50; read waste) <&1
804                 fi
805             fi
806         fi
807         if (lsattr -E -O -l `lsdev -c processor|awk '{print$1;exit}'` | grep -i powerpc) >/dev/null 2>&1; then
808             :   # this applies even to Power3 and later, as they return PowerPC_POWER[345]
809         else
810             options="$options no-asm"
811         fi
812         ;;
813   # these are all covered by the catchall below
814   i[3456]86-*-cygwin) OUT="Cygwin-x86" ;;
815   *-*-cygwin) OUT="Cygwin-${MACHINE}" ;;
816   x86pc-*-qnx6) OUT="QNX6-i386" ;;
817   *-*-qnx6) OUT="QNX6" ;;
818   x86-*-android|i?86-*-android) OUT="android-x86" ;;
819   armv[7-9]*-*-android)
820       OUT="android-armeabi"; options="$options -march=armv7-a" ;;
821   arm*-*-android) OUT="android-armeabi" ;;
822   *) OUT=`echo $GUESSOS | awk -F- '{print $3}'`;;
823 esac
824
825 # NB: This atalla support has been superseded by the ENGINE support
826 # That contains its own header and definitions anyway. Support can
827 # be enabled or disabled on any supported platform without external
828 # headers, eg. by adding the "hw-atalla" switch to ./config or
829 # perl Configure
830 #
831 # See whether we can compile Atalla support
832 #if [ -f /usr/include/atasi.h ]
833 #then
834 #  options="$options -DATALLA"
835 #fi
836
837 if [ -n "$CONFIG_OPTIONS" ]; then
838   options="$options $CONFIG_OPTIONS"
839 fi
840
841 if expr "$options" : '.*no\-asm' > /dev/null; then :; else
842   sh -c "$CROSS_COMPILE${CC:-gcc} -Wa,--help -c -o /tmp/null.$$.o -x assembler /dev/null && rm /tmp/null.$$.o" 2>&1 | \
843   grep \\--noexecstack >/dev/null && \
844   options="$options -Wa,--noexecstack"
845 fi
846
847 # gcc < 2.8 does not support -march=ultrasparc
848 if [ "$OUT" = solaris-sparcv9-gcc -a $GCCVER -lt 28 ]
849 then
850   echo "WARNING! Falling down to 'solaris-sparcv8-gcc'."
851   echo "         Upgrade to gcc-2.8 or later."
852   sleep 5
853   OUT=solaris-sparcv8-gcc
854 fi
855 if [ "$OUT" = "linux-sparcv9" -a $GCCVER -lt 28 ]
856 then
857   echo "WARNING! Falling down to 'linux-sparcv8'."
858   echo "         Upgrade to gcc-2.8 or later."
859   sleep 5
860   OUT=linux-sparcv8
861 fi
862
863 case "$GUESSOS" in
864   i386-*) options="$options 386" ;;
865 esac
866
867 for i in aes aria bf camellia cast des dh dsa ec hmac idea md2 md5 mdc2 rc2 rc4 rc5 ripemd rsa seed sha
868 do
869   if [ ! -d $THERE/crypto/$i ]
870   then
871     options="$options no-$i"
872   fi
873 done
874
875 if [ -z "$OUT" ]; then
876   OUT="$CC"
877 fi
878
879 if [ ".$PERL" = . ] ; then
880         for i in . `echo $PATH | sed 's/:/ /g'`; do
881                 if [ -f "$i/perl5$EXE" ] ; then
882                         PERL="$i/perl5$EXE"
883                         break;
884                 fi;
885         done
886 fi
887
888 if [ ".$PERL" = . ] ; then
889         for i in . `echo $PATH | sed 's/:/ /g'`; do
890                 if [ -f "$i/perl$EXE" ] ; then
891                         if "$i/perl$EXE" -e 'exit($]<5.0)'; then
892                                 PERL="$i/perl$EXE"
893                                 break;
894                         fi;
895                 fi;
896         done
897 fi
898
899 if [ ".$PERL" = . ] ; then
900         echo "You need Perl 5."
901         exit 1
902 fi
903
904 # run Configure to check to see if we need to specify the 
905 # compiler for the platform ... in which case we add it on
906 # the end ... otherwise we leave it off
907
908 $PERL $THERE/Configure LIST | grep "$OUT-$CC" > /dev/null
909 if [ $? = "0" ]; then
910   OUT="$OUT-$CC"
911 fi
912
913 OUT="$OUT"
914
915 $PERL $THERE/Configure LIST | grep "$OUT" > /dev/null
916 if [ $? = "0" ]; then
917   if [ "$VERBOSE" = "true" ]; then
918     echo $PERL $THERE/Configure $OUT $options
919   fi  
920   if [ "$DRYRUN" = "false" ]; then
921     $PERL $THERE/Configure $OUT $options
922   fi
923 else
924   echo "This system ($OUT) is not supported. See file INSTALL for details."
925   exit 1
926 fi
927
928 if [ "$OUT" = "darwin64-x86_64-cc" ]; then
929     echo "WARNING! If you wish to build 32-bit libraries, then you have to"
930     echo "         invoke 'KERNEL_BITS=32 $THERE/config $options'."
931 fi
932 )