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