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