3faeec8347cfe60a727501c1fa16023623fce7a3
[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 test: tests
255 {- dependmagic('tests'); -}: build_programs_nodep build_engines_nodep link-utils
256         @ : {- output_off() if $disabled{tests}; "" -}
257         ( cd test; \
258           SRCTOP=../$(SRCDIR) \
259           BLDTOP=../$(BLDDIR) \
260           PERL="$(PERL)" \
261           EXE_EXT={- $exeext -} \
262           OPENSSL_ENGINES=../$(BLDDIR)/engines \
263           OPENSSL_DEBUG_MEMORY=on \
264             $(PERL) ../$(SRCDIR)/test/run_tests.pl $(TESTS) )
265         @ : {- if ($disabled{tests}) { output_on(); } else { output_off(); } "" -}
266         @echo "Tests are not supported with your chosen Configure options"
267         @ : {- output_on() if !$disabled{tests}; "" -}
268
269 list-tests:
270         @ : {- output_off() if $disabled{tests}; "" -}
271         @SRCTOP="$(SRCDIR)" \
272          $(PERL) $(SRCDIR)/test/run_tests.pl list
273         @ : {- if ($disabled{tests}) { output_on(); } else { output_off(); } "" -}
274         @echo "Tests are not supported with your chosen Configure options"
275         @ : {- output_on() if !$disabled{tests}; "" -}
276
277 install: install_sw install_ssldirs install_docs
278
279 uninstall: uninstall_docs uninstall_sw
280
281 libclean:
282         @set -e; for s in $(SHLIB_INFO); do \
283                 s1=`echo "$$s" | cut -f1 -d";"`; \
284                 s2=`echo "$$s" | cut -f2 -d";"`; \
285                 echo $(RM) $$s1; \
286                 $(RM) $$s1; \
287                 if [ "$$s1" != "$$s2" ]; then \
288                         echo $(RM) $$s2; \
289                         $(RM) $$s2; \
290                 fi; \
291         done
292         $(RM) $(LIBS)
293         $(RM) *.map
294
295 clean: libclean
296         $(RM) $(PROGRAMS) $(TESTPROGS) $(ENGINES) $(SCRIPTS)
297         $(RM) $(GENERATED)
298         -$(RM) `find . -name '*{- $depext -}' -a \! -path "./.git/*"`
299         -$(RM) `find . -name '*{- $objext -}' -a \! -path "./.git/*"`
300         $(RM) core
301         $(RM) tags TAGS doc-nits
302         $(RM) test/.rnd
303         $(RM) openssl.pc libcrypto.pc libssl.pc
304         -$(RM) `find . -type l -a \! -path "./.git/*"`
305         $(RM) $(TARFILE)
306
307 distclean: clean
308         $(RM) configdata.pm
309         $(RM) Makefile
310
311 # We check if any depfile is newer than Makefile and decide to
312 # concatenate only if that is true.
313 depend:
314         @: {- output_off() if $disabled{makedepend}; "" -}
315         @if egrep "^# DO NOT DELETE THIS LINE" Makefile >/dev/null && [ -z "`find $(DEPS) -newer Makefile 2>/dev/null; exit 0`" ]; then :; else \
316           ( $(PERL) -pe 'exit 0 if /^# DO NOT DELETE THIS LINE.*/' < Makefile; \
317             echo '# DO NOT DELETE THIS LINE -- make depend depends on it.'; \
318             echo; \
319             for f in $(DEPS); do \
320               if [ -f $$f ]; then cat $$f; fi; \
321             done ) > Makefile.new; \
322           if cmp Makefile.new Makefile >/dev/null 2>&1; then \
323             rm -f Makefile.new; \
324           else \
325             mv -f Makefile.new Makefile; \
326           fi; \
327         fi
328         @: {- output_on() if $disabled{makedepend}; "" -}
329
330 # Install helper targets #############################################
331
332 install_sw: all install_dev install_engines install_runtime
333
334 uninstall_sw: uninstall_runtime uninstall_engines uninstall_dev
335
336 install_docs: install_man_docs install_html_docs
337
338 uninstall_docs: uninstall_man_docs uninstall_html_docs
339         $(RM) -r -v $(DESTDIR)$(DOCDIR)
340
341 install_ssldirs:
342         @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(OPENSSLDIR)/certs
343         @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(OPENSSLDIR)/private
344         @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(OPENSSLDIR)/misc
345         @set -e; for x in dummy $(MISC_SCRIPTS); do \
346                 if [ "$$x" = "dummy" ]; then continue; fi; \
347                 fn=`basename $$x`; \
348                 echo "install $$x -> $(DESTDIR)$(OPENSSLDIR)/misc/$$fn"; \
349                 cp $$x $(DESTDIR)$(OPENSSLDIR)/misc/$$fn.new; \
350                 chmod 755 $(DESTDIR)$(OPENSSLDIR)/misc/$$fn.new; \
351                 mv -f $(DESTDIR)$(OPENSSLDIR)/misc/$$fn.new \
352                       $(DESTDIR)$(OPENSSLDIR)/misc/$$fn; \
353         done
354         @echo "install $(SRCDIR)/apps/openssl.cnf -> $(DESTDIR)$(OPENSSLDIR)/openssl.cnf.dist"
355         @cp $(SRCDIR)/apps/openssl.cnf $(DESTDIR)$(OPENSSLDIR)/openssl.cnf.new
356         @chmod 644 $(DESTDIR)$(OPENSSLDIR)/openssl.cnf.new
357         @mv -f  $(DESTDIR)$(OPENSSLDIR)/openssl.cnf.new $(DESTDIR)$(OPENSSLDIR)/openssl.cnf.dist
358         @if [ ! -f "$(DESTDIR)$(OPENSSLDIR)/openssl.cnf" ]; then \
359                 echo "install $(SRCDIR)/apps/openssl.cnf -> $(DESTDIR)$(OPENSSLDIR)/openssl.cnf"; \
360                 cp $(SRCDIR)/apps/openssl.cnf $(DESTDIR)$(OPENSSLDIR)/openssl.cnf; \
361                 chmod 644 $(DESTDIR)$(OPENSSLDIR)/openssl.cnf; \
362         fi
363         @echo "install $(SRCDIR)/apps/ct_log_list.cnf -> $(DESTDIR)$(OPENSSLDIR)/ct_log_list.cnf.dist"
364         @cp $(SRCDIR)/apps/ct_log_list.cnf $(DESTDIR)$(OPENSSLDIR)/ct_log_list.cnf.new
365         @chmod 644 $(DESTDIR)$(OPENSSLDIR)/ct_log_list.cnf.new
366         @mv -f  $(DESTDIR)$(OPENSSLDIR)/ct_log_list.cnf.new $(DESTDIR)$(OPENSSLDIR)/ct_log_list.cnf.dist
367         @if [ ! -f "$(DESTDIR)$(OPENSSLDIR)/ct_log_list.cnf" ]; then \
368                 echo "install $(SRCDIR)/apps/ct_log_list.cnf -> $(DESTDIR)$(OPENSSLDIR)/ct_log_list.cnf"; \
369                 cp $(SRCDIR)/apps/ct_log_list.cnf $(DESTDIR)$(OPENSSLDIR)/ct_log_list.cnf; \
370                 chmod 644 $(DESTDIR)$(OPENSSLDIR)/ct_log_list.cnf; \
371         fi
372
373 install_dev:
374         @[ -n "$(INSTALLTOP)" ] || (echo INSTALLTOP should not be empty; exit 1)
375         @echo "*** Installing development files"
376         @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(INSTALLTOP)/include/openssl
377         @ : {- output_off() unless grep { $_ eq "OPENSSL_USE_APPLINK" } @{$target{defines}}; "" -}
378         @echo "install $(SRCDIR)/ms/applink.c -> $(DESTDIR)$(INSTALLTOP)/include/openssl/applink.c"
379         @cp $(SRCDIR)/ms/applink.c $(DESTDIR)$(INSTALLTOP)/include/openssl/applink.c
380         @chmod 644 $(DESTDIR)$(INSTALLTOP)/include/openssl/applink.c
381         @ : {- output_on() unless grep { $_ eq "OPENSSL_USE_APPLINK" } @{$target{defines}}; "" -}
382         @set -e; for i in $(SRCDIR)/include/openssl/*.h \
383                           $(BLDDIR)/include/openssl/*.h; do \
384                 fn=`basename $$i`; \
385                 echo "install $$i -> $(DESTDIR)$(INSTALLTOP)/include/openssl/$$fn"; \
386                 cp $$i $(DESTDIR)$(INSTALLTOP)/include/openssl/$$fn; \
387                 chmod 644 $(DESTDIR)$(INSTALLTOP)/include/openssl/$$fn; \
388         done
389         @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)
390         @set -e; for l in $(INSTALL_LIBS); do \
391                 fn=`basename $$l`; \
392                 echo "install $$l -> $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn"; \
393                 cp $$l $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn.new; \
394                 $(RANLIB) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn.new; \
395                 chmod 644 $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn.new; \
396                 mv -f $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn.new \
397                       $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn; \
398         done
399         @ : {- output_off() if $disabled{shared}; "" -}
400         @set -e; for s in $(INSTALL_SHLIB_INFO); do \
401                 s1=`echo "$$s" | cut -f1 -d";"`; \
402                 s2=`echo "$$s" | cut -f2 -d";"`; \
403                 fn1=`basename $$s1`; \
404                 fn2=`basename $$s2`; \
405                 : {- output_off() if windowsdll(); "" -}; \
406                 echo "install $$s1 -> $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn1"; \
407                 cp $$s1 $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn1.new; \
408                 chmod 755 $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn1.new; \
409                 mv -f $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn1.new \
410                       $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn1; \
411                 if [ "$$fn1" != "$$fn2" ]; then \
412                         echo "link $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn2 -> $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn1"; \
413                         ln -sf $$fn1 $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn2; \
414                 fi; \
415                 : {- output_on() if windowsdll(); "" -}{- output_off() unless windowsdll(); "" -}; \
416                 echo "install $$s2 -> $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn2"; \
417                 cp $$s2 $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn2.new; \
418                 chmod 755 $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn2.new; \
419                 mv -f $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn2.new \
420                       $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn2; \
421                 : {- output_on() unless windowsdll(); "" -}; \
422         done
423         @ : {- output_on() if $disabled{shared}; "" -}
424         @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig
425         @echo "install libcrypto.pc -> $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/libcrypto.pc"
426         @cp libcrypto.pc $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig
427         @chmod 644 $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/libcrypto.pc
428         @echo "install libssl.pc -> $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/libssl.pc"
429         @cp libssl.pc $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig
430         @chmod 644 $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/libssl.pc
431         @echo "install openssl.pc -> $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/openssl.pc"
432         @cp openssl.pc $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig
433         @chmod 644 $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/openssl.pc
434
435 uninstall_dev:
436         @echo "*** Uninstalling development files"
437         @ : {- output_off() unless grep { $_ eq "OPENSSL_USE_APPLINK" } @{$target{defines}}; "" -}
438         @echo "$(RM) $(DESTDIR)$(INSTALLTOP)/include/openssl/applink.c"
439         @$(RM) $(DESTDIR)$(INSTALLTOP)/include/openssl/applink.c
440         @ : {- output_on() unless grep { $_ eq "OPENSSL_USE_APPLINK" } @{$target{defines}}; "" -}
441         @set -e; for i in $(SRCDIR)/include/openssl/*.h \
442                           $(BLDDIR)/include/openssl/*.h; do \
443                 fn=`basename $$i`; \
444                 echo "$(RM) $(DESTDIR)$(INSTALLTOP)/include/openssl/$$fn"; \
445                 $(RM) $(DESTDIR)$(INSTALLTOP)/include/openssl/$$fn; \
446         done
447         -$(RMDIR) $(DESTDIR)$(INSTALLTOP)/include/openssl
448         -$(RMDIR) $(DESTDIR)$(INSTALLTOP)/include
449         @set -e; for l in $(INSTALL_LIBS); do \
450                 fn=`basename $$l`; \
451                 echo "$(RM) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn"; \
452                 $(RM) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn; \
453         done
454         @ : {- output_off() if $disabled{shared}; "" -}
455         @set -e; for s in $(INSTALL_SHLIB_INFO); do \
456                 s1=`echo "$$s" | cut -f1 -d";"`; \
457                 s2=`echo "$$s" | cut -f2 -d";"`; \
458                 fn1=`basename $$s1`; \
459                 fn2=`basename $$s2`; \
460                 : {- output_off() if windowsdll(); "" -}; \
461                 echo "$(RM) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn1"; \
462                 $(RM) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn1; \
463                 if [ "$$fn1" != "$$fn2" ]; then \
464                         echo "$(RM) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn2"; \
465                         $(RM) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn2; \
466                 fi; \
467                 : {- output_on() if windowsdll(); "" -}{- output_off() unless windowsdll(); "" -}; \
468                 echo "$(RM) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn2"; \
469                 $(RM) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn2; \
470                 : {- output_on() unless windowsdll(); "" -}; \
471         done
472         @ : {- output_on() if $disabled{shared}; "" -}
473         $(RM) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/libcrypto.pc
474         $(RM) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/libssl.pc
475         $(RM) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/openssl.pc
476         -$(RMDIR) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig
477         -$(RMDIR) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)
478
479 install_engines:
480         @[ -n "$(INSTALLTOP)" ] || (echo INSTALLTOP should not be empty; exit 1)
481         @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(ENGINESDIR)/
482         @echo "*** Installing engines"
483         @set -e; for e in dummy $(INSTALL_ENGINES); do \
484                 if [ "$$e" = "dummy" ]; then continue; fi; \
485                 fn=`basename $$e`; \
486                 echo "install $$e -> $(DESTDIR)$(ENGINESDIR)/$$fn"; \
487                 cp $$e $(DESTDIR)$(ENGINESDIR)/$$fn.new; \
488                 chmod 755 $(DESTDIR)$(ENGINESDIR)/$$fn.new; \
489                 mv -f $(DESTDIR)$(ENGINESDIR)/$$fn.new \
490                       $(DESTDIR)$(ENGINESDIR)/$$fn; \
491         done
492
493 uninstall_engines:
494         @echo "*** Uninstalling engines"
495         @set -e; for e in dummy $(INSTALL_ENGINES); do \
496                 if [ "$$e" = "dummy" ]; then continue; fi; \
497                 fn=`basename $$e`; \
498                 if [ "$$fn" = '{- dso("ossltest") -}' ]; then \
499                         continue; \
500                 fi; \
501                 echo "$(RM) $(DESTDIR)$(ENGINESDIR)/$$fn"; \
502                 $(RM) $(DESTDIR)$(ENGINESDIR)/$$fn; \
503         done
504         -$(RMDIR) $(DESTDIR)$(ENGINESDIR)
505
506 install_runtime:
507         @[ -n "$(INSTALLTOP)" ] || (echo INSTALLTOP should not be empty; exit 1)
508         @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(INSTALLTOP)/bin
509         @ : {- output_off() if windowsdll(); "" -}
510         @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)
511         @ : {- output_on() if windowsdll(); "" -}
512         @echo "*** Installing runtime files"
513         @set -e; for s in dummy $(INSTALL_SHLIBS); do \
514                 if [ "$$s" = "dummy" ]; then continue; fi; \
515                 fn=`basename $$s`; \
516                 : {- output_off() unless windowsdll(); "" -}; \
517                 echo "install $$s -> $(DESTDIR)$(INSTALLTOP)/bin/$$fn"; \
518                 cp $$s $(DESTDIR)$(INSTALLTOP)/bin/$$fn.new; \
519                 chmod 644 $(DESTDIR)$(INSTALLTOP)/bin/$$fn.new; \
520                 mv -f $(DESTDIR)$(INSTALLTOP)/bin/$$fn.new \
521                       $(DESTDIR)$(INSTALLTOP)/bin/$$fn; \
522                 : {- output_on() unless windowsdll(); "" -}{- output_off() if windowsdll(); "" -}; \
523                 echo "install $$s -> $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn"; \
524                 cp $$s $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn.new; \
525                 chmod 755 $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn.new; \
526                 mv -f $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn.new \
527                       $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn; \
528                 : {- output_on() if windowsdll(); "" -}; \
529         done
530         @set -e; for x in dummy $(INSTALL_PROGRAMS); do \
531                 if [ "$$x" = "dummy" ]; then continue; fi; \
532                 fn=`basename $$x`; \
533                 echo "install $$x -> $(DESTDIR)$(INSTALLTOP)/bin/$$fn"; \
534                 cp $$x $(DESTDIR)$(INSTALLTOP)/bin/$$fn.new; \
535                 chmod 755 $(DESTDIR)$(INSTALLTOP)/bin/$$fn.new; \
536                 mv -f $(DESTDIR)$(INSTALLTOP)/bin/$$fn.new \
537                       $(DESTDIR)$(INSTALLTOP)/bin/$$fn; \
538         done
539         @set -e; for x in dummy $(BIN_SCRIPTS); do \
540                 if [ "$$x" = "dummy" ]; then continue; fi; \
541                 fn=`basename $$x`; \
542                 echo "install $$x -> $(DESTDIR)$(INSTALLTOP)/bin/$$fn"; \
543                 cp $$x $(DESTDIR)$(INSTALLTOP)/bin/$$fn.new; \
544                 chmod 755 $(DESTDIR)$(INSTALLTOP)/bin/$$fn.new; \
545                 mv -f $(DESTDIR)$(INSTALLTOP)/bin/$$fn.new \
546                       $(DESTDIR)$(INSTALLTOP)/bin/$$fn; \
547         done
548
549 uninstall_runtime:
550         @echo "*** Uninstalling runtime files"
551         @set -e; for x in dummy $(INSTALL_PROGRAMS); \
552         do  \
553                 if [ "$$x" = "dummy" ]; then continue; fi; \
554                 fn=`basename $$x`; \
555                 echo "$(RM) $(DESTDIR)$(INSTALLTOP)/bin/$$fn"; \
556                 $(RM) $(DESTDIR)$(INSTALLTOP)/bin/$$fn; \
557         done;
558         @set -e; for x in dummy $(BIN_SCRIPTS); \
559         do  \
560                 if [ "$$x" = "dummy" ]; then continue; fi; \
561                 fn=`basename $$x`; \
562                 echo "$(RM) $(DESTDIR)$(INSTALLTOP)/bin/$$fn"; \
563                 $(RM) $(DESTDIR)$(INSTALLTOP)/bin/$$fn; \
564         done
565         @ : {- output_off() unless windowsdll(); "" -}
566         @set -e; for s in dummy $(INSTALL_SHLIBS); do \
567                 if [ "$$s" = "dummy" ]; then continue; fi; \
568                 fn=`basename $$s`; \
569                 echo "$(RM) $(DESTDIR)$(INSTALLTOP)/bin/$$fn"; \
570                 $(RM) $(DESTDIR)$(INSTALLTOP)/bin/$$fn; \
571         done
572         @ : {- output_on() unless windowsdll(); "" -}
573         -$(RMDIR) $(DESTDIR)$(INSTALLTOP)/bin
574
575
576 install_man_docs:
577         @[ -n "$(INSTALLTOP)" ] || (echo INSTALLTOP should not be empty; exit 1)
578         @echo "*** Installing manpages"
579         $(PERL) $(SRCDIR)/util/process_docs.pl \
580                 --destdir=$(DESTDIR)$(MANDIR) --type=man --suffix=$(MANSUFFIX)
581
582 uninstall_man_docs:
583         @echo "*** Uninstalling manpages"
584         $(PERL) $(SRCDIR)/util/process_docs.pl \
585                 --destdir=$(DESTDIR)$(MANDIR) --type=man --suffix=$(MANSUFFIX) \
586                 --remove
587
588 install_html_docs:
589         @[ -n "$(INSTALLTOP)" ] || (echo INSTALLTOP should not be empty; exit 1)
590         @echo "*** Installing HTML manpages"
591         $(PERL) $(SRCDIR)/util/process_docs.pl \
592                 --destdir=$(DESTDIR)$(HTMLDIR) --type=html
593
594 uninstall_html_docs:
595         @echo "*** Uninstalling manpages"
596         $(PERL) $(SRCDIR)/util/process_docs.pl \
597                 --destdir=$(DESTDIR)$(HTMLDIR) --type=html --remove
598
599
600 # Developer targets (note: these are only available on Unix) #########
601
602 update: generate errors ordinals
603
604 generate: generate_apps generate_crypto_bn generate_crypto_objects \
605           generate_crypto_conf generate_crypto_asn1
606
607 doc-nits:
608         (cd $(SRCDIR); $(PERL) util/find-doc-nits -n -p ) >doc-nits
609         if [ -s doc-nits ] ; then cat doc-nits; rm doc-nits ; exit 1; fi
610
611 # Test coverage is a good idea for the future
612 #coverage: $(PROGRAMS) $(TESTPROGRAMS)
613 #       ...
614
615 lint:
616         lint -DLINT $(INCLUDES) $(SRCS)
617
618 generate_apps:
619         ( cd $(SRCDIR); $(PERL) VMS/VMSify-conf.pl \
620                                 < apps/openssl.cnf > apps/openssl-vms.cnf )
621
622 generate_crypto_bn:
623         ( cd $(SRCDIR); $(PERL) crypto/bn/bn_prime.pl > crypto/bn/bn_prime.h )
624
625 generate_crypto_objects:
626         ( cd $(SRCDIR); $(PERL) crypto/objects/objects.pl \
627                                 crypto/objects/objects.txt \
628                                 crypto/objects/obj_mac.num \
629                                 include/openssl/obj_mac.h )
630         ( cd $(SRCDIR); $(PERL) crypto/objects/obj_dat.pl \
631                                 include/openssl/obj_mac.h \
632                                 crypto/objects/obj_dat.h )
633         ( cd $(SRCDIR); $(PERL) crypto/objects/objxref.pl \
634                                 crypto/objects/obj_mac.num \
635                                 crypto/objects/obj_xref.txt \
636                                 > crypto/objects/obj_xref.h )
637
638 generate_crypto_conf:
639         ( cd $(SRCDIR); $(PERL) crypto/conf/keysets.pl \
640                                 > crypto/conf/conf_def.h )
641
642 generate_crypto_asn1:
643         ( cd $(SRCDIR); $(PERL) crypto/asn1/charmap.pl \
644                                 > crypto/asn1/charmap.h )
645
646 # Set to -force to force a rebuild
647 ERROR_REBUILD=
648 errors:
649         ( cd $(SRCDIR); $(PERL) util/ck_errf.pl -strict */*.c */*/*.c )
650         ( cd $(SRCDIR); $(PERL) util/mkerr.pl $(ERROR_REBUILD) -internal )
651         ( cd $(SRCDIR)/engines; \
652           for E in *.ec ; do \
653               $(PERL) ../util/mkerr.pl $(ERROR_REBUILD) -static \
654                 -conf $$E `basename $$E .ec`.c ; \
655           done )
656
657 ordinals:
658         ( b=`pwd`; cd $(SRCDIR); $(PERL) -I$$b util/mkdef.pl crypto update )
659         ( b=`pwd`; cd $(SRCDIR); $(PERL) -I$$b util/mkdef.pl ssl update )
660
661 test_ordinals:
662         ( cd test; \
663           SRCTOP=../$(SRCDIR) \
664           BLDTOP=../$(BLDDIR) \
665             $(PERL) ../$(SRCDIR)/test/run_tests.pl test_ordinals )
666
667 tags TAGS: FORCE
668         rm -f TAGS tags
669         -ctags -R .
670         -etags `find . -name '*.[ch]' -o -name '*.pm'`
671
672 # Release targets (note: only available on Unix) #####################
673
674 TAR_COMMAND=$(TAR) $(TARFLAGS) --owner 0 --group 0 -cvf -
675 PREPARE_CMD=:
676 tar:
677         TMPDIR=/var/tmp/openssl-copy.$$$$; \
678         DISTDIR=$(NAME); \
679         mkdir -p $$TMPDIR/$$DISTDIR; \
680         (cd $(SRCDIR); \
681          git ls-tree -r --name-only --full-tree HEAD \
682          | grep -v '^fuzz/corpora' \
683          | while read F; do \
684                mkdir -p $$TMPDIR/$$DISTDIR/`dirname $$F`; \
685                cp $$F $$TMPDIR/$$DISTDIR/$$F; \
686            done); \
687         (cd $$TMPDIR; \
688          $(PREPARE_CMD); \
689          find $$TMPDIR/$$DISTDIR -type d -print | xargs chmod 755; \
690          find $$TMPDIR/$$DISTDIR -type f -print | xargs chmod a+r; \
691          find $$TMPDIR/$$DISTDIR -type f -perm -0100 -print | xargs chmod a+x; \
692          $(TAR_COMMAND) $$DISTDIR) \
693         | (cd $(SRCDIR); gzip --best > $(TARFILE).gz); \
694         rm -rf $$TMPDIR
695         cd $(SRCDIR); ls -l $(TARFILE).gz
696
697 dist:
698         @$(MAKE) PREPARE_CMD='$(PERL) ./Configure dist' tar
699
700 # Helper targets #####################################################
701
702 link-utils: $(BLDDIR)/util/opensslwrap.sh
703
704 $(BLDDIR)/util/opensslwrap.sh: configdata.pm
705         @if [ "$(SRCDIR)" != "$(BLDDIR)" ]; then \
706             mkdir -p "$(BLDDIR)/util"; \
707             ln -sf "../$(SRCDIR)/util/opensslwrap.sh" "$(BLDDIR)/util"; \
708         fi
709
710 FORCE:
711
712 # Building targets ###################################################
713
714 libcrypto.pc libssl.pc openssl.pc: configdata.pm $(LIBS) {- join(" ",map { shlib_simple($_) } @{$unified_info{libraries}}) -}
715 libcrypto.pc:
716         @ ( echo 'prefix=$(INSTALLTOP)'; \
717             echo 'exec_prefix=$${prefix}'; \
718             echo 'libdir=$${exec_prefix}/$(LIBDIR)'; \
719             echo 'includedir=$${prefix}/include'; \
720             echo 'enginesdir=$${libdir}/engines-{- $sover -}'; \
721             echo ''; \
722             echo 'Name: OpenSSL-libcrypto'; \
723             echo 'Description: OpenSSL cryptography library'; \
724             echo 'Version: '$(VERSION); \
725             echo 'Libs: -L$${libdir} -lcrypto'; \
726             echo 'Libs.private: $(EX_LIBS)'; \
727             echo 'Cflags: -I$${includedir}' ) > libcrypto.pc
728
729 libssl.pc:
730         @ ( echo 'prefix=$(INSTALLTOP)'; \
731             echo 'exec_prefix=$${prefix}'; \
732             echo 'libdir=$${exec_prefix}/$(LIBDIR)'; \
733             echo 'includedir=$${prefix}/include'; \
734             echo ''; \
735             echo 'Name: OpenSSL-libssl'; \
736             echo 'Description: Secure Sockets Layer and cryptography libraries'; \
737             echo 'Version: '$(VERSION); \
738             echo 'Requires.private: libcrypto'; \
739             echo 'Libs: -L$${libdir} -lssl'; \
740             echo 'Libs.private: $(EX_LIBS)'; \
741             echo 'Cflags: -I$${includedir}' ) > libssl.pc
742
743 openssl.pc:
744         @ ( echo 'prefix=$(INSTALLTOP)'; \
745             echo 'exec_prefix=$${prefix}'; \
746             echo 'libdir=$${exec_prefix}/$(LIBDIR)'; \
747             echo 'includedir=$${prefix}/include'; \
748             echo ''; \
749             echo 'Name: OpenSSL'; \
750             echo 'Description: Secure Sockets Layer and cryptography libraries and tools'; \
751             echo 'Version: '$(VERSION); \
752             echo 'Requires: libssl libcrypto' ) > openssl.pc
753
754 configdata.pm: $(SRCDIR)/Configure $(SRCDIR)/config {- join(" ", @{$config{build_file_templates}}, @{$config{build_infos}}, @{$config{conf_files}}) -}
755         @echo "Detected changed: $?"
756         @echo "Reconfiguring..."
757         $(PERL) $(SRCDIR)/Configure reconf
758         @echo "**************************************************"
759         @echo "***                                            ***"
760         @echo "***   Please run the same make command again   ***"
761         @echo "***                                            ***"
762         @echo "**************************************************"
763         @false
764
765 {-
766   use File::Basename;
767   use File::Spec::Functions qw/:DEFAULT abs2rel rel2abs/;
768
769   # Helper function to figure out dependencies on libraries
770   # It takes a list of library names and outputs a list of dependencies
771   sub compute_lib_depends {
772       if ($disabled{shared}) {
773           return map { lib($_) } @_;
774       }
775
776       # Depending on shared libraries:
777       # On Windows POSIX layers, we depend on {libname}.dll.a
778       # On Unix platforms, we depend on {shlibname}.so
779       return map { $_ =~ /\.a$/ ? $`.$libext : shlib_simple($_) } @_;
780   }
781
782   sub generatesrc {
783       my %args = @_;
784       my $generator = join(" ", @{$args{generator}});
785       my $generator_incs = join("", map { " -I".$_ } @{$args{generator_incs}});
786       my $incs = join("", map { " -I".$_ } @{$args{incs}});
787       my $deps = join(" ", @{$args{generator_deps}}, @{$args{deps}});
788
789       if ($args{src} !~ /\.[sS]$/) {
790           if ($args{generator}->[0] =~ m|^.*\.in$|) {
791               my $dofile = abs2rel(rel2abs(catfile($config{sourcedir},
792                                                    "util", "dofile.pl")),
793                                    rel2abs($config{builddir}));
794               return <<"EOF";
795 $args{src}: $args{generator}->[0] $deps
796         \$(PERL) "-I\$(BLDDIR)" -Mconfigdata "$dofile" \\
797             "-o$target{build_file}" $generator > \$@
798 EOF
799           } else {
800               return <<"EOF";
801 $args{src}: $args{generator}->[0] $deps
802         \$(PERL)$generator_incs $generator > \$@
803 EOF
804           }
805       } else {
806           if ($args{generator}->[0] =~ /\.pl$/) {
807               $generator = 'CC="$(CC)" $(PERL)'.$generator_incs.' '.$generator;
808           } elsif ($args{generator}->[0] =~ /\.m4$/) {
809               $generator = 'm4 -B 8192'.$generator_incs.' '.$generator.' >'
810           } elsif ($args{generator}->[0] =~ /\.S$/) {
811               $generator = undef;
812           } else {
813               die "Generator type for $args{src} unknown: $generator\n";
814           }
815
816           if (defined($generator)) {
817               # If the target is named foo.S in build.info, we want to
818               # end up generating foo.s in two steps.
819               if ($args{src} =~ /\.S$/) {
820                    (my $target = $args{src}) =~ s|\.S$|.s|;
821                    return <<"EOF";
822 $target: $args{generator}->[0] $deps
823         ( trap "rm -f \$@.*" INT 0; \\
824           $generator \$@.S; \\
825           \$(CC) $incs \$(CFLAGS) -E \$@.S | \\
826           \$(PERL) -ne '/^#(line)?\\s*[0-9]+/ or print' > \$@.i && \\
827           mv -f \$@.i \$@ )
828 EOF
829               }
830               # Otherwise....
831               return <<"EOF";
832 $args{src}: $args{generator}->[0] $deps
833         $generator \$@
834 EOF
835           }
836           return <<"EOF";
837 $args{src}: $args{generator}->[0] $deps
838         \$(CC) $incs \$(CFLAGS) -E \$< | \\
839         \$(PERL) -ne '/^#(line)?\\s*[0-9]+/ or print' > \$@
840 EOF
841       }
842   }
843
844   # Should one wonder about the end of the Perl snippet, it's because this
845   # second regexp eats up line endings as well, if the removed path is the
846   # last in the line.  We may therefore need to put back a line ending.
847   sub src2obj {
848       my %args = @_;
849       my $obj = $args{obj};
850       my @srcs = map { if ($unified_info{generate}->{$_}) {
851                            (my $x = $_) =~ s/\.S$/.s/; $x
852                        } else {
853                            $_
854                        }
855                      } ( @{$args{srcs}} );
856       my $srcs = join(" ",  @srcs);
857       my $deps = join(" ", @srcs, @{$args{deps}});
858       my $incs = join("", map { " -I".$_ } @{$args{incs}});
859       unless ($disabled{zlib}) {
860           if ($withargs{zlib_include}) {
861               $incs .= " -I".$withargs{zlib_include};
862           }
863       }
864       my $cc = '$(CC)';
865       my $cflags = '$(CFLAGS)';
866       if (grep /\.(cc|cpp)$/, @srcs) {
867           $cc = '$(CXX)';
868           $cflags = '$(CXXFLAGS)';
869           $cflags .= ' ' . { lib => '$(LIB_CXXFLAGS)',
870                              dso => '$(DSO_CXXFLAGS)',
871                              bin => '$(BIN_CXXFLAGS)' } -> {$args{intent}};
872       } else {
873           $cflags .= ' ' . { lib => '$(LIB_CFLAGS)',
874                              dso => '$(DSO_CFLAGS)',
875                              bin => '$(BIN_CFLAGS)' } -> {$args{intent}};
876       }
877       my $makedepprog = $config{makedepprog};
878       my $recipe = <<"EOF";
879 $obj$objext: $deps
880 EOF
881       if (!$disabled{makedepend} && $makedepprog !~ /\/makedepend/) {
882           $recipe .= <<"EOF";
883         $cc $incs $cflags -MMD -MF $obj$depext.tmp -MT \$\@ -c -o \$\@ $srcs
884         \@touch $obj$depext.tmp
885         \@if cmp $obj$depext.tmp $obj$depext > /dev/null 2> /dev/null; then \\
886                 rm -f $obj$depext.tmp; \\
887         else \\
888                 mv $obj$depext.tmp $obj$depext; \\
889         fi
890 EOF
891       } else {
892           $recipe .= <<"EOF";
893         $cc $incs $cflags -c -o \$\@ $srcs
894 EOF
895           if (!$disabled{makedepend} && $makedepprog =~ /\/makedepend/) {
896               $recipe .= <<"EOF";
897         -\$(MAKEDEPEND) -f- -o"|\$\@" -- $incs $cflags -- $srcs \\
898             >$obj$depext.tmp 2>/dev/null
899         -\$(PERL) -i -pe 's/^.*\\|//; s/ \\/(\\\\.|[^ ])*//; \$\$_ = undef if (/: *\$\$/ || /^(#.*| *)\$\$/); \$\$_.="\\n" unless !defined(\$\$_) or /\\R\$\$/g;' $obj$depext.tmp
900         \@if cmp $obj$depext.tmp $obj$depext > /dev/null 2> /dev/null; then \\
901                 rm -f $obj$depext.tmp; \\
902         else \\
903                 mv $obj$depext.tmp $obj$depext; \\
904         fi
905 EOF
906           }
907       }
908       return $recipe;
909   }
910   # On Unix, we build shlibs from static libs, so we're ignoring the
911   # object file array.  We *know* this routine is only called when we've
912   # configure 'shared'.
913   sub libobj2shlib {
914       my %args = @_;
915       my $lib = $args{lib};
916       my $shlib = $args{shlib};
917       my $libd = dirname($lib);
918       my $libn = basename($lib);
919       (my $libname = $libn) =~ s/^lib//;
920       my $linklibs = join("", map { my $d = dirname($_);
921                                     my $f = basename($_);
922                                     (my $l = $f) =~ s/^lib//;
923                                     " -L$d -l$l" } @{$args{deps}});
924       my $deps = join(" ",compute_lib_depends(@{$args{deps}}));
925       my $shlib_target = $target{shared_target};
926       my $ordinalsfile = defined($args{ordinals}) ? $args{ordinals}->[1] : "";
927       my $target = shlib_simple($lib);
928       return <<"EOF"
929 # With a build on a Windows POSIX layer (Cygwin or Mingw), we know for a fact
930 # that two files get produced, {shlibname}.dll and {libname}.dll.a.
931 # With all other Unix platforms, we often build a shared library with the
932 # SO version built into the file name and a symlink without the SO version
933 # It's not necessary to have both as targets.  The choice falls on the
934 # simplest, {libname}$shlibextimport for Windows POSIX layers and
935 # {libname}$shlibextsimple for the Unix platforms.
936 $target: $lib$libext $deps $ordinalsfile
937         \$(MAKE) -f \$(SRCDIR)/Makefile.shared -e \\
938                 PLATFORM=\$(PLATFORM) \\
939                 PERL="\$(PERL)" SRCDIR='\$(SRCDIR)' DSTDIR="$libd" \\
940                 INSTALLTOP='\$(INSTALLTOP)' LIBDIR='\$(LIBDIR)' \\
941                 LIBDEPS='\$(PLIB_LDFLAGS) '"$linklibs"' \$(EX_LIBS)' \\
942                 LIBNAME=$libname LIBVERSION=\$(SHLIB_MAJOR).\$(SHLIB_MINOR) \\
943                 LIBCOMPATVERSIONS=';\$(SHLIB_VERSION_HISTORY)' \\
944                 CC='\$(CC)' CFLAGS='\$(CFLAGS) \$(LIB_CFLAGS)' \\
945                 LDFLAGS='\$(LDFLAGS)' \\
946                 SHARED_LDFLAGS='\$(LIB_LDFLAGS)' SHLIB_EXT=$shlibext \\
947                 RC='\$(RC)' SHARED_RCFLAGS='\$(RCFLAGS)' \\
948                 link_shlib.$shlib_target
949 EOF
950           . (windowsdll() ? <<"EOF" : "");
951         rm -f apps/$shlib$shlibext
952         rm -f test/$shlib$shlibext
953         cp -p $shlib$shlibext apps/
954         cp -p $shlib$shlibext test/
955 EOF
956   }
957   sub obj2dso {
958       my %args = @_;
959       my $lib = $args{lib};
960       my $libd = dirname($lib);
961       my $libn = basename($lib);
962       (my $libname = $libn) =~ s/^lib//;
963       my $shlibdeps = join("", map { my $d = dirname($_);
964                                      my $f = basename($_);
965                                      (my $l = $f) =~ s/^lib//;
966                                      " -L$d -l$l" } @{$args{deps}});
967       my $deps = join(" ",compute_lib_depends(@{$args{deps}}));
968       my $shlib_target = $target{shared_target};
969       my $objs = join(" ", map { $_.$objext } @{$args{objs}});
970       my $target = dso($lib);
971       return <<"EOF";
972 $target: $objs $deps
973         \$(MAKE) -f \$(SRCDIR)/Makefile.shared -e \\
974                 PLATFORM=\$(PLATFORM) \\
975                 PERL="\$(PERL)" SRCDIR='\$(SRCDIR)' DSTDIR="$libd" \\
976                 LIBDEPS='\$(PLIB_LDFLAGS) '"$shlibdeps"' \$(EX_LIBS)' \\
977                 LIBNAME=$libname LDFLAGS='\$(LDFLAGS)' \\
978                 CC='\$(CC)' CFLAGS='\$(CFLAGS) \$(DSO_CFLAGS)' \\
979                 SHARED_LDFLAGS='\$(DSO_LDFLAGS)' \\
980                 SHLIB_EXT=$dsoext \\
981                 LIBEXTRAS="$objs" \\
982                 link_dso.$shlib_target
983 EOF
984   }
985   sub obj2lib {
986       my %args = @_;
987       (my $lib = $args{lib}) =~ s/\.a$//;
988       my $objs = join(" ", map { $_.$objext } @{$args{objs}});
989       return <<"EOF";
990 $lib$libext: $objs
991         \$(AR) \$\@ \$\?
992         \$(RANLIB) \$\@ || echo Never mind.
993 EOF
994   }
995   sub obj2bin {
996       my %args = @_;
997       my $bin = $args{bin};
998       my $bind = dirname($bin);
999       my $binn = basename($bin);
1000       my $objs = join(" ", map { $_.$objext } @{$args{objs}});
1001       my $deps = join(" ",compute_lib_depends(@{$args{deps}}));
1002       my $linklibs = join("", map { if ($_ =~ /\.a$/) {
1003                                         " $_";
1004                                     } else {
1005                                         my $d = dirname($_);
1006                                         my $f = basename($_);
1007                                         $d = "." if $d eq $f;
1008                                         (my $l = $f) =~ s/^lib//;
1009                                         " -L$d -l$l"
1010                                     }
1011                                   } @{$args{deps}});
1012       my $shlib_target = $disabled{shared} ? "" : $target{shared_target};
1013       my $cc = '$(CC)';
1014       my $cflags = '$(CFLAGS) $(BIN_CFLAGS)';
1015       if (grep /_cc$/, @{$args{objs}}) {
1016           $cc = '$(CXX)';
1017           $cflags = '$(CXXFLAGS) $(BIN_CXXFLAGS)';
1018       }
1019       return <<"EOF";
1020 $bin$exeext: $objs $deps
1021         \$(RM) $bin$exeext
1022         \$(MAKE) -f \$(SRCDIR)/Makefile.shared -e \\
1023                 PERL="\$(PERL)" SRCDIR=\$(SRCDIR) \\
1024                 APPNAME=$bin$exeext OBJECTS="$objs" \\
1025                 LIBDEPS='\$(PLIB_LDFLAGS) '"$linklibs"' \$(EX_LIBS)' \\
1026                 CC='$cc' CFLAGS='$cflags' \\
1027                 LDFLAGS='\$(LDFLAGS)' \\
1028                 link_app.$shlib_target
1029 EOF
1030   }
1031   sub in2script {
1032       my %args = @_;
1033       my $script = $args{script};
1034       my $sources = join(" ", @{$args{sources}});
1035       my $dofile = abs2rel(rel2abs(catfile($config{sourcedir},
1036                                            "util", "dofile.pl")),
1037                            rel2abs($config{builddir}));
1038       return <<"EOF";
1039 $script: $sources
1040         \$(PERL) "-I\$(BLDDIR)" -Mconfigdata "$dofile" \\
1041             "-o$target{build_file}" $sources > "$script"
1042         chmod a+x $script
1043 EOF
1044   }
1045   sub generatedir {
1046       my %args = @_;
1047       my $dir = $args{dir};
1048       my @deps = map { s|\.o$|$objext|; $_ } @{$args{deps}};
1049       my @actions = ();
1050       my %extinfo = ( dso => $dsoext,
1051                       lib => $libext,
1052                       bin => $exeext );
1053
1054       foreach my $type (("dso", "lib", "bin", "script")) {
1055           next unless defined($unified_info{dirinfo}->{$dir}->{products}->{$type});
1056           # For lib object files, we could update the library.  However, it
1057           # was decided that it's enough to build the directory local object
1058           # files, so we don't need to add any actions, and the dependencies
1059           # are already taken care of.
1060           if ($type ne "lib") {
1061               foreach my $prod (@{$unified_info{dirinfo}->{$dir}->{products}->{$type}}) {
1062                   if (dirname($prod) eq $dir) {
1063                       push @deps, $prod.$extinfo{$type};
1064                   } else {
1065                       push @actions, "\t@ : No support to produce $type ".join(", ", @{$unified_info{dirinfo}->{$dir}->{products}->{$type}});
1066                   }
1067               }
1068           }
1069       }
1070
1071       my $deps = join(" ", @deps);
1072       my $actions = join("\n", "", @actions);
1073       return <<"EOF";
1074 $args{dir} $args{dir}/: $deps$actions
1075 EOF
1076   }
1077   ""    # Important!  This becomes part of the template result.
1078 -}