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