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