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