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