Make "make variables" config attributes for overridable flags
[openssl.git] / Configurations / 10-main.conf
1 ## -*- mode: perl; -*-
2 ## Standard openssl configuration targets.
3
4 # Helper functions for the Windows configs
5 my $vc_win64a_info = {};
6 sub vc_win64a_info {
7     unless (%$vc_win64a_info) {
8         if (`nasm -v 2>NUL` =~ /NASM version ([0-9]+\.[0-9]+)/ && $1 >= 2.0) {
9             $vc_win64a_info = { AS        => "nasm",
10                                 ASFLAGS   => "-g",
11                                 asflags   => "-Ox -f win64 -DNEAR",
12                                 asoutflag => "-o" };
13         } elsif ($disabled{asm}) {
14             $vc_win64a_info = { AS        => "ml64",
15                                 ASFLAGS   => "/Zi",
16                                 asflags   => "/c /Cp /Cx",
17                                 asoutflag => "/Fo" };
18         } else {
19             $die->("NASM not found - please read INSTALL and NOTES.WIN for further details\n");
20             $vc_win64a_info = { AS        => "{unknown}",
21                                 ASFLAGS   => "",
22                                 asflags   => "",
23                                 asoutflag => "" };
24         }
25     }
26     return $vc_win64a_info;
27 }
28
29 my $vc_win32_info = {};
30 sub vc_win32_info {
31     unless (%$vc_win32_info) {
32         my $ver=`nasm -v 2>NUL`;
33         my $vew=`nasmw -v 2>NUL`;
34         if ($ver ne "" || $vew ne "") {
35             $vc_win32_info = { AS        => $ver ge $vew ? "nasm" : "nasmw",
36                                ASFLAGS   => "",
37                                asflags   => "-f win32",
38                                asoutflag => "-o",
39                                perlasm_scheme => "win32n" };
40         } elsif ($disabled{asm}) {
41             $vc_win32_info = { AS        => "ml",
42                                ASFLAGS   => "/nologo /Zi",
43                                asflags   => "/Cp /coff /c /Cx",
44                                asoutflag => "/Fo",
45                                perlasm_scheme => "win32" };
46         } else {
47             $die->("NASM not found - please read INSTALL and NOTES.WIN for further details\n");
48             $vc_win32_info = { AS        => "{unknown}",
49                                ASFLAGS   => "",
50                                asflags   => "",
51                                asoutflag => "",
52                                perlasm_scheme => "win32" };
53         }
54     }
55     return $vc_win32_info;
56 }
57
58 my $vc_wince_info = {};
59 sub vc_wince_info {
60     unless (%$vc_wince_info) {
61         # sanity check
62         $die->('%OSVERSION% is not defined') if (!defined(env('OSVERSION')));
63         $die->('%PLATFORM% is not defined')  if (!defined(env('PLATFORM')));
64         $die->('%TARGETCPU% is not defined') if (!defined(env('TARGETCPU')));
65
66         #
67         # Idea behind this is to mimic flags set by eVC++ IDE...
68         #
69         my $wcevers = env('OSVERSION');                     # WCENNN
70         my $wcevernum;
71         my $wceverdotnum;
72         if ($wcevers =~ /^WCE([1-9])([0-9]{2})$/) {
73             $wcevernum = "$1$2";
74             $wceverdotnum = "$1.$2";
75         } else {
76             $die->('%OSVERSION% value is insane');
77             $wcevernum = "{unknown}";
78             $wceverdotnum = "{unknown}";
79         }
80         my $wcecdefs = "-D_WIN32_WCE=$wcevernum -DUNDER_CE=$wcevernum"; # -D_WIN32_WCE=NNN
81         my $wcelflag = "/subsystem:windowsce,$wceverdotnum";        # ...,N.NN
82
83         my $wceplatf =  env('PLATFORM');
84
85         $wceplatf =~ tr/a-z0-9 /A-Z0-9_/;
86         $wcecdefs .= " -DWCE_PLATFORM_$wceplatf";
87
88         my $wcetgt = env('TARGETCPU');                      # just shorter name...
89       SWITCH: for($wcetgt) {
90           /^X86/        && do { $wcecdefs.=" -Dx86 -D_X86_ -D_i386_ -Di_386_";
91                                 $wcelflag.=" /machine:X86";     last; };
92           /^ARMV4[IT]/  && do { $wcecdefs.=" -DARM -D_ARM_ -D$wcetgt";
93                                 $wcecdefs.=" -DTHUMB -D_THUMB_" if($wcetgt=~/T$/);
94                                 $wcecdefs.=" -QRarch4T -QRinterwork-return";
95                                 $wcelflag.=" /machine:THUMB";   last; };
96           /^ARM/        && do { $wcecdefs.=" -DARM -D_ARM_ -D$wcetgt";
97                                 $wcelflag.=" /machine:ARM";     last; };
98           /^MIPSIV/     && do { $wcecdefs.=" -DMIPS -D_MIPS_ -DR4000 -D$wcetgt";
99                                 $wcecdefs.=" -D_MIPS64 -QMmips4 -QMn32";
100                                 $wcelflag.=" /machine:MIPSFPU"; last; };
101           /^MIPS16/     && do { $wcecdefs.=" -DMIPS -D_MIPS_ -DR4000 -D$wcetgt";
102                                 $wcecdefs.=" -DMIPSII -QMmips16";
103                                 $wcelflag.=" /machine:MIPS16";  last; };
104           /^MIPSII/     && do { $wcecdefs.=" -DMIPS -D_MIPS_ -DR4000 -D$wcetgt";
105                                 $wcecdefs.=" -QMmips2";
106                                 $wcelflag.=" /machine:MIPS";    last; };
107           /^R4[0-9]{3}/ && do { $wcecdefs.=" -DMIPS -D_MIPS_ -DR4000";
108                                 $wcelflag.=" /machine:MIPS";    last; };
109           /^SH[0-9]/    && do { $wcecdefs.=" -D$wcetgt -D_${wcetgt}_ -DSHx";
110                                 $wcecdefs.=" -Qsh4" if ($wcetgt =~ /^SH4/);
111                                 $wcelflag.=" /machine:$wcetgt"; last; };
112           { $wcecdefs.=" -D$wcetgt -D_${wcetgt}_";
113             $wcelflag.=" /machine:$wcetgt";                     last; };
114       }
115
116         $vc_wince_info = { cppflags => $wcecdefs,
117                            lflags => $wcelflag };
118     }
119     return $vc_wince_info;
120 }
121
122 # Helper functions for the VMS configs
123 my $vms_info = {};
124 sub vms_info {
125     my $pointer_size_str = $config{target} =~ m|-p(\d+)$| ? $1 : "";
126
127     # For the case where Configure iterate through all config targets, such
128     # as when listing them and their details, we reset info if the pointer
129     # size changes.
130     if (%$vms_info && $vms_info->{pointer_size} ne $pointer_size_str) {
131         $vms_info = {};
132     }
133
134     unless (%$vms_info) {
135         $vms_info->{disable_warns} = [ ];
136         $vms_info->{pointer_size} = $pointer_size_str;
137         if ($pointer_size_str eq "64") {
138             `PIPE CC /NOCROSS_REFERENCE /NOLIST /NOOBJECT /WARNINGS = DISABLE = ( MAYLOSEDATA3, EMPTYFILE ) NL: 2> NL:`;
139             if ($? == 0) {
140                 push @{$vms_info->{disable_warns}}, "MAYLOSEDATA3";
141             }
142         }
143
144         unless ($disabled{zlib}) {
145             my $default_zlib = 'GNV$LIBZSHR' . $pointer_size_str;
146             if (defined($disabled{"zlib-dynamic"})) {
147                 $vms_info->{zlib} = $withargs{zlib_lib} || "$default_zlib/SHARE";
148             } else {
149                 $vms_info->{def_zlib} = $withargs{zlib_lib} || $default_zlib;
150                 # In case the --with-zlib-lib value contains something like
151                 # /SHARE or /LIB or so at the end, remove it.
152                 $vms_info->{def_zlib} =~ s|/.*$||g;
153             }
154         }
155
156         if ($config{target} =~ /-ia64/) {
157             `PIPE ias -H 2> NL:`;
158             if ($? == 0) {
159                 $vms_info->{AS} = "ias";
160                 $vms_info->{ASFLAGS} = '-d debug';
161                 $vms_info->{asflags} = '"-N" vms_upcase';
162                 $vms_info->{asoutflag} = "-o";
163                 $vms_info->{perlasm_scheme} = "ias";
164             }
165         }
166     }
167     return $vms_info;
168 }
169
170 my %targets = (
171
172 #### Basic configs that should work on any 32-bit box
173     "gcc" => {
174         inherit_from     => [ "BASE_unix" ],
175         CC               => "gcc",
176         CFLAGS           => picker(debug   => "-O0 -g",
177                                    release => "-O3"),
178         thread_scheme    => "(unknown)",
179         bn_ops           => "BN_LLONG",
180     },
181     "cc" => {
182         inherit_from     => [ "BASE_unix" ],
183         CC               => "cc",
184         CFLAGS           => "-O",
185         thread_scheme    => "(unknown)",
186     },
187
188 #### VOS Configurations
189     "vos-gcc" => {
190         inherit_from     => [ "BASE_unix" ],
191         CC               => "gcc",
192         CFLAGS           => picker(default => "-Wall",
193                                    debug   => "-O0 -g",
194                                    release => "-O3"),
195         cppflags         => "-D_POSIX_C_SOURCE=200112L -D_BSD -D_VOS_EXTENDED_NAMES -DB_ENDIAN",
196         thread_scheme    => "(unknown)",
197         sys_id           => "VOS",
198         lflags           => add("-Wl,-map"),
199         bn_ops           => "BN_LLONG",
200         shared_extension => ".so",
201     },
202
203 #### Solaris configurations
204     "solaris-common" => {
205         inherit_from     => [ "BASE_unix" ],
206         template         => 1,
207         cppflags         => "-DFILIO_H",
208         ex_libs          => add("-lsocket -lnsl -ldl"),
209         dso_scheme       => "dlfcn",
210         thread_scheme    => "pthreads",
211         shared_target    => "solaris-shared",
212         shared_extension => ".so.\$(SHLIB_VERSION_NUMBER)",
213     },
214 #### Solaris x86 with GNU C setups
215     "solaris-x86-gcc" => {
216         # NB. GNU C has to be configured to use GNU assembler, and not
217         # /usr/ccs/bin/as. Failure to comply will result in compile
218         # failures [at least] in 32-bit build.
219         inherit_from     => [ "solaris-common", asm("x86_elf_asm") ],
220         CC               => "gcc",
221         CFLAGS           => add_before(picker(default => "-Wall",
222                                               debug   => "-O0 -g",
223                                               release => "-O3 -fomit-frame-pointer")),
224         cflags           => add(threads("-pthread")),
225         cppflags         => add("-DL_ENDIAN"),
226         ex_libs          => add(threads("-pthread")),
227         bn_ops           => "BN_LLONG",
228         shared_cflag     => "-fPIC",
229         shared_ldflag    => "-shared -static-libgcc",
230     },
231     "solaris64-x86_64-gcc" => {
232         # -shared -static-libgcc might appear controversial, but modules
233         # taken from static libgcc do not have relocations and linking
234         # them into our shared objects doesn't have any negative side
235         # effects. On the contrary, doing so makes it possible to use
236         # gcc shared build with Sun C. Given that gcc generates faster
237         # code [thanks to inline assembler], I would actually recommend
238         # to consider using gcc shared build even with vendor compiler:-)
239         #                        -- <appro@openssl.org>
240         inherit_from     => [ "solaris-common", asm("x86_64_asm") ],
241         CC               => "gcc",
242         CFLAGS           => add_before(picker(default => "-Wall",
243                                               debug   => "-O0 -g",
244                                               release => "-O3")),
245         cflags           => add_before("-m64", threads("-pthread")),
246         cppflags         => add("-DL_ENDIAN"),
247         ex_libs          => add(threads("-pthread")),
248         bn_ops           => "SIXTY_FOUR_BIT_LONG",
249         perlasm_scheme   => "elf",
250         shared_cflag     => "-fPIC",
251         shared_ldflag    => "-shared -static-libgcc",
252         multilib         => "/64",
253     },
254
255 #### Solaris x86 with Sun C setups
256     # There used to be solaris-x86-cc target, but it was removed,
257     # primarily because vendor assembler can't assemble our modules
258     # with -KPIC flag. As result it, assembly support, was not even
259     # available as option. But its lack means lack of side-channel
260     # resistant code, which is incompatible with security by todays
261     # standards. Fortunately gcc is readily available prepackaged
262     # option, which we can firmly point at...
263     #
264     # On related note, solaris64-x86_64-cc target won't compile code
265     # paths utilizing AVX and post-Haswell instruction extensions.
266     # Consider switching to solaris64-x86_64-gcc even here...
267     #
268     "solaris64-x86_64-cc" => {
269         inherit_from     => [ "solaris-common", asm("x86_64_asm") ],
270         CC               => "cc",
271         CFLAGS           => add_before(picker(debug   => "-g",
272                                               release => "-xO5 -xdepend -xbuiltin")),
273         cflags           => add_before("-xarch=generic64 -xstrconst -Xa"),
274         cppflags         => add("-DL_ENDIAN", threads("-D_REENTRANT")),
275         thread_scheme    => "pthreads",
276         lflags           => add(threads("-mt")),
277         ex_libs          => add(threads("-lpthread")),
278         bn_ops           => "SIXTY_FOUR_BIT_LONG",
279         perlasm_scheme   => "elf",
280         shared_cflag     => "-KPIC",
281         shared_ldflag    => "-G -dy -z text",
282         multilib         => "/64",
283     },
284
285 #### SPARC Solaris with GNU C setups
286     "solaris-sparcv7-gcc" => {
287         inherit_from     => [ "solaris-common" ],
288         CC               => "gcc",
289         CFLAGS           => add_before(picker(default => "-Wall",
290                                               debug   => "-O0 -g",
291                                               release => "-O3")),
292         cflags           => add(threads("-pthread")),
293         cppflags         => add("-DB_ENDIAN -DBN_DIV2W"),
294         ex_libs          => add(threads("-pthread")),
295         bn_ops           => "BN_LLONG RC4_CHAR",
296         shared_cflag     => "-fPIC",
297         shared_ldflag    => "-shared",
298     },
299     "solaris-sparcv8-gcc" => {
300         inherit_from     => [ "solaris-sparcv7-gcc", asm("sparcv8_asm") ],
301         cflags           => add_before("-mcpu=v8"),
302     },
303     "solaris-sparcv9-gcc" => {
304         # -m32 should be safe to add as long as driver recognizes
305         # -mcpu=ultrasparc
306         inherit_from     => [ "solaris-sparcv7-gcc", asm("sparcv9_asm") ],
307         cflags           => add_before("-m32 -mcpu=ultrasparc"),
308     },
309     "solaris64-sparcv9-gcc" => {
310         inherit_from     => [ "solaris-sparcv9-gcc" ],
311         cflags           => sub { my $f=join(" ",@_); $f =~ s/\-m32/-m64/; $f; },
312         bn_ops           => "BN_LLONG RC4_CHAR",
313         multilib         => "/64",
314     },
315
316 #### SPARC Solaris with Sun C setups
317 # SC4.0 doesn't pass 'make test', upgrade to SC5.0 or SC4.2.
318 # SC4.2 is ok, better than gcc even on bn as long as you tell it -xarch=v8
319 # SC5.0 note: Compiler common patch 107357-01 or later is required!
320     "solaris-sparcv7-cc" => {
321         inherit_from     => [ "solaris-common" ],
322         CC               => "cc",
323         CFLAGS           => add_before(picker(debug   => "-g",
324                                               release => "-xO5 -xdepend")),
325         cflags           => add_before("-xstrconst -Xa"),
326         cppflags         => add("-DB_ENDIAN -DBN_DIV2W",
327                                 threads("-D_REENTRANT")),
328         lflags           => add(threads("-mt")),
329         ex_libs          => add(threads("-lpthread")),
330         bn_ops           => "BN_LLONG RC4_CHAR",
331         shared_cflag     => "-KPIC",
332         shared_ldflag    => "-G -dy -z text",
333     },
334 ####
335     "solaris-sparcv8-cc" => {
336         inherit_from     => [ "solaris-sparcv7-cc", asm("sparcv8_asm") ],
337         cflags           => add_before("-xarch=v8"),
338     },
339     "solaris-sparcv9-cc" => {
340         inherit_from     => [ "solaris-sparcv7-cc", asm("sparcv9_asm") ],
341         cflags           => add_before("-xarch=v8plus"),
342     },
343     "solaris64-sparcv9-cc" => {
344         inherit_from     => [ "solaris-sparcv7-cc", asm("sparcv9_asm") ],
345         cflags           => add_before("-xarch=v9"),
346         bn_ops           => "BN_LLONG RC4_CHAR",
347         multilib         => "/64",
348     },
349
350 #### IRIX 6.x configs
351 # Only N32 and N64 ABIs are supported.
352     "irix-mips3-gcc" => {
353         inherit_from     => [ "BASE_unix", asm("mips64_asm") ],
354         CC               => "gcc",
355         CFLAGS           => picker(debug   => "-g -O0",
356                                    release => "-O3"),
357         cflags           => "-mabi=n32",
358         cppflags         => combine("-DB_ENDIAN -DBN_DIV3W",
359                                     threads("-D_SGI_MP_SOURCE")),
360         ex_libs          => add(threads("-lpthread")),
361         bn_ops           => "RC4_CHAR SIXTY_FOUR_BIT",
362         thread_scheme    => "pthreads",
363         perlasm_scheme   => "n32",
364         dso_scheme       => "dlfcn",
365         shared_target    => "irix-shared",
366         shared_extension => ".so.\$(SHLIB_VERSION_NUMBER)",
367         multilib         => "32",
368     },
369     "irix-mips3-cc" => {
370         inherit_from     => [ "BASE_unix", asm("mips64_asm") ],
371         CC               => "cc",
372         CFLAGS           => picker(debug   => "-g -O0",
373                                    release => "-O2"),
374         cflags           => "-n32 -mips3 -use_readonly_const -G0 -rdata_shared",
375         cppflags         => combine("-DB_ENDIAN -DBN_DIV3W",
376                                     threads("-D_SGI_MP_SOURCE")),
377         ex_libs          => add(threads("-lpthread")),
378         bn_ops           => "RC4_CHAR SIXTY_FOUR_BIT",
379         thread_scheme    => "pthreads",
380         perlasm_scheme   => "n32",
381         dso_scheme       => "dlfcn",
382         shared_target    => "irix-shared",
383         shared_extension => ".so.\$(SHLIB_VERSION_NUMBER)",
384         multilib         => "32",
385     },
386     # N64 ABI builds.
387     "irix64-mips4-gcc" => {
388         inherit_from     => [ "BASE_unix", asm("mips64_asm") ],
389         CC               => "gcc",
390         CFLAGS           => picker(debug   => "-g -O0",
391                                    release => "-O3"),
392         cflags           => "-mabi=64 -mips4",
393         cppflags         => combine("-DB_ENDIAN -DBN_DIV3W",
394                                     threads("-D_SGI_MP_SOURCE")),
395         ex_libs          => add(threads("-lpthread")),
396         bn_ops           => "RC4_CHAR SIXTY_FOUR_BIT_LONG",
397         thread_scheme    => "pthreads",
398         perlasm_scheme   => "64",
399         dso_scheme       => "dlfcn",
400         shared_target    => "irix-shared",
401         shared_extension => ".so.\$(SHLIB_VERSION_NUMBER)",
402         multilib         => "64",
403     },
404     "irix64-mips4-cc" => {
405         inherit_from     => [ "BASE_unix", asm("mips64_asm") ],
406         CC               => "cc",
407         CFLAGS           => picker(debug   => "-g -O0",
408                                    release => "-O2"),
409         cppflags         => threads("-D_SGI_MP_SOURCE"),
410         cflags           => "-64 -mips4 -use_readonly_const -G0 -rdata_shared",
411         cppflags         => combine("-DB_ENDIAN -DBN_DIV3W",
412                                     threads("-D_SGI_MP_SOURCE")),
413         ex_libs          => threads("-lpthread"),
414         bn_ops           => "RC4_CHAR SIXTY_FOUR_BIT_LONG",
415         thread_scheme    => "pthreads",
416         perlasm_scheme   => "64",
417         dso_scheme       => "dlfcn",
418         shared_target    => "irix-shared",
419         shared_extension => ".so.\$(SHLIB_VERSION_NUMBER)",
420         multilib         => "64",
421     },
422
423 #### Unified HP-UX ANSI C configs.
424 # Special notes:
425 # - Originally we were optimizing at +O4 level. It should be noted
426 #   that the only difference between +O3 and +O4 is global inter-
427 #   procedural analysis. As it has to be performed during the link
428 #   stage the compiler leaves behind certain pseudo-code in lib*.a
429 #   which might be release or even patch level specific. Generating
430 #   the machine code for and analyzing the *whole* program appears
431 #   to be *extremely* memory demanding while the performance gain is
432 #   actually questionable. The situation is intensified by the default
433 #   HP-UX data set size limit (infamous 'maxdsiz' tunable) of 64MB
434 #   which is way too low for +O4. In other words, doesn't +O3 make
435 #   more sense?
436 # - Keep in mind that the HP compiler by default generates code
437 #   suitable for execution on the host you're currently compiling at.
438 #   If the toolkit is meant to be used on various PA-RISC processors
439 #   consider './Configure hpux-parisc-[g]cc +DAportable'.
440 # - -DMD32_XARRAY triggers workaround for compiler bug we ran into in
441 #   32-bit message digests. (For the moment of this writing) HP C
442 #   doesn't seem to "digest" too many local variables (they make "him"
443 #   chew forever:-). For more details look-up MD32_XARRAY comment in
444 #   crypto/sha/sha_lcl.h.
445 # - originally there were 32-bit hpux-parisc2-* targets. They were
446 #   scrapped, because a) they were not interchangeable with other 32-bit
447 #   targets; b) performance-critical 32-bit assembly modules implement
448 #   even PA-RISC 2.0-specific code paths, which are chosen at run-time,
449 #   thus adequate performance is provided even with PA-RISC 1.1 build.
450     "hpux-parisc-gcc" => {
451         inherit_from     => [ "BASE_unix" ],
452         CC               => "gcc",
453         CFLAGS           => picker(debug   => "-O0 -g",
454                                    release => "-O3"),
455         cflags           => add(threads("-pthread")),
456         cppflags         => "-DB_ENDIAN -DBN_DIV2W",
457         ex_libs          => add("-Wl,+s -ldld", threads("-pthread")),
458         bn_ops           => "BN_LLONG",
459         thread_scheme    => "pthreads",
460         dso_scheme       => "dl",
461         shared_target    => "hpux-shared",
462         shared_cflag     => "-fPIC",
463         shared_ldflag    => "-shared",
464         shared_extension => ".sl.\$(SHLIB_VERSION_NUMBER)",
465     },
466     "hpux-parisc1_1-gcc" => {
467         inherit_from     => [ "hpux-parisc-gcc", asm("parisc11_asm") ],
468         multilib         => "/pa1.1",
469     },
470     "hpux64-parisc2-gcc" => {
471         inherit_from     => [ "BASE_unix", asm("parisc20_64_asm") ],
472         CC               => "gcc",
473         CFLAGS           => combine(picker(debug   => "-O0 -g",
474                                            release => "-O3")),
475         cppflags         => combine("-DB_ENDIAN", threads("-D_REENTRANT")),
476         ex_libs          => add("-ldl"),
477         bn_ops           => "SIXTY_FOUR_BIT_LONG RC4_CHAR",
478         thread_scheme    => "pthreads",
479         dso_scheme       => "dlfcn",
480         shared_target    => "hpux-shared",
481         shared_cflag     => "-fpic",
482         shared_ldflag    => "-shared",
483         shared_extension => ".sl.\$(SHLIB_VERSION_NUMBER)",
484         multilib         => "/pa20_64",
485     },
486
487     # More attempts at unified 10.X and 11.X targets for HP C compiler.
488     "hpux-parisc-cc" => {
489         inherit_from     => [ "BASE_unix" ],
490         CC               => "cc",
491         CFLAGS           => picker(debug   => "+O0 +d -g",
492                                    release => "+O3"),
493         cflags           => "+Optrs_strongly_typed -Ae +ESlit",
494         cppflags         => combine("-DB_ENDIAN -DBN_DIV2W -DMD32_XARRAY",
495                                     threads("-D_REENTRANT")),
496         ex_libs          => add("-Wl,+s -ldld",threads("-lpthread")),
497         bn_ops           => "RC4_CHAR",
498         thread_scheme    => "pthreads",
499         dso_scheme       => "dl",
500         shared_target    => "hpux-shared",
501         shared_cflag     => "+Z",
502         shared_ldflag    => "-b",
503         shared_extension => ".sl.\$(SHLIB_VERSION_NUMBER)",
504     },
505     "hpux-parisc1_1-cc" => {
506         inherit_from     => [ "hpux-parisc-cc", asm("parisc11_asm") ],
507         cflags           => add_before("+DA1.1"),
508         multilib         => "/pa1.1",
509     },
510     "hpux64-parisc2-cc" => {
511         inherit_from     => [ "BASE_unix", asm("parisc20_64_asm") ],
512         CC               => "cc",
513         CFLAGS           => picker(debug   => "+O0 +d -g",
514                                    release => "+O3") ,
515         cflags           => "+DD64 +Optrs_strongly_typed -Ae +ESlit",
516         cppflags         => combine("-DB_ENDIAN -DMD32_XARRAY",
517                                     threads("-D_REENTRANT")),
518         ex_libs          => add("-ldl",threads("-lpthread")),
519         bn_ops           => "SIXTY_FOUR_BIT_LONG RC4_CHAR",
520         thread_scheme    => "pthreads",
521         dso_scheme       => "dlfcn",
522         shared_target    => "hpux-shared",
523         shared_cflag     => "+Z",
524         shared_ldflag    => "-b",
525         shared_extension => ".sl.\$(SHLIB_VERSION_NUMBER)",
526         multilib         => "/pa20_64",
527     },
528
529     # HP/UX IA-64 targets
530     "hpux-ia64-cc" => {
531         inherit_from     => [ "BASE_unix", asm("ia64_asm") ],
532         CC               => "cc",
533         CFLAGS           => picker(debug   => "+O0 +d -g",
534                                    release => "+O2"),
535         cflags           => "-Ae +DD32 +Olit=all -z",
536         cppflags         => combine("-DB_ENDIAN", threads("-D_REENTRANT")),
537         ex_libs          => add("-ldl",threads("-lpthread")),
538         bn_ops           => "SIXTY_FOUR_BIT",
539         thread_scheme    => "pthreads",
540         dso_scheme       => "dlfcn",
541         shared_target    => "hpux-shared",
542         shared_cflag     => "+Z",
543         shared_ldflag    => "-b",
544         shared_extension => ".so.\$(SHLIB_VERSION_NUMBER)",
545         multilib         => "/hpux32",
546     },
547     "hpux64-ia64-cc" => {
548         inherit_from     => [ "BASE_unix", asm("ia64_asm") ],
549         CC               => "cc",
550         CFLAGS           => picker(debug   => "+O0 +d -g",
551                                    release => "+O3"),
552         cflags           => "-Ae +DD64 +Olit=all -z",
553         cppflags         => combine("-DB_ENDIAN", threads("-D_REENTRANT")),
554         ex_libs          => add("-ldl", threads("-lpthread")),
555         bn_ops           => "SIXTY_FOUR_BIT_LONG",
556         thread_scheme    => "pthreads",
557         dso_scheme       => "dlfcn",
558         shared_target    => "hpux-shared",
559         shared_cflag     => "+Z",
560         shared_ldflag    => "-b",
561         shared_extension => ".so.\$(SHLIB_VERSION_NUMBER)",
562         multilib         => "/hpux64",
563     },
564     # GCC builds...
565     "hpux-ia64-gcc" => {
566         inherit_from     => [ "BASE_unix", asm("ia64_asm") ],
567         CC               => "gcc",
568         CFLAGS           => picker(debug   => "-O0 -g",
569                                    release => "-O3"),
570         cflags           => add(threads("-pthread")),
571         cppflags         => "-DB_ENDIAN",
572         ex_libs          => add("-ldl", threads("-pthread")),
573         bn_ops           => "SIXTY_FOUR_BIT",
574         thread_scheme    => "pthreads",
575         dso_scheme       => "dlfcn",
576         shared_target    => "hpux-shared",
577         shared_cflag     => "-fpic",
578         shared_ldflag    => "-shared",
579         shared_extension => ".so.\$(SHLIB_VERSION_NUMBER)",
580         multilib         => "/hpux32",
581     },
582     "hpux64-ia64-gcc" => {
583         inherit_from     => [ "BASE_unix", asm("ia64_asm") ],
584         CC               => "gcc",
585         CFLAGS           => picker(debug   => "-O0 -g",
586                                    release => "-O3"),
587         cflags           => combine("-mlp64", threads("-pthread")),
588         cppflags         => "-DB_ENDIAN",
589         ex_libs          => add("-ldl", threads("-pthread")),
590         bn_ops           => "SIXTY_FOUR_BIT_LONG",
591         thread_scheme    => "pthreads",
592         dso_scheme       => "dlfcn",
593         shared_target    => "hpux-shared",
594         shared_cflag     => "-fpic",
595         shared_ldflag    => "-shared",
596         shared_extension => ".so.\$(SHLIB_VERSION_NUMBER)",
597         multilib         => "/hpux64",
598     },
599
600 #### HP MPE/iX http://jazz.external.hp.com/src/openssl/
601     "MPE/iX-gcc" => {
602         inherit_from     => [ "BASE_unix" ],
603         CC               => "gcc",
604         CFLAGS           => "-O3",
605         cppflags         => "-D_ENDIAN -DBN_DIV2W -D_POSIX_SOURCE -D_SOCKET_SOURCE",
606         includes         => add("/SYSLOG/PUB"),
607         sys_id           => "MPE",
608         lflags           => add("-L/SYSLOG/PUB"),
609         ex_libs          => add("-lsyslog -lsocket -lcurses"),
610         thread_scheme    => "(unknown)",
611         bn_ops           => "BN_LLONG",
612     },
613
614 #### DEC Alpha Tru64 targets. Tru64 is marketing name for OSF/1 version 4
615 #### and forward. In reality 'uname -s' still returns "OSF1". Originally
616 #### there were even osf1-* configs targeting prior versions provided,
617 #### but not anymore...
618     "tru64-alpha-gcc" => {
619         inherit_from     => [ "BASE_unix", asm("alpha_asm") ],
620         CC               => "gcc",
621         CFLAGS           => "-O3",
622         cflags           => add("-std=c9x", threads("-pthread")),
623         cppflags         => "-D_XOPEN_SOURCE=500 -D_OSF_SOURCE",
624         ex_libs          => add("-lrt", threads("-pthread")), # for mlock(2)
625         bn_ops           => "SIXTY_FOUR_BIT_LONG",
626         thread_scheme    => "pthreads",
627         dso_scheme       => "dlfcn",
628         shared_target    => "alpha-osf1-shared",
629         shared_extension => ".so",
630     },
631     "tru64-alpha-cc" => {
632         inherit_from     => [ "BASE_unix", asm("alpha_asm") ],
633         CC               => "cc",
634         CFLAGS           => "-tune host -fast",
635         cflags           => add("-std1 -readonly_strings",
636                                 threads("-pthread")),
637         cppflags         => "-D_XOPEN_SOURCE=500 -D_OSF_SOURCE",
638         ex_libs          => add("-lrt", threads("-pthread")), # for mlock(2)
639         bn_ops           => "SIXTY_FOUR_BIT_LONG",
640         thread_scheme    => "pthreads",
641         dso_scheme       => "dlfcn",
642         shared_target    => "alpha-osf1-shared",
643         shared_ldflag    => "-msym",
644         shared_extension => ".so",
645     },
646
647 ####
648 #### Variety of LINUX:-)
649 ####
650 # *-generic* is endian-neutral target, but ./config is free to
651 # throw in -D[BL]_ENDIAN, whichever appropriate...
652     "linux-generic32" => {
653         inherit_from     => [ "BASE_unix" ],
654         CC               => "gcc",
655         CXX              => "g++",
656         CFLAGS           => picker(default => "-Wall",
657                                    debug   => "-O0 -g",
658                                    release => "-O3"),
659         CXXFLAGS         => picker(default => "-Wall",
660                                    debug   => "-O0 -g",
661                                    release => "-O3"),
662         cflags           => threads("-pthread"),
663         cxxflags         => combine("-std=c++11", threads("-pthread")),
664         cppflags         => "-DOPENSSL_USE_NODELETE",
665         ex_libs          => add("-ldl", threads("-pthread")),
666         bn_ops           => "BN_LLONG RC4_CHAR",
667         thread_scheme    => "pthreads",
668         dso_scheme       => "dlfcn",
669         shared_target    => "linux-shared",
670         shared_cflag     => "-fPIC",
671         shared_ldflag    => "-Wl,-znodelete",
672         shared_extension => ".so.\$(SHLIB_VERSION_NUMBER)",
673     },
674     "linux-generic64" => {
675         inherit_from     => [ "linux-generic32" ],
676         bn_ops           => "SIXTY_FOUR_BIT_LONG RC4_CHAR",
677     },
678
679     "linux-ppc" => {
680         inherit_from     => [ "linux-generic32", asm("ppc32_asm") ],
681         perlasm_scheme   => "linux32",
682     },
683     "linux-ppc64" => {
684         inherit_from     => [ "linux-generic64", asm("ppc64_asm") ],
685         cflags           => add("-m64"),
686         cppflags         => add("-DB_ENDIAN"),
687         perlasm_scheme   => "linux64",
688         multilib         => "64",
689     },
690     "linux-ppc64le" => {
691         inherit_from     => [ "linux-generic64", asm("ppc64_asm") ],
692         cflags           => add("-m64"),
693         cppflags         => add("-DL_ENDIAN"),
694         perlasm_scheme   => "linux64le",
695     },
696
697     "linux-armv4" => {
698         ################################################################
699         # Note that -march is not among compiler options in linux-armv4
700         # target description. Not specifying one is intentional to give
701         # you choice to:
702         #
703         # a) rely on your compiler default by not specifying one;
704         # b) specify your target platform explicitly for optimal
705         # performance, e.g. -march=armv6 or -march=armv7-a;
706         # c) build "universal" binary that targets *range* of platforms
707         # by specifying minimum and maximum supported architecture;
708         #
709         # As for c) option. It actually makes no sense to specify
710         # maximum to be less than ARMv7, because it's the least
711         # requirement for run-time switch between platform-specific
712         # code paths. And without run-time switch performance would be
713         # equivalent to one for minimum. Secondly, there are some
714         # natural limitations that you'd have to accept and respect.
715         # Most notably you can *not* build "universal" binary for
716         # big-endian platform. This is because ARMv7 processor always
717         # picks instructions in little-endian order. Another similar
718         # limitation is that -mthumb can't "cross" -march=armv6t2
719         # boundary, because that's where it became Thumb-2. Well, this
720         # limitation is a bit artificial, because it's not really
721         # impossible, but it's deemed too tricky to support. And of
722         # course you have to be sure that your binutils are actually
723         # up to the task of handling maximum target platform. With all
724         # this in mind here is an example of how to configure
725         # "universal" build:
726         #
727         # ./Configure linux-armv4 -march=armv6 -D__ARM_MAX_ARCH__=8
728         #
729         inherit_from     => [ "linux-generic32", asm("armv4_asm") ],
730         perlasm_scheme   => "linux32",
731     },
732     "linux-aarch64" => {
733         inherit_from     => [ "linux-generic64", asm("aarch64_asm") ],
734         perlasm_scheme   => "linux64",
735     },
736     "linux-arm64ilp32" => {  # https://wiki.linaro.org/Platform/arm64-ilp32
737         inherit_from     => [ "linux-generic32", asm("aarch64_asm") ],
738         cflags           => add("-mabi=ilp32"),
739         bn_ops           => "SIXTY_FOUR_BIT RC4_CHAR",
740         perlasm_scheme   => "linux64",
741     },
742
743     "linux-mips32" => {
744         # Configure script adds minimally required -march for assembly
745         # support, if no -march was specified at command line.
746         inherit_from     => [ "linux-generic32", asm("mips32_asm") ],
747         cflags           => add("-mabi=32"),
748         cppflags         => add("-DBN_DIV3W"),
749         perlasm_scheme   => "o32",
750     },
751     # mips32 and mips64 below refer to contemporary MIPS Architecture
752     # specifications, MIPS32 and MIPS64, rather than to kernel bitness.
753     "linux-mips64" => {
754         inherit_from     => [ "linux-generic32", asm("mips64_asm") ],
755         cflags           => add("-mabi=n32"),
756         cppflags         => add("-DBN_DIV3W"),
757         bn_ops           => "SIXTY_FOUR_BIT RC4_CHAR",
758         perlasm_scheme   => "n32",
759         multilib         => "32",
760     },
761     "linux64-mips64" => {
762         inherit_from     => [ "linux-generic64", asm("mips64_asm") ],
763         cflags           => add("-mabi=64"),
764         cppflags         => add("-DBN_DIV3W"),
765         perlasm_scheme   => "64",
766         multilib         => "64",
767     },
768
769     #### IA-32 targets...
770     #### These two targets are a bit aged and are to be used on older Linux
771     #### machines where gcc doesn't understand -m32 and -m64
772     "linux-elf" => {
773         inherit_from     => [ "linux-generic32", asm("x86_elf_asm") ],
774         CFLAGS           => add(picker(release => "-fomit-frame-pointer")),
775         cppflags         => add("-DL_ENDIAN"),
776         bn_ops           => "BN_LLONG",
777     },
778     "linux-aout" => {
779         inherit_from     => [ "BASE_unix", asm("x86_asm") ],
780         CC               => "gcc",
781         CFLAGS           => add(picker(default => "-Wall",
782                                        debug   => "-O0 -g",
783                                        release => "-O3 -fomit-frame-pointer")),
784         cppflags         => add("-DL_ENDIAN"),
785         bn_ops           => "BN_LLONG",
786         thread_scheme    => "(unknown)",
787         perlasm_scheme   => "a.out",
788     },
789
790     #### X86 / X86_64 targets
791     "linux-x86" => {
792         inherit_from     => [ "linux-generic32", asm("x86_asm") ],
793         CFLAGS           => add(picker(release => "-fomit-frame-pointer")),
794         cflags           => add("-m32"),
795         cppflags         => add("-DL_ENDIAN"),
796         bn_ops           => "BN_LLONG",
797         perlasm_scheme   => "elf",
798     },
799     "linux-x86-clang" => {
800         inherit_from     => [ "linux-x86" ],
801         CC               => "clang",
802         CXX              => "clang++",
803         CFLAGS           => add("-Wextra"),
804     },
805     "linux-x86_64" => {
806         inherit_from     => [ "linux-generic64", asm("x86_64_asm") ],
807         cflags           => add("-m64"),
808         cppflags         => add("-DL_ENDIAN"),
809         bn_ops           => "SIXTY_FOUR_BIT_LONG",
810         perlasm_scheme   => "elf",
811         multilib         => "64",
812     },
813     "linux-x86_64-clang" => {
814         inherit_from     => [ "linux-x86_64" ],
815         CC               => "clang",
816         CXX              => "clang++",
817         CFLAGS           => add("-Wextra"),
818     },
819     "linux-x32" => {
820         inherit_from     => [ "linux-generic32", asm("x86_64_asm") ],
821         cflags           => add("-mx32"),
822         cppflags         => add("-DL_ENDIAN"),
823         bn_ops           => "SIXTY_FOUR_BIT",
824         perlasm_scheme   => "elf32",
825         multilib         => "x32",
826     },
827
828     "linux-ia64" => {
829         inherit_from     => [ "linux-generic64", asm("ia64_asm") ],
830         bn_ops           => "SIXTY_FOUR_BIT_LONG",
831     },
832
833     "linux64-s390x" => {
834         inherit_from     => [ "linux-generic64", asm("s390x_asm") ],
835         cflags           => add("-m64"),
836         cppflags         => add("-DB_ENDIAN"),
837         perlasm_scheme   => "64",
838         multilib         => "64",
839     },
840     "linux32-s390x" => {
841         #### So called "highgprs" target for z/Architecture CPUs
842         # "Highgprs" is kernel feature first implemented in Linux
843         # 2.6.32, see /proc/cpuinfo. The idea is to preserve most
844         # significant bits of general purpose registers not only
845         # upon 32-bit process context switch, but even on
846         # asynchronous signal delivery to such process. This makes
847         # it possible to deploy 64-bit instructions even in legacy
848         # application context and achieve better [or should we say
849         # adequate] performance. The build is binary compatible with
850         # linux-generic32, and the idea is to be able to install the
851         # resulting libcrypto.so alongside generic one, e.g. as
852         # /lib/highgprs/libcrypto.so.x.y, for ldconfig and run-time
853         # linker to autodiscover. Unfortunately it doesn't work just
854         # yet, because of couple of bugs in glibc
855         # sysdeps/s390/dl-procinfo.c affecting ldconfig and ld.so.1...
856         #
857         inherit_from     => [ "linux-generic32", asm("s390x_asm") ],
858         cflags           => add("-m31 -Wa,-mzarch"),
859         cppflags         => add("-DB_ENDIAN"),
860         bn_asm_src       => sub { my $r=join(" ",@_); $r=~s|asm/s390x\.S|bn_asm.c|; $r; },
861         perlasm_scheme   => "31",
862         multilib         => "/highgprs",
863     },
864
865     #### SPARC Linux setups
866     "linux-sparcv8" => {
867         inherit_from     => [ "linux-generic32", asm("sparcv8_asm") ],
868         cflags           => add("-mcpu=v8"),
869         lib_cppflags     => add("-DB_ENDIAN -DBN_DIV2W"),
870     },
871     "linux-sparcv9" => {
872         # it's a real mess with -mcpu=ultrasparc option under Linux,
873         # but -Wa,-Av8plus should do the trick no matter what.
874         inherit_from     => [ "linux-generic32", asm("sparcv9_asm") ],
875         cflags           => add("-m32 -mcpu=ultrasparc -Wa,-Av8plus"),
876         lib_cppflags     => add("-DB_ENDIAN -DBN_DIV2W"),
877     },
878     "linux64-sparcv9" => {
879         # GCC 3.1 is a requirement
880         inherit_from     => [ "linux-generic64", asm("sparcv9_asm") ],
881         cflags           => add("-m64 -mcpu=ultrasparc"),
882         lib_cppflags     => add("-DB_ENDIAN"),
883         bn_ops           => "BN_LLONG RC4_CHAR",
884         multilib         => "64",
885     },
886
887     "linux-alpha-gcc" => {
888         inherit_from     => [ "linux-generic64", asm("alpha_asm") ],
889         lib_cppflags     => add("-DL_ENDIAN"),
890         bn_ops           => "SIXTY_FOUR_BIT_LONG",
891     },
892     "linux-c64xplus" => {
893         inherit_from     => [ "BASE_unix" ],
894         # TI_CGT_C6000_7.3.x is a requirement
895         CC               => "cl6x",
896         CFLAGS           => "-o2 -ox -ms",
897         cflags           => "--linux -ea=.s -eo=.o -mv6400+ -pden",
898         cppflags         => combine("-DOPENSSL_SMALL_FOOTPRINT",
899                                     threads("-D_REENTRANT")),
900         bn_ops           => "BN_LLONG",
901         cpuid_asm_src    => "c64xpluscpuid.s",
902         bn_asm_src       => "asm/bn-c64xplus.asm c64xplus-gf2m.s",
903         aes_asm_src      => "aes-c64xplus.s aes_cbc.c aes-ctr.fake",
904         sha1_asm_src     => "sha1-c64xplus.s sha256-c64xplus.s sha512-c64xplus.s",
905         rc4_asm_src      => "rc4-c64xplus.s",
906         modes_asm_src    => "ghash-c64xplus.s",
907         chacha_asm_src   => "chacha-c64xplus.s",
908         poly1305_asm_src => "poly1305-c64xplus.s",
909         thread_scheme    => "pthreads",
910         perlasm_scheme   => "void",
911         dso_scheme       => "dlfcn",
912         shared_target    => "linux-shared",
913         shared_cflag     => "--pic",
914         shared_ldflag    => add("-z --sysv --shared"),
915         shared_extension => ".so.\$(SHLIB_VERSION_NUMBER)",
916         ranlib           => "true",
917     },
918
919 #### Android: linux-* but without pointers to headers and libs.
920     #
921     # It takes pair of prior-set environment variables to make it work:
922     #
923     # CROSS_SYSROOT=/some/where/android-ndk-<ver>/platforms/android-<apiver>/arch-<arch>
924     # CROSS_COMPILE=<prefix>
925     #
926     # As well as PATH adjusted to cover ${CROSS_COMPILE}gcc and company.
927     # For example to compile for ICS and ARM with NDK 10d, you'd:
928     #
929     # ANDROID_NDK=/some/where/android-ndk-10d
930     # CROSS_SYSROOT=$ANDROID_NDK/platforms/android-14/arch-arm
931     # CROSS_COMPILE=arm-linux-androideabi-
932     # PATH=$ANDROID_NDK/toolchains/arm-linux-androideabi-4.8/prebuild/linux-x86_64/bin
933     #
934     "android" => {
935         inherit_from     => [ "linux-generic32" ],
936         # Special note about unconditional -fPIC and -pie. The underlying
937         # reason is that Lollipop refuses to run non-PIE. But what about
938         # older systems and NDKs? -fPIC was never problem, so the only
939         # concern is -pie. Older toolchains, e.g. r4, appear to handle it
940         # and binaries turn mostly functional. "Mostly" means that oldest
941         # Androids, such as Froyo, fail to handle executable, but newer
942         # systems are perfectly capable of executing binaries targeting
943         # Froyo. Keep in mind that in the nutshell Android builds are
944         # about JNI, i.e. shared libraries, not applications.
945         cflags           => add(picker(default => "-mandroid -fPIC --sysroot=\$(CROSS_SYSROOT) -Wa,--noexecstack")),
946         bin_cflags       => "-pie",
947     },
948     "android-x86" => {
949         inherit_from     => [ "android", asm("x86_asm") ],
950         CFLAGS           => add(picker(release => "-fomit-frame-pointer")),
951         bn_ops           => "BN_LLONG",
952         perlasm_scheme   => "android",
953     },
954     ################################################################
955     # Contemporary Android applications can provide multiple JNI
956     # providers in .apk, targeting multiple architectures. Among
957     # them there is "place" for two ARM flavours: generic eabi and
958     # armv7-a/hard-float. However, it should be noted that OpenSSL's
959     # ability to engage NEON is not constrained by ABI choice, nor
960     # is your ability to call OpenSSL from your application code
961     # compiled with floating-point ABI other than default 'soft'.
962     # [Latter thanks to __attribute__((pcs("aapcs"))) declaration.]
963     # This means that choice of ARM libraries you provide in .apk
964     # is driven by application needs. For example if application
965     # itself benefits from NEON or is floating-point intensive, then
966     # it might be appropriate to provide both libraries. Otherwise
967     # just generic eabi would do. But in latter case it would be
968     # appropriate to
969     #
970     #   ./Configure android-armeabi -D__ARM_MAX_ARCH__=8
971     #
972     # in order to build "universal" binary and allow OpenSSL take
973     # advantage of NEON when it's available.
974     #
975     "android-armeabi" => {
976         inherit_from     => [ "android", asm("armv4_asm") ],
977     },
978     "android-mips" => {
979         inherit_from     => [ "android", asm("mips32_asm") ],
980         perlasm_scheme   => "o32",
981     },
982
983     "android64" => {
984         inherit_from     => [ "linux-generic64" ],
985         cflags           => add(picker(default => "-mandroid -fPIC --sysroot=\$(CROSS_SYSROOT) -Wa,--noexecstack")),
986         bin_cflags       => "-pie",
987     },
988     "android64-aarch64" => {
989         inherit_from     => [ "android64", asm("aarch64_asm") ],
990         perlasm_scheme   => "linux64",
991     },
992     "android64-x86_64" => {
993         inherit_from     => [ "android64", asm("x86_64_asm") ],
994         perlasm_scheme   => "elf",
995     },
996     "android64-mips64" => {
997         ############################################################
998         # You are more than likely have to specify target processor
999         # on ./Configure command line. Trouble is that toolchain's
1000         # default is MIPS64r6 (at least in r10d), but there are no
1001         # such processors around (or they are too rare to spot one).
1002         # Actual problem is that MIPS64r6 is binary incompatible
1003         # with previous MIPS ISA versions, in sense that unlike
1004         # prior versions original MIPS binary code will fail.
1005         #
1006         inherit_from     => [ "android64", asm("mips64_asm") ],
1007         perlasm_scheme   => "64",
1008     },
1009
1010 #### *BSD
1011     "BSD-generic32" => {
1012         # As for thread cflag. Idea is to maintain "collective" set of
1013         # flags, which would cover all BSD flavors. -pthread applies
1014         # to them all, but is treated differently. OpenBSD expands is
1015         # as -D_POSIX_THREAD -lc_r, which is sufficient. FreeBSD 4.x
1016         # expands it as -lc_r, which has to be accompanied by explicit
1017         # -D_THREAD_SAFE and sometimes -D_REENTRANT. FreeBSD 5.x
1018         # expands it as -lc_r, which seems to be sufficient?
1019         inherit_from     => [ "BASE_unix" ],
1020         CC               => "cc",
1021         CFLAGS           => picker(default => "-Wall",
1022                                    debug   => "-O0 -g",
1023                                    release => "-O3"),
1024         cflags           => threads("-pthread"),
1025         cppflags         => threads("-D_THREAD_SAFE -D_REENTRANT"),
1026         ex_libs          => add(threads("-pthread")),
1027         enable           => add("devcryptoeng"),
1028         bn_ops           => "BN_LLONG",
1029         thread_scheme    => "pthreads",
1030         dso_scheme       => "dlfcn",
1031         shared_target    => "bsd-gcc-shared",
1032         shared_cflag     => "-fPIC",
1033         shared_extension => ".so.\$(SHLIB_VERSION_NUMBER)",
1034     },
1035     "BSD-generic64" => {
1036         inherit_from     => [ "BSD-generic32" ],
1037         bn_ops           => "SIXTY_FOUR_BIT_LONG",
1038     },
1039
1040     "BSD-x86" => {
1041         inherit_from     => [ "BSD-generic32", asm("x86_asm") ],
1042         CFLAGS           => add(picker(release => "-fomit-frame-pointer")),
1043         cppflags         => add("-DL_ENDIAN"),
1044         bn_ops           => "BN_LLONG",
1045         shared_target    => "bsd-shared",
1046         perlasm_scheme   => "a.out",
1047     },
1048     "BSD-x86-elf" => {
1049         inherit_from     => [ "BSD-x86" ],
1050         perlasm_scheme   => "elf",
1051     },
1052
1053     "BSD-sparcv8" => {
1054         inherit_from     => [ "BSD-generic32", asm("sparcv8_asm") ],
1055         cflags           => add("-mcpu=v8"),
1056         cppflags         => add("-DB_ENDIAN"),
1057     },
1058     "BSD-sparc64" => {
1059         # -DMD32_REG_T=int doesn't actually belong in sparc64 target, it
1060         # simply *happens* to work around a compiler bug in gcc 3.3.3,
1061         # triggered by RIPEMD160 code.
1062         inherit_from     => [ "BSD-generic64", asm("sparcv9_asm") ],
1063         cppflags         => add("-DB_ENDIAN -DMD32_REG_T=int"),
1064         bn_ops           => "BN_LLONG",
1065     },
1066
1067     "BSD-ia64" => {
1068         inherit_from     => [ "BSD-generic64", asm("ia64_asm") ],
1069         cppflags         => add("-DL_ENDIAN"),
1070         bn_ops           => "SIXTY_FOUR_BIT_LONG",
1071     },
1072
1073     "BSD-x86_64" => {
1074         inherit_from     => [ "BSD-generic64", asm("x86_64_asm") ],
1075         cppflags         => add("-DL_ENDIAN"),
1076         bn_ops           => "SIXTY_FOUR_BIT_LONG",
1077         perlasm_scheme   => "elf",
1078     },
1079
1080     "bsdi-elf-gcc" => {
1081         inherit_from     => [ "BASE_unix", asm("x86_elf_asm") ],
1082         CC               => "gcc",
1083         CFLAGS           => "-fomit-frame-pointer -O3 -Wall",
1084         cppflags         => "-DPERL5 -DL_ENDIAN",
1085         ex_libs          => add("-ldl"),
1086         bn_ops           => "BN_LLONG",
1087         thread_scheme    => "(unknown)",
1088         dso_scheme       => "dlfcn",
1089         shared_target    => "bsd-gcc-shared",
1090         shared_cflag     => "-fPIC",
1091         shared_extension => ".so.\$(SHLIB_VERSION_NUMBER)",
1092     },
1093
1094     "nextstep" => {
1095         inherit_from     => [ "BASE_unix" ],
1096         CC               => "cc",
1097         CFLAGS           => "-O -Wall",
1098         unistd           => "<libc.h>",
1099         bn_ops           => "BN_LLONG",
1100         thread_scheme    => "(unknown)",
1101     },
1102     "nextstep3.3" => {
1103         inherit_from     => [ "BASE_unix" ],
1104         CC               => "cc",
1105         CFLAGS           => "-O3 -Wall",
1106         unistd           => "<libc.h>",
1107         bn_ops           => "BN_LLONG",
1108         thread_scheme    => "(unknown)",
1109     },
1110
1111 # QNX
1112     "qnx4" => {
1113         inherit_from     => [ "BASE_unix" ],
1114         CC               => "cc",
1115         CFLAGS           => "",
1116         cppflags         => "-DL_ENDIAN -DTERMIO",
1117         thread_scheme    => "(unknown)",
1118     },
1119     "QNX6" => {
1120         inherit_from     => [ "BASE_unix" ],
1121         CC               => "gcc",
1122         ex_libs          => add("-lsocket"),
1123         dso_scheme       => "dlfcn",
1124         shared_target    => "bsd-gcc-shared",
1125         shared_cflag     => "-fPIC",
1126         shared_extension => ".so.\$(SHLIB_VERSION_NUMBER)",
1127     },
1128     "QNX6-i386" => {
1129         inherit_from     => [ "BASE_unix", asm("x86_elf_asm") ],
1130         CC               => "gcc",
1131         CFLAGS           => "-O2 -Wall",
1132         cppflags         => "-DL_ENDIAN",
1133         ex_libs          => add("-lsocket"),
1134         dso_scheme       => "dlfcn",
1135         shared_target    => "bsd-gcc-shared",
1136         shared_cflag     => "-fPIC",
1137         shared_extension => ".so.\$(SHLIB_VERSION_NUMBER)",
1138     },
1139
1140 #### SCO/Caldera targets.
1141 #
1142 # Originally we had like unixware-*, unixware-*-pentium, unixware-*-p6, etc.
1143 # Now we only have blended unixware-* as it's the only one used by ./config.
1144 # If you want to optimize for particular microarchitecture, bypass ./config
1145 # and './Configure unixware-7 -Kpentium_pro' or whatever appropriate.
1146 # Note that not all targets include assembler support. Mostly because of
1147 # lack of motivation to support out-of-date platforms with out-of-date
1148 # compiler drivers and assemblers.
1149 #
1150 # UnixWare 2.0x fails destest with -O.
1151     "unixware-2.0" => {
1152         inherit_from     => [ "BASE_unix" ],
1153         CC               => "cc",
1154         cflags           => threads("-Kthread"),
1155         cppflags         => "-DFILIO_H -DNO_STRINGS_H",
1156         ex_libs          => add("-lsocket -lnsl -lresolv -lx"),
1157         thread_scheme    => "uithreads",
1158     },
1159     "unixware-2.1" => {
1160         inherit_from     => [ "BASE_unix" ],
1161         CC               => "cc",
1162         CFLAGS           => "-O",
1163         cflags           => threads("-Kthread"),
1164         cppflags         => "-DFILIO_H",
1165         ex_libs          => add("-lsocket -lnsl -lresolv -lx"),
1166         thread_scheme    => "uithreads",
1167     },
1168     "unixware-7" => {
1169         inherit_from     => [ "BASE_unix", asm("x86_elf_asm") ],
1170         CC               => "cc",
1171         CFLAGS           => "-O",
1172         cflags           => combine("-Kalloca", threads("-Kthread")),
1173         cppflags         => "-DFILIO_H",
1174         ex_libs          => add("-lsocket -lnsl"),
1175         thread_scheme    => "uithreads",
1176         bn_ops           => "BN_LLONG",
1177         perlasm_scheme   => "elf-1",
1178         dso_scheme       => "dlfcn",
1179         shared_target    => "svr5-shared",
1180         shared_cflag     => "-Kpic",
1181         shared_extension => ".so.\$(SHLIB_VERSION_NUMBER)",
1182     },
1183     "unixware-7-gcc" => {
1184         inherit_from     => [ "BASE_unix", asm("x86_elf_asm") ],
1185         CC               => "gcc",
1186         CFLAGS           => "-O3 -fomit-frame-pointer -Wall",
1187         cppflags         => add("-DL_ENDIAN -DFILIO_H",
1188                                 threads("-D_REENTRANT")),
1189         ex_libs          => add("-lsocket -lnsl"),
1190         bn_ops           => "BN_LLONG",
1191         thread_scheme    => "pthreads",
1192         perlasm_scheme   => "elf-1",
1193         dso_scheme       => "dlfcn",
1194         shared_target    => "gnu-shared",
1195         shared_cflag     => "-fPIC",
1196         shared_extension => ".so.\$(SHLIB_VERSION_NUMBER)",
1197     },
1198 # SCO 5 - Ben Laurie says the -O breaks the SCO cc.
1199     "sco5-cc" => {
1200         inherit_from     => [ "BASE_unix", asm("x86_elf_asm") ],
1201         cc               => "cc",
1202         cflags           => "-belf",
1203         ex_libs          => add("-lsocket -lnsl"),
1204         thread_scheme    => "(unknown)",
1205         perlasm_scheme   => "elf-1",
1206         dso_scheme       => "dlfcn",
1207         shared_target    => "svr3-shared",
1208         shared_cflag     => "-Kpic",
1209         shared_extension => ".so.\$(SHLIB_VERSION_NUMBER)",
1210     },
1211     "sco5-gcc" => {
1212         inherit_from     => [ "BASE_unix", asm("x86_elf_asm") ],
1213         cc               => "gcc",
1214         cflags           => "-O3 -fomit-frame-pointer",
1215         ex_libs          => add("-lsocket -lnsl"),
1216         bn_ops           => "BN_LLONG",
1217         thread_scheme    => "(unknown)",
1218         perlasm_scheme   => "elf-1",
1219         dso_scheme       => "dlfcn",
1220         shared_target    => "svr3-shared",
1221         shared_cflag     => "-fPIC",
1222         shared_extension => ".so.\$(SHLIB_VERSION_NUMBER)",
1223     },
1224
1225 #### IBM's AIX.
1226     # Below targets assume AIX >=5. Caveat lector. If you are accustomed
1227     # to control compilation "bitness" by setting $OBJECT_MODE environment
1228     # variable, then you should know that in OpenSSL case it's considered
1229     # only in ./config. Once configured, build procedure remains "deaf" to
1230     # current value of $OBJECT_MODE.
1231     "aix-gcc" => {
1232         inherit_from     => [ "BASE_unix", asm("ppc32_asm") ],
1233         CC               => "gcc",
1234         CFLAGS           => picker(debug   => "-O0 -g",
1235                                    release => "-O"),
1236         cflags           => add(threads("-pthread")),
1237         cppflags         => "-DB_ENDIAN",
1238         ex_libs          => add(threads("-pthread")),
1239         sys_id           => "AIX",
1240         bn_ops           => "BN_LLONG RC4_CHAR",
1241         thread_scheme    => "pthreads",
1242         perlasm_scheme   => "aix32",
1243         dso_scheme       => "dlfcn",
1244         shared_target    => "aix-shared",
1245         shared_ldflag    => "-shared -static-libgcc -Wl,-G",
1246         shared_extension => ".so.\$(SHLIB_VERSION_NUMBER)",
1247         arflags          => "-X32 r",
1248     },
1249     "aix64-gcc" => {
1250         inherit_from     => [ "BASE_unix", asm("ppc64_asm") ],
1251         CC               => "gcc",
1252         CFLAGS           => picker(debug   => "-O0 -g",
1253                                    release => "-O"),
1254         cflags           => combine("-maix64", threads("-pthread")),
1255         cppflags         => "-DB_ENDIAN",
1256         ex_libs          => add(threads("-pthread")),
1257         sys_id           => "AIX",
1258         bn_ops           => "SIXTY_FOUR_BIT_LONG RC4_CHAR",
1259         thread_scheme    => "pthreads",
1260         perlasm_scheme   => "aix64",
1261         dso_scheme       => "dlfcn",
1262         shared_target    => "aix-shared",
1263         shared_ldflag    => "-shared -static-libgcc -Wl,-G",
1264         shared_extension => ".so.\$(SHLIB_VERSION_NUMBER)",
1265         arflags          => "-X64 r",
1266     },
1267     "aix-cc" => {
1268         inherit_from     => [ "BASE_unix", asm("ppc32_asm") ],
1269         CC               => "cc",
1270         CFLAGS           => picker(debug   => "-O0 -g",
1271                                    release => "-O"),
1272         cflags           => combine("-q32 -qmaxmem=16384 -qro -qroconst",
1273                                     threads("-qthreaded")),
1274         cppflags         => combine("-DB_ENDIAN", threads("-D_THREAD_SAFE")),
1275         sys_id           => "AIX",
1276         bn_ops           => "BN_LLONG RC4_CHAR",
1277         thread_scheme    => "pthreads",
1278         ex_libs          => threads("-lpthreads"),
1279         perlasm_scheme   => "aix32",
1280         dso_scheme       => "dlfcn",
1281         shared_target    => "aix-shared",
1282         shared_ldflag    => "-G",
1283         shared_extension => ".so.\$(SHLIB_VERSION_NUMBER)",
1284         arflags          => "-X32 r",
1285     },
1286     "aix64-cc" => {
1287         inherit_from     => [ "BASE_unix", asm("ppc64_asm") ],
1288         CC               => "cc",
1289         CFLAGS           => picker(debug   => "-O0 -g",
1290                                    release => "-O"),
1291         cflags           => combine("-q64 -qmaxmem=16384 -qro -qroconst",
1292                                     threads("-qthreaded")),
1293         cppflags         => combine("-DB_ENDIAN", threads("-D_THREAD_SAFE")),
1294         sys_id           => "AIX",
1295         bn_ops           => "SIXTY_FOUR_BIT_LONG RC4_CHAR",
1296         thread_scheme    => "pthreads",
1297         ex_libs          => threads("-lpthreads"),
1298         perlasm_scheme   => "aix64",
1299         dso_scheme       => "dlfcn",
1300         shared_target    => "aix-shared",
1301         shared_ldflag    => "-G",
1302         shared_extension => ".so.\$(SHLIB_VERSION_NUMBER)",
1303         arflags          => "-X64 r",
1304     },
1305
1306 # SIEMENS BS2000/OSD: an EBCDIC-based mainframe
1307     "BS2000-OSD" => {
1308         inherit_from     => [ "BASE_unix" ],
1309         CC               => "c89",
1310         CFLAGS           => "-O",
1311         cflags           => "-XLLML -XLLMK -XL",
1312         cppflags         => "-DB_ENDIAN -DCHARSET_EBCDIC",
1313         ex_libs          => add("-lsocket -lnsl"),
1314         bn_ops           => "THIRTY_TWO_BIT RC4_CHAR",
1315         thread_scheme    => "(unknown)",
1316     },
1317
1318 #### Visual C targets
1319 #
1320 # Win64 targets, WIN64I denotes IA-64 and WIN64A - AMD64
1321 #
1322 # Note about -wd4090, disable warning C4090. This warning returns false
1323 # positives in some situations. Disabling it altogether masks both
1324 # legitimate and false cases, but as we compile on multiple platforms,
1325 # we rely on other compilers to catch legitimate cases.
1326 #
1327 # Also note that we force threads no matter what.  Configuring "no-threads"
1328 # is ignored.
1329     "VC-common" => {
1330         inherit_from     => [ "BASE_Windows" ],
1331         template         => 1,
1332         CC               => "cl",
1333         CPP              => '$(CC) /EP /C',
1334         CFLAGS           => "-W3 -wd4090 -nologo",
1335         LDFLAGS          => add("/debug"),
1336         coutflag         => "/Fo",
1337         cflags           => '-Gs0 -GF -Gy',
1338         defines          => add("OPENSSL_SYS_WIN32", "WIN32_LEAN_AND_MEAN",
1339                                 "L_ENDIAN", "_CRT_SECURE_NO_DEPRECATE",
1340                                 "_WINSOCK_DEPRECATED_NO_WARNINGS",
1341                                 sub { my @defs = ();
1342                                       unless ($disabled{"zlib-dynamic"}) {
1343                                           my $zlib =
1344                                               $withargs{zlib_lib} // "ZLIB1";
1345                                           push @defs,
1346                                               quotify("perl",
1347                                                       'LIBZ="' . $zlib . '"');
1348                                       }
1349                                       return [ @defs ];
1350                                   }),
1351         lib_cflags       => add("/Zi /Fdossl_static"),
1352         dso_cflags       => "/Zi /Fddso",
1353         bin_cflags       => "/Zi /Fdapp",
1354         shared_ldflag    => "/dll",
1355         shared_target    => "win-shared", # meaningless except it gives Configure a hint
1356         thread_scheme    => "winthreads",
1357         dso_scheme       => "win32",
1358         apps_aux_src     => add("win32_init.c"),
1359     },
1360     "VC-noCE-common" => {
1361         inherit_from     => [ "VC-common" ],
1362         template         => 1,
1363         CFLAGS           => add(picker(debug   => '/Od',
1364                                        release => '/O2')),
1365         cflags           => add(picker(debug   =>
1366                                        sub {
1367                                            ($disabled{shared} ? "" : "/MDd");
1368                                        },
1369                                        release =>
1370                                        sub {
1371                                            ($disabled{shared} ? "" : "/MD");
1372                                        })),
1373         defines          => add(picker(default => [ "UNICODE", "_UNICODE" ],
1374                                        debug   => [ "DEBUG", "_DEBUG" ])),
1375         lib_cflags       => add(sub { $disabled{shared} ? "/MT /Zl" : () }),
1376         # Following might/should appears controversial, i.e. defining
1377         # /MDd without evaluating $disabled{shared}. It works in
1378         # non-shared build because static library is compiled with /Zl
1379         # and bares no reference to specific RTL. And it works in
1380         # shared build because multiple /MDd options are not prohibited.
1381         # But why /MDd in static build? Well, basically this is just a
1382         # reference point, which allows to catch eventual errors that
1383         # would prevent those who want to wrap OpenSSL into own .DLL.
1384         # Why not /MD in release build then? Well, some are likely to
1385         # prefer [non-debug] openssl.exe to be free from Micorosoft RTL
1386         # redistributable.
1387         bin_cflags       => add(picker(debug   => "/MDd",
1388                                        release => sub { $disabled{shared} ? "/MT" : () },
1389                                       )),
1390         bin_lflags       => add("/subsystem:console /opt:ref"),
1391         ex_libs          => add(sub {
1392             my @ex_libs = ();
1393             push @ex_libs, 'ws2_32.lib' unless $disabled{sock};
1394             push @ex_libs, 'gdi32.lib advapi32.lib crypt32.lib user32.lib';
1395             return join(" ", @ex_libs);
1396         }),
1397     },
1398     "VC-WIN64-common" => {
1399         inherit_from     => [ "VC-noCE-common" ],
1400         template         => 1,
1401         ex_libs          => add(sub {
1402             my @ex_libs = ();
1403             push @ex_libs, 'bufferoverflowu.lib' if (`cl 2>&1` =~ /14\.00\.4[0-9]{4}\./);
1404             return join(" ", @_, @ex_libs);
1405         }),
1406         bn_ops           => "SIXTY_FOUR_BIT EXPORT_VAR_AS_FN",
1407         build_scheme     => add("VC-W64", { separator => undef }),
1408     },
1409     "VC-WIN64I" => {
1410         inherit_from     => [ "VC-WIN64-common", asm("ia64_asm"),
1411                               sub { $disabled{shared} ? () : "ia64_uplink" } ],
1412         AS               => "ias",
1413         ASFLAGS          => "-d debug",
1414         asoutflag        => "-o",
1415         sys_id           => "WIN64I",
1416         bn_asm_src       => sub { return undef unless @_;
1417                                   my $r=join(" ",@_); $r=~s|bn-ia64.s|bn_asm.c|; $r; },
1418         perlasm_scheme   => "ias",
1419         multilib         => "-ia64",
1420     },
1421     "VC-WIN64A" => {
1422         inherit_from     => [ "VC-WIN64-common", asm("x86_64_asm"),
1423                               sub { $disabled{shared} ? () : "x86_64_uplink" } ],
1424         AS               => sub { vc_win64a_info()->{AS} },
1425         ASFLAGS          => sub { vc_win64a_info()->{ASFLAGS} },
1426         asoutflag        => sub { vc_win64a_info()->{asoutflag} },
1427         asflags          => sub { vc_win64a_info()->{asflags} },
1428         sys_id           => "WIN64A",
1429         bn_asm_src       => sub { return undef unless @_;
1430                                   my $r=join(" ",@_); $r=~s|asm/x86_64-gcc|bn_asm|; $r; },
1431         perlasm_scheme   => "auto",
1432         multilib         => "-x64",
1433     },
1434     "VC-WIN32" => {
1435         # x86 Win32 target defaults to ANSI API, if you want UNICODE,
1436         # configure with 'perl Configure VC-WIN32 -DUNICODE -D_UNICODE'
1437         inherit_from     => [ "VC-noCE-common", asm("x86_asm"),
1438                               sub { $disabled{shared} ? () : "uplink_common" } ],
1439         CFLAGS           => add("-WX"),
1440         AS               => sub { vc_win32_info()->{AS} },
1441         ASFLAGS          => sub { vc_win32_info()->{ASFLAGS} },
1442         asoutflag        => sub { vc_win32_info()->{asoutflag} },
1443         asflags          => sub { vc_win32_info()->{asflags} },
1444         ex_libs          => add(sub {
1445             my @ex_libs = ();
1446             # WIN32 UNICODE build gets linked with unicows.lib for
1447             # backward compatibility with Win9x.
1448             push @ex_libs, 'unicows.lib'
1449                 if (grep { $_ eq "UNICODE" } @{$user{CPPDEFINES}});
1450             return join(" ", @ex_libs, @_);
1451         }),
1452         sys_id           => "WIN32",
1453         bn_ops           => "BN_LLONG EXPORT_VAR_AS_FN",
1454         perlasm_scheme   => sub { vc_win32_info()->{perlasm_scheme} },
1455         build_scheme     => add("VC-W32", { separator => undef }),
1456     },
1457     "VC-CE" => {
1458         inherit_from     => [ "VC-common" ],
1459         AS               => "ml",
1460         ASFLAGS          => "/nologo",
1461         asoutflag        => "/Fo",
1462         asflags          => "/Cp /coff /c /Cx /Zi",
1463         CC               => "cl",
1464         CFLAGS           => picker(default => '/W3 /WX /nologo',
1465                                    debug   => "/Od",
1466                                    release => "/O1i"),
1467         CPPDEFINES       => picker(debug   => [ "DEBUG", "_DEBUG" ]),
1468         LDFLAGS          => add("/nologo /opt:ref"),
1469         cflags           =>
1470             combine('/GF /Gy',
1471                     sub { vc_wince_info()->{cflags}; },
1472                     sub { `cl 2>&1` =~ /Version ([0-9]+)\./ && $1>=14
1473                               ? ($disabled{shared} ? " /MT" : " /MD")
1474                               : " /MC"; }),
1475         cppflags         => sub { vc_wince_info()->{cppflags}; },
1476         defines          => [ "UNICODE", "_UNICODE", "L_ENDIAN", "DSO_WIN32",
1477                               "NO_CHMOD", "OPENSSL_SMALL_FOOTPRINT",
1478                               "WIN32_LEAN_AND_MEAN" ],
1479         includes         =>
1480             add(combine(sub { defined(env('WCECOMPAT'))
1481                               ? '$(WCECOMPAT)/include' : (); },
1482                         sub { defined(env('PORTSDK_LIBPATH'))
1483                                   ? '$(PORTSDK_LIBPATH)/../../include'
1484                                   : (); })),
1485         lflags           => add(combine(sub { vc_wince_info()->{lflags}; },
1486                                         sub { defined(env('PORTSDK_LIBPATH'))
1487                                                   ? "/entry:mainCRTstartup" : (); })),
1488         sys_id           => "WINCE",
1489         bn_ops           => "BN_LLONG EXPORT_VAR_AS_FN",
1490         ex_libs          => add(sub {
1491             my @ex_libs = ();
1492             push @ex_libs, 'ws2.lib' unless $disabled{sock};
1493             push @ex_libs, 'crypt32.lib';
1494             if (defined(env('WCECOMPAT'))) {
1495                 my $x = '$(WCECOMPAT)/lib';
1496                 if (-f "$x/env('TARGETCPU')/wcecompatex.lib") {
1497                     $x .= '/$(TARGETCPU)/wcecompatex.lib';
1498                 } else {
1499                     $x .= '/wcecompatex.lib';
1500                 }
1501                 push @ex_libs, $x;
1502             }
1503             push @ex_libs, '$(PORTSDK_LIBPATH)/portlib.lib'
1504                 if (defined(env('PORTSDK_LIBPATH')));
1505             push @ex_libs, ' /nodefaultlib coredll.lib corelibc.lib'
1506                 if (env('TARGETCPU') eq "X86");
1507             return @ex_libs;
1508         }),
1509         build_scheme     => add("VC-WCE", { separator => undef }),
1510     },
1511
1512 #### MinGW
1513     "mingw" => {
1514         inherit_from     => [ "BASE_unix", asm("x86_asm"),
1515                               sub { $disabled{shared} ? () : "x86_uplink" } ],
1516         CC               => "gcc",
1517         CFLAGS           => picker(default => "-Wall",
1518                                    debug   => "-g -O0",
1519                                    release => "-O3 -fomit-frame-pointer"),
1520         cflags           => "-m32",
1521         cppflags         => combine("-DL_ENDIAN -DUNICODE -D_UNICODE",
1522                                     "-DWIN32_LEAN_AND_MEAN",
1523                                     threads("-D_MT")),
1524         sys_id           => "MINGW32",
1525         ex_libs          => add("-lws2_32 -lgdi32 -lcrypt32"),
1526         bn_ops           => "BN_LLONG EXPORT_VAR_AS_FN",
1527         thread_scheme    => "winthreads",
1528         perlasm_scheme   => "coff",
1529         dso_scheme       => "win32",
1530         shared_target    => "mingw-shared",
1531         shared_cppflags  => add("_WINDLL"),
1532         shared_ldflag    => "-static-libgcc",
1533         shared_rcflag    => "--target=pe-i386",
1534         shared_extension => ".dll",
1535         multilib         => "",
1536         apps_aux_src     => add("win32_init.c"),
1537     },
1538     "mingw64" => {
1539         # As for OPENSSL_USE_APPLINK. Applink makes it possible to use
1540         # .dll compiled with one compiler with application compiled with
1541         # another compiler. It's possible to engage Applink support in
1542         # mingw64 build, but it's not done, because till mingw64
1543         # supports structured exception handling, one can't seriously
1544         # consider its binaries for using with non-mingw64 run-time
1545         # environment. And as mingw64 is always consistent with itself,
1546         # Applink is never engaged and can as well be omitted.
1547         inherit_from     => [ "BASE_unix", asm("x86_64_asm") ],
1548         CC               => "gcc",
1549         CFLAGS           => picker(default => "-Wall",
1550                                    debug   => "-g -O0",
1551                                    release => "-O3"),
1552         cflags           => "-m64",
1553         cppflags         => combine("-DL_ENDIAN -DUNICODE -D_UNICODE",
1554                                     "-DWIN32_LEAN_AND_MEAN",
1555                                     threads("-D_MT")),
1556         sys_id           => "MINGW64",
1557         ex_libs          => add("-lws2_32 -lgdi32 -lcrypt32"),
1558         bn_ops           => "SIXTY_FOUR_BIT EXPORT_VAR_AS_FN",
1559         thread_scheme    => "winthreads",
1560         perlasm_scheme   => "mingw64",
1561         dso_scheme       => "win32",
1562         shared_target    => "mingw-shared",
1563         shared_cppflags  => add("_WINDLL"),
1564         shared_ldflag    => "-static-libgcc",
1565         shared_rcflag    => "--target=pe-x86-64",
1566         shared_extension => ".dll",
1567         multilib         => "64",
1568         apps_aux_src     => add("win32_init.c"),
1569     },
1570
1571 #### UEFI
1572     "UEFI" => {
1573         inherit_from     => [ "BASE_unix" ],
1574         CC               => "cc",
1575         CFLAGS           => "-O",
1576         cppflags         => "-DL_ENDIAN",
1577         sys_id           => "UEFI",
1578     },
1579
1580 #### UWIN
1581     "UWIN" => {
1582         inherit_from     => [ "BASE_unix" ],
1583         CC               => "cc",
1584         CFLAGS           => "-O -Wall",
1585         lib_cppflags     => "-DTERMIOS -DL_ENDIAN",
1586         sys_id           => "UWIN",
1587         bn_ops           => "BN_LLONG",
1588         dso_scheme       => "win32",
1589     },
1590
1591 #### Cygwin
1592     "Cygwin-x86" => {
1593         inherit_from     => [ "BASE_unix", asm("x86_asm") ],
1594         CC               => "gcc",
1595         CFLAGS           => picker(default => "-Wall",
1596                                    debug   => "-g -O0",
1597                                    release => "-O3 -fomit-frame-pointer"),
1598         cppflags         => "-DTERMIOS -DL_ENDIAN",
1599         sys_id           => "CYGWIN",
1600         bn_ops           => "BN_LLONG",
1601         thread_scheme    => "pthread",
1602         perlasm_scheme   => "coff",
1603         dso_scheme       => "dlfcn",
1604         shared_target    => "cygwin-shared",
1605         shared_cppflags  => "-D_WINDLL",
1606         shared_extension => ".dll",
1607     },
1608     "Cygwin-x86_64" => {
1609         inherit_from     => [ "BASE_unix", asm("x86_64_asm") ],
1610         CC               => "gcc",
1611         CFLAGS           => picker(default => "-Wall",
1612                                    debug   => "-g -O0",
1613                                    release => "-O3"),
1614         cppflags         => "-DTERMIOS -DL_ENDIAN",
1615         sys_id           => "CYGWIN",
1616         bn_ops           => "SIXTY_FOUR_BIT_LONG",
1617         thread_scheme    => "pthread",
1618         perlasm_scheme   => "mingw64",
1619         dso_scheme       => "dlfcn",
1620         shared_target    => "cygwin-shared",
1621         shared_cppflags  => "-D_WINDLL",
1622         shared_extension => ".dll",
1623     },
1624     # Backward compatibility for those using this target
1625     "Cygwin" => {
1626         inherit_from     => [ "Cygwin-x86" ]
1627     },
1628     # In case someone constructs the Cygwin target name themself
1629     "Cygwin-i386" => {
1630         inherit_from     => [ "Cygwin-x86" ]
1631     },
1632     "Cygwin-i486" => {
1633         inherit_from     => [ "Cygwin-x86" ]
1634     },
1635     "Cygwin-i586" => {
1636         inherit_from     => [ "Cygwin-x86" ]
1637     },
1638     "Cygwin-i686" => {
1639         inherit_from     => [ "Cygwin-x86" ]
1640     },
1641
1642 ##### MacOS X (a.k.a. Darwin) setup
1643     "darwin-common" => {
1644         inherit_from     => [ "BASE_unix" ],
1645         template         => 1,
1646         CC               => "cc",
1647         CFLAGS           => picker(debug   => "-g -O0",
1648                                    release => "-O3"),
1649         cppflags         => threads("-D_REENTRANT"),
1650         lflags           => "-Wl,-search_paths_first",
1651         sys_id           => "MACOSX",
1652         bn_ops           => "BN_LLONG RC4_CHAR",
1653         thread_scheme    => "pthreads",
1654         perlasm_scheme   => "osx32",
1655         dso_scheme       => "dlfcn",
1656         ranlib           => "ranlib -c",
1657         shared_target    => "darwin-shared",
1658         shared_cflag     => "-fPIC",
1659         shared_extension => ".\$(SHLIB_VERSION_NUMBER).dylib",
1660     },
1661     # Option "freeze" such as -std=gnu9x can't negatively interfere
1662     # with future defaults for below two targets, because MacOS X
1663     # for PPC has no future, it was discontinued by vendor in 2009.
1664     "darwin-ppc-cc" => {
1665         inherit_from     => [ "darwin-common", asm("ppc32_asm") ],
1666         cflags           => add("-arch ppc -std=gnu9x -Wa,-force_cpusubtype_ALL"),
1667         cppflags         => add("-DB_ENDIAN"),
1668         shared_cflag     => add("-fno-common"),
1669         perlasm_scheme   => "osx32",
1670     },
1671     "darwin64-ppc-cc" => {
1672         inherit_from     => [ "darwin-common", asm("ppc64_asm") ],
1673         cflags           => add("-arch ppc64 -std=gnu9x"),
1674         cppflags         => add("-DB_ENDIAN"),
1675         bn_ops           => "SIXTY_FOUR_BIT_LONG RC4_CHAR",
1676         perlasm_scheme   => "osx64",
1677     },
1678     "darwin-i386-cc" => {
1679         inherit_from     => [ "darwin-common", asm("x86_asm") ],
1680         CFLAGS           => add(picker(release => "-fomit-frame-pointer")),
1681         cflags           => add("-arch i386"),
1682         cppflags         => add("-DL_ENDIAN"),
1683         bn_ops           => "BN_LLONG RC4_INT",
1684         perlasm_scheme   => "macosx",
1685     },
1686     "darwin64-x86_64-cc" => {
1687         inherit_from     => [ "darwin-common", asm("x86_64_asm") ],
1688         CFLAGS           => add("-Wall"),
1689         cflags           => add("-arch x86_64"),
1690         cppflags         => add("-DL_ENDIAN"),
1691         bn_ops           => "SIXTY_FOUR_BIT_LONG",
1692         perlasm_scheme   => "macosx",
1693     },
1694
1695 #### iPhoneOS/iOS
1696 #
1697 # It takes three prior-set environment variables to make it work:
1698 #
1699 # CROSS_COMPILE=/where/toolchain/is/usr/bin/ [note ending slash]
1700 # CROSS_TOP=/where/SDKs/are
1701 # CROSS_SDK=iPhoneOSx.y.sdk
1702 #
1703 # Exact paths vary with Xcode releases, but for couple of last ones
1704 # they would look like this:
1705 #
1706 # CROSS_COMPILE=`xcode-select --print-path`/Toolchains/XcodeDefault.xctoolchain/usr/bin/
1707 # CROSS_TOP=`xcode-select --print-path`/Platforms/iPhoneOS.platform/Developer
1708 # CROSS_SDK=iPhoneOS.sdk
1709 #
1710     "iphoneos-cross" => {
1711         inherit_from     => [ "darwin-common" ],
1712         cflags           => add("-isysroot \$(CROSS_TOP)/SDKs/\$(CROSS_SDK) -fno-common"),
1713         sys_id           => "iOS",
1714     },
1715     "ios-cross" => {
1716         inherit_from     => [ "darwin-common", asm("armv4_asm") ],
1717         # It should be possible to go below iOS 6 and even add -arch armv6,
1718         # thus targeting iPhone pre-3GS, but it's assumed to be irrelevant
1719         # at this point.
1720         cflags           => add("-arch armv7 -mios-version-min=6.0.0 -isysroot \$(CROSS_TOP)/SDKs/\$(CROSS_SDK) -fno-common"),
1721         sys_id           => "iOS",
1722         perlasm_scheme   => "ios32",
1723     },
1724     "ios64-cross" => {
1725         inherit_from     => [ "darwin-common", asm("aarch64_asm") ],
1726         cflags           => add("-arch arm64 -mios-version-min=7.0.0 -isysroot \$(CROSS_TOP)/SDKs/\$(CROSS_SDK) -fno-common"),
1727         sys_id           => "iOS",
1728         bn_ops           => "SIXTY_FOUR_BIT_LONG RC4_CHAR",
1729         perlasm_scheme   => "ios64",
1730     },
1731
1732 ##### GNU Hurd
1733     "hurd-x86" => {
1734         inherit_from     => [ "BASE_unix" ],
1735         inherit_from     => [ asm("x86_elf_asm") ],
1736         CC               => "gcc",
1737         CFLAGS           => "-O3 -fomit-frame-pointer -Wall",
1738         cflags           => threads("-pthread"),
1739         cppflags         => "-DL_ENDIAN",
1740         ex_libs          => add("-ldl", threads("-pthread")),
1741         bn_ops           => "BN_LLONG",
1742         thread_scheme    => "pthreads",
1743         dso_scheme       => "dlfcn",
1744         shared_target    => "linux-shared",
1745         shared_cflag     => "-fPIC",
1746         shared_extension => ".so.\$(SHLIB_VERSION_NUMBER)",
1747     },
1748
1749 ##### VxWorks for various targets
1750     "vxworks-ppc60x" => {
1751         inherit_from     => [ "BASE_unix" ],
1752         CC               => "ccppc",
1753         CFLAGS           => "-O2 -Wall -fstrength-reduce",
1754         cflags           => "-mrtp -mhard-float -mstrict-align -fno-implicit-fp -fno-builtin -fno-strict-aliasing",
1755         cppflags         => combine("-D_REENTRANT -DPPC32_fp60x -DCPU=PPC32",
1756                                     "_DTOOL_FAMILY=gnu -DTOOL=gnu",
1757                                     "-I\$(WIND_BASE)/target/usr/h",
1758                                     "-I\$(WIND_BASE)/target/usr/h/wrn/coreip"),
1759         sys_id           => "VXWORKS",
1760         lflags           => add("-L \$(WIND_BASE)/target/usr/lib/ppc/PPC32/common"),
1761         ex_libs          => add("-Wl,--defsym,__wrs_rtp_base=0xe0000000"),
1762     },
1763     "vxworks-ppcgen" => {
1764         inherit_from     => [ "BASE_unix" ],
1765         CC               => "ccppc",
1766         CFLAGS           => "-O1 -Wall",
1767         cflags           => "-mrtp -msoft-float -mstrict-align -fno-builtin -fno-strict-aliasing",
1768         cppflags         => combine("-D_REENTRANT -DPPC32 -DCPU=PPC32",
1769                                     "-DTOOL_FAMILY=gnu -DTOOL=gnu",
1770                                     "-I\$(WIND_BASE)/target/usr/h",
1771                                     "-I\$(WIND_BASE)/target/usr/h/wrn/coreip"),
1772         sys_id           => "VXWORKS",
1773         lflags           => add("-L \$(WIND_BASE)/target/usr/lib/ppc/PPC32/sfcommon"),
1774         ex_libs          => add("-Wl,--defsym,__wrs_rtp_base=0xe0000000"),
1775     },
1776     "vxworks-ppc405" => {
1777         inherit_from     => [ "BASE_unix" ],
1778         CC               => "ccppc",
1779         CFLAGS           => "-g",
1780         cflags           => "-msoft-float -mlongcall",
1781         cppflags         => combine("-D_REENTRANT -DPPC32 -DCPU=PPC405",
1782                                     "-DTOOL_FAMILY=gnu -DTOOL=gnu",
1783                                     "-I\$(WIND_BASE)/target/h"),
1784         sys_id           => "VXWORKS",
1785         lflags           => add("-r"),
1786     },
1787     "vxworks-ppc750" => {
1788         inherit_from     => [ "BASE_unix" ],
1789         CC               => "ccppc",
1790         CFLAGS           => "-ansi -fvolatile -Wall \$(DEBUG_FLAG)",
1791         cflags           => "-nostdinc -fno-builtin -fno-for-scope -fsigned-char -msoft-float -mlongcall",
1792         cppflags         => combine("-DPPC750 -D_REENTRANT -DCPU=PPC604",
1793                                     "-I\$(WIND_BASE)/target/h"),
1794         sys_id           => "VXWORKS",
1795         lflags           => add("-r"),
1796     },
1797     "vxworks-ppc750-debug" => {
1798         inherit_from     => [ "BASE_unix" ],
1799         CC               => "ccppc",
1800         CFLAGS           => "-ansi -fvolatile -Wall -g",
1801         cflags           => "-nostdinc -fno-builtin -fno-for-scope -fsigned-char -msoft-float -mlongcall",
1802         cppflags         => combine("-DPPC750 -D_REENTRANT -DCPU=PPC604",
1803                                     "-DPEDANTIC -DDEBUG",
1804                                     "-I\$(WIND_BASE)/target/h"),
1805         sys_id           => "VXWORKS",
1806         lflags           => add("-r"),
1807     },
1808     "vxworks-ppc860" => {
1809         inherit_from     => [ "BASE_unix" ],
1810         CC               => "ccppc",
1811         cflags           => "-nostdinc -msoft-float",
1812         cppflags         => combine("-DCPU=PPC860 -DNO_STRINGS_H",
1813                                     "-I\$(WIND_BASE)/target/h"),
1814         sys_id           => "VXWORKS",
1815         lflags           => add("-r"),
1816     },
1817     "vxworks-simlinux" => {
1818         inherit_from     => [ "BASE_unix" ],
1819         CC               => "ccpentium",
1820         cflags           => "-B\$(WIND_BASE)/host/\$(WIND_HOST_TYPE)/lib/gcc-lib/ -fno-builtin -fno-defer-pop",
1821         cppflags         => combine("-D_VSB_CONFIG_FILE=\"\$(WIND_BASE)/target/lib/h/config/vsbConfig.h\"",
1822                                     "-DL_ENDIAN -DCPU=SIMLINUX -DNO_STRINGS_H",
1823                                     "-DTOOL_FAMILY=gnu -DTOOL=gnu",
1824                                     "-DOPENSSL_NO_HW_PADLOCK",
1825                                     "-I\$(WIND_BASE)/target/h",
1826                                     "-I\$(WIND_BASE)/target/h/wrn/coreip"),
1827         sys_id           => "VXWORKS",
1828         lflags           => add("-r"),
1829         ranlib           => "ranlibpentium",
1830     },
1831     "vxworks-mips" => {
1832         inherit_from     => [ "BASE_unix", asm("mips32_asm") ],
1833         CC               => "ccmips",
1834         CFLAGS           => "-O -G 0",
1835         cflags           => "-mrtp -mips2 -B\$(WIND_BASE)/host/\$(WIND_HOST_TYPE)/lib/gcc-lib/ -msoft-float -mno-branch-likely -fno-builtin -fno-defer-pop",
1836         cppflags         => combine("-D_VSB_CONFIG_FILE=\"\$(WIND_BASE)/target/lib/h/config/vsbConfig.h\"",
1837                                     "-DCPU=MIPS32 -DNO_STRINGS_H",
1838                                     "-DTOOL_FAMILY=gnu -DTOOL=gnu",
1839                                     "-DOPENSSL_NO_HW_PADLOCK",
1840                                     threads("-D_REENTRANT"),
1841                                     "-I\$(WIND_BASE)/target/h",
1842                                     "-I\$(WIND_BASE)/target/h/wrn/coreip"),
1843         sys_id           => "VXWORKS",
1844         lflags           => add("-L \$(WIND_BASE)/target/usr/lib/mips/MIPSI32/sfcommon"),
1845         ex_libs          => add("-Wl,--defsym,__wrs_rtp_base=0xe0000000"),
1846         thread_scheme    => "pthreads",
1847         perlasm_scheme   => "o32",
1848         ranlib           => "ranlibmips",
1849     },
1850
1851 #### uClinux
1852     "uClinux-dist" => {
1853         inherit_from     => [ "BASE_unix" ],
1854         CC               => sub { env('CC') },
1855         cppflags         => threads("-D_REENTRANT"),
1856         ex_libs          => add("\$(LDLIBS)"),
1857         bn_ops           => "BN_LLONG",
1858         thread_scheme    => "pthreads",
1859         dso_scheme       => sub { env('LIBSSL_dlfcn') },
1860         shared_target    => "linux-shared",
1861         shared_cflag     => "-fPIC",
1862         shared_extension => ".so.\$(SHLIB_VERSION_NUMBER)",
1863         ranlib           => sub { env('RANLIB') },
1864     },
1865     "uClinux-dist64" => {
1866         inherit_from     => [ "BASE_unix" ],
1867         CC               => sub { env('CC') },
1868         cppflags         => threads("-D_REENTRANT"),
1869         ex_libs          => add("\$(LDLIBS)"),
1870         bn_ops           => "SIXTY_FOUR_BIT_LONG",
1871         thread_scheme    => "pthreads",
1872         dso_scheme       => sub { env('LIBSSL_dlfcn') },
1873         shared_target    => "linux-shared",
1874         shared_cflag     => "-fPIC",
1875         shared_extension => ".so.\$(SHLIB_VERSION_NUMBER)",
1876         ranlib           => sub { env('RANLIB') },
1877     },
1878
1879     ##### VMS
1880     # Most things happen in vms-generic.
1881     # Note that vms_info extracts the pointer size from the end of
1882     # the target name, and will assume that anything matching /-p\d+$/
1883     # indicates the pointer size setting for the desired target.
1884     "vms-generic" => {
1885         inherit_from     => [ "BASE_VMS" ],
1886         template         => 1,
1887         CC               => "CC/DECC",
1888         CPP              => '$(CC)/PREPROCESS_ONLY=SYS$OUTPUT:',
1889         CFLAGS           =>
1890             combine(picker(default => "/STANDARD=(ISOC94,RELAXED)/NOLIST/PREFIX=ALL",
1891                            debug   => "/NOOPTIMIZE/DEBUG",
1892                            release => "/OPTIMIZE/NODEBUG"),
1893                     sub { my @warnings =
1894                               @{vms_info()->{disable_warns}};
1895                           @warnings
1896                               ? "/WARNINGS=DISABLE=(".join(",",@warnings).")" : (); }),
1897         defines          =>
1898             add("OPENSSL_USE_NODELETE",
1899                 sub {
1900                     return vms_info()->{def_zlib}
1901                         ? "LIBZ=\"\"\"".vms_info()->{def_zlib}."\"\"\"" : ();
1902                 }),
1903         lflags           => picker(default => "/MAP='F\$PARSE(\".MAP\",\"\$\@\")'",
1904                                    debug   => "/DEBUG/TRACEBACK",
1905                                    release => "/NODEBUG/NOTRACEBACK"),
1906         lib_cflags       => add("/NAMES=(AS_IS,SHORTENED)/EXTERN_MODEL=STRICT_REFDEF"),
1907         # no_inst_lib_cflags is used instead of lib_cflags by descrip.mms.tmpl
1908         # for object files belonging to selected internal libraries
1909         no_inst_lib_cflags => "",
1910         ex_libs          => add(sub { return vms_info()->{zlib} || (); }),
1911         shared_target    => "vms-shared",
1912         dso_scheme       => "vms",
1913         thread_scheme    => "pthreads",
1914
1915         AS               => sub { vms_info()->{AS} },
1916         ASFLAGS          => sub { vms_info()->{ASFLAGS} },
1917         asoutflag        => sub { vms_info()->{asoutflag} },
1918         asflags          => sub { vms_info()->{asflags} },
1919         perlasm_scheme   => sub { vms_info()->{perlasm_scheme} },
1920
1921         apps_aux_src     => "vms_term_sock.c",
1922         apps_init_src    => "vms_decc_init.c",
1923     },
1924
1925     # From HELP CC/POINTER_SIZE:
1926     #
1927     # ----------
1928     # LONG[=ARGV] The compiler assumes 64-bit pointers. If the ARGV option to
1929     #             LONG or 64 is present, the main argument argv will be an
1930     #             array of long pointers instead of an array of short pointers.
1931     #
1932     # 64[=ARGV]   Same as LONG.
1933     # ----------
1934     #
1935     # We don't want the hassle of dealing with 32-bit pointers with argv, so
1936     # we force it to have 64-bit pointers, see the added cflags in the -p64
1937     # config targets below.
1938
1939     "vms-alpha" => {
1940         inherit_from     => [ "vms-generic" ],
1941         bn_ops           => "SIXTY_FOUR_BIT RC4_INT",
1942         pointer_size     => "",
1943     },
1944     "vms-alpha-p32" => {
1945         inherit_from     => [ "vms-alpha" ],
1946         cflags           => add("/POINTER_SIZE=32"),
1947         pointer_size     => "32",
1948     },
1949     "vms-alpha-p64" => {
1950         inherit_from     => [ "vms-alpha" ],
1951         cflags           => add("/POINTER_SIZE=64=ARGV"),
1952         pointer_size     => "64",
1953     },
1954     "vms-ia64" => {
1955         inherit_from     => [ "vms-generic",
1956                               sub { vms_info()->{as}
1957                                         ? asm("ia64_asm")->() : () } ],
1958         bn_ops           => "SIXTY_FOUR_BIT RC4_INT",
1959         pointer_size     => "",
1960
1961         modes_asm_src    => "", # Because ghash-ia64.s doesn't work on VMS
1962     },
1963     "vms-ia64-p32" => {
1964         inherit_from     => [ "vms-ia64" ],
1965         cflags           => add("/POINTER_SIZE=32"),
1966         pointer_size     => "32",
1967     },
1968     "vms-ia64-p64" => {
1969         inherit_from     => [ "vms-ia64" ],
1970         cflags           => add("/POINTER_SIZE=64=ARGV"),
1971         pointer_size     => "64",
1972     },
1973
1974 );