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