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