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