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