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