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