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