config.pm 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057
  1. #! /usr/bin/env perl
  2. # Copyright 1998-2024 The OpenSSL Project Authors. All Rights Reserved.
  3. #
  4. # Licensed under the Apache License 2.0 (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. # Determine the operating system and run ./Configure. Far descendant from
  9. # Apache's minarch and GuessOS.
  10. package OpenSSL::config;
  11. use strict;
  12. use warnings;
  13. use Getopt::Std;
  14. use File::Basename;
  15. use File::Spec;
  16. use IPC::Cmd;
  17. use POSIX;
  18. use Config;
  19. use Carp;
  20. # These control our behavior.
  21. my $DRYRUN;
  22. my $VERBOSE;
  23. my $WHERE = dirname($0);
  24. my $WAIT = 1;
  25. # Machine type, etc., used to determine the platform
  26. my $MACHINE;
  27. my $RELEASE;
  28. my $SYSTEM;
  29. my $VERSION;
  30. my $CCVENDOR;
  31. my $CCVER;
  32. my $CL_ARCH;
  33. my $GCC_BITS;
  34. my $GCC_ARCH;
  35. # Some environment variables; they will affect Configure
  36. my $CONFIG_OPTIONS = $ENV{CONFIG_OPTIONS} // '';
  37. my $CC;
  38. my $CROSS_COMPILE;
  39. # For determine_compiler_settings, the list of known compilers
  40. my @c_compilers = qw(clang gcc cc);
  41. # Methods to determine compiler version. The expected output is one of
  42. # MAJOR or MAJOR.MINOR or MAJOR.MINOR.PATCH... or false if the compiler
  43. # isn't of the given brand.
  44. # This is a list to ensure that gnu comes last, as we've made it a fallback
  45. my @cc_version =
  46. (
  47. clang => sub {
  48. return undef unless IPC::Cmd::can_run("$CROSS_COMPILE$CC");
  49. my $v = `$CROSS_COMPILE$CC -v 2>&1`;
  50. $v =~ m/(?:(?:clang|LLVM) version|.*based on LLVM)\s+([0-9]+\.[0-9]+)/;
  51. return $1;
  52. },
  53. gnu => sub {
  54. return undef unless IPC::Cmd::can_run("$CROSS_COMPILE$CC");
  55. my $nul = File::Spec->devnull();
  56. my $v = `$CROSS_COMPILE$CC -dumpversion 2> $nul`;
  57. # Strip off whatever prefix egcs prepends the number with.
  58. # Hopefully, this will work for any future prefixes as well.
  59. $v =~ s/^[a-zA-Z]*\-//;
  60. return $v;
  61. },
  62. );
  63. # This is what we will set as the target for calling Configure.
  64. my $options = '';
  65. # Pattern matches against "${SYSTEM}:${RELEASE}:${VERSION}:${MACHINE}"
  66. # The patterns are assumed to be wrapped like this: /^(${pattern})$/
  67. my $guess_patterns = [
  68. [ 'A\/UX:.*', 'm68k-apple-aux3' ],
  69. [ 'AIX:[3-9]:4:.*', '${MACHINE}-ibm-aix' ],
  70. [ 'AIX:.*?:[5-9]:.*', '${MACHINE}-ibm-aix' ],
  71. [ 'AIX:.*', '${MACHINE}-ibm-aix3' ],
  72. [ 'HI-UX:.*', '${MACHINE}-hi-hiux' ],
  73. [ 'HP-UX:.*',
  74. sub {
  75. my $HPUXVER = $RELEASE;
  76. $HPUXVER =~ s/[^.]*.[0B]*//;
  77. # HPUX 10 and 11 targets are unified
  78. return "${MACHINE}-hp-hpux1x" if $HPUXVER =~ m@1[0-9]@;
  79. return "${MACHINE}-hp-hpux";
  80. }
  81. ],
  82. [ 'IRIX:6\..*', 'mips3-sgi-irix' ],
  83. [ 'IRIX64:.*', 'mips4-sgi-irix64' ],
  84. [ 'Linux:[2-9]\..*', '${MACHINE}-whatever-linux2' ],
  85. [ 'Linux:1\..*', '${MACHINE}-whatever-linux1' ],
  86. [ 'GNU:.*86-AT386', 'hurd-x86' ],
  87. [ 'GNU:.*86_64-AT386', 'hurd-x86_64' ],
  88. [ 'LynxOS:.*', '${MACHINE}-lynx-lynxos' ],
  89. # BSD/OS always says 386
  90. [ 'BSD\/OS:4\..*', 'i486-whatever-bsdi4' ],
  91. # Order is important, this has to appear before 'BSD\/386:'
  92. [ 'BSD/386:.*?:.*?:.*486.*|BSD/OS:.*?:.*?:.*?:.*486.*',
  93. sub {
  94. my $BSDVAR = `/sbin/sysctl -n hw.model`;
  95. return "i586-whatever-bsdi" if $BSDVAR =~ m@Pentium@;
  96. return "i386-whatever-bsdi";
  97. }
  98. ],
  99. [ 'BSD\/386:.*|BSD\/OS:.*', '${MACHINE}-whatever-bsdi' ],
  100. # Order is important, this has to appear before 'FreeBSD:'
  101. [ 'FreeBSD:.*?:.*?:.*386.*',
  102. sub {
  103. my $VERS = $RELEASE;
  104. $VERS =~ s/[-(].*//;
  105. my $MACH = `sysctl -n hw.model`;
  106. $MACH = "i386" if $MACH =~ m@386@;
  107. $MACH = "i486" if $MACH =~ m@486@;
  108. $MACH = "i686" if $MACH =~ m@Pentium II@;
  109. $MACH = "i586" if $MACH =~ m@Pentium@;
  110. $MACH = "$MACHINE" if $MACH !~ /i.86/;
  111. my $ARCH = 'whatever';
  112. $ARCH = "pc" if $MACH =~ m@i[0-9]86@;
  113. return "${MACH}-${ARCH}-freebsd${VERS}";
  114. }
  115. ],
  116. [ 'DragonFly:.*', '${MACHINE}-whatever-dragonfly' ],
  117. [ 'FreeBSD:.*', '${MACHINE}-whatever-freebsd' ],
  118. [ 'Haiku:.*', '${MACHINE}-whatever-haiku' ],
  119. # Order is important, this has to appear before 'NetBSD:.*'
  120. [ 'NetBSD:.*?:.*?:.*386.*',
  121. sub {
  122. my $hw = `/usr/sbin/sysctl -n hw.model || /sbin/sysctl -n hw.model`;
  123. $hw =~ s@.*(.)86-class.*@i${1}86@;
  124. return "${hw}-whatever-netbsd";
  125. }
  126. ],
  127. [ 'NetBSD:.*', '${MACHINE}-whatever-netbsd' ],
  128. [ 'OpenBSD:.*', '${MACHINE}-whatever-openbsd' ],
  129. [ 'OpenUNIX:.*', '${MACHINE}-unknown-OpenUNIX${VERSION}' ],
  130. [ 'OSF1:.*?:.*?:.*alpha.*',
  131. sub {
  132. my $OSFMAJOR = $RELEASE;
  133. $OSFMAJOR =~ 's/^V([0-9]*)\..*$/\1/';
  134. return "${MACHINE}-dec-tru64" if $OSFMAJOR =~ m@[45]@;
  135. return "${MACHINE}-dec-osf";
  136. }
  137. ],
  138. [ 'Paragon.*?:.*', 'i860-intel-osf1' ],
  139. [ 'Rhapsody:.*', 'ppc-apple-rhapsody' ],
  140. [ 'Darwin:.*?:.*?:Power.*', 'ppc-apple-darwin' ],
  141. [ 'Darwin:.*', '${MACHINE}-apple-darwin' ],
  142. [ 'SunOS:5\..*', '${MACHINE}-whatever-solaris2' ],
  143. [ 'SunOS:.*', '${MACHINE}-sun-sunos4' ],
  144. [ 'UNIX_System_V:4\..*?:.*', '${MACHINE}-whatever-sysv4' ],
  145. [ 'VOS:.*?:.*?:i786', 'i386-stratus-vos' ],
  146. [ 'VOS:.*?:.*?:.*', 'hppa1.1-stratus-vos' ],
  147. [ '.*?:4.*?:R4.*?:m88k', '${MACHINE}-whatever-sysv4' ],
  148. [ 'DYNIX\/ptx:4.*?:.*', '${MACHINE}-whatever-sysv4' ],
  149. [ '.*?:4\.0:3\.0:3[34]..(,.*)?', 'i486-ncr-sysv4' ],
  150. [ 'ULTRIX:.*', '${MACHINE}-unknown-ultrix' ],
  151. [ 'POSIX-BC.*', 'BS2000-siemens-sysv4' ],
  152. [ 'machten:.*', '${MACHINE}-tenon-${SYSTEM}' ],
  153. [ 'library:.*', '${MACHINE}-ncr-sysv4' ],
  154. [ 'ConvexOS:.*?:11\.0:.*', '${MACHINE}-v11-${SYSTEM}' ],
  155. [ 'MINGW64.*?:.*?:.*?:x86_64', '${MACHINE}-whatever-mingw64' ],
  156. [ 'MINGW.*', '${MACHINE}-whatever-mingw' ],
  157. [ 'CYGWIN.*', '${MACHINE}-pc-cygwin' ],
  158. [ 'vxworks.*', '${MACHINE}-whatever-vxworks' ],
  159. # The MACHINE part of the array POSIX::uname() returns on VMS isn't
  160. # worth the bits wasted on it. It's better, then, to rely on perl's
  161. # %Config, which has a trustworthy item 'archname', especially since
  162. # VMS installation aren't multiarch (yet)
  163. [ 'OpenVMS:.*', "$Config{archname}-whatever-OpenVMS" ],
  164. # Note: there's also NEO and NSR, but they are old and unsupported
  165. [ 'NONSTOP_KERNEL:.*:NSE-.*?', 'nse-tandem-nsk${RELEASE}' ],
  166. [ 'NONSTOP_KERNEL:.*:NSV-.*?', 'nsv-tandem-nsk${RELEASE}' ],
  167. [ 'NONSTOP_KERNEL:.*:NSX-.*?', 'nsx-tandem-nsk${RELEASE}' ],
  168. [ sub { -d '/usr/apollo' }, 'whatever-apollo-whatever' ],
  169. ];
  170. # Run a command, return true if exit zero else false.
  171. # Multiple args are glued together into a pipeline.
  172. # Name comes from OpenSSL tests, often written as "ok(run(...."
  173. sub okrun {
  174. my $command = join(' | ', @_);
  175. my $status = system($command) >> 8;
  176. return $status == 0;
  177. }
  178. # Give user a chance to abort/interrupt if interactive if interactive.
  179. sub maybe_abort {
  180. if ( $WAIT && -t 1 ) {
  181. eval {
  182. local $SIG{ALRM} = sub { die "Timeout"; };
  183. local $| = 1;
  184. alarm(5);
  185. print "You have about five seconds to abort: ";
  186. my $ignored = <STDIN>;
  187. alarm(0);
  188. };
  189. print "\n" if $@ =~ /Timeout/;
  190. }
  191. }
  192. # Look for ISC/SCO with its unique uname program
  193. sub is_sco_uname {
  194. return undef unless IPC::Cmd::can_run('uname');
  195. open UNAME, "uname -X 2>/dev/null|" or return '';
  196. my $line = "";
  197. my $os = "";
  198. while ( <UNAME> ) {
  199. chop;
  200. $line = $_ if m@^Release@;
  201. $os = $_ if m@^System@;
  202. }
  203. close UNAME;
  204. return undef if $line eq '' or $os eq 'System = SunOS';
  205. my @fields = split(/\s+/, $line);
  206. return $fields[2];
  207. }
  208. sub get_sco_type {
  209. my $REL = shift;
  210. if ( -f "/etc/kconfig" ) {
  211. return "${MACHINE}-whatever-isc4" if $REL eq '4.0' || $REL eq '4.1';
  212. } else {
  213. return "whatever-whatever-sco3" if $REL eq '3.2v4.2';
  214. return "whatever-whatever-sco5" if $REL =~ m@3\.2v5\.0.*@;
  215. if ( $REL eq "4.2MP" ) {
  216. return "whatever-whatever-unixware20" if $VERSION =~ m@2\.0.*@;
  217. return "whatever-whatever-unixware21" if $VERSION =~ m@2\.1.*@;
  218. return "whatever-whatever-unixware2" if $VERSION =~ m@2.*@;
  219. }
  220. return "whatever-whatever-unixware1" if $REL eq "4.2";
  221. if ( $REL =~ m@5.*@ ) {
  222. # We hardcode i586 in place of ${MACHINE} for the following
  223. # reason: even though Pentium is minimum requirement for
  224. # platforms in question, ${MACHINE} gets always assigned to
  225. # i386. This means i386 gets passed to Configure, which will
  226. # cause bad assembler code to be generated.
  227. return "i586-sco-unixware7" if $VERSION =~ m@[678].*@;
  228. }
  229. }
  230. }
  231. # Return the cputype-vendor-osversion
  232. sub guess_system {
  233. ($SYSTEM, undef, $RELEASE, $VERSION, $MACHINE) = POSIX::uname();
  234. my $sys = "${SYSTEM}:${RELEASE}:${VERSION}:${MACHINE}";
  235. # Special-cases for ISC, SCO, Unixware
  236. my $REL = is_sco_uname();
  237. if ( defined $REL ) {
  238. my $result = get_sco_type($REL);
  239. return eval "\"$result\"" if $result ne '';
  240. }
  241. # Now pattern-match
  242. # Simple cases
  243. foreach my $tuple ( @$guess_patterns ) {
  244. my $pat = @$tuple[0];
  245. my $check = ref $pat eq 'CODE' ? $pat->($sys) : $sys =~ /^(${pat})$/;
  246. next unless $check;
  247. my $result = @$tuple[1];
  248. $result = $result->() if ref $result eq 'CODE';
  249. return eval "\"$result\"";
  250. }
  251. # Oh well.
  252. return "${MACHINE}-whatever-${SYSTEM}";
  253. }
  254. # We would use List::Util::pair() for this... unfortunately, that function
  255. # only appeared in perl v5.19.3, and we claim to support perl v5.10 and on.
  256. # Therefore, we implement a quick cheap variant of our own.
  257. sub _pairs (@) {
  258. croak "Odd number of arguments" if @_ & 1;
  259. my @pairlist = ();
  260. while (@_) {
  261. my $x = [ shift, shift ];
  262. push @pairlist, $x;
  263. }
  264. return @pairlist;
  265. }
  266. # Figure out CC, GCCVAR, etc.
  267. sub determine_compiler_settings {
  268. # Make a copy and don't touch it. That helps determine if we're finding
  269. # the compiler here (false), or if it was set by the user (true.
  270. my $cc = $CC;
  271. # Set certain default
  272. $CCVER = 0; # Unknown
  273. $CCVENDOR = ''; # Dunno, don't care (unless found later)
  274. # Find a compiler if we don't already have one
  275. if ( ! $cc ) {
  276. foreach (@c_compilers) {
  277. next unless IPC::Cmd::can_run("$CROSS_COMPILE$_");
  278. $CC = $_;
  279. last;
  280. }
  281. }
  282. if ( $CC ) {
  283. # Find the compiler vendor and version number for certain compilers
  284. foreach my $pair (_pairs @cc_version) {
  285. # Try to get the version number.
  286. # Failure gets us undef or an empty string
  287. my ( $k, $v ) = @$pair;
  288. $v = $v->();
  289. # If we got a version number, process it
  290. if ($v) {
  291. $v =~ s/[^.]*.0*// if $SYSTEM eq 'HP-UX';
  292. $CCVENDOR = $k;
  293. # The returned version is expected to be one of
  294. #
  295. # MAJOR
  296. # MAJOR.MINOR
  297. # MAJOR.MINOR.{whatever}
  298. #
  299. # We don't care what comes after MAJOR.MINOR. All we need is
  300. # to have them calculated into a single number, using this
  301. # formula:
  302. #
  303. # MAJOR * 100 + MINOR
  304. # Here are a few examples of what we should get:
  305. #
  306. # 2.95.1 => 295
  307. # 3.1 => 301
  308. # 9 => 900
  309. my @numbers = split /\./, $v;
  310. my @factors = (100, 1);
  311. while (@numbers && @factors) {
  312. $CCVER += shift(@numbers) * shift(@factors)
  313. }
  314. last;
  315. }
  316. }
  317. }
  318. # Vendor specific overrides, only if we didn't determine the compiler here
  319. if ( ! $cc ) {
  320. if ( $SYSTEM eq 'OpenVMS' ) {
  321. my $v = `CC/VERSION NLA0:`;
  322. if ($? == 0) {
  323. # The normal releases have a version number prefixed with a V.
  324. # However, other letters have been seen as well (for example X),
  325. # and it's documented that HP (now VSI) reserve the letter W, X,
  326. # Y and Z for their own uses.
  327. my ($vendor, $arch, $version, $extra) =
  328. ( $v =~ m/^
  329. ([A-Z]+) # Usually VSI
  330. \s+ C
  331. (?:\s+(.*?))? # Possible build arch
  332. \s+ [VWXYZ]([0-9\.-]+) # Version
  333. (?:\s+\((.*?)\))? # Possible extra data
  334. \s+ on
  335. /x );
  336. my ($major, $minor, $patch) =
  337. ( $version =~ m/^([0-9]+)\.([0-9]+)-0*?(0|[1-9][0-9]*)$/ );
  338. $CC = 'CC';
  339. $CCVENDOR = $vendor;
  340. $CCVER = ( $major * 100 + $minor ) * 100 + $patch;
  341. }
  342. }
  343. if ( ${SYSTEM} eq 'AIX' ) {
  344. # favor vendor cc over gcc
  345. if (IPC::Cmd::can_run('cc')) {
  346. $CC = 'cc';
  347. $CCVENDOR = ''; # Determine later
  348. $CCVER = 0;
  349. }
  350. }
  351. if ( $SYSTEM eq "SunOS" ) {
  352. # check for Oracle Developer Studio, expected output is "cc: blah-blah C x.x blah-blah"
  353. my $v = `(cc -V 2>&1) 2>/dev/null | egrep -e '^cc: .* C [0-9]\.[0-9]'`;
  354. my @numbers =
  355. ( $v =~ m/^.* C ([0-9]+)\.([0-9]+) .*/ );
  356. my @factors = (100, 1);
  357. $v = 0;
  358. while (@numbers && @factors) {
  359. $v += shift(@numbers) * shift(@factors)
  360. }
  361. if ($v > 500) {
  362. $CC = 'cc';
  363. $CCVENDOR = 'sun';
  364. $CCVER = $v;
  365. }
  366. }
  367. # 'Windows NT' is the system name according to POSIX::uname()!
  368. if ( $SYSTEM eq "Windows NT" ) {
  369. # favor vendor cl over gcc
  370. if (IPC::Cmd::can_run('cl')) {
  371. $CC = 'cl';
  372. $CCVENDOR = ''; # Determine later
  373. $CCVER = 0;
  374. my $v = `cl 2>&1`;
  375. if ( $v =~ /Microsoft .* Version ([0-9\.]+) for (x86|x64|ARM|ia64)/ ) {
  376. $CCVER = $1;
  377. $CL_ARCH = $2;
  378. }
  379. }
  380. }
  381. }
  382. # If no C compiler has been determined at this point, we die. Hard.
  383. die <<_____
  384. ERROR!
  385. No C compiler found, please specify one with the environment variable CC,
  386. or configure with an explicit configuration target.
  387. _____
  388. unless $CC;
  389. # On some systems, we assume a cc vendor if it's not already determined
  390. if ( ! $CCVENDOR ) {
  391. $CCVENDOR = 'aix' if $SYSTEM eq 'AIX';
  392. $CCVENDOR = 'sun' if $SYSTEM eq 'SunOS';
  393. }
  394. # Some systems need to know extra details
  395. if ( $SYSTEM eq "HP-UX" && $CCVENDOR eq 'gnu' ) {
  396. # By default gcc is a ILP32 compiler (with long long == 64).
  397. $GCC_BITS = "32";
  398. if ( $CCVER >= 300 ) {
  399. # PA64 support only came in with gcc 3.0.x.
  400. # We check if the preprocessor symbol __LP64__ is defined.
  401. if ( okrun('echo __LP64__',
  402. "$CC -v -E -x c - 2>/dev/null",
  403. 'grep "^__LP64__" 2>&1 >/dev/null') ) {
  404. # __LP64__ has slipped through, it therefore is not defined
  405. } else {
  406. $GCC_BITS = '64';
  407. }
  408. }
  409. }
  410. if ( $SYSTEM eq "SunOS" && $CCVENDOR eq 'gnu' ) {
  411. if ( $CCVER >= 300 ) {
  412. # 64-bit ABI isn't officially supported in gcc 3.0, but seems
  413. # to be working; at the very least 'make test' passes.
  414. if ( okrun("$CC -v -E -x c /dev/null 2>&1",
  415. 'grep __arch64__ >/dev/null') ) {
  416. $GCC_ARCH = "-m64"
  417. } else {
  418. $GCC_ARCH = "-m32"
  419. }
  420. }
  421. }
  422. if ($VERBOSE) {
  423. my $vendor = $CCVENDOR ? $CCVENDOR : "(undetermined)";
  424. my $version = $CCVER ? $CCVER : "(undetermined)";
  425. print "C compiler: $CC\n";
  426. print "C compiler vendor: $vendor\n";
  427. print "C compiler version: $version\n";
  428. }
  429. }
  430. my $map_patterns =
  431. [ [ 'uClinux.*64.*', { target => 'uClinux-dist64' } ],
  432. [ 'uClinux.*', { target => 'uClinux-dist' } ],
  433. [ 'mips3-sgi-irix', { target => 'irix-mips3' } ],
  434. [ 'mips4-sgi-irix64',
  435. sub {
  436. print <<EOF;
  437. WARNING! To build 64-bit package, do this:
  438. $WHERE/Configure irix64-mips4-$CC
  439. EOF
  440. maybe_abort();
  441. return { target => "irix-mips3" };
  442. }
  443. ],
  444. [ 'ppc-apple-rhapsody', { target => "rhapsody-ppc" } ],
  445. [ 'ppc-apple-darwin.*',
  446. sub {
  447. my $KERNEL_BITS = $ENV{KERNEL_BITS} // '';
  448. my $ISA64 = `sysctl -n hw.optional.64bitops 2>/dev/null`;
  449. if ( $ISA64 == 1 && $KERNEL_BITS eq '' ) {
  450. print <<EOF;
  451. WARNING! To build 64-bit package, do this:
  452. $WHERE/Configure darwin64-ppc-cc
  453. EOF
  454. maybe_abort();
  455. }
  456. return { target => "darwin64-ppc" }
  457. if $ISA64 == 1 && $KERNEL_BITS eq '64';
  458. return { target => "darwin-ppc" };
  459. }
  460. ],
  461. [ 'i.86-apple-darwin.*',
  462. sub {
  463. my $KERNEL_BITS = $ENV{KERNEL_BITS} // '';
  464. my $ISA64 = `sysctl -n hw.optional.x86_64 2>/dev/null`;
  465. if ( $ISA64 == 1 && $KERNEL_BITS eq '' ) {
  466. print <<EOF;
  467. WARNING! To build 64-bit package, do this:
  468. KERNEL_BITS=64 $WHERE/Configure [options...]
  469. EOF
  470. maybe_abort();
  471. }
  472. return { target => "darwin64-x86_64" }
  473. if $ISA64 == 1 && $KERNEL_BITS eq '64';
  474. return { target => "darwin-i386" };
  475. }
  476. ],
  477. [ 'x86_64-apple-darwin.*',
  478. sub {
  479. my $KERNEL_BITS = $ENV{KERNEL_BITS} // '';
  480. # macOS >= 10.15 is 64-bit only
  481. my $SW_VERS = `sw_vers -productVersion 2>/dev/null`;
  482. if ($SW_VERS =~ /^(\d+)\.(\d+)\.(\d+)$/) {
  483. if ($1 > 10 || ($1 == 10 && $2 >= 15)) {
  484. die "32-bit applications not supported on macOS 10.15 or later\n" if $KERNEL_BITS eq '32';
  485. return { target => "darwin64-x86_64" };
  486. }
  487. }
  488. return { target => "darwin-i386" } if $KERNEL_BITS eq '32';
  489. print <<EOF;
  490. WARNING! To build 32-bit package, do this:
  491. KERNEL_BITS=32 $WHERE/Configure [options...]
  492. EOF
  493. maybe_abort();
  494. return { target => "darwin64-x86_64" };
  495. }
  496. ],
  497. [ 'arm64-apple-darwin.*', { target => "darwin64-arm64" } ],
  498. [ 'armv6\+7-.*-iphoneos',
  499. { target => "iphoneos-cross",
  500. cflags => [ qw(-arch armv6 -arch armv7) ],
  501. cxxflags => [ qw(-arch armv6 -arch armv7) ] }
  502. ],
  503. [ 'arm64-.*-iphoneos|.*-.*-ios64',
  504. { target => "ios64-cross" }
  505. ],
  506. [ '.*-.*-iphoneos',
  507. sub { return { target => "iphoneos-cross",
  508. cflags => [ "-arch ${MACHINE}" ],
  509. cxxflags => [ "-arch ${MACHINE}" ] }; }
  510. ],
  511. [ 'alpha-.*-linux2.*',
  512. sub {
  513. my $ISA = `awk '/cpu model/{print \$4;exit(0);}' /proc/cpuinfo`;
  514. $ISA //= 'generic';
  515. my %config = ();
  516. if ( $CCVENDOR eq "gnu" ) {
  517. if ( $ISA =~ 'EV5|EV45' ) {
  518. %config = ( cflags => [ '-mcpu=ev5' ],
  519. cxxflags => [ '-mcpu=ev5' ] );
  520. } elsif ( $ISA =~ 'EV56|PCA56' ) {
  521. %config = ( cflags => [ '-mcpu=ev56' ],
  522. cxxflags => [ '-mcpu=ev56' ] );
  523. } else {
  524. %config = ( cflags => [ '-mcpu=ev6' ],
  525. cxxflags => [ '-mcpu=ev6' ] );
  526. }
  527. }
  528. return { target => "linux-alpha",
  529. %config };
  530. }
  531. ],
  532. [ 'ppc64-.*-linux2',
  533. sub {
  534. my $KERNEL_BITS = $ENV{KERNEL_BITS} // '';
  535. if ( $KERNEL_BITS eq '' ) {
  536. print <<EOF;
  537. WARNING! To build 64-bit package, do this:
  538. $WHERE/Configure linux-ppc64
  539. EOF
  540. maybe_abort();
  541. }
  542. return { target => "linux-ppc64" } if $KERNEL_BITS eq '64';
  543. my %config = ();
  544. if (!okrun('echo __LP64__',
  545. 'gcc -E -x c - 2>/dev/null',
  546. 'grep "^__LP64__" 2>&1 >/dev/null') ) {
  547. %config = ( cflags => [ '-m32' ],
  548. cxxflags => [ '-m32' ] );
  549. }
  550. return { target => "linux-ppc",
  551. %config };
  552. }
  553. ],
  554. [ 'ppc64le-.*-linux2', { target => "linux-ppc64le" } ],
  555. [ 'ppc-.*-linux2', { target => "linux-ppc" } ],
  556. [ 'mips64.*-*-linux2',
  557. sub {
  558. print <<EOF;
  559. WARNING! To build 64-bit package, do this:
  560. $WHERE/Configure linux64-mips64
  561. EOF
  562. maybe_abort();
  563. return { target => "linux-mips64" };
  564. }
  565. ],
  566. [ 'mips.*-.*-linux2', { target => "linux-mips32" } ],
  567. [ 'ppc60x-.*-vxworks.*', { target => "vxworks-ppc60x" } ],
  568. [ 'ppcgen-.*-vxworks.*', { target => "vxworks-ppcgen" } ],
  569. [ 'pentium-.*-vxworks.*', { target => "vxworks-pentium" } ],
  570. [ 'simlinux-.*-vxworks.*', { target => "vxworks-simlinux" } ],
  571. [ 'mips-.*-vxworks.*', { target => "vxworks-mips" } ],
  572. [ 'e2k-.*-linux.*', { target => "linux-generic64",
  573. defines => [ 'L_ENDIAN' ] } ],
  574. [ 'ia64-.*-linux.', { target => "linux-ia64" } ],
  575. [ 'sparc64-.*-linux2',
  576. sub {
  577. print <<EOF;
  578. WARNING! If you *know* that your GNU C supports 64-bit/V9 ABI and you
  579. want to build 64-bit library, do this:
  580. $WHERE/Configure linux64-sparcv9
  581. EOF
  582. maybe_abort();
  583. return { target => "linux-sparcv9" };
  584. }
  585. ],
  586. [ 'sparc-.*-linux2',
  587. sub {
  588. my $KARCH = `awk '/^type/{print \$3;exit(0);}' /proc/cpuinfo`;
  589. $KARCH //= "sun4";
  590. return { target => "linux-sparcv9" } if $KARCH =~ 'sun4u.*';
  591. return { target => "linux-sparcv8" } if $KARCH =~ 'sun4[md]';
  592. return { target => "linux-generic32",
  593. defines => [ 'L_ENDIAN' ] };
  594. }
  595. ],
  596. [ 'parisc.*-.*-linux2',
  597. sub {
  598. # 64-bit builds under parisc64 linux are not supported and
  599. # compiler is expected to generate 32-bit objects...
  600. my $CPUARCH =
  601. `awk '/cpu family/{print substr(\$5,1,3); exit(0);}' /proc/cpuinfo`;
  602. my $CPUSCHEDULE =
  603. `awk '/^cpu.[ ]*: PA/{print substr(\$3,3); exit(0);}' /proc/cpuinfo`;
  604. # TODO XXX Model transformations
  605. # 0. CPU Architecture for the 1.1 processor has letter suffixes.
  606. # We strip that off assuming no further arch. identification
  607. # will ever be used by GCC.
  608. # 1. I'm most concerned about whether is a 7300LC is closer to a
  609. # 7100 versus a 7100LC.
  610. # 2. The variant 64-bit processors cause concern should GCC support
  611. # explicit schedulers for these chips in the future.
  612. # PA7300LC -> 7100LC (1.1)
  613. # PA8200 -> 8000 (2.0)
  614. # PA8500 -> 8000 (2.0)
  615. # PA8600 -> 8000 (2.0)
  616. $CPUSCHEDULE =~ s/7300LC/7100LC/;
  617. $CPUSCHEDULE =~ s/8.00/8000/;
  618. return
  619. { target => "linux-generic32",
  620. defines => [ 'B_ENDIAN' ],
  621. cflags => [ "-mschedule=$CPUSCHEDULE", "-march=$CPUARCH" ],
  622. cxxflags => [ "-mschedule=$CPUSCHEDULE", "-march=$CPUARCH" ]
  623. };
  624. }
  625. ],
  626. [ 'armv[1-3].*-.*-linux2', { target => "linux-generic32" } ],
  627. [ 'armv[7-9].*-.*-linux2', { target => "linux-armv4",
  628. cflags => [ '-march=armv7-a' ],
  629. cxxflags => [ '-march=armv7-a' ] } ],
  630. [ 'arm.*-.*-linux2', { target => "linux-armv4" } ],
  631. [ 'aarch64-.*-linux2', { target => "linux-aarch64" } ],
  632. [ 'sh.*b-.*-linux2', { target => "linux-generic32",
  633. defines => [ 'B_ENDIAN' ] } ],
  634. [ 'sh.*-.*-linux2', { target => "linux-generic32",
  635. defines => [ 'L_ENDIAN' ] } ],
  636. [ 'loongarch64-.*-linux2',
  637. sub {
  638. my $disable = [ 'asm' ];
  639. if ( okrun('echo xvadd.w \$xr0,\$xr0,\$xr0',
  640. "$CC -c -x assembler - -o /dev/null 2>/dev/null") ) {
  641. $disable = [];
  642. }
  643. return { target => "linux64-loongarch64",
  644. disable => $disable, };
  645. }
  646. ],
  647. [ 'm68k.*-.*-linux2', { target => "linux-generic32",
  648. defines => [ 'B_ENDIAN' ] } ],
  649. [ 's390-.*-linux2', { target => "linux-generic32",
  650. defines => [ 'B_ENDIAN' ] } ],
  651. [ 's390x-.*-linux2',
  652. sub {
  653. # Disabled until a glibc bug is fixed; see Configure.
  654. if (0
  655. || okrun('egrep -e \'^features.* highgprs\' /proc/cpuinfo >/dev/null') )
  656. {
  657. print <<EOF;
  658. WARNING! To build "highgprs" 32-bit package, do this:
  659. $WHERE/Configure linux32-s390x
  660. EOF
  661. maybe_abort();
  662. }
  663. return { target => "linux64-s390x" };
  664. }
  665. ],
  666. [ 'x86_64-.*-linux.',
  667. sub {
  668. return { target => "linux-x32" }
  669. if okrun("$CC -dM -E -x c /dev/null 2>&1",
  670. 'grep -q ILP32 >/dev/null');
  671. return { target => "linux-x86_64" };
  672. }
  673. ],
  674. [ '.*86-.*-linux2',
  675. sub {
  676. # On machines where the compiler understands -m32, prefer a
  677. # config target that uses it
  678. return { target => "linux-x86" }
  679. if okrun("$CC -m32 -E -x c /dev/null >/dev/null 2>&1");
  680. return { target => "linux-elf" };
  681. }
  682. ],
  683. [ '.*86-.*-linux1', { target => "linux-aout" } ],
  684. [ 'riscv64-.*-linux.', { target => "linux64-riscv64" } ],
  685. [ '.*-.*-linux.', { target => "linux-generic32" } ],
  686. [ 'sun4[uv].*-.*-solaris2',
  687. sub {
  688. my $KERNEL_BITS = $ENV{KERNEL_BITS};
  689. my $ISA64 = `isainfo 2>/dev/null | grep sparcv9`;
  690. my $KB = $KERNEL_BITS // '64';
  691. if ( $ISA64 ne "" && $KB eq '64' ) {
  692. if ( $CCVENDOR eq "sun" && $CCVER >= 500 ) {
  693. print <<EOF;
  694. WARNING! To build 32-bit package, do this:
  695. $WHERE/Configure solaris-sparcv9-cc
  696. EOF
  697. maybe_abort();
  698. } elsif ( $CCVENDOR eq "gnu" && $GCC_ARCH eq "-m64" ) {
  699. # $GCC_ARCH denotes default ABI chosen by compiler driver
  700. # (first one found on the $PATH). I assume that user
  701. # expects certain consistency with the rest of his builds
  702. # and therefore switch over to 64-bit. <appro>
  703. print <<EOF;
  704. WARNING! To build 32-bit package, do this:
  705. $WHERE/Configure solaris-sparcv9-gcc
  706. EOF
  707. maybe_abort();
  708. return { target => "solaris64-sparcv9-gcc" };
  709. } elsif ( $GCC_ARCH eq "-m32" ) {
  710. print <<EOF;
  711. NOTICE! If you *know* that your GNU C supports 64-bit/V9 ABI and you wish
  712. to build 64-bit library, do this:
  713. $WHERE/Configure solaris64-sparcv9-gcc
  714. EOF
  715. maybe_abort();
  716. }
  717. }
  718. return { target => "solaris64-sparcv9-cc" }
  719. if $ISA64 ne "" && $KB eq '64';
  720. return { target => "solaris-sparcv9-cc" };
  721. }
  722. ],
  723. [ 'sun4m-.*-solaris2', { target => "solaris-sparcv8" } ],
  724. [ 'sun4d-.*-solaris2', { target => "solaris-sparcv8" } ],
  725. [ 'sun4.*-.*-solaris2', { target => "solaris-sparcv7" } ],
  726. [ '.*86.*-.*-solaris2',
  727. sub {
  728. my $KERNEL_BITS = $ENV{KERNEL_BITS};
  729. my $ISA64 = `isainfo 2>/dev/null | grep amd64`;
  730. my $KB = $KERNEL_BITS // '64';
  731. if ($ISA64 ne "" && $KB eq '64') {
  732. return { target => "solaris64-x86_64-gcc" } if $CCVENDOR eq "gnu";
  733. return { target => "solaris64-x86_64-cc" };
  734. }
  735. my $REL = uname('-r');
  736. $REL =~ s/5\.//;
  737. my @tmp_disable = ();
  738. push @tmp_disable, 'sse2' if int($REL) < 10;
  739. #There is no solaris-x86-cc target
  740. return { target => "solaris-x86-gcc",
  741. disable => [ @tmp_disable ] };
  742. }
  743. ],
  744. # We don't have any sunos target in Configurations/*.conf, so why here?
  745. [ '.*-.*-sunos4', { target => "sunos" } ],
  746. [ '.*86.*-.*-bsdi4', { target => "BSD-x86-elf",
  747. lflags => [ '-ldl' ],
  748. disable => [ 'sse2' ] } ],
  749. [ 'alpha.*-.*-.*bsd.*', { target => "BSD-generic64",
  750. defines => [ 'L_ENDIAN' ] } ],
  751. [ 'powerpc-.*-.*bsd.*', { target => "BSD-ppc" } ],
  752. [ 'powerpc64-.*-.*bsd.*', { target => "BSD-ppc64" } ],
  753. [ 'powerpc64le-.*-.*bsd.*', { target => "BSD-ppc64le" } ],
  754. [ 'riscv64-.*-.*bsd.*', { target => "BSD-riscv64" } ],
  755. [ 'sparc64-.*-.*bsd.*', { target => "BSD-sparc64" } ],
  756. [ 'ia64-.*-openbsd.*', { target => "BSD-nodef-ia64" } ],
  757. [ 'ia64-.*-.*bsd.*', { target => "BSD-ia64" } ],
  758. [ 'x86_64-.*-dragonfly.*', { target => "BSD-x86_64" } ],
  759. [ 'amd64-.*-openbsd.*', { target => "BSD-nodef-x86_64" } ],
  760. [ 'amd64-.*-.*bsd.*', { target => "BSD-x86_64" } ],
  761. [ 'arm64-.*-.*bsd.*', { target => "BSD-aarch64" } ],
  762. [ 'armv6-.*-.*bsd.*', { target => "BSD-armv4" } ],
  763. [ 'armv7-.*-.*bsd.*', { target => "BSD-armv4" } ],
  764. [ '.*86.*-.*-.*bsd.*',
  765. sub {
  766. # mimic ld behaviour when it's looking for libc...
  767. my $libc;
  768. if ( -l "/usr/lib/libc.so" ) {
  769. $libc = "/usr/lib/libc.so";
  770. } else {
  771. # ld searches for highest libc.so.* and so do we
  772. $libc =
  773. `(ls /usr/lib/libc.so.* /lib/libc.so.* | tail -1) 2>/dev/null`;
  774. }
  775. my $what = `file -L $libc 2>/dev/null`;
  776. return { target => "BSD-x86-elf" } if $what =~ /ELF/;
  777. return { target => "BSD-x86",
  778. disable => [ 'sse2' ] };
  779. }
  780. ],
  781. [ '.*-.*-openbsd.*', { target => "BSD-nodef-generic32" } ],
  782. [ '.*-.*-.*bsd.*', { target => "BSD-generic32" } ],
  783. [ 'x86_64-.*-haiku', { target => "haiku-x86_64" } ],
  784. [ '.*-.*-haiku', { target => "haiku-x86" } ],
  785. [ '.*-.*-osf', { target => "osf1-alpha" } ],
  786. [ '.*-.*-tru64', { target => "tru64-alpha" } ],
  787. [ '.*-.*-[Uu]nix[Ww]are7',
  788. sub {
  789. return { target => "unixware-7",
  790. disable => [ 'sse2' ] } if $CCVENDOR eq "gnu";
  791. return { target => "unixware-7",
  792. defines => [ '__i386__' ] };
  793. }
  794. ],
  795. [ '.*-.*-[Uu]nix[Ww]are20.*', { target => "unixware-2.0",
  796. disable => [ 'sse2', 'sha512' ] } ],
  797. [ '.*-.*-[Uu]nix[Ww]are21.*', { target => "unixware-2.1",
  798. disable => [ 'sse2', 'sha512' ] } ],
  799. [ '.*-.*-vos', { target => "vos",
  800. disable => [ 'threads', 'shared', 'asm',
  801. 'dso' ] } ],
  802. [ 'BS2000-siemens-sysv4', { target => "BS2000-OSD" } ],
  803. [ 'i[3456]86-.*-cygwin', { target => "Cygwin-x86" } ],
  804. [ '.*-.*-cygwin',
  805. sub { return { target => "Cygwin-${MACHINE}" } } ],
  806. [ 'x86-.*-android|i.86-.*-android', { target => "android-x86" } ],
  807. [ 'armv[7-9].*-.*-android', { target => "android-armeabi",
  808. cflags => [ '-march=armv7-a' ],
  809. cxxflags => [ '-march=armv7-a' ] } ],
  810. [ 'arm.*-.*-android', { target => "android-armeabi" } ],
  811. [ 'riscv64-.*-android', { target => "android-riscv64" } ],
  812. [ '.*-hpux1.*',
  813. sub {
  814. my $KERNEL_BITS = $ENV{KERNEL_BITS};
  815. my %common_return = ( defines => [ '_REENTRANT' ] );
  816. $KERNEL_BITS ||= `getconf KERNEL_BITS 2>/dev/null` // '32';
  817. # See <sys/unistd.h> for further info on CPU_VERSION.
  818. my $CPU_VERSION = `getconf CPU_VERSION 2>/dev/null` // 0;
  819. if ( $CPU_VERSION >= 768 ) {
  820. # IA-64 CPU
  821. return { target => "hpux64-ia64",
  822. %common_return }
  823. if $KERNEL_BITS eq '64' && ! $CCVENDOR;
  824. return { target => "hpux-ia64",
  825. %common_return };
  826. }
  827. if ( $CPU_VERSION >= 532 ) {
  828. # PA-RISC 2.x CPU
  829. # PA-RISC 2.0 is no longer supported as separate 32-bit
  830. # target. This is compensated for by run-time detection
  831. # in most critical assembly modules and taking advantage
  832. # of 2.0 architecture in PA-RISC 1.1 build.
  833. my $target = ($CCVENDOR eq "gnu" && $GCC_BITS eq '64')
  834. ? "hpux64-parisc2"
  835. : "hpux-parisc1_1";
  836. if ( $KERNEL_BITS eq '64' && ! $CCVENDOR ) {
  837. print <<EOF;
  838. WARNING! To build 64-bit package, do this:
  839. $WHERE/Configure hpux64-parisc2-cc
  840. EOF
  841. maybe_abort();
  842. }
  843. return { target => $target,
  844. %common_return };
  845. }
  846. # PA-RISC 1.1+ CPU?
  847. return { target => "hpux-parisc1_1",
  848. %common_return } if $CPU_VERSION >= 528;
  849. # PA-RISC 1.0 CPU
  850. return { target => "hpux-parisc",
  851. %common_return } if $CPU_VERSION >= 523;
  852. # Motorola(?) CPU
  853. return { target => "hpux",
  854. %common_return };
  855. }
  856. ],
  857. [ '.*-hpux', { target => "hpux-parisc" } ],
  858. [ '.*-aix',
  859. sub {
  860. my %config = ();
  861. my $KERNEL_BITS = $ENV{KERNEL_BITS};
  862. $KERNEL_BITS ||= `getconf KERNEL_BITMODE 2>/dev/null`;
  863. $KERNEL_BITS ||= '32';
  864. my $OBJECT_MODE = $ENV{OBJECT_MODE};
  865. $OBJECT_MODE ||= 32;
  866. $config{target} = "aix";
  867. if ( $OBJECT_MODE == 64 ) {
  868. print 'Your $OBJECT_MODE was found to be set to 64';
  869. $config{target} = "aix64";
  870. } else {
  871. if ( $CCVENDOR ne 'gnu' && $KERNEL_BITS eq '64' ) {
  872. print <<EOF;
  873. WARNING! To build 64-bit package, do this:
  874. $WHERE/Configure aix64-cc
  875. EOF
  876. maybe_abort();
  877. }
  878. }
  879. if ( okrun(
  880. "(lsattr -E -O -l `lsdev -c processor|awk '{print \$1;exit}'`",
  881. 'grep -i powerpc) >/dev/null 2>&1') ) {
  882. # this applies even to Power3 and later, as they return
  883. # PowerPC_POWER[345]
  884. } else {
  885. $config{disable} = [ 'asm' ];
  886. }
  887. return { %config };
  888. }
  889. ],
  890. # Windows values found by looking at Perl 5's win32/win32.c
  891. [ '(amd64|ia64|x86|ARM)-.*?-Windows NT',
  892. sub {
  893. # If we determined the arch by asking cl, take that value,
  894. # otherwise the SYSTEM we got from from POSIX::uname().
  895. my $arch = $CL_ARCH // $1;
  896. my $config;
  897. if ($arch) {
  898. $config = { 'amd64' => { target => 'VC-WIN64A' },
  899. 'ia64' => { target => 'VC-WIN64I' },
  900. 'x86' => { target => 'VC-WIN32' },
  901. 'x64' => { target => 'VC-WIN64A' },
  902. 'ARM' => { target => 'VC-WIN64-ARM' },
  903. } -> {$arch};
  904. die <<_____ unless defined $config;
  905. ERROR
  906. I do not know how to handle ${arch}.
  907. _____
  908. }
  909. die <<_____ unless defined $config;
  910. ERROR
  911. Could not figure out the architecture.
  912. _____
  913. return $config;
  914. }
  915. ],
  916. # VMS values found by observation on existing machinery.
  917. [ 'VMS_AXP-.*?-OpenVMS', { target => 'vms-alpha' } ],
  918. [ 'VMS_IA64-.*?-OpenVMS', { target => 'vms-ia64' } ],
  919. [ 'VMS_x86_64-.*?-OpenVMS', { target => 'vms-x86_64' } ],
  920. # TODO: There are a few more choices among OpenSSL config targets, but
  921. # reaching them involves a bit more than just a host tripet. Select
  922. # environment variables could do the job to cover for more granular
  923. # build options such as data model (ILP32 or LP64), thread support
  924. # model (PUT, SPT or nothing), target execution environment (OSS or
  925. # GUARDIAN). And still, there must be some kind of default when
  926. # nothing else is said.
  927. #
  928. # nsv is a virtual x86 environment, equivalent to nsx, so we enforce
  929. # the latter.
  930. [ 'nse-tandem-nsk.*', { target => 'nonstop-nse' } ],
  931. [ 'nsv-tandem-nsk.*', { target => 'nonstop-nsx' } ],
  932. [ 'nsx-tandem-nsk.*', { target => 'nonstop-nsx' } ],
  933. ];
  934. # Map GUESSOS into OpenSSL terminology.
  935. # Returns a hash table with diverse entries, most importantly 'target',
  936. # but also other entries that are fitting for Configure's %config
  937. # and MACHINE.
  938. # It would be nice to fix this so that this weren't necessary. :( XXX
  939. sub map_guess {
  940. my $GUESSOS = shift;
  941. foreach my $tuple ( @$map_patterns ) {
  942. my $pat = @$tuple[0];
  943. next if $GUESSOS !~ /^${pat}$/;
  944. my $result = @$tuple[1];
  945. $result = $result->() if ref $result eq 'CODE';
  946. return %$result;
  947. }
  948. # Last case, return "z" from x-y-z
  949. my @fields = split(/-/, $GUESSOS);
  950. return ( target => $fields[2] );
  951. }
  952. # gcc < 2.8 does not support -march=ultrasparc
  953. sub check_solaris_sparc8 {
  954. my $OUT = shift;
  955. if ( $CCVENDOR eq 'gnu' && $CCVER < 208 ) {
  956. if ( $OUT eq 'solaris-sparcv9-gcc' ) {
  957. print <<EOF;
  958. WARNING! Downgrading to solaris-sparcv8-gcc
  959. Upgrade to gcc-2.8 or later.
  960. EOF
  961. maybe_abort();
  962. return 'solaris-sparcv8-gcc';
  963. }
  964. if ( $OUT eq "linux-sparcv9" ) {
  965. print <<EOF;
  966. WARNING! Downgrading to linux-sparcv8
  967. Upgrade to gcc-2.8 or later.
  968. EOF
  969. maybe_abort();
  970. return 'linux-sparcv8';
  971. }
  972. }
  973. return $OUT;
  974. }
  975. ###
  976. ### MAIN PROCESSING
  977. ###
  978. sub get_platform {
  979. my %options = @_;
  980. $VERBOSE = 1 if defined $options{verbose};
  981. $WAIT = 0 if defined $options{nowait};
  982. $CC = $options{CC};
  983. $CROSS_COMPILE = $options{CROSS_COMPILE} // '';
  984. my $GUESSOS = guess_system();
  985. determine_compiler_settings();
  986. my %ret = map_guess($GUESSOS);
  987. $ret{target} = check_solaris_sparc8($ret{target});
  988. return %ret;
  989. }
  990. 1;