1# -*- Mode: perl -*-
2my %targets=(
3    DEFAULTS => {
4	template	=> 1,
5
6	cflags		=> "",
7	cppflags	=> "",
8	lflags		=> "",
9	defines		=> [],
10	includes	=> [],
11	lib_cflags	=> "",
12	lib_cppflags	=> "",
13	lib_defines	=> [],
14	thread_scheme	=> "(unknown)", # Assume we don't know
15	thread_defines	=> [],
16
17	unistd		=> "<unistd.h>",
18	shared_target	=> "",
19	shared_cflag	=> "",
20	shared_defines	=> [],
21	shared_ldflag	=> "",
22	shared_rcflag	=> "",
23
24	#### Defaults for the benefit of the config targets who don't inherit
25	#### a BASE and assume Unix defaults
26	#### THESE WILL DISAPPEAR IN OpenSSL 1.2
27	build_scheme	=> [ "unified", "unix" ],
28	build_file	=> "Makefile",
29
30	AR		=> "(unused)",
31	ARFLAGS		=> "(unused)",
32	CC		=> "cc",
33	HASHBANGPERL	=> "/usr/bin/env perl",
34	RANLIB		=> sub { which("$config{cross_compile_prefix}ranlib")
35                                     ? "ranlib" : "" },
36	RC		=> "windres",
37
38	#### THESE WILL BE ENABLED IN OpenSSL 1.2
39	#HASHBANGPERL	=> "PERL", # Only Unix actually cares
40    },
41
42    BASE_common => {
43	template	=> 1,
44
45	enable		=> [],
46	disable		=> [],
47
48	defines		=>
49	    sub {
50                my @defs = ( 'OPENSSL_BUILDING_OPENSSL' );
51                push @defs, "BROTLI" unless $disabled{brotli};
52                push @defs, "BROTLI_SHARED" unless $disabled{"brotli-dynamic"};
53                push @defs, "ZLIB" unless $disabled{zlib};
54                push @defs, "ZLIB_SHARED" unless $disabled{"zlib-dynamic"};
55                push @defs, "ZSTD" unless $disabled{zstd};
56                push @defs, "ZSTD_SHARED" unless $disabled{"zstd-dynamic"};
57                return [ @defs ];
58            },
59        includes        =>
60            sub {
61                my @incs = ();
62                push @incs, $withargs{jitter_include}
63                    if !$disabled{jitter} && $withargs{jitter_include};
64                push @incs, $withargs{brotli_include}
65                    if !$disabled{brotli} && $withargs{brotli_include};
66                push @incs, $withargs{zlib_include}
67                    if !$disabled{zlib} && $withargs{zlib_include};
68                push @incs, $withargs{zstd_include}
69                    if !$disabled{zstd} && $withargs{zstd_include};
70                return [ @incs ];
71            },
72    },
73
74    BASE_unix => {
75        inherit_from    => [ "BASE_common" ],
76        template        => 1,
77
78        AR              => "ar",
79        ARFLAGS         => "qc",
80        CC              => "cc",
81        OBJCOPY         => "objcopy",
82        bin_cflags      =>
83            sub {
84                my @flags = ();
85                if (!defined($disabled{pie})) {
86                    push(@flags, "-fPIE");
87                }
88                return join(" ", @flags);
89            },
90        bin_lflags      =>
91            sub {
92                my @flags = ();
93                if (!defined($disabled{pie})) {
94                    push(@flags, "-pie");
95                }
96                return join(" ", @flags);
97            },
98        lflags          =>
99            sub {
100                my @libs = ();
101                push(@libs, "-L".$withargs{jitter_lib}) if $withargs{jitter_lib};
102                push(@libs, "-L".$withargs{zlib_lib}) if $withargs{zlib_lib};
103                push(@libs, "-L".$withargs{brotli_lib}) if $withargs{brotli_lib};
104                push(@libs, "-L".$withargs{zstd_lib}) if $withargs{zstd_lib};
105                return join(" ", @libs);
106            },
107        ex_libs         =>
108            sub {
109                my @libs = ();
110                push(@libs, "-l:libjitterentropy.a") if !defined($disabled{jitter});
111                push(@libs, "-lz") if !defined($disabled{zlib}) && defined($disabled{"zlib-dynamic"});
112                if (!defined($disabled{brotli}) && defined($disabled{"brotli-dynamic"})) {
113                    push(@libs, "-lbrotlienc");
114                    push(@libs, "-lbrotlidec");
115                    push(@libs, "-lbrotlicommon");
116                    push(@libs, "-lm");
117                }
118                push(@libs, "-lzstd") if !defined($disabled{zstd}) && defined($disabled{"zstd-dynamic"});
119                return join(" ", @libs);
120            },
121        HASHBANGPERL    => "/usr/bin/env perl", # Only Unix actually cares
122        RANLIB          => sub { which("$config{cross_compile_prefix}ranlib")
123                                     ? "ranlib" : "" },
124        RC              => "windres",
125
126        build_scheme    => [ "unified", "unix" ],
127        build_file      => "Makefile",
128
129        perl_platform   => 'Unix',
130    },
131
132    BASE_Windows => {
133        inherit_from    => [ "BASE_common" ],
134        template        => 1,
135
136        lib_defines      =>
137            sub {
138                my @defs = ();
139                unless ($disabled{"zlib-dynamic"}) {
140                    my $zlib = $withargs{zlib_lib} // "ZLIB1";
141                    push @defs, 'LIBZ=' . (quotify("perl", $zlib))[0];
142                }
143                return [ @defs ];
144            },
145        ex_libs         =>
146            sub {
147                my @libs = ();
148                unless ($disabled{zlib}) {
149                    if (defined($disabled{"zlib-dynamic"})) {
150                        push(@libs, $withargs{zlib_lib} // "ZLIB1");
151                    }
152                }
153                unless ($disabled{zstd}) {
154                    if (defined($disabled{"zstd-dynamic"})) {
155                        push(@libs, $withargs{zstd_lib} // "libzstd");
156                    }
157                }
158                unless ($disabled{brotli}) {
159                    if (defined($disabled{"brotli-dynamic"})) {
160                        my $path = "";
161                        if (defined($withargs{brotli_lib})) {
162                            $path = $withargs{brotli_lib} . "\\";
163                        }
164                        push(@libs, $path . "brotlicommon.lib");
165                        push(@libs, $path . "brotlidec.lib");
166                        push(@libs, $path . "brotlienc.lib");
167                    }
168                }
169                return join(" ", @libs);
170            },
171
172        MT              => "mt",
173        MTFLAGS         => "-nologo",
174        mtinflag        => "-manifest ",
175        mtoutflag       => "-outputresource:",
176
177        build_file      => "makefile",
178        build_scheme    => [ "unified", "windows" ],
179
180        perl_platform   => 'Windows',
181    },
182
183    BASE_VMS => {
184        inherit_from    => [ "BASE_common" ],
185        template        => 1,
186
187        includes        =>
188            add(sub {
189                    my @incs = ();
190                    # GNV$ZLIB_INCLUDE is the standard logical name for later
191                    # zlib incarnations.
192                    push @incs, 'GNV$ZLIB_INCLUDE:'
193                        if !$disabled{zlib} && !$withargs{zlib_include};
194                    return [ @incs ];
195                }),
196
197        build_file       => "descrip.mms",
198        build_scheme     => [ "unified", "VMS" ],
199
200        perl_platform    => 'VMS',
201    },
202);
203