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