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