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