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