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