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