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