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