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