eefb50a8ea0874fe27c1d987f866def9a1f083f6
[openssl.git] / Configurations / unix-Makefile.tmpl
1 ##
2 ## Makefile for OpenSSL
3 ##
4 ## {- join("\n## ", @autowarntext) -}
5 {-
6      our $objext = $target{obj_extension} || ".o";
7      our $depext = $target{dep_extension} || ".d";
8      our $exeext = $target{exe_extension} || "";
9      our $libext = $target{lib_extension} || ".a";
10      our $shlibext = $target{shared_extension} || ".so";
11      our $shlibextsimple = $target{shared_extension_simple} || ".so";
12      our $shlibextimport = $target{shared_import_extension} || "";
13      our $dsoext = $target{dso_extension} || ".so";
14
15      sub windowsdll { $config{target} =~ /^(?:Cygwin|mingw)/ }
16
17      our $sover = $config{target} =~ /^mingw/
18          ? $config{shlib_major}."_".$config{shlib_minor}
19          : $config{shlib_major}.".".$config{shlib_minor};
20
21      # shlib and shlib_simple both take a static library name and figure
22      # out what the shlib name should be.
23      #
24      # When OpenSSL is configured "no-shared", these functions will just
25      # return empty lists, making them suitable to join().
26      #
27      # With Windows DLL producers, shlib($libname) will return the shared
28      # library name (which usually is different from the static library
29      # name) with the default shared extension appended to it, while
30      # shlib_simple($libname) will return the static library name with
31      # the shared extension followed by ".a" appended to it.  The former
32      # result is used as the runtime shared library while the latter is
33      # used as the DLL import library.
34      #
35      # On all Unix systems, shlib($libname) will return the library name
36      # with the default shared extension, while shlib_simple($libname)
37      # will return the name from shlib($libname) with any SO version number
38      # removed.  On some systems, they may therefore return the exact same
39      # string.
40      sub shlib {
41          return () if $disabled{shared};
42          my $lib = shift;
43          return $unified_info{sharednames}->{$lib} . $shlibext;
44      }
45      sub shlib_simple {
46          return () if $disabled{shared};
47
48          my $lib = shift;
49          if (windowsdll()) {
50              return $lib . $shlibextimport;
51          }
52          return $lib .  $shlibextsimple;
53      }
54
55      # dso is a complement to shlib / shlib_simple that returns the
56      # given libname with the simple shared extension (possible SO version
57      # removed).  This differs from shlib_simple() by being unconditional.
58      sub dso {
59          my $engine = shift;
60
61          return $engine . $dsoext;
62      }
63      # This makes sure things get built in the order they need
64      # to. You're welcome.
65      sub dependmagic {
66          my $target = shift;
67
68          return "$target: build_generated\n\t\$(MAKE) depend && \$(MAKE) _$target\n_$target";
69      }
70      '';
71 -}
72 PLATFORM={- $config{target} -}
73 OPTIONS={- $config{options} -}
74 CONFIGURE_ARGS=({- join(", ",quotify_l(@{$config{perlargv}})) -})
75 SRCDIR={- $config{sourcedir} -}
76 BLDDIR={- $config{builddir} -}
77
78 VERSION={- $config{version} -}
79 MAJOR={- $config{major} -}
80 MINOR={- $config{minor} -}
81 SHLIB_VERSION_NUMBER={- $config{shlib_version_number} -}
82 SHLIB_VERSION_HISTORY={- $config{shlib_version_history} -}
83 SHLIB_MAJOR={- $config{shlib_major} -}
84 SHLIB_MINOR={- $config{shlib_minor} -}
85 SHLIB_TARGET={- $target{shared_target} -}
86
87 LIBS={- join(" ", map { $_.$libext } @{$unified_info{libraries}}) -}
88 SHLIBS={- join(" ", map { shlib($_) } @{$unified_info{libraries}}) -}
89 SHLIB_INFO={- join(" ", map { "\"".shlib($_).";".shlib_simple($_)."\"" } @{$unified_info{libraries}}) -}
90 ENGINES={- join(" ", map { dso($_) } @{$unified_info{engines}}) -}
91 PROGRAMS={- join(" ", map { $_.$exeext } @{$unified_info{programs}}) -}
92 SCRIPTS={- join(" ", @{$unified_info{scripts}}) -}
93 {- output_off() if $disabled{makedepend}; "" -}
94 DEPS={- join(" ", map { (my $x = $_) =~ s|\.o$|$depext|; $x; }
95                   grep { $unified_info{sources}->{$_}->[0] =~ /\.c$/ }
96                   keys %{$unified_info{sources}}); -}
97 {- output_on() if $disabled{makedepend}; "" -}
98 GENERATED_MANDATORY={- join(" ", @{$unified_info{depends}->{""}} ) -}
99 GENERATED={- join(" ",
100                   ( map { (my $x = $_) =~ s|\.S$|\.s|; $x }
101                     grep { defined $unified_info{generate}->{$_} }
102                     map { @{$unified_info{sources}->{$_}} }
103                     grep { /\.o$/ } keys %{$unified_info{sources}} ),
104                   ( grep { /\.h$/ } keys %{$unified_info{generate}} )) -}
105
106 INSTALL_LIBS={- join(" ", map { $_.$libext } @{$unified_info{install}->{libraries}}) -}
107 INSTALL_SHLIBS={- join(" ", map { shlib($_) } @{$unified_info{install}->{libraries}}) -}
108 INSTALL_SHLIB_INFO={- join(" ", map { "\"".shlib($_).";".shlib_simple($_)."\"" } @{$unified_info{install}->{libraries}}) -}
109 INSTALL_ENGINES={- join(" ", map { dso($_) } @{$unified_info{install}->{engines}}) -}
110 INSTALL_PROGRAMS={- join(" ", map { $_.$exeext } @{$unified_info{install}->{programs}}) -}
111 {- output_off() if $disabled{apps}; "" -}
112 BIN_SCRIPTS=$(BLDDIR)/tools/c_rehash
113 MISC_SCRIPTS=$(BLDDIR)/apps/CA.pl $(BLDDIR)/apps/tsget
114 {- output_on() if $disabled{apps}; "" -}
115
116 # DESTDIR is for package builders so that they can configure for, say,
117 # /usr/ and yet have everything installed to /tmp/somedir/usr/.
118 # Normally it is left empty.
119 DESTDIR=
120
121 # Do not edit these manually. Use Configure with --prefix or --openssldir
122 # to change this!  Short explanation in the top comment in Configure
123 INSTALLTOP={- # $prefix is used in the OPENSSLDIR perl snippet
124               #
125               our $prefix = $config{prefix} || "/usr/local";
126               $prefix -}
127 OPENSSLDIR={- #
128               # The logic here is that if no --openssldir was given,
129               # OPENSSLDIR will get the value from $prefix plus "/ssl".
130               # If --openssldir was given and the value is an absolute
131               # path, OPENSSLDIR will get its value without change.
132               # If the value from --openssldir is a relative path,
133               # OPENSSLDIR will get $prefix with the --openssldir
134               # value appended as a subdirectory.
135               #
136               use File::Spec::Functions;
137               our $openssldir =
138                   $config{openssldir} ?
139                       (file_name_is_absolute($config{openssldir}) ?
140                            $config{openssldir}
141                            : catdir($prefix, $config{openssldir}))
142                       : catdir($prefix, "ssl");
143               $openssldir -}
144 LIBDIR={- #
145           # if $prefix/lib$target{multilib} is not an existing
146           # directory, then assume that it's not searched by linker
147           # automatically, in which case adding $target{multilib} suffix
148           # causes more grief than we're ready to tolerate, so don't...
149           our $multilib =
150               -d "$prefix/lib$target{multilib}" ? $target{multilib} : "";
151           our $libdir = $config{libdir} || "lib$multilib";
152           $libdir -}
153 ENGINESDIR={- use File::Spec::Functions;
154               catdir($prefix,$libdir,"engines-$sover") -}
155
156 # Convenience variable for those who want to set the rpath in shared
157 # libraries and applications
158 LIBRPATH=$(INSTALLTOP)/$(LIBDIR)
159
160 MANDIR=$(INSTALLTOP)/share/man
161 DOCDIR=$(INSTALLTOP)/share/doc/$(BASENAME)
162 HTMLDIR=$(DOCDIR)/html
163
164 # MANSUFFIX is for the benefit of anyone who may want to have a suffix
165 # appended after the manpage file section number.  "ssl" is popular,
166 # resulting in files such as config.5ssl rather than config.5.
167 MANSUFFIX=
168 HTMLSUFFIX=html
169
170
171
172 CROSS_COMPILE= {- $config{cross_compile_prefix} -}
173 CC= $(CROSS_COMPILE){- $target{cc} -}
174 CFLAGS={- our $cflags2 = join(" ",(map { "-D".$_} @{$target{defines}}, @{$config{defines}}),"-DOPENSSLDIR=\"\\\"\$(OPENSSLDIR)\\\"\"","-DENGINESDIR=\"\\\"\$(ENGINESDIR)\\\"\"") -} {- $target{cflags} -} {- $config{cflags} -}
175 CFLAGS_Q={- $cflags2 =~ s|([\\"])|\\$1|g; $cflags2 -} {- $config{cflags} -}
176 CXX= $(CROSS_COMPILE){- $target{cxx} -}
177 CXXFLAGS={- our $cxxflags2 = join(" ",(map { "-D".$_} @{$target{defines}}, @{$config{defines}}),"-DOPENSSLDIR=\"\\\"\$(OPENSSLDIR)\\\"\"","-DENGINESDIR=\"\\\"\$(ENGINESDIR)\\\"\"") -} {- $target{cxxflags} -} {- $config{cxxflags} -} -std=c++11
178 LDFLAGS= {- $target{lflags} -}
179 PLIB_LDFLAGS= {- $target{plib_lflags} -}
180 EX_LIBS= {- $target{ex_libs} -} {- $config{ex_libs} -}
181 LIB_CFLAGS={- $target{shared_cflag} || "" -}
182 LIB_CXXFLAGS={- $target{shared_cxxflag} || "" -}
183 LIB_LDFLAGS={- $target{shared_ldflag}." ".$config{shared_ldflag} -}
184 DSO_CFLAGS={- $target{shared_cflag} || "" -}
185 DSO_CXXFLAGS={- $target{shared_cxxflag} || "" -}
186 DSO_LDFLAGS=$(LIB_LDFLAGS)
187 BIN_CFLAGS={- $target{bin_cflags} -}
188 BIN_CXXFLAGS={- $target{bin_cxxflag} || "" -}
189
190 PERL={- $config{perl} -}
191
192 ARFLAGS= {- $target{arflags} -}
193 AR=$(CROSS_COMPILE){- $target{ar} || "ar" -} $(ARFLAGS) r
194 RANLIB= {- $target{ranlib} -}
195 NM= $(CROSS_COMPILE){- $target{nm} || "nm" -}
196 RCFLAGS={- $target{shared_rcflag} -}
197 RC= $(CROSS_COMPILE){- $target{rc} || "windres" -}
198 RM= rm -f
199 RMDIR= rmdir
200 TAR= {- $target{tar} || "tar" -}
201 TARFLAGS= {- $target{tarflags} -}
202 MAKEDEPEND={- $config{makedepprog} -}
203
204 BASENAME=       openssl
205 NAME=           $(BASENAME)-$(VERSION)
206 TARFILE=        ../$(NAME).tar
207
208 # We let the C compiler driver to take care of .s files. This is done in
209 # order to be excused from maintaining a separate set of architecture
210 # dependent assembler flags. E.g. if you throw -mcpu=ultrasparc at SPARC
211 # gcc, then the driver will automatically translate it to -xarch=v8plus
212 # and pass it down to assembler.
213 AS=$(CC) -c
214 ASFLAG=$(CFLAGS)
215 PERLASM_SCHEME= {- $target{perlasm_scheme} -}
216
217 # For x86 assembler: Set PROCESSOR to 386 if you want to support
218 # the 80386.
219 PROCESSOR= {- $config{processor} -}
220
221 # We want error [and other] messages in English. Trouble is that make(1)
222 # doesn't pass macros down as environment variables unless there already
223 # was corresponding variable originally set. In other words we can only
224 # reassign environment variables, but not set new ones, not in portable
225 # manner that is. That's why we reassign several, just to be sure...
226 LC_ALL=C
227 LC_MESSAGES=C
228 LANG=C
229
230 # The main targets ###################################################
231
232 {- dependmagic('all'); -}: build_libs_nodep build_engines_nodep build_programs_nodep link-utils
233 {- dependmagic('build_libs'); -}: build_libs_nodep
234 {- dependmagic('build_engines'); -}: build_engines_nodep
235 {- dependmagic('build_programs'); -}: build_programs_nodep
236
237 build_generated: $(GENERATED_MANDATORY)
238 build_libs_nodep: libcrypto.pc libssl.pc openssl.pc
239 build_engines_nodep: $(ENGINES)
240 build_programs_nodep: $(PROGRAMS) $(SCRIPTS)
241
242 # Kept around for backward compatibility
243 build_apps build_tests: build_programs
244
245 test: tests
246 {- dependmagic('tests'); -}: build_programs_nodep build_engines_nodep link-utils
247         @ : {- output_off() if $disabled{tests}; "" -}
248         ( cd test; \
249           SRCTOP=../$(SRCDIR) \
250           BLDTOP=../$(BLDDIR) \
251           PERL="$(PERL)" \
252           EXE_EXT={- $exeext -} \
253           OPENSSL_ENGINES=../$(BLDDIR)/engines \
254           OPENSSL_DEBUG_MEMORY=on \
255             $(PERL) ../$(SRCDIR)/test/run_tests.pl $(TESTS) )
256         @ : {- if ($disabled{tests}) { output_on(); } else { output_off(); } "" -}
257         @echo "Tests are not supported with your chosen Configure options"
258         @ : {- output_on() if !$disabled{tests}; "" -}
259
260 list-tests:
261         @ : {- output_off() if $disabled{tests}; "" -}
262         @SRCTOP="$(SRCDIR)" \
263          $(PERL) $(SRCDIR)/test/run_tests.pl list
264         @ : {- if ($disabled{tests}) { output_on(); } else { output_off(); } "" -}
265         @echo "Tests are not supported with your chosen Configure options"
266         @ : {- output_on() if !$disabled{tests}; "" -}
267
268 install: install_sw install_ssldirs install_docs
269
270 uninstall: uninstall_docs uninstall_sw
271
272 libclean:
273         @set -e; for s in $(SHLIB_INFO); do \
274                 s1=`echo "$$s" | cut -f1 -d";"`; \
275                 s2=`echo "$$s" | cut -f2 -d";"`; \
276                 echo $(RM) $$s1; \
277                 $(RM) $$s1; \
278                 if [ "$$s1" != "$$s2" ]; then \
279                         echo $(RM) $$s2; \
280                         $(RM) $$s2; \
281                 fi; \
282         done
283         $(RM) $(LIBS)
284         $(RM) *.map
285
286 clean: libclean
287         $(RM) $(PROGRAMS) $(TESTPROGS) $(ENGINES) $(SCRIPTS)
288         $(RM) $(GENERATED)
289         -$(RM) `find . -name '*{- $depext -}' -a \! -path "./.git/*"`
290         -$(RM) `find . -name '*{- $objext -}' -a \! -path "./.git/*"`
291         $(RM) core
292         $(RM) tags TAGS
293         $(RM) openssl.pc libcrypto.pc libssl.pc
294         -$(RM) `find . -type l -a \! -path "./.git/*"`
295         $(RM) $(TARFILE)
296
297 distclean: clean
298         $(RM) configdata.pm
299         $(RM) Makefile
300
301 # We check if any depfile is newer than Makefile and decide to
302 # concatenate only if that is true.
303 depend:
304         @: {- output_off() if $disabled{makedepend}; "" -}
305         @if egrep "^# DO NOT DELETE THIS LINE" Makefile >/dev/null && [ -z "`find $(DEPS) -newer Makefile 2>/dev/null; exit 0`" ]; then :; else \
306           ( $(PERL) -pe 'exit 0 if /^# DO NOT DELETE THIS LINE.*/' < Makefile; \
307             echo '# DO NOT DELETE THIS LINE -- make depend depends on it.'; \
308             echo; \
309             for f in $(DEPS); do \
310               if [ -f $$f ]; then cat $$f; fi; \
311             done ) > Makefile.new; \
312           if cmp Makefile.new Makefile >/dev/null 2>&1; then \
313             rm -f Makefile.new; \
314           else \
315             mv -f Makefile.new Makefile; \
316           fi; \
317         fi
318         @: {- output_on() if $disabled{makedepend}; "" -}
319
320 # Install helper targets #############################################
321
322 install_sw: all install_dev install_engines install_runtime
323
324 uninstall_sw: uninstall_runtime uninstall_engines uninstall_dev
325
326 doc-nits:
327         $(PERL) util/find-doc-nits.pl -n
328
329 install_docs: install_man_docs install_html_docs
330
331 uninstall_docs: uninstall_man_docs uninstall_html_docs
332         $(RM) -r -v $(DESTDIR)$(DOCDIR)
333
334 install_ssldirs:
335         @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(OPENSSLDIR)/certs
336         @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(OPENSSLDIR)/private
337         @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(OPENSSLDIR)/misc
338         @set -e; for x in dummy $(MISC_SCRIPTS); do \
339                 if [ "$$x" = "dummy" ]; then continue; fi; \
340                 fn=`basename $$x`; \
341                 echo "install $$x -> $(DESTDIR)$(OPENSSLDIR)/misc/$$fn"; \
342                 cp $$x $(DESTDIR)$(OPENSSLDIR)/misc/$$fn.new; \
343                 chmod 755 $(DESTDIR)$(OPENSSLDIR)/misc/$$fn.new; \
344                 mv -f $(DESTDIR)$(OPENSSLDIR)/misc/$$fn.new \
345                       $(DESTDIR)$(OPENSSLDIR)/misc/$$fn; \
346         done
347         @echo "install $(SRCDIR)/apps/openssl.cnf -> $(DESTDIR)$(OPENSSLDIR)/openssl.cnf.dist"
348         @cp $(SRCDIR)/apps/openssl.cnf $(DESTDIR)$(OPENSSLDIR)/openssl.cnf.new
349         @chmod 644 $(DESTDIR)$(OPENSSLDIR)/openssl.cnf.new
350         @mv -f  $(DESTDIR)$(OPENSSLDIR)/openssl.cnf.new $(DESTDIR)$(OPENSSLDIR)/openssl.cnf.dist
351         @if [ ! -f "$(DESTDIR)$(OPENSSLDIR)/openssl.cnf" ]; then \
352                 echo "install $(SRCDIR)/apps/openssl.cnf -> $(DESTDIR)$(OPENSSLDIR)/openssl.cnf"; \
353                 cp $(SRCDIR)/apps/openssl.cnf $(DESTDIR)$(OPENSSLDIR)/openssl.cnf; \
354                 chmod 644 $(DESTDIR)$(OPENSSLDIR)/openssl.cnf; \
355         fi
356         @echo "install $(SRCDIR)/apps/ct_log_list.cnf -> $(DESTDIR)$(OPENSSLDIR)/ct_log_list.cnf.dist"
357         @cp $(SRCDIR)/apps/ct_log_list.cnf $(DESTDIR)$(OPENSSLDIR)/ct_log_list.cnf.new
358         @chmod 644 $(DESTDIR)$(OPENSSLDIR)/ct_log_list.cnf.new
359         @mv -f  $(DESTDIR)$(OPENSSLDIR)/ct_log_list.cnf.new $(DESTDIR)$(OPENSSLDIR)/ct_log_list.cnf.dist
360         @if [ ! -f "$(DESTDIR)$(OPENSSLDIR)/ct_log_list.cnf" ]; then \
361                 echo "install $(SRCDIR)/apps/ct_log_list.cnf -> $(DESTDIR)$(OPENSSLDIR)/ct_log_list.cnf"; \
362                 cp $(SRCDIR)/apps/ct_log_list.cnf $(DESTDIR)$(OPENSSLDIR)/ct_log_list.cnf; \
363                 chmod 644 $(DESTDIR)$(OPENSSLDIR)/ct_log_list.cnf; \
364         fi
365
366 install_dev:
367         @[ -n "$(INSTALLTOP)" ] || (echo INSTALLTOP should not be empty; exit 1)
368         @echo "*** Installing development files"
369         @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(INSTALLTOP)/include/openssl
370         @ : {- output_off() unless grep { $_ eq "OPENSSL_USE_APPLINK" } @{$target{defines}}; "" -}
371         @echo "install $(SRCDIR)/ms/applink.c -> $(DESTDIR)$(INSTALLTOP)/include/openssl/applink.c"
372         @cp $(SRCDIR)/ms/applink.c $(DESTDIR)$(INSTALLTOP)/include/openssl/applink.c
373         @chmod 644 $(DESTDIR)$(INSTALLTOP)/include/openssl/applink.c
374         @ : {- output_on() unless grep { $_ eq "OPENSSL_USE_APPLINK" } @{$target{defines}}; "" -}
375         @set -e; for i in $(SRCDIR)/include/openssl/*.h \
376                           $(BLDDIR)/include/openssl/*.h; do \
377                 fn=`basename $$i`; \
378                 echo "install $$i -> $(DESTDIR)$(INSTALLTOP)/include/openssl/$$fn"; \
379                 cp $$i $(DESTDIR)$(INSTALLTOP)/include/openssl/$$fn; \
380                 chmod 644 $(DESTDIR)$(INSTALLTOP)/include/openssl/$$fn; \
381         done
382         @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)
383         @set -e; for l in $(INSTALL_LIBS); do \
384                 fn=`basename $$l`; \
385                 echo "install $$l -> $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn"; \
386                 cp $$l $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn.new; \
387                 $(RANLIB) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn.new; \
388                 chmod 644 $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn.new; \
389                 mv -f $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn.new \
390                       $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn; \
391         done
392         @ : {- output_off() if $disabled{shared}; "" -}
393         @set -e; for s in $(INSTALL_SHLIB_INFO); do \
394                 s1=`echo "$$s" | cut -f1 -d";"`; \
395                 s2=`echo "$$s" | cut -f2 -d";"`; \
396                 fn1=`basename $$s1`; \
397                 fn2=`basename $$s2`; \
398                 : {- output_off() if windowsdll(); "" -}; \
399                 echo "install $$s1 -> $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn1"; \
400                 cp $$s1 $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn1.new; \
401                 chmod 755 $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn1.new; \
402                 mv -f $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn1.new \
403                       $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn1; \
404                 if [ "$$fn1" != "$$fn2" ]; then \
405                         echo "link $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn2 -> $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn1"; \
406                         ln -sf $$fn1 $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn2; \
407                 fi; \
408                 : {- output_on() if windowsdll(); "" -}{- output_off() unless windowsdll(); "" -}; \
409                 echo "install $$s2 -> $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn2"; \
410                 cp $$s2 $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn2.new; \
411                 chmod 755 $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn2.new; \
412                 mv -f $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn2.new \
413                       $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn2; \
414                 : {- output_on() unless windowsdll(); "" -}; \
415         done
416         @ : {- output_on() if $disabled{shared}; "" -}
417         @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig
418         @echo "install libcrypto.pc -> $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/libcrypto.pc"
419         @cp libcrypto.pc $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig
420         @chmod 644 $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/libcrypto.pc
421         @echo "install libssl.pc -> $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/libssl.pc"
422         @cp libssl.pc $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig
423         @chmod 644 $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/libssl.pc
424         @echo "install openssl.pc -> $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/openssl.pc"
425         @cp openssl.pc $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig
426         @chmod 644 $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/openssl.pc
427
428 uninstall_dev:
429         @echo "*** Uninstalling development files"
430         @ : {- output_off() unless grep { $_ eq "OPENSSL_USE_APPLINK" } @{$target{defines}}; "" -}
431         @echo "$(RM) $(DESTDIR)$(INSTALLTOP)/include/openssl/applink.c"
432         @$(RM) $(DESTDIR)$(INSTALLTOP)/include/openssl/applink.c
433         @ : {- output_on() unless grep { $_ eq "OPENSSL_USE_APPLINK" } @{$target{defines}}; "" -}
434         @set -e; for i in $(SRCDIR)/include/openssl/*.h \
435                           $(BLDDIR)/include/openssl/*.h; do \
436                 fn=`basename $$i`; \
437                 echo "$(RM) $(DESTDIR)$(INSTALLTOP)/include/openssl/$$fn"; \
438                 $(RM) $(DESTDIR)$(INSTALLTOP)/include/openssl/$$fn; \
439         done
440         -$(RMDIR) $(DESTDIR)$(INSTALLTOP)/include/openssl
441         -$(RMDIR) $(DESTDIR)$(INSTALLTOP)/include
442         @set -e; for l in $(INSTALL_LIBS); do \
443                 fn=`basename $$l`; \
444                 echo "$(RM) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn"; \
445                 $(RM) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn; \
446         done
447         @ : {- output_off() if $disabled{shared}; "" -}
448         @set -e; for s in $(INSTALL_SHLIB_INFO); do \
449                 s1=`echo "$$s" | cut -f1 -d";"`; \
450                 s2=`echo "$$s" | cut -f2 -d";"`; \
451                 fn1=`basename $$s1`; \
452                 fn2=`basename $$s2`; \
453                 : {- output_off() if windowsdll(); "" -}; \
454                 echo "$(RM) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn1"; \
455                 $(RM) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn1; \
456                 if [ "$$fn1" != "$$fn2" ]; then \
457                         echo "$(RM) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn2"; \
458                         $(RM) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn2; \
459                 fi; \
460                 : {- output_on() if windowsdll(); "" -}{- output_off() unless windowsdll(); "" -}; \
461                 echo "$(RM) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn2"; \
462                 $(RM) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn2; \
463                 : {- output_on() unless windowsdll(); "" -}; \
464         done
465         @ : {- output_on() if $disabled{shared}; "" -}
466         $(RM) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/libcrypto.pc
467         $(RM) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/libssl.pc
468         $(RM) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/openssl.pc
469         -$(RMDIR) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig
470         -$(RMDIR) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)
471
472 install_engines:
473         @[ -n "$(INSTALLTOP)" ] || (echo INSTALLTOP should not be empty; exit 1)
474         @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(ENGINESDIR)/
475         @echo "*** Installing engines"
476         @set -e; for e in dummy $(INSTALL_ENGINES); do \
477                 if [ "$$e" = "dummy" ]; then continue; fi; \
478                 fn=`basename $$e`; \
479                 echo "install $$e -> $(DESTDIR)$(ENGINESDIR)/$$fn"; \
480                 cp $$e $(DESTDIR)$(ENGINESDIR)/$$fn.new; \
481                 chmod 755 $(DESTDIR)$(ENGINESDIR)/$$fn.new; \
482                 mv -f $(DESTDIR)$(ENGINESDIR)/$$fn.new \
483                       $(DESTDIR)$(ENGINESDIR)/$$fn; \
484         done
485
486 uninstall_engines:
487         @echo "*** Uninstalling engines"
488         @set -e; for e in dummy $(INSTALL_ENGINES); do \
489                 if [ "$$e" = "dummy" ]; then continue; fi; \
490                 fn=`basename $$e`; \
491                 if [ "$$fn" = '{- dso("ossltest") -}' ]; then \
492                         continue; \
493                 fi; \
494                 echo "$(RM) $(DESTDIR)$(ENGINESDIR)/$$fn"; \
495                 $(RM) $(DESTDIR)$(ENGINESDIR)/$$fn; \
496         done
497         -$(RMDIR) $(DESTDIR)$(ENGINESDIR)
498
499 install_runtime:
500         @[ -n "$(INSTALLTOP)" ] || (echo INSTALLTOP should not be empty; exit 1)
501         @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(INSTALLTOP)/bin
502         @ : {- output_off() if windowsdll(); "" -}
503         @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)
504         @ : {- output_on() if windowsdll(); "" -}
505         @echo "*** Installing runtime files"
506         @set -e; for s in dummy $(INSTALL_SHLIBS); do \
507                 if [ "$$s" = "dummy" ]; then continue; fi; \
508                 fn=`basename $$s`; \
509                 : {- output_off() unless windowsdll(); "" -}; \
510                 echo "install $$s -> $(DESTDIR)$(INSTALLTOP)/bin/$$fn"; \
511                 cp $$s $(DESTDIR)$(INSTALLTOP)/bin/$$fn.new; \
512                 chmod 644 $(DESTDIR)$(INSTALLTOP)/bin/$$fn.new; \
513                 mv -f $(DESTDIR)$(INSTALLTOP)/bin/$$fn.new \
514                       $(DESTDIR)$(INSTALLTOP)/bin/$$fn; \
515                 : {- output_on() unless windowsdll(); "" -}{- output_off() if windowsdll(); "" -}; \
516                 echo "install $$s -> $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn"; \
517                 cp $$s $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn.new; \
518                 chmod 755 $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn.new; \
519                 mv -f $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn.new \
520                       $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn; \
521                 : {- output_on() if windowsdll(); "" -}; \
522         done
523         @set -e; for x in dummy $(INSTALL_PROGRAMS); do \
524                 if [ "$$x" = "dummy" ]; then continue; fi; \
525                 fn=`basename $$x`; \
526                 echo "install $$x -> $(DESTDIR)$(INSTALLTOP)/bin/$$fn"; \
527                 cp $$x $(DESTDIR)$(INSTALLTOP)/bin/$$fn.new; \
528                 chmod 755 $(DESTDIR)$(INSTALLTOP)/bin/$$fn.new; \
529                 mv -f $(DESTDIR)$(INSTALLTOP)/bin/$$fn.new \
530                       $(DESTDIR)$(INSTALLTOP)/bin/$$fn; \
531         done
532         @set -e; for x in dummy $(BIN_SCRIPTS); do \
533                 if [ "$$x" = "dummy" ]; then continue; fi; \
534                 fn=`basename $$x`; \
535                 echo "install $$x -> $(DESTDIR)$(INSTALLTOP)/bin/$$fn"; \
536                 cp $$x $(DESTDIR)$(INSTALLTOP)/bin/$$fn.new; \
537                 chmod 755 $(DESTDIR)$(INSTALLTOP)/bin/$$fn.new; \
538                 mv -f $(DESTDIR)$(INSTALLTOP)/bin/$$fn.new \
539                       $(DESTDIR)$(INSTALLTOP)/bin/$$fn; \
540         done
541
542 uninstall_runtime:
543         @echo "*** Uninstalling runtime files"
544         @set -e; for x in dummy $(INSTALL_PROGRAMS); \
545         do  \
546                 if [ "$$x" = "dummy" ]; then continue; fi; \
547                 fn=`basename $$x`; \
548                 echo "$(RM) $(DESTDIR)$(INSTALLTOP)/bin/$$fn"; \
549                 $(RM) $(DESTDIR)$(INSTALLTOP)/bin/$$fn; \
550         done;
551         @set -e; for x in dummy $(BIN_SCRIPTS); \
552         do  \
553                 if [ "$$x" = "dummy" ]; then continue; fi; \
554                 fn=`basename $$x`; \
555                 echo "$(RM) $(DESTDIR)$(INSTALLTOP)/bin/$$fn"; \
556                 $(RM) $(DESTDIR)$(INSTALLTOP)/bin/$$fn; \
557         done
558         @ : {- output_off() unless windowsdll(); "" -}
559         @set -e; for s in dummy $(INSTALL_SHLIBS); do \
560                 if [ "$$s" = "dummy" ]; then continue; fi; \
561                 fn=`basename $$s`; \
562                 echo "$(RM) $(DESTDIR)$(INSTALLTOP)/bin/$$fn"; \
563                 $(RM) $(DESTDIR)$(INSTALLTOP)/bin/$$fn; \
564         done
565         @ : {- output_on() unless windowsdll(); "" -}
566         -$(RMDIR) $(DESTDIR)$(INSTALLTOP)/bin
567
568 # A method to extract all names from a .pod file
569 # The first sed extracts everything between "=head1 NAME" and the next =head1
570 # The perl command joins all the lines into one
571 # The second sed removes the description and turns all commas into spaces
572 # Voilà, you have a space separated list of names!
573 EXTRACT_NAMES=sed -e '1,/^=head1  *NAME *$$/d;/^=head1/,$$d' | \
574               $(PERL) -p -0 -e 's/\n/ /g; END {print "\n"}' | \
575               sed -e 's/ - .*$$//;s/,/ /g'
576 PROCESS_PODS=\
577         set -e; \
578         here=`cd $(SRCDIR); pwd`; \
579         point=$$here/util/point.sh; \
580         for ds in man1 man3 man5 man7 ; do \
581             SEC=`echo $$ds | sed -e s/man//`; \
582             for p in $(SRCDIR)/doc/$$ds/*.pod; do \
583                 fn=`basename $$p .pod`; \
584                 Name=$$fn; \
585                 NAME=`echo $$fn | tr '[a-z]' '[A-Z]'`; \
586                 suf=`eval "echo $$OUTSUFFIX"`; \
587                 top=`eval "echo $$OUTTOP"`; \
588                 $(PERL) $(SRCDIR)/util/mkdir-p.pl $$top/man$$SEC; \
589                 echo "install $$p -> $$top/man$$SEC/$$fn$$suf"; \
590                 cat $$p | eval "$$GENERATE" \
591                         >  $$top/man$$SEC/$$fn$$suf; \
592                 names=`cat $$p | $(EXTRACT_NAMES)`; \
593                 ( cd $$top/man$$SEC; \
594                   for n in $$names; do \
595                       comp_n="$$n"; \
596                       comp_fn="$$fn"; \
597                       case "$(PLATFORM)" in DJGPP|Cygwin*|mingw*|darwin*-*-cc) \
598                           comp_n=`echo "$$n" | tr '[A-Z]' '[a-z]'`; \
599                           comp_fn=`echo "$$fn" | tr '[A-Z]' '[a-z]'`; \
600                           ;; \
601                       esac; \
602                       if [ "$$comp_n" != "$$comp_fn" ]; then \
603                           echo "link $$top/man$$SEC/$$n$$suf -> $$top/man$$SEC/$$fn$$suf"; \
604                           PLATFORM=$(PLATFORM) $$point $$fn$$suf $$n$$suf; \
605                       fi; \
606                   done ); \
607             done; \
608         done
609 UNINSTALL_DOCS=\
610         set -e; \
611         here=`cd $(SRCDIR); pwd`; \
612         for ds in man1 man3 man5 man7 ; do \
613             SEC=`echo $$ds | sed -e s/man//`; \
614             for p in $(SRCDIR)/doc/$$ds/*.pod; do \
615                 fn=`basename $$p .pod`; \
616                 suf=`eval "echo $$OUTSUFFIX"`; \
617                 top=`eval "echo $$OUTTOP"`; \
618                 echo "$(RM) $$top/man$$SEC/$$fn$$suf"; \
619                 $(RM) $$top/man$$SEC/$$fn$$suf; \
620                 names=`cat $$p | $(EXTRACT_NAMES)`; \
621                 for n in $$names; do \
622                     comp_n="$$n"; \
623                     comp_fn="$$fn"; \
624                     case "$(PLATFORM)" in DJGPP|Cygwin*|mingw*|darwin*-*-cc) \
625                         comp_n=`echo "$$n" | tr '[A-Z]' '[a-z]'`; \
626                         comp_fn=`echo "$$fn" | tr '[A-Z]' '[a-z]'`; \
627                         ;; \
628                     esac; \
629                     if [ "$$comp_n" != "$$comp_fn" ]; then \
630                         echo "$(RM) $$top/man$$SEC/$$n$$suf"; \
631                         $(RM) $$top/man$$SEC/$$n$$suf; \
632                     fi; \
633                 done; \
634                 ( $(RMDIR) $$top/man$$SEC 2>/dev/null || exit 0 ); \
635             done; \
636         done
637
638 install_man_docs:
639         @[ -n "$(INSTALLTOP)" ] || (echo INSTALLTOP should not be empty; exit 1)
640         @echo "*** Installing manpages"
641         @\
642         OUTSUFFIX='.$${SEC}$(MANSUFFIX)'; \
643         OUTTOP="$(DESTDIR)$(MANDIR)"; \
644         GENERATE='pod2man --name=$$NAME --section=$$SEC --center=OpenSSL --release=$(VERSION)'; \
645         $(PROCESS_PODS)
646
647 uninstall_man_docs:
648         @echo "*** Uninstalling manpages"
649         @\
650         OUTSUFFIX='.$${SEC}$(MANSUFFIX)'; \
651         OUTTOP="$(DESTDIR)$(MANDIR)"; \
652         $(UNINSTALL_DOCS)
653
654 install_html_docs:
655         @[ -n "$(INSTALLTOP)" ] || (echo INSTALLTOP should not be empty; exit 1)
656         @echo "*** Installing HTML manpages"
657         @\
658         OUTSUFFIX='.$(HTMLSUFFIX)'; \
659         OUTTOP="$(DESTDIR)$(HTMLDIR)"; \
660         GENERATE="pod2html --podroot=$(SRCDIR)/doc --htmldir=.. \
661                            --podpath=apps:crypto:ssl --title=\$$Name \
662                   | perl -pe 's|href=\"http://man.he.net/man|href=\"../man|g; s|href=\"(.*/man.*)(?<!\.html)\">|href=\"\$$1.html\">|g;'"; \
663         $(PROCESS_PODS)
664
665 uninstall_html_docs:
666         @echo "*** Uninstalling manpages"
667         @\
668         OUTSUFFIX='.$(HTMLSUFFIX)'; \
669         OUTTOP="$(DESTDIR)$(HTMLDIR)"; \
670         $(UNINSTALL_DOCS)
671
672
673 # Developer targets (note: these are only available on Unix) #########
674
675 update: generate errors ordinals
676
677 generate: generate_apps generate_crypto_bn generate_crypto_objects \
678           generate_crypto_conf generate_crypto_asn1
679
680 # Test coverage is a good idea for the future
681 #coverage: $(PROGRAMS) $(TESTPROGRAMS)
682 #       ...
683
684 lint:
685         lint -DLINT $(INCLUDES) $(SRCS)
686
687 {- # because the program apps/openssl has object files as sources, and
688    # they then have the corresponding C files as source, we need to chain
689    # the lookups in %unified_info
690    my $apps_openssl = catfile("apps","openssl");
691    our @openssl_source = map { @{$unified_info{sources}->{$_}} }
692                          @{$unified_info{sources}->{$apps_openssl}};
693    ""; -}
694 generate_apps:
695         ( cd $(SRCDIR); $(PERL) VMS/VMSify-conf.pl \
696                                 < apps/openssl.cnf > apps/openssl-vms.cnf )
697         ( b=`pwd`; cd $(SRCDIR); $(PERL) -I$$b apps/progs.pl \
698                                         {- join(" ", @openssl_source) -} \
699                                         > apps/progs.h )
700
701 generate_crypto_bn:
702         ( cd $(SRCDIR); $(PERL) crypto/bn/bn_prime.pl > crypto/bn/bn_prime.h )
703
704 generate_crypto_objects:
705         ( cd $(SRCDIR); $(PERL) crypto/objects/objects.pl \
706                                 crypto/objects/objects.txt \
707                                 crypto/objects/obj_mac.num \
708                                 include/openssl/obj_mac.h )
709         ( cd $(SRCDIR); $(PERL) crypto/objects/obj_dat.pl \
710                                 include/openssl/obj_mac.h \
711                                 crypto/objects/obj_dat.h )
712         ( cd $(SRCDIR); $(PERL) crypto/objects/objxref.pl \
713                                 crypto/objects/obj_mac.num \
714                                 crypto/objects/obj_xref.txt \
715                                 > crypto/objects/obj_xref.h )
716
717 generate_crypto_conf:
718         ( cd $(SRCDIR); $(PERL) crypto/conf/keysets.pl \
719                                 > crypto/conf/conf_def.h )
720
721 generate_crypto_asn1:
722         ( cd $(SRCDIR); $(PERL) crypto/asn1/charmap.pl \
723                                 > crypto/asn1/charmap.h )
724
725 errors:
726         ( cd $(SRCDIR); $(PERL) util/ck_errf.pl -strict */*.c */*/*.c )
727         ( cd $(SRCDIR); $(PERL) util/mkerr.pl -recurse -write )
728         ( cd $(SRCDIR)/engines; \
729           for e in *.ec; do \
730               $(PERL) ../util/mkerr.pl -conf $$e \
731                       -nostatic -staticloader -write *.c; \
732           done )
733
734 ordinals:
735         ( b=`pwd`; cd $(SRCDIR); $(PERL) -I$$b util/mkdef.pl crypto update )
736         ( b=`pwd`; cd $(SRCDIR); $(PERL) -I$$b util/mkdef.pl ssl update )
737
738 test_ordinals:
739         ( cd test; \
740           SRCTOP=../$(SRCDIR) \
741           BLDTOP=../$(BLDDIR) \
742             $(PERL) ../$(SRCDIR)/test/run_tests.pl test_ordinals )
743
744 tags TAGS: FORCE
745         rm -f TAGS tags
746         -ctags -R .
747         -etags `find . -name '*.[ch]' -o -name '*.pm'`
748
749 # Release targets (note: only available on Unix) #####################
750
751 TAR_COMMAND=$(TAR) $(TARFLAGS) --owner 0 --group 0 -cvf -
752 PREPARE_CMD=:
753 tar:
754         TMPDIR=/var/tmp/openssl-copy.$$$$; \
755         DISTDIR=$(NAME); \
756         mkdir -p $$TMPDIR/$$DISTDIR; \
757         (cd $(SRCDIR); \
758          git ls-tree -r --name-only --full-tree HEAD \
759          | grep -v '^fuzz/corpora' \
760          | while read F; do \
761                mkdir -p $$TMPDIR/$$DISTDIR/`dirname $$F`; \
762                cp $$F $$TMPDIR/$$DISTDIR/$$F; \
763            done); \
764         (cd $$TMPDIR; \
765          $(PREPARE_CMD); \
766          find $$TMPDIR/$$DISTDIR -type d -print | xargs chmod 755; \
767          find $$TMPDIR/$$DISTDIR -type f -print | xargs chmod a+r; \
768          find $$TMPDIR/$$DISTDIR -type f -perm -0100 -print | xargs chmod a+x; \
769          $(TAR_COMMAND) $$DISTDIR) \
770         | (cd $(SRCDIR); gzip --best > $(TARFILE).gz); \
771         rm -rf $$TMPDIR
772         cd $(SRCDIR); ls -l $(TARFILE).gz
773
774 dist:
775         @$(MAKE) PREPARE_CMD='$(PERL) ./Configure dist' tar
776
777 # Helper targets #####################################################
778
779 link-utils: $(BLDDIR)/util/opensslwrap.sh
780
781 $(BLDDIR)/util/opensslwrap.sh: configdata.pm
782         @if [ "$(SRCDIR)" != "$(BLDDIR)" ]; then \
783             mkdir -p "$(BLDDIR)/util"; \
784             ln -sf "../$(SRCDIR)/util/opensslwrap.sh" "$(BLDDIR)/util"; \
785         fi
786
787 FORCE:
788
789 # Building targets ###################################################
790
791 libcrypto.pc libssl.pc openssl.pc: configdata.pm $(LIBS) {- join(" ",map { shlib_simple($_) } @{$unified_info{libraries}}) -}
792 libcrypto.pc:
793         @ ( echo 'prefix=$(INSTALLTOP)'; \
794             echo 'exec_prefix=$${prefix}'; \
795             echo 'libdir=$${exec_prefix}/$(LIBDIR)'; \
796             echo 'includedir=$${prefix}/include'; \
797             echo 'enginesdir=$${libdir}/engines-{- $sover -}'; \
798             echo ''; \
799             echo 'Name: OpenSSL-libcrypto'; \
800             echo 'Description: OpenSSL cryptography library'; \
801             echo 'Version: '$(VERSION); \
802             echo 'Libs: -L$${libdir} -lcrypto'; \
803             echo 'Libs.private: $(EX_LIBS)'; \
804             echo 'Cflags: -I$${includedir}' ) > libcrypto.pc
805
806 libssl.pc:
807         @ ( echo 'prefix=$(INSTALLTOP)'; \
808             echo 'exec_prefix=$${prefix}'; \
809             echo 'libdir=$${exec_prefix}/$(LIBDIR)'; \
810             echo 'includedir=$${prefix}/include'; \
811             echo ''; \
812             echo 'Name: OpenSSL-libssl'; \
813             echo 'Description: Secure Sockets Layer and cryptography libraries'; \
814             echo 'Version: '$(VERSION); \
815             echo 'Requires.private: libcrypto'; \
816             echo 'Libs: -L$${libdir} -lssl'; \
817             echo 'Libs.private: $(EX_LIBS)'; \
818             echo 'Cflags: -I$${includedir}' ) > libssl.pc
819
820 openssl.pc:
821         @ ( echo 'prefix=$(INSTALLTOP)'; \
822             echo 'exec_prefix=$${prefix}'; \
823             echo 'libdir=$${exec_prefix}/$(LIBDIR)'; \
824             echo 'includedir=$${prefix}/include'; \
825             echo ''; \
826             echo 'Name: OpenSSL'; \
827             echo 'Description: Secure Sockets Layer and cryptography libraries and tools'; \
828             echo 'Version: '$(VERSION); \
829             echo 'Requires: libssl libcrypto' ) > openssl.pc
830
831 configdata.pm: $(SRCDIR)/Configure $(SRCDIR)/config {- join(" ", @{$config{build_file_templates}}, @{$config{build_infos}}, @{$config{conf_files}}) -}
832         @echo "Detected changed: $?"
833         @echo "Reconfiguring..."
834         $(PERL) $(SRCDIR)/Configure reconf
835         @echo "**************************************************"
836         @echo "***                                            ***"
837         @echo "***   Please run the same make command again   ***"
838         @echo "***                                            ***"
839         @echo "**************************************************"
840         @false
841
842 {-
843   use File::Basename;
844   use File::Spec::Functions qw/:DEFAULT abs2rel rel2abs/;
845
846   # Helper function to figure out dependencies on libraries
847   # It takes a list of library names and outputs a list of dependencies
848   sub compute_lib_depends {
849       if ($disabled{shared}) {
850           return map { $_ =~ /\.a$/ ? $`.$libext : $_.$libext } @_;
851       }
852
853       # Depending on shared libraries:
854       # On Windows POSIX layers, we depend on {libname}.dll.a
855       # On Unix platforms, we depend on {shlibname}.so
856       return map { $_ =~ /\.a$/ ? $`.$libext : shlib_simple($_) } @_;
857   }
858
859   sub generatesrc {
860       my %args = @_;
861       my $generator = join(" ", @{$args{generator}});
862       my $generator_incs = join("", map { " -I".$_ } @{$args{generator_incs}});
863       my $incs = join("", map { " -I".$_ } @{$args{incs}});
864       my $deps = join(" ", @{$args{generator_deps}}, @{$args{deps}});
865
866       if ($args{src} !~ /\.[sS]$/) {
867           if ($args{generator}->[0] =~ m|^.*\.in$|) {
868               my $dofile = abs2rel(rel2abs(catfile($config{sourcedir},
869                                                    "util", "dofile.pl")),
870                                    rel2abs($config{builddir}));
871               return <<"EOF";
872 $args{src}: $args{generator}->[0] $deps
873         \$(PERL) "-I\$(BLDDIR)" -Mconfigdata "$dofile" \\
874             "-o$target{build_file}" $generator > \$@
875 EOF
876           } else {
877               return <<"EOF";
878 $args{src}: $args{generator}->[0] $deps
879         \$(PERL)$generator_incs $generator > \$@
880 EOF
881           }
882       } else {
883           if ($args{generator}->[0] =~ /\.pl$/) {
884               $generator = 'CC="$(CC)" $(PERL)'.$generator_incs.' '.$generator;
885           } elsif ($args{generator}->[0] =~ /\.m4$/) {
886               $generator = 'm4 -B 8192'.$generator_incs.' '.$generator.' >'
887           } elsif ($args{generator}->[0] =~ /\.S$/) {
888               $generator = undef;
889           } else {
890               die "Generator type for $args{src} unknown: $generator\n";
891           }
892
893           if (defined($generator)) {
894               # If the target is named foo.S in build.info, we want to
895               # end up generating foo.s in two steps.
896               if ($args{src} =~ /\.S$/) {
897                    (my $target = $args{src}) =~ s|\.S$|.s|;
898                    return <<"EOF";
899 $target: $args{generator}->[0] $deps
900         ( trap "rm -f \$@.*" INT 0; \\
901           $generator \$@.S; \\
902           \$(CC) $incs \$(CFLAGS) -E \$@.S | \\
903           \$(PERL) -ne '/^#(line)?\\s*[0-9]+/ or print' > \$@.i && \\
904           mv -f \$@.i \$@ )
905 EOF
906               }
907               # Otherwise....
908               return <<"EOF";
909 $args{src}: $args{generator}->[0] $deps
910         $generator \$@
911 EOF
912           }
913           return <<"EOF";
914 $args{src}: $args{generator}->[0] $deps
915         \$(CC) $incs \$(CFLAGS) -E \$< | \\
916         \$(PERL) -ne '/^#(line)?\\s*[0-9]+/ or print' > \$@
917 EOF
918       }
919   }
920
921   # Should one wonder about the end of the Perl snippet, it's because this
922   # second regexp eats up line endings as well, if the removed path is the
923   # last in the line.  We may therefore need to put back a line ending.
924   sub src2obj {
925       my %args = @_;
926       my $obj = $args{obj};
927       my @srcs = map { if ($unified_info{generate}->{$_}) {
928                            (my $x = $_) =~ s/\.S$/.s/; $x
929                        } else {
930                            $_
931                        }
932                      } ( @{$args{srcs}} );
933       my $srcs = join(" ",  @srcs);
934       my $deps = join(" ", @srcs, @{$args{deps}});
935       my $incs = join("", map { " -I".$_ } @{$args{incs}});
936       unless ($disabled{zlib}) {
937           if ($withargs{zlib_include}) {
938               $incs .= " -I".$withargs{zlib_include};
939           }
940       }
941       my $cc = '$(CC)';
942       my $cflags = '$(CFLAGS)';
943       if (grep /\.(cc|cpp)$/, @srcs) {
944           $cc = '$(CXX)';
945           $cflags = '$(CXXFLAGS)';
946           $cflags .= ' ' . { lib => '$(LIB_CXXFLAGS)',
947                              dso => '$(DSO_CXXFLAGS)',
948                              bin => '$(BIN_CXXFLAGS)' } -> {$args{intent}};
949       } else {
950           $cflags .= ' ' . { lib => '$(LIB_CFLAGS)',
951                              dso => '$(DSO_CFLAGS)',
952                              bin => '$(BIN_CFLAGS)' } -> {$args{intent}};
953       }
954       my $makedepprog = $config{makedepprog};
955       my $recipe = <<"EOF";
956 $obj$objext: $deps
957 EOF
958       if (!$disabled{makedepend} && $makedepprog !~ /\/makedepend/) {
959           $recipe .= <<"EOF";
960         $cc $incs $cflags -MMD -MF $obj$depext.tmp -MT \$\@ -c -o \$\@ $srcs
961         \@touch $obj$depext.tmp
962         \@if cmp $obj$depext.tmp $obj$depext > /dev/null 2> /dev/null; then \\
963                 rm -f $obj$depext.tmp; \\
964         else \\
965                 mv $obj$depext.tmp $obj$depext; \\
966         fi
967 EOF
968       } else {
969           $recipe .= <<"EOF";
970         $cc $incs $cflags -c -o \$\@ $srcs
971 EOF
972           if (!$disabled{makedepend} && $makedepprog =~ /\/makedepend/) {
973               $recipe .= <<"EOF";
974         -\$(MAKEDEPEND) -f- -o"|\$\@" -- $incs $cflags -- $srcs \\
975             >$obj$depext.tmp 2>/dev/null
976         -\$(PERL) -i -pe 's/^.*\\|//; s/ \\/(\\\\.|[^ ])*//; \$\$_ = undef if (/: *\$\$/ || /^(#.*| *)\$\$/); \$\$_.="\\n" unless !defined(\$\$_) or /\\R\$\$/g;' $obj$depext.tmp
977         \@if cmp $obj$depext.tmp $obj$depext > /dev/null 2> /dev/null; then \\
978                 rm -f $obj$depext.tmp; \\
979         else \\
980                 mv $obj$depext.tmp $obj$depext; \\
981         fi
982 EOF
983           }
984       }
985       return $recipe;
986   }
987   # On Unix, we build shlibs from static libs, so we're ignoring the
988   # object file array.  We *know* this routine is only called when we've
989   # configure 'shared'.
990   sub libobj2shlib {
991       my %args = @_;
992       my $lib = $args{lib};
993       my $shlib = $args{shlib};
994       my $libd = dirname($lib);
995       my $libn = basename($lib);
996       (my $libname = $libn) =~ s/^lib//;
997       my $linklibs = join("", map { my $d = dirname($_);
998                                     my $f = basename($_);
999                                     (my $l = $f) =~ s/^lib//;
1000                                     " -L$d -l$l" } @{$args{deps}});
1001       my $deps = join(" ",compute_lib_depends(@{$args{deps}}));
1002       my $shlib_target = $target{shared_target};
1003       my $ordinalsfile = defined($args{ordinals}) ? $args{ordinals}->[1] : "";
1004       my $target = shlib_simple($lib);
1005       return <<"EOF"
1006 # With a build on a Windows POSIX layer (Cygwin or Mingw), we know for a fact
1007 # that two files get produced, {shlibname}.dll and {libname}.dll.a.
1008 # With all other Unix platforms, we often build a shared library with the
1009 # SO version built into the file name and a symlink without the SO version
1010 # It's not necessary to have both as targets.  The choice falls on the
1011 # simplest, {libname}$shlibextimport for Windows POSIX layers and
1012 # {libname}$shlibextsimple for the Unix platforms.
1013 $target: $lib$libext $deps $ordinalsfile
1014         \$(MAKE) -f \$(SRCDIR)/Makefile.shared -e \\
1015                 PLATFORM=\$(PLATFORM) \\
1016                 PERL="\$(PERL)" SRCDIR='\$(SRCDIR)' DSTDIR="$libd" \\
1017                 INSTALLTOP='\$(INSTALLTOP)' LIBDIR='\$(LIBDIR)' \\
1018                 LIBDEPS='\$(PLIB_LDFLAGS) '"$linklibs"' \$(EX_LIBS)' \\
1019                 LIBNAME=$libname LIBVERSION=\$(SHLIB_MAJOR).\$(SHLIB_MINOR) \\
1020                 LIBCOMPATVERSIONS=';\$(SHLIB_VERSION_HISTORY)' \\
1021                 CC='\$(CC)' CFLAGS='\$(CFLAGS) \$(LIB_CFLAGS)' \\
1022                 LDFLAGS='\$(LDFLAGS)' \\
1023                 SHARED_LDFLAGS='\$(LIB_LDFLAGS)' SHLIB_EXT=$shlibext \\
1024                 RC='\$(RC)' SHARED_RCFLAGS='\$(RCFLAGS)' \\
1025                 link_shlib.$shlib_target
1026 EOF
1027           . (windowsdll() ? <<"EOF" : "");
1028         rm -f apps/$shlib$shlibext
1029         rm -f test/$shlib$shlibext
1030         cp -p $shlib$shlibext apps/
1031         cp -p $shlib$shlibext test/
1032 EOF
1033   }
1034   sub obj2dso {
1035       my %args = @_;
1036       my $lib = $args{lib};
1037       my $libd = dirname($lib);
1038       my $libn = basename($lib);
1039       (my $libname = $libn) =~ s/^lib//;
1040       my $shlibdeps = join("", map { my $d = dirname($_);
1041                                      my $f = basename($_);
1042                                      (my $l = $f) =~ s/^lib//;
1043                                      " -L$d -l$l" } @{$args{deps}});
1044       my $deps = join(" ",compute_lib_depends(@{$args{deps}}));
1045       my $shlib_target = $target{shared_target};
1046       my $objs = join(" ", map { $_.$objext } @{$args{objs}});
1047       my $target = dso($lib);
1048       return <<"EOF";
1049 $target: $objs $deps
1050         \$(MAKE) -f \$(SRCDIR)/Makefile.shared -e \\
1051                 PLATFORM=\$(PLATFORM) \\
1052                 PERL="\$(PERL)" SRCDIR='\$(SRCDIR)' DSTDIR="$libd" \\
1053                 LIBDEPS='\$(PLIB_LDFLAGS) '"$shlibdeps"' \$(EX_LIBS)' \\
1054                 LIBNAME=$libname LDFLAGS='\$(LDFLAGS)' \\
1055                 CC='\$(CC)' CFLAGS='\$(CFLAGS) \$(DSO_CFLAGS)' \\
1056                 SHARED_LDFLAGS='\$(DSO_LDFLAGS)' \\
1057                 SHLIB_EXT=$dsoext \\
1058                 LIBEXTRAS="$objs" \\
1059                 link_dso.$shlib_target
1060 EOF
1061   }
1062   sub obj2lib {
1063       my %args = @_;
1064       my $lib = $args{lib};
1065       my $objs = join(" ", map { $_.$objext } @{$args{objs}});
1066       return <<"EOF";
1067 $lib$libext: $objs
1068         \$(AR) \$\@ \$\?
1069         \$(RANLIB) \$\@ || echo Never mind.
1070 EOF
1071   }
1072   sub obj2bin {
1073       my %args = @_;
1074       my $bin = $args{bin};
1075       my $bind = dirname($bin);
1076       my $binn = basename($bin);
1077       my $objs = join(" ", map { $_.$objext } @{$args{objs}});
1078       my $deps = join(" ",compute_lib_depends(@{$args{deps}}));
1079       my $linklibs = join("", map { if ($_ =~ /\.a$/) {
1080                                         " $_";
1081                                     } else {
1082                                         my $d = dirname($_);
1083                                         my $f = basename($_);
1084                                         $d = "." if $d eq $f;
1085                                         (my $l = $f) =~ s/^lib//;
1086                                         " -L$d -l$l"
1087                                     }
1088                                   } @{$args{deps}});
1089       my $shlib_target = $disabled{shared} ? "" : $target{shared_target};
1090       my $cc = '$(CC)';
1091       my $cflags = '$(CFLAGS) $(BIN_CFLAGS)';
1092       if (grep /_cc$/, @{$args{objs}}) {
1093           $cc = '$(CXX)';
1094           $cflags = '$(CXXFLAGS) $(BIN_CXXFLAGS)';
1095       }
1096       return <<"EOF";
1097 $bin$exeext: $objs $deps
1098         \$(RM) $bin$exeext
1099         \$(MAKE) -f \$(SRCDIR)/Makefile.shared -e \\
1100                 PERL="\$(PERL)" SRCDIR=\$(SRCDIR) \\
1101                 APPNAME=$bin$exeext OBJECTS="$objs" \\
1102                 LIBDEPS='\$(PLIB_LDFLAGS) '"$linklibs"' \$(EX_LIBS)' \\
1103                 CC='$cc' CFLAGS='$cflags' \\
1104                 LDFLAGS='\$(LDFLAGS)' \\
1105                 link_app.$shlib_target
1106 EOF
1107   }
1108   sub in2script {
1109       my %args = @_;
1110       my $script = $args{script};
1111       my $sources = join(" ", @{$args{sources}});
1112       my $dofile = abs2rel(rel2abs(catfile($config{sourcedir},
1113                                            "util", "dofile.pl")),
1114                            rel2abs($config{builddir}));
1115       return <<"EOF";
1116 $script: $sources
1117         \$(PERL) "-I\$(BLDDIR)" -Mconfigdata "$dofile" \\
1118             "-o$target{build_file}" $sources > "$script"
1119         chmod a+x $script
1120 EOF
1121   }
1122   sub generatedir {
1123       my %args = @_;
1124       my $dir = $args{dir};
1125       my @deps = map { s|\.o$|$objext|; $_ } @{$args{deps}};
1126       my @actions = ();
1127       my %extinfo = ( dso => $dsoext,
1128                       lib => $libext,
1129                       bin => $exeext );
1130
1131       foreach my $type (("dso", "lib", "bin", "script")) {
1132           next unless defined($unified_info{dirinfo}->{$dir}->{products}->{$type});
1133           # For lib object files, we could update the library.  However, it
1134           # was decided that it's enough to build the directory local object
1135           # files, so we don't need to add any actions, and the dependencies
1136           # are already taken care of.
1137           if ($type ne "lib") {
1138               foreach my $prod (@{$unified_info{dirinfo}->{$dir}->{products}->{$type}}) {
1139                   if (dirname($prod) eq $dir) {
1140                       push @deps, $prod.$extinfo{$type};
1141                   } else {
1142                       push @actions, "\t@ : No support to produce $type ".join(", ", @{$unified_info{dirinfo}->{$dir}->{products}->{$type}});
1143                   }
1144               }
1145           }
1146       }
1147
1148       my $deps = join(" ", @deps);
1149       my $actions = join("\n", "", @actions);
1150       return <<"EOF";
1151 $args{dir} $args{dir}/: $deps$actions
1152 EOF
1153   }
1154   ""    # Important!  This becomes part of the template result.
1155 -}