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