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