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