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