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