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