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