Don't make a difference between building test programs and other programs
[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 # The main targets ###################################################
226
227 {- dependmagic('all'); -}: build_libs_nodep build_engines_nodep build_programs_nodep link-utils
228 {- dependmagic('build_libs'); -}: build_libs_nodep
229 {- dependmagic('build_engines'); -}: build_engines_nodep
230 {- dependmagic('build_programs'); -}: build_programs_nodep
231
232 build_generated: $(GENERATED_MANDATORY)
233 build_libs_nodep: libcrypto.pc libssl.pc openssl.pc
234 build_engines_nodep: $(ENGINES)
235 build_programs_nodep: $(PROGRAMS) $(SCRIPTS)
236
237 # Kept around for backward compatibility
238 build_apps build_tests: build_programs
239
240 test: tests
241 {- dependmagic('tests'); -}: build_programs_nodep build_engines_nodep link-utils
242         @ : {- output_off() if $disabled{tests}; "" -}
243         ( cd test; \
244           SRCTOP=../$(SRCDIR) \
245           BLDTOP=../$(BLDDIR) \
246           PERL="$(PERL)" \
247           EXE_EXT={- $exeext -} \
248           OPENSSL_ENGINES=../$(BLDDIR)/engines \
249             $(PERL) ../$(SRCDIR)/test/run_tests.pl $(TESTS) )
250         @ : {- if ($disabled{tests}) { output_on(); } else { output_off(); } "" -}
251         @echo "Tests are not supported with your chosen Configure options"
252         @ : {- output_on() if !$disabled{tests}; "" -}
253
254 list-tests:
255         @ : {- output_off() if $disabled{tests}; "" -}
256         @SRCTOP="$(SRCDIR)" \
257          $(PERL) $(SRCDIR)/test/run_tests.pl list
258         @ : {- if ($disabled{tests}) { output_on(); } else { output_off(); } "" -}
259         @echo "Tests are not supported with your chosen Configure options"
260         @ : {- output_on() if !$disabled{tests}; "" -}
261
262 install: install_sw install_ssldirs install_docs
263
264 uninstall: uninstall_docs uninstall_sw
265
266 libclean:
267         @set -e; for s in $(SHLIB_INFO); do \
268                 s1=`echo "$$s" | cut -f1 -d";"`; \
269                 s2=`echo "$$s" | cut -f2 -d";"`; \
270                 echo $(RM) $$s1; \
271                 $(RM) $$s1; \
272                 if [ "$$s1" != "$$s2" ]; then \
273                         echo $(RM) $$s2; \
274                         $(RM) $$s2; \
275                 fi; \
276         done
277         $(RM) $(LIBS)
278         $(RM) *.map
279
280 clean: libclean
281         $(RM) $(PROGRAMS) $(TESTPROGS) $(ENGINES) $(SCRIPTS)
282         $(RM) $(GENERATED)
283         -$(RM) `find . -name '*{- $depext -}' -a \! -path "./.git/*"`
284         -$(RM) `find . -name '*{- $objext -}' -a \! -path "./.git/*"`
285         $(RM) core
286         $(RM) tags TAGS
287         $(RM) openssl.pc libcrypto.pc libssl.pc
288         -$(RM) `find . -type l -a \! -path "./.git/*"`
289         $(RM) $(TARFILE)
290
291 distclean: clean
292         $(RM) configdata.pm
293         $(RM) Makefile
294
295 # This exists solely for those who still type 'make depend'
296 #
297 # We check if any depfile is newer than Makefile and decide to
298 # concatenate only if that is true.
299 depend:
300         @: {- output_off() if $disabled{makedepend}; "" -}
301         @if [ -n "`find $(DEPS) -newer Makefile 2>/dev/null; exit 0`" ]; then \
302           ( sed -e '/^# DO NOT DELETE THIS LINE.*/,$$d' < Makefile; \
303             echo '# DO NOT DELETE THIS LINE -- make depend depends on it.'; \
304             echo; \
305             for f in $(DEPS); do \
306               if [ -f $$f ]; then cat $$f; fi; \
307             done ) > Makefile.new; \
308           if cmp Makefile.new Makefile >/dev/null 2>&1; then \
309             rm -f Makefile.new; \
310           else \
311             mv -f Makefile.new Makefile; \
312           fi; \
313         fi
314         @: {- output_on() if $disabled{makedepend}; "" -}
315
316 # Install helper targets #############################################
317
318 install_sw: all install_dev install_engines install_runtime
319
320 uninstall_sw: uninstall_runtime uninstall_engines uninstall_dev
321
322 install_docs: install_man_docs install_html_docs
323
324 uninstall_docs: uninstall_man_docs uninstall_html_docs
325         $(RM) -r -v $(DESTDIR)$(DOCDIR)
326
327 install_ssldirs:
328         @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(OPENSSLDIR)/certs
329         @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(OPENSSLDIR)/private
330         @set -e; for x in dummy $(MISC_SCRIPTS); do \
331                 if [ "$$x" = "dummy" ]; then continue; fi; \
332                 fn=`basename $$x`; \
333                 echo "install $$x -> $(DESTDIR)$(OPENSSLDIR)/misc/$$fn"; \
334                 cp $$x $(DESTDIR)$(OPENSSLDIR)/misc/$$fn.new; \
335                 chmod 755 $(DESTDIR)$(OPENSSLDIR)/misc/$$fn.new; \
336                 mv -f $(DESTDIR)$(OPENSSLDIR)/misc/$$fn.new \
337                       $(DESTDIR)$(OPENSSLDIR)/misc/$$fn; \
338         done
339         @echo "install $(SRCDIR)/apps/openssl.cnf -> $(DESTDIR)$(OPENSSLDIR)/openssl.cnf"
340         @cp $(SRCDIR)/apps/openssl.cnf $(DESTDIR)$(OPENSSLDIR)/openssl.cnf.new
341         @chmod 644 $(DESTDIR)$(OPENSSLDIR)/openssl.cnf.new
342         @mv -f  $(DESTDIR)$(OPENSSLDIR)/openssl.cnf.new $(DESTDIR)$(OPENSSLDIR)/openssl.cnf
343
344 install_dev:
345         @[ -n "$(INSTALLTOP)" ] || (echo INSTALLTOP should not be empty; exit 1)
346         @echo "*** Installing development files"
347         @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(INSTALLTOP)/include/openssl
348         @ : {- output_off() unless grep { $_ eq "OPENSSL_USE_APPLINK" } @{$target{defines}}; "" -}
349         @echo "install $(SRCDIR)/ms/applink.c -> $(DESTDIR)$(INSTALLTOP)/include/openssl/applink.c"
350         @cp $(SRCDIR)/ms/applink.c $(DESTDIR)$(INSTALLTOP)/include/openssl/applink.c
351         @chmod 644 $(DESTDIR)$(INSTALLTOP)/include/openssl/applink.c
352         @ : {- output_on() unless grep { $_ eq "OPENSSL_USE_APPLINK" } @{$target{defines}}; "" -}
353         @set -e; for i in $(SRCDIR)/include/openssl/*.h \
354                           $(BLDDIR)/include/openssl/*.h; do \
355                 fn=`basename $$i`; \
356                 echo "install $$i -> $(DESTDIR)$(INSTALLTOP)/include/openssl/$$fn"; \
357                 cp $$i $(DESTDIR)$(INSTALLTOP)/include/openssl/$$fn; \
358                 chmod 644 $(DESTDIR)$(INSTALLTOP)/include/openssl/$$fn; \
359         done
360         @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)
361         @set -e; for l in $(INSTALL_LIBS); do \
362                 fn=`basename $$l`; \
363                 echo "install $$l -> $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn"; \
364                 cp $$l $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn.new; \
365                 $(RANLIB) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn.new; \
366                 chmod 644 $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn.new; \
367                 mv -f $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn.new \
368                       $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn; \
369         done
370         @ : {- output_off() if $disabled{shared}; "" -}
371         @set -e; for s in $(INSTALL_SHLIB_INFO); do \
372                 s1=`echo "$$s" | cut -f1 -d";"`; \
373                 s2=`echo "$$s" | cut -f2 -d";"`; \
374                 fn1=`basename $$s1`; \
375                 fn2=`basename $$s2`; \
376                 : {- output_off() if windowsdll(); "" -}; \
377                 echo "install $$s1 -> $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn1"; \
378                 cp $$s1 $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn1.new; \
379                 chmod 755 $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn1.new; \
380                 mv -f $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn1.new \
381                       $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn1; \
382                 if [ "$$fn1" != "$$fn2" ]; then \
383                         echo "link $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn2 -> $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn1"; \
384                         ln -sf $$fn1 $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn2; \
385                 fi; \
386                 : {- output_on() if windowsdll(); "" -}{- output_off() unless windowsdll(); "" -}; \
387                 echo "install $$s2 -> $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn2"; \
388                 cp $$s2 $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn2.new; \
389                 chmod 755 $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn2.new; \
390                 mv -f $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn2.new \
391                       $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn2; \
392                 : {- output_on() unless windowsdll(); "" -}; \
393         done
394         @ : {- output_on() if $disabled{shared}; "" -}
395         @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig
396         @echo "install libcrypto.pc -> $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/libcrypto.pc"
397         @cp libcrypto.pc $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig
398         @chmod 644 $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/libcrypto.pc
399         @echo "install libssl.pc -> $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/libssl.pc"
400         @cp libssl.pc $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig
401         @chmod 644 $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/libssl.pc
402         @echo "install openssl.pc -> $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/openssl.pc"
403         @cp openssl.pc $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig
404         @chmod 644 $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/openssl.pc
405
406 uninstall_dev:
407         @echo "*** Uninstalling development files"
408         @ : {- output_off() unless grep { $_ eq "OPENSSL_USE_APPLINK" } @{$target{defines}}; "" -}
409         @echo "$(RM) $(DESTDIR)$(INSTALLTOP)/include/openssl/applink.c"
410         @$(RM) $(DESTDIR)$(INSTALLTOP)/include/openssl/applink.c
411         @ : {- output_on() unless grep { $_ eq "OPENSSL_USE_APPLINK" } @{$target{defines}}; "" -}
412         @set -e; for i in $(SRCDIR)/include/openssl/*.h \
413                           $(BLDDIR)/include/openssl/*.h; do \
414                 fn=`basename $$i`; \
415                 echo "$(RM) $(DESTDIR)$(INSTALLTOP)/include/openssl/$$fn"; \
416                 $(RM) $(DESTDIR)$(INSTALLTOP)/include/openssl/$$fn; \
417         done
418         -$(RMDIR) $(DESTDIR)$(INSTALLTOP)/include/openssl
419         -$(RMDIR) $(DESTDIR)$(INSTALLTOP)/include
420         @set -e; for l in $(INSTALL_LIBS); do \
421                 fn=`basename $$l`; \
422                 echo "$(RM) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn"; \
423                 $(RM) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn; \
424         done
425         @ : {- output_off() if $disabled{shared}; "" -}
426         @set -e; for s in $(INSTALL_SHLIB_INFO); do \
427                 s1=`echo "$$s" | cut -f1 -d";"`; \
428                 s2=`echo "$$s" | cut -f2 -d";"`; \
429                 fn1=`basename $$s1`; \
430                 fn2=`basename $$s2`; \
431                 : {- output_off() if windowsdll(); "" -}; \
432                 echo "$(RM) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn1"; \
433                 $(RM) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn1; \
434                 if [ "$$fn1" != "$$fn2" ]; then \
435                         echo "$(RM) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn2"; \
436                         $(RM) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn2; \
437                 fi; \
438                 : {- output_on() if windowsdll(); "" -}{- output_off() unless windowsdll(); "" -}; \
439                 echo "$(RM) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn2"; \
440                 $(RM) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn2; \
441                 : {- output_on() unless windowsdll(); "" -}; \
442         done
443         @ : {- output_on() if $disabled{shared}; "" -}
444         $(RM) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/libcrypto.pc
445         $(RM) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/libssl.pc
446         $(RM) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/openssl.pc
447         -$(RMDIR) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig
448         -$(RMDIR) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)
449
450 install_engines:
451         @[ -n "$(INSTALLTOP)" ] || (echo INSTALLTOP should not be empty; exit 1)
452         @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(ENGINESDIR)/
453         @echo "*** Installing engines"
454         @set -e; for e in dummy $(INSTALL_ENGINES); do \
455                 if [ "$$e" = "dummy" ]; then continue; fi; \
456                 fn=`basename $$e`; \
457                 echo "install $$e -> $(DESTDIR)$(ENGINESDIR)/$$fn"; \
458                 cp $$e $(DESTDIR)$(ENGINESDIR)/$$fn.new; \
459                 chmod 755 $(DESTDIR)$(ENGINESDIR)/$$fn.new; \
460                 mv -f $(DESTDIR)$(ENGINESDIR)/$$fn.new \
461                       $(DESTDIR)$(ENGINESDIR)/$$fn; \
462         done
463
464 uninstall_engines:
465         @echo "*** Uninstalling engines"
466         @set -e; for e in dummy $(INSTALL_ENGINES); do \
467                 if [ "$$e" = "dummy" ]; then continue; fi; \
468                 fn=`basename $$e`; \
469                 if [ "$$fn" = '{- dso("ossltest") -}' ]; then \
470                         continue; \
471                 fi; \
472                 echo "$(RM) $(DESTDIR)$(ENGINESDIR)/$$fn"; \
473                 $(RM) $(DESTDIR)$(ENGINESDIR)/$$fn; \
474         done
475         -$(RMDIR) $(DESTDIR)$(ENGINESDIR)
476
477 install_runtime:
478         @[ -n "$(INSTALLTOP)" ] || (echo INSTALLTOP should not be empty; exit 1)
479         @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(INSTALLTOP)/bin
480         @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(OPENSSLDIR)/misc
481         @echo "*** Installing runtime files"
482         @ : {- output_off() unless windowsdll(); "" -}
483         @set -e; for s in dummy $(INSTALL_SHLIBS); do \
484                 if [ "$$s" = "dummy" ]; then continue; fi; \
485                 fn=`basename $$s`; \
486                 echo "install $$s -> $(DESTDIR)$(INSTALLTOP)/bin/$$fn"; \
487                 cp $$s $(DESTDIR)$(INSTALLTOP)/bin/$$fn.new; \
488                 chmod 644 $(DESTDIR)$(INSTALLTOP)/bin/$$fn.new; \
489                 mv -f $(DESTDIR)$(INSTALLTOP)/bin/$$fn.new \
490                       $(DESTDIR)$(INSTALLTOP)/bin/$$fn; \
491         done
492         @ : {- output_on() unless windowsdll(); "" -}
493         @set -e; for x in dummy $(INSTALL_PROGRAMS); do \
494                 if [ "$$x" = "dummy" ]; then continue; fi; \
495                 fn=`basename $$x`; \
496                 echo "install $$x -> $(DESTDIR)$(INSTALLTOP)/bin/$$fn"; \
497                 cp $$x $(DESTDIR)$(INSTALLTOP)/bin/$$fn.new; \
498                 chmod 755 $(DESTDIR)$(INSTALLTOP)/bin/$$fn.new; \
499                 mv -f $(DESTDIR)$(INSTALLTOP)/bin/$$fn.new \
500                       $(DESTDIR)$(INSTALLTOP)/bin/$$fn; \
501         done
502         @set -e; for x in dummy $(BIN_SCRIPTS); do \
503                 if [ "$$x" = "dummy" ]; then continue; fi; \
504                 fn=`basename $$x`; \
505                 echo "install $$x -> $(DESTDIR)$(INSTALLTOP)/bin/$$fn"; \
506                 cp $$x $(DESTDIR)$(INSTALLTOP)/bin/$$fn.new; \
507                 chmod 755 $(DESTDIR)$(INSTALLTOP)/bin/$$fn.new; \
508                 mv -f $(DESTDIR)$(INSTALLTOP)/bin/$$fn.new \
509                       $(DESTDIR)$(INSTALLTOP)/bin/$$fn; \
510         done
511
512 uninstall_runtime:
513         @echo "*** Uninstalling runtime files"
514         @set -e; for x in dummy $(INSTALL_PROGRAMS); \
515         do  \
516                 if [ "$$x" = "dummy" ]; then continue; fi; \
517                 fn=`basename $$x`; \
518                 echo "$(RM) $(DESTDIR)$(INSTALLTOP)/bin/$$fn"; \
519                 $(RM) $(DESTDIR)$(INSTALLTOP)/bin/$$fn; \
520         done;
521         @set -e; for x in dummy $(BIN_SCRIPTS); \
522         do  \
523                 if [ "$$x" = "dummy" ]; then continue; fi; \
524                 fn=`basename $$x`; \
525                 echo "$(RM) $(DESTDIR)$(INSTALLTOP)/bin/$$fn"; \
526                 $(RM) $(DESTDIR)$(INSTALLTOP)/bin/$$fn; \
527         done
528         @set -e; for x in dummy $(MISC_SCRIPTS); \
529         do  \
530                 if [ "$$x" = "dummy" ]; then continue; fi; \
531                 fn=`basename $$x`; \
532                 echo "$(RM) $(DESTDIR)$(OPENSSLDIR)/misc/$$fn"; \
533                 $(RM) $(DESTDIR)$(OPENSSLDIR)/misc/$$fn; \
534         done
535         @ : {- output_off() unless windowsdll(); "" -}
536         @set -e; for s in dummy $(INSTALL_SHLIBS); do \
537                 if [ "$$s" = "dummy" ]; then continue; fi; \
538                 fn=`basename $$s`; \
539                 echo "$(RM) $(DESTDIR)$(INSTALLTOP)/bin/$$fn"; \
540                 $(RM) $(DESTDIR)$(INSTALLTOP)/bin/$$fn; \
541         done
542         @ : {- output_on() unless windowsdll(); "" -}
543         $(RM) $(DESTDIR)$(OPENSSLDIR)/openssl.cnf
544         -$(RMDIR) $(DESTDIR)$(INSTALLTOP)/bin
545         -$(RMDIR) $(DESTDIR)$(OPENSSLDIR)/misc
546
547 # A method to extract all names from a .pod file
548 # The first sed extracts everything between "=head1 NAME" and the next =head1
549 # The perl command joins all the lines into one
550 # The second sed removes the description and turns all commas into spaces
551 # Voilà, you have a space separated list of names!
552 EXTRACT_NAMES=sed -e '1,/^=head1  *NAME *$$/d;/^=head1/,$$d' | \
553               $(PERL) -p -0 -e 's/\n/ /g; END {print "\n"}' | \
554               sed -e 's/ - .*$$//;s/,/ /g'
555 PROCESS_PODS=\
556         set -e; \
557         here=`cd $(SRCDIR); pwd`; \
558         point=$$here/util/point.sh; \
559         for ds in apps:1 crypto:3 ssl:3; do \
560             defdir=`echo $$ds | cut -f1 -d:`; \
561             defsec=`echo $$ds | cut -f2 -d:`; \
562             for p in $(SRCDIR)/doc/$$defdir/*.pod; do \
563                 SEC=`sed -ne 's/^=for  *comment  *openssl_manual_section: *\([0-9]\) *$$/\1/p' $$p`; \
564                 [ -z "$$SEC" ] && SEC=$$defsec; \
565                 fn=`basename $$p .pod`; \
566                 Name=$$fn; \
567                 NAME=`echo $$fn | tr [a-z] [A-Z]`; \
568                 suf=`eval "echo $$OUTSUFFIX"`; \
569                 top=`eval "echo $$OUTTOP"`; \
570                 $(PERL) $(SRCDIR)/util/mkdir-p.pl $$top/man$$SEC; \
571                 echo "install $$p -> $$top/man$$SEC/$$fn$$suf"; \
572                 cat $$p | eval "$$GENERATE" \
573                         >  $$top/man$$SEC/$$fn$$suf; \
574                 names=`cat $$p | $(EXTRACT_NAMES)`; \
575                 ( cd $$top/man$$SEC; \
576                   for n in $$names; do \
577                       comp_n="$$n"; \
578                       comp_fn="$$fn"; \
579                       case "$(PLATFORM)" in DJGPP|Cygwin*|mingw*|darwin*-*-cc) \
580                           comp_n=`echo "$$n" | tr [A-Z] [a-z]`; \
581                           comp_fn=`echo "$$fn" | tr [A-Z] [a-z]`; \
582                           ;; \
583                       esac; \
584                       if [ "$$comp_n" != "$$comp_fn" ]; then \
585                           echo "link $$top/man$$SEC/$$n$$suf -> $$top/man$$SEC/$$fn$$suf"; \
586                           PLATFORM=$(PLATFORM) $$point $$fn$$suf $$n$$suf; \
587                       fi; \
588                   done ); \
589             done; \
590         done
591 UNINSTALL_DOCS=\
592         set -e; \
593         here=`cd $(SRCDIR); pwd`; \
594         for ds in apps:1 crypto:3 ssl:3; do \
595             defdir=`echo $$ds | cut -f1 -d:`; \
596             defsec=`echo $$ds | cut -f2 -d:`; \
597             for p in $(SRCDIR)/doc/$$defdir/*.pod; do \
598                 SEC=`sed -ne 's/^=for  *comment  *openssl_manual_section: *\([0-9]\) *$$/\1/p' $$p`; \
599                 [ -z "$$SEC" ] && SEC=$$defsec; \
600                 fn=`basename $$p .pod`; \
601                 suf=`eval "echo $$OUTSUFFIX"`; \
602                 top=`eval "echo $$OUTTOP"`; \
603                 echo "$(RM) $$top/man$$SEC/$$fn$$suf"; \
604                 $(RM) $$top/man$$SEC/$$fn$$suf; \
605                 names=`cat $$p | $(EXTRACT_NAMES)`; \
606                 for n in $$names; do \
607                     comp_n="$$n"; \
608                     comp_fn="$$fn"; \
609                     case "$(PLATFORM)" in DJGPP|Cygwin*|mingw*|darwin*-*-cc) \
610                         comp_n=`echo "$$n" | tr [A-Z] [a-z]`; \
611                         comp_fn=`echo "$$fn" | tr [A-Z] [a-z]`; \
612                         ;; \
613                     esac; \
614                     if [ "$$comp_n" != "$$comp_fn" ]; then \
615                         echo "$(RM) $$top/man$$SEC/$$n$$suf"; \
616                         $(RM) $$top/man$$SEC/$$n$$suf; \
617                     fi; \
618                 done; \
619                 ( $(RMDIR) $$top/man$$SEC 2>/dev/null || exit 0 ); \
620             done; \
621         done
622
623 install_man_docs:
624         @[ -n "$(INSTALLTOP)" ] || (echo INSTALLTOP should not be empty; exit 1)
625         @echo "*** Installing manpages"
626         @\
627         OUTSUFFIX='.$${SEC}$(MANSUFFIX)'; \
628         OUTTOP="$(DESTDIR)$(MANDIR)"; \
629         GENERATE='pod2man --name=$$NAME --section=$$SEC --center=OpenSSL --release=$(VERSION)'; \
630         $(PROCESS_PODS)
631
632 uninstall_man_docs:
633         @echo "*** Uninstalling manpages"
634         @\
635         OUTSUFFIX='.$${SEC}$(MANSUFFIX)'; \
636         OUTTOP="$(DESTDIR)$(MANDIR)"; \
637         $(UNINSTALL_DOCS)
638
639 install_html_docs:
640         @[ -n "$(INSTALLTOP)" ] || (echo INSTALLTOP should not be empty; exit 1)
641         @echo "*** Installing HTML manpages"
642         @\
643         OUTSUFFIX='.$(HTMLSUFFIX)'; \
644         OUTTOP="$(DESTDIR)$(HTMLDIR)"; \
645         GENERATE="pod2html --podroot=$(SRCDIR)/doc --htmldir=.. \
646                            --podpath=apps:crypto:ssl --title=\$$Name \
647                   | perl -pe 's|href=\"http://man.he.net/man|href=\"../man|g; s|href=\"(.*/man.*)(?<!\.html)\">|href=\"\$$1.html\">|g;'"; \
648         $(PROCESS_PODS)
649
650 uninstall_html_docs:
651         @echo "*** Uninstalling manpages"
652         @\
653         OUTSUFFIX='.$(HTMLSUFFIX)'; \
654         OUTTOP="$(DESTDIR)$(HTMLDIR)"; \
655         $(UNINSTALL_DOCS)
656
657
658 # Developer targets (note: these are only available on Unix) #########
659
660 update: generate errors ordinals
661
662 generate: generate_apps generate_crypto_bn generate_crypto_objects \
663           generate_crypto_conf generate_crypto_asn1
664
665 # Test coverage is a good idea for the future
666 #coverage: $(PROGRAMS) $(TESTPROGRAMS)
667 #       ...
668
669 lint:
670         lint -DLINT $(INCLUDES) $(SRCS)
671
672 {- # because the program apps/openssl has object files as sources, and
673    # they then have the corresponding C files as source, we need to chain
674    # the lookups in %unified_info
675    my $apps_openssl = catfile("apps","openssl");
676    our @openssl_source = map { @{$unified_info{sources}->{$_}} }
677                          @{$unified_info{sources}->{$apps_openssl}};
678    ""; -}
679 generate_apps:
680         ( cd $(SRCDIR); $(PERL) VMS/VMSify-conf.pl \
681                                 < apps/openssl.cnf > apps/openssl-vms.cnf )
682         ( b=`pwd`; cd $(SRCDIR); $(PERL) -I$$b apps/progs.pl \
683                                         {- join(" ", @openssl_source) -} \
684                                         > apps/progs.h )
685
686 generate_crypto_bn:
687         ( cd $(SRCDIR); $(PERL) crypto/bn/bn_prime.pl > crypto/bn/bn_prime.h )
688
689 generate_crypto_objects:
690         ( cd $(SRCDIR); $(PERL) crypto/objects/objects.pl \
691                                 crypto/objects/objects.txt \
692                                 crypto/objects/obj_mac.num \
693                                 include/openssl/obj_mac.h )
694         ( cd $(SRCDIR); $(PERL) crypto/objects/obj_dat.pl \
695                                 include/openssl/obj_mac.h \
696                                 crypto/objects/obj_dat.h )
697         ( cd $(SRCDIR); $(PERL) crypto/objects/objxref.pl \
698                                 crypto/objects/obj_mac.num \
699                                 crypto/objects/obj_xref.txt \
700                                 > crypto/objects/obj_xref.h )
701
702 generate_crypto_conf:
703         ( cd $(SRCDIR); $(PERL) crypto/conf/keysets.pl \
704                                 > crypto/conf/conf_def.h )
705
706 generate_crypto_asn1:
707         ( cd $(SRCDIR); $(PERL) crypto/asn1/charmap.pl \
708                                 > crypto/asn1/charmap.h )
709
710 errors:
711         ( cd $(SRCDIR); $(PERL) util/ck_errf.pl -strict */*.c */*/*.c )
712         ( cd $(SRCDIR); $(PERL) util/mkerr.pl -recurse -write )
713         ( cd $(SRCDIR)/engines; \
714           for e in *.ec; do \
715               $(PERL) ../util/mkerr.pl -conf $$e \
716                       -nostatic -staticloader -write *.c; \
717           done )
718
719 ordinals:
720         ( b=`pwd`; cd $(SRCDIR); $(PERL) -I$$b util/mkdef.pl crypto update )
721         ( b=`pwd`; cd $(SRCDIR); $(PERL) -I$$b util/mkdef.pl ssl update )
722
723 test_ordinals:
724         ( cd test; \
725           SRCTOP=../$(SRCDIR) \
726           BLDTOP=../$(BLDDIR) \
727             $(PERL) ../$(SRCDIR)/test/run_tests.pl test_ordinals )
728
729 tags TAGS: FORCE
730         rm -f TAGS tags
731         -ctags -R .
732         -etags `find . -name '*.[ch]' -o -name '*.pm'`
733
734 # Release targets (note: only available on Unix) #####################
735
736 TAR_COMMAND=$(TAR) $(TARFLAGS) --owner 0 --group 0 -cvf -
737 PREPARE_CMD=:
738 tar:
739         TMPDIR=/var/tmp/openssl-copy.$$$$; \
740         DISTDIR=$(NAME); \
741         mkdir -p $$TMPDIR/$$DISTDIR; \
742         (cd $(SRCDIR); \
743          git ls-tree -r --name-only --full-tree HEAD \
744          | grep -v '^fuzz/corpora' \
745          | while read F; do \
746                mkdir -p $$TMPDIR/$$DISTDIR/`dirname $$F`; \
747                cp $$F $$TMPDIR/$$DISTDIR/$$F; \
748            done); \
749         (cd $$TMPDIR; \
750          $(PREPARE_CMD); \
751          find $$TMPDIR/$$DISTDIR -type d -print | xargs chmod 755; \
752          find $$TMPDIR/$$DISTDIR -type f -print | xargs chmod a+r; \
753          find $$TMPDIR/$$DISTDIR -type f -perm -0100 -print | xargs chmod a+x; \
754          $(TAR_COMMAND) $$DISTDIR) \
755         | (cd $(SRCDIR); gzip --best > $(TARFILE).gz); \
756         rm -rf $$TMPDIR
757         cd $(SRCDIR); ls -l $(TARFILE).gz
758
759 dist:
760         @$(MAKE) PREPARE_CMD='./Configure dist' tar
761
762 # Helper targets #####################################################
763
764 link-utils: $(BLDDIR)/util/opensslwrap.sh $(BLDDIR)/util/shlib_wrap.sh
765
766 $(BLDDIR)/util/opensslwrap.sh: configdata.pm
767         @if [ "$(SRCDIR)" != "$(BLDDIR)" ]; then \
768             mkdir -p "$(BLDDIR)/util"; \
769             ln -sf "../$(SRCDIR)/util/opensslwrap.sh" "$(BLDDIR)/util"; \
770         fi
771 $(BLDDIR)/util/shlib_wrap.sh: configdata.pm
772         @if [ "$(SRCDIR)" != "$(BLDDIR)" ]; then \
773             mkdir -p "$(BLDDIR)/util"; \
774             ln -sf "../$(SRCDIR)/util/shlib_wrap.sh" "$(BLDDIR)/util"; \
775         fi
776 FORCE:
777
778 # Building targets ###################################################
779
780 libcrypto.pc libssl.pc openssl.pc: configdata.pm $(LIBS) {- join(" ",map { shlib_simple($_) } @{$unified_info{libraries}}) -}
781 libcrypto.pc:
782         @ ( echo 'prefix=$(INSTALLTOP)'; \
783             echo 'exec_prefix=$${prefix}'; \
784             echo 'libdir=$${exec_prefix}/$(LIBDIR)'; \
785             echo 'includedir=$${prefix}/include'; \
786             echo ''; \
787             echo 'Name: OpenSSL-libcrypto'; \
788             echo 'Description: OpenSSL cryptography library'; \
789             echo 'Version: '$(VERSION); \
790             echo 'Libs: -L$${libdir} -lcrypto'; \
791             echo 'Libs.private: $(EX_LIBS)'; \
792             echo 'Cflags: -I$${includedir}' ) > libcrypto.pc
793
794 libssl.pc:
795         @ ( echo 'prefix=$(INSTALLTOP)'; \
796             echo 'exec_prefix=$${prefix}'; \
797             echo 'libdir=$${exec_prefix}/$(LIBDIR)'; \
798             echo 'includedir=$${prefix}/include'; \
799             echo ''; \
800             echo 'Name: OpenSSL-libssl'; \
801             echo 'Description: Secure Sockets Layer and cryptography libraries'; \
802             echo 'Version: '$(VERSION); \
803             echo 'Requires.private: libcrypto'; \
804             echo 'Libs: -L$${libdir} -lssl'; \
805             echo 'Libs.private: $(EX_LIBS)'; \
806             echo 'Cflags: -I$${includedir}' ) > libssl.pc
807
808 openssl.pc:
809         @ ( echo 'prefix=$(INSTALLTOP)'; \
810             echo 'exec_prefix=$${prefix}'; \
811             echo 'libdir=$${exec_prefix}/$(LIBDIR)'; \
812             echo 'includedir=$${prefix}/include'; \
813             echo ''; \
814             echo 'Name: OpenSSL'; \
815             echo 'Description: Secure Sockets Layer and cryptography libraries and tools'; \
816             echo 'Version: '$(VERSION); \
817             echo 'Requires: libssl libcrypto' ) > openssl.pc
818
819 configdata.pm: {- $config{build_file_template} -} $(SRCDIR)/Configurations/common.tmpl $(SRCDIR)/Configure $(SRCDIR)/config {- join(" ", @{$config{build_infos}}) -}
820         @echo "Detected changed: $?"
821         @echo "Reconfiguring..."
822         $(SRCDIR)/Configure reconf
823         @echo "**************************************************"
824         @echo "***                                            ***"
825         @echo "***   Please run the same make command again   ***"
826         @echo "***                                            ***"
827         @echo "**************************************************"
828         @false
829
830 {-
831   use File::Basename;
832   use File::Spec::Functions qw/:DEFAULT abs2rel rel2abs/;
833
834   # Helper function to figure out dependencies on libraries
835   # It takes a list of library names and outputs a list of dependencies
836   sub compute_lib_depends {
837       if ($disabled{shared}) {
838           return map { $_.$libext } @_;
839       }
840
841       # Depending on shared libraries:
842       # On Windows POSIX layers, we depend on {libname}.dll.a
843       # On Unix platforms, we depend on {shlibname}.so
844       return map { shlib_simple($_) } @_;
845   }
846
847   sub generatesrc {
848       my %args = @_;
849       my $generator = join(" ", @{$args{generator}});
850       my $generator_incs = join("", map { " -I".$_ } @{$args{generator_incs}});
851       my $incs = join("", map { " -I".$_ } @{$args{incs}});
852       my $deps = join(" ", @{$args{generator_deps}}, @{$args{deps}});
853
854       if ($args{src} !~ /\.[sS]$/) {
855           if ($args{generator}->[0] =~ m|^.*\.in$|) {
856               my $dofile = abs2rel(rel2abs(catfile($config{sourcedir},
857                                                    "util", "dofile.pl")),
858                                    rel2abs($config{builddir}));
859               return <<"EOF";
860 $args{src}: $args{generator}->[0] $deps
861         \$(PERL) "-I\$(BLDDIR)" -Mconfigdata "$dofile" \\
862             "-o$target{build_file}" $generator > \$@
863 EOF
864           } else {
865               return <<"EOF";
866 $args{src}: $args{generator}->[0] $deps
867         \$(PERL)$generator_incs $generator > \$@
868 EOF
869           }
870       } else {
871           if ($args{generator}->[0] =~ /\.pl$/) {
872               $generator = 'CC="$(CC)" $(PERL)'.$generator_incs.' '.$generator;
873           } elsif ($args{generator}->[0] =~ /\.m4$/) {
874               $generator = 'm4 -B 8192'.$generator_incs.' '.$generator.' >'
875           } elsif ($args{generator}->[0] =~ /\.S$/) {
876               $generator = undef;
877           } else {
878               die "Generator type for $args{src} unknown: $generator\n";
879           }
880
881           if (defined($generator)) {
882               # If the target is named foo.S in build.info, we want to
883               # end up generating foo.s in two steps.
884               if ($args{src} =~ /\.S$/) {
885                    (my $target = $args{src}) =~ s|\.S$|.s|;
886                    return <<"EOF";
887 $target: $args{generator}->[0] $deps
888         ( trap "rm -f \$@.*" INT 0; \\
889           $generator \$@.S; \\
890           \$(CC) $incs \$(CFLAGS) -E \$@.S | \\
891           \$(PERL) -ne '/^#(line)?\\s*[0-9]+/ or print' > \$@.i && \\
892           mv -f \$@.i \$@ )
893 EOF
894               }
895               # Otherwise....
896               return <<"EOF";
897 $args{src}: $args{generator}->[0] $deps
898         $generator \$@
899 EOF
900           }
901           return <<"EOF";
902 $args{src}: $args{generator}->[0] $deps
903         \$(CC) $incs \$(CFLAGS) -E \$< | \\
904         \$(PERL) -ne '/^#(line)?\\s*[0-9]+/ or print' > \$@
905 EOF
906       }
907   }
908
909   # Should one wonder about the end of the Perl snippet, it's because this
910   # second regexp eats up line endings as well, if the removed path is the
911   # last in the line.  We may therefore need to put back a line ending.
912   sub src2obj {
913       my %args = @_;
914       my $obj = $args{obj};
915       my @srcs = map { if ($unified_info{generate}->{$_}) {
916                            (my $x = $_) =~ s/\.S$/.s/; $x
917                        } else {
918                            $_
919                        }
920                      } ( @{$args{srcs}} );
921       my $srcs = join(" ",  @srcs);
922       my $deps = join(" ", @srcs, @{$args{deps}});
923       my $incs = join("", map { " -I".$_ } @{$args{incs}});
924       unless ($disabled{zlib}) {
925           if ($withargs{zlib_include}) {
926               $incs .= " -I".$withargs{zlib_include};
927           }
928       }
929       my $ecflags = { lib => '$(LIB_CFLAGS)',
930                       dso => '$(DSO_CFLAGS)',
931                       bin => '$(BIN_CFLAGS)' } -> {$args{intent}};
932       my $makedepprog = $config{makedepprog};
933       my $recipe = "";
934       if (!$disabled{makedepend} && $makedepprog =~ /\/makedepend/) {
935           $recipe .= <<"EOF";
936 $obj$depext: $deps
937         -\$(MAKEDEPEND) -f- -o"|$obj$objext" -- $incs \$(CFLAGS) $ecflags -- $srcs \\
938             >\$\@.tmp 2>/dev/null
939         -\$(PERL) -i -pe 's/^.*\\|//; s/ \\/(\\\\.|[^ ])*//; \$\$_ = undef if (/: *\$\$/ || /^(#.*| *)\$\$/); \$\$_.="\\n" unless !defined(\$\$_) or /\\R\$\$/g;' \$\@.tmp
940         \@if cmp \$\@.tmp \$\@ > /dev/null 2> /dev/null; then \\
941                 rm -f \$\@.tmp; \\
942         else \\
943                 mv \$\@.tmp \$\@; \\
944         fi
945 EOF
946           $deps = $obj.$depext;
947       }
948       if ($disabled{makedepend} || $makedepprog =~ /\/makedepend/) {
949           $recipe .= <<"EOF";
950 $obj$objext: $deps
951         \$(CC) $incs \$(CFLAGS) $ecflags -c -o \$\@ $srcs
952 EOF
953       }
954       if (!$disabled{makedepend} && $makedepprog !~ /\/makedepend/) {
955           $recipe .= <<"EOF";
956 $obj$objext: $deps
957         \$(CC) $incs \$(CFLAGS) $ecflags -MMD -MF $obj$depext.tmp -MT \$\@ -c -o \$\@ $srcs
958         \@touch $obj$depext.tmp
959         \@if cmp $obj$depext.tmp $obj$depext > /dev/null 2> /dev/null; then \\
960                 rm -f $obj$depext.tmp; \\
961         else \\
962                 mv $obj$depext.tmp $obj$depext; \\
963         fi
964 EOF
965       }
966       return $recipe;
967   }
968   # On Unix, we build shlibs from static libs, so we're ignoring the
969   # object file array.  We *know* this routine is only called when we've
970   # configure 'shared'.
971   sub libobj2shlib {
972       my %args = @_;
973       my $lib = $args{lib};
974       my $shlib = $args{shlib};
975       my $libd = dirname($lib);
976       my $libn = basename($lib);
977       (my $libname = $libn) =~ s/^lib//;
978       my $linklibs = join("", map { my $d = dirname($_);
979                                     my $f = basename($_);
980                                     (my $l = $f) =~ s/^lib//;
981                                     " -L$d -l$l" } @{$args{deps}});
982       my $deps = join(" ",compute_lib_depends(@{$args{deps}}));
983       my $shlib_target = $target{shared_target};
984       my $ordinalsfile = defined($args{ordinals}) ? $args{ordinals}->[1] : "";
985       my $target = shlib_simple($lib);
986       return <<"EOF"
987 # With a build on a Windows POSIX layer (Cygwin or Mingw), we know for a fact
988 # that two files get produced, {shlibname}.dll and {libname}.dll.a.
989 # With all other Unix platforms, we often build a shared library with the
990 # SO version built into the file name and a symlink without the SO version
991 # It's not necessary to have both as targets.  The choice falls on the
992 # simplest, {libname}$shlibextimport for Windows POSIX layers and
993 # {libname}$shlibextsimple for the Unix platforms.
994 $target: $lib$libext $deps $ordinalsfile
995         \$(MAKE) -f \$(SRCDIR)/Makefile.shared -e \\
996                 PLATFORM=\$(PLATFORM) \\
997                 PERL="\$(PERL)" SRCDIR='\$(SRCDIR)' DSTDIR="$libd" \\
998                 INSTALLTOP='\$(INSTALLTOP)' LIBDIR='\$(LIBDIR)' \\
999                 LIBDEPS='\$(PLIB_LDFLAGS) '"$linklibs"' \$(EX_LIBS)' \\
1000                 LIBNAME=$libname LIBVERSION=\$(SHLIB_MAJOR).\$(SHLIB_MINOR) \\
1001                 LIBCOMPATVERSIONS=';\$(SHLIB_VERSION_HISTORY)' \\
1002                 CC='\$(CC)' CFLAGS='\$(CFLAGS) \$(LIB_CFLAGS)' \\
1003                 LDFLAGS='\$(LDFLAGS)' \\
1004                 SHARED_LDFLAGS='\$(LIB_LDFLAGS)' SHLIB_EXT=$shlibext \\
1005                 RC='\$(RC)' SHARED_RCFLAGS='\$(RCFLAGS)' \\
1006                 link_shlib.$shlib_target
1007 EOF
1008           . (windowsdll() ? <<"EOF" : "");
1009         rm -f apps/$shlib$shlibext
1010         rm -f test/$shlib$shlibext
1011         cp -p $shlib$shlibext apps/
1012         cp -p $shlib$shlibext test/
1013 EOF
1014   }
1015   sub obj2dso {
1016       my %args = @_;
1017       my $lib = $args{lib};
1018       my $libd = dirname($lib);
1019       my $libn = basename($lib);
1020       (my $libname = $libn) =~ s/^lib//;
1021       my $shlibdeps = join("", map { my $d = dirname($_);
1022                                      my $f = basename($_);
1023                                      (my $l = $f) =~ s/^lib//;
1024                                      " -L$d -l$l" } @{$args{deps}});
1025       my $deps = join(" ",compute_lib_depends(@{$args{deps}}));
1026       my $shlib_target = $target{shared_target};
1027       my $objs = join(" ", map { $_.$objext } @{$args{objs}});
1028       my $target = dso($lib);
1029       return <<"EOF";
1030 $target: $objs $deps
1031         \$(MAKE) -f \$(SRCDIR)/Makefile.shared -e \\
1032                 PLATFORM=\$(PLATFORM) \\
1033                 PERL="\$(PERL)" SRCDIR='\$(SRCDIR)' DSTDIR="$libd" \\
1034                 LIBDEPS='\$(PLIB_LDFLAGS) '"$shlibdeps"' \$(EX_LIBS)' \\
1035                 LIBNAME=$libname LDFLAGS='\$(LDFLAGS)' \\
1036                 CC='\$(CC)' CFLAGS='\$(CFLAGS) \$(DSO_CFLAGS)' \\
1037                 SHARED_LDFLAGS='\$(DSO_LDFLAGS)' \\
1038                 SHLIB_EXT=$dsoext \\
1039                 LIBEXTRAS="$objs" \\
1040                 link_dso.$shlib_target
1041 EOF
1042   }
1043   sub obj2lib {
1044       my %args = @_;
1045       my $lib = $args{lib};
1046       my $objs = join(" ", map { $_.$objext } @{$args{objs}});
1047       return <<"EOF";
1048 $lib$libext: $objs
1049         \$(AR) \$\@ \$\?
1050         \$(RANLIB) \$\@ || echo Never mind.
1051 EOF
1052   }
1053   sub obj2bin {
1054       my %args = @_;
1055       my $bin = $args{bin};
1056       my $bind = dirname($bin);
1057       my $binn = basename($bin);
1058       my $objs = join(" ", map { $_.$objext } @{$args{objs}});
1059       my $deps = join(" ",compute_lib_depends(@{$args{deps}}));
1060       my $linklibs = join("", map { my $d = dirname($_);
1061                                     my $f = basename($_);
1062                                     $d = "." if $d eq $f;
1063                                     (my $l = $f) =~ s/^lib//;
1064                                     " -L$d -l$l" } @{$args{deps}});
1065       my $shlib_target = $disabled{shared} ? "" : $target{shared_target};
1066       return <<"EOF";
1067 $bin$exeext: $objs $deps
1068         \$(RM) $bin$exeext
1069         \$(MAKE) -f \$(SRCDIR)/Makefile.shared -e \\
1070                 PERL="\$(PERL)" SRCDIR=\$(SRCDIR) \\
1071                 APPNAME=$bin$exeext OBJECTS="$objs" \\
1072                 LIBDEPS='\$(PLIB_LDFLAGS) '"$linklibs"' \$(EX_LIBS)' \\
1073                 CC='\$(CC)' CFLAGS='\$(CFLAGS) \$(BIN_CFLAGS)' \\
1074                 LDFLAGS='\$(LDFLAGS)' LIBRPATH='\$(INSTALLTOP)/\$(LIBDIR)' \\
1075                 link_app.$shlib_target
1076 EOF
1077   }
1078   sub in2script {
1079       my %args = @_;
1080       my $script = $args{script};
1081       my $sources = join(" ", @{$args{sources}});
1082       my $dofile = abs2rel(rel2abs(catfile($config{sourcedir},
1083                                            "util", "dofile.pl")),
1084                            rel2abs($config{builddir}));
1085       return <<"EOF";
1086 $script: $sources
1087         \$(PERL) "-I\$(BLDDIR)" -Mconfigdata "$dofile" \\
1088             "-o$target{build_file}" $sources > "$script"
1089         chmod a+x $script
1090 EOF
1091   }
1092   sub generatedir {
1093       my %args = @_;
1094       my $dir = $args{dir};
1095       my @deps = map { s|\.o$|$objext|; $_ } @{$args{deps}};
1096       my @actions = ();
1097       my %extinfo = ( dso => $dsoext,
1098                       lib => $libext,
1099                       bin => $exeext );
1100
1101       foreach my $type (("dso", "lib", "bin", "script")) {
1102           next unless defined($unified_info{dirinfo}->{$dir}->{products}->{$type});
1103           # For lib object files, we could update the library.  However, it
1104           # was decided that it's enough to build the directory local object
1105           # files, so we don't need to add any actions, and the dependencies
1106           # are already taken care of.
1107           if ($type ne "lib") {
1108               foreach my $prod (@{$unified_info{dirinfo}->{$dir}->{products}->{$type}}) {
1109                   if (dirname($prod) eq $dir) {
1110                       push @deps, $prod.$extinfo{$type};
1111                   } else {
1112                       push @actions, "\t@ : No support to produce $type ".join(", ", @{$unified_info{dirinfo}->{$dir}->{products}->{$type}});
1113                   }
1114               }
1115           }
1116       }
1117
1118       my $deps = join(" ", @deps);
1119       my $actions = join("\n", "", @actions);
1120       return <<"EOF";
1121 $args{dir} $args{dir}/: $deps$actions
1122 EOF
1123   }
1124   ""    # Important!  This becomes part of the template result.
1125 -}