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