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