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