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