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