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