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