9e05fd1d5f785decca117b0f2247143ae77c294e
[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         ( b=`pwd`; cd $(SRCDIR); \
678           $(PERL) -I$$b util/mkerr.pl $(ERROR_REBUILD) -internal )
679         ( b=`pwd`; cd $(SRCDIR)/engines; \
680           for E in *.ec ; do \
681               $(PERL) -I$$b ../util/mkerr.pl $(ERROR_REBUILD) -static \
682                 -conf $$E `basename $$E .ec`.c ; \
683           done )
684
685 ordinals:
686         ( b=`pwd`; cd $(SRCDIR); $(PERL) -I$$b util/mkdef.pl crypto update )
687         ( b=`pwd`; cd $(SRCDIR); $(PERL) -I$$b util/mkdef.pl ssl update )
688
689 test_ordinals:
690         ( cd test; \
691           SRCTOP=../$(SRCDIR) \
692           BLDTOP=../$(BLDDIR) \
693             $(PERL) ../$(SRCDIR)/test/run_tests.pl test_ordinals )
694
695 tags TAGS: FORCE
696         rm -f TAGS tags
697         -ctags -R .
698         -etags `find . -name '*.[ch]' -o -name '*.pm'`
699
700 # Release targets (note: only available on Unix) #####################
701
702 # If your tar command doesn't support --owner and --group, make sure to
703 # use one that does, for example GNU tar
704 TAR_COMMAND=$(TAR) $(TARFLAGS) --owner 0 --group 0 -cvf -
705 PREPARE_CMD=:
706 tar:
707         set -e; \
708         TMPDIR=/var/tmp/openssl-copy.$$$$; \
709         DISTDIR=$(NAME); \
710         mkdir -p $$TMPDIR/$$DISTDIR; \
711         (cd $(SRCDIR); \
712          excl_re=`git submodule status | sed -e 's/^.//' | cut -d' ' -f2`; \
713          excl_re="^(fuzz/corpora|`echo $$excl_re | sed -e 's/ /$$|/g'`\$$)"; \
714          echo "$$excl_re"; \
715          git ls-tree -r --name-only --full-tree HEAD \
716          | egrep -v "$$excl_re" \
717          | while read F; do \
718                mkdir -p $$TMPDIR/$$DISTDIR/`dirname $$F`; \
719                cp $$F $$TMPDIR/$$DISTDIR/$$F; \
720            done); \
721         (cd $$TMPDIR/$$DISTDIR; \
722          $(PREPARE_CMD); \
723          find . -type d -print | xargs chmod 755; \
724          find . -type f -print | xargs chmod a+r; \
725          find . -type f -perm -0100 -print | xargs chmod a+x); \
726         (cd $$TMPDIR; $(TAR_COMMAND) $$DISTDIR) \
727         | (cd $(SRCDIR); gzip --best > $(TARFILE).gz); \
728         rm -rf $$TMPDIR
729         cd $(SRCDIR); ls -l $(TARFILE).gz
730
731 dist:
732         @$(MAKE) PREPARE_CMD='$(PERL) ./Configure dist' TARFILE="$(TARFILE)" NAME="$(NAME)" tar
733
734 # Helper targets #####################################################
735
736 link-utils: $(BLDDIR)/util/opensslwrap.sh
737
738 $(BLDDIR)/util/opensslwrap.sh: configdata.pm
739         @if [ "$(SRCDIR)" != "$(BLDDIR)" ]; then \
740             mkdir -p "$(BLDDIR)/util"; \
741             ln -sf "../$(SRCDIR)/util/opensslwrap.sh" "$(BLDDIR)/util"; \
742         fi
743
744 FORCE:
745
746 # Building targets ###################################################
747
748 libcrypto.pc libssl.pc openssl.pc: configdata.pm $(LIBS) {- join(" ",map { shlib_simple($_) } @{$unified_info{libraries}}) -}
749 libcrypto.pc:
750         @ ( echo 'prefix=$(INSTALLTOP)'; \
751             echo 'exec_prefix=$${prefix}'; \
752             echo 'libdir=$${exec_prefix}/$(LIBDIR)'; \
753             echo 'includedir=$${prefix}/include'; \
754             echo 'enginesdir=$${libdir}/engines-{- $sover_dirname -}'; \
755             echo ''; \
756             echo 'Name: OpenSSL-libcrypto'; \
757             echo 'Description: OpenSSL cryptography library'; \
758             echo 'Version: '$(VERSION); \
759             echo 'Libs: -L$${libdir} -lcrypto'; \
760             echo 'Libs.private: $(EX_LIBS)'; \
761             echo 'Cflags: -I$${includedir}' ) > libcrypto.pc
762
763 libssl.pc:
764         @ ( echo 'prefix=$(INSTALLTOP)'; \
765             echo 'exec_prefix=$${prefix}'; \
766             echo 'libdir=$${exec_prefix}/$(LIBDIR)'; \
767             echo 'includedir=$${prefix}/include'; \
768             echo ''; \
769             echo 'Name: OpenSSL-libssl'; \
770             echo 'Description: Secure Sockets Layer and cryptography libraries'; \
771             echo 'Version: '$(VERSION); \
772             echo 'Requires.private: libcrypto'; \
773             echo 'Libs: -L$${libdir} -lssl'; \
774             echo 'Cflags: -I$${includedir}' ) > libssl.pc
775
776 openssl.pc:
777         @ ( echo 'prefix=$(INSTALLTOP)'; \
778             echo 'exec_prefix=$${prefix}'; \
779             echo 'libdir=$${exec_prefix}/$(LIBDIR)'; \
780             echo 'includedir=$${prefix}/include'; \
781             echo ''; \
782             echo 'Name: OpenSSL'; \
783             echo 'Description: Secure Sockets Layer and cryptography libraries and tools'; \
784             echo 'Version: '$(VERSION); \
785             echo 'Requires: libssl libcrypto' ) > openssl.pc
786
787 configdata.pm: $(SRCDIR)/Configure $(SRCDIR)/config {- join(" ", @{$config{build_file_templates}}, @{$config{build_infos}}, @{$config{conf_files}}) -}
788         @echo "Detected changed: $?"
789         $(PERL) configdata.pm -r -v
790         @echo "**************************************************"
791         @echo "***                                            ***"
792         @echo "***   Please run the same make command again   ***"
793         @echo "***                                            ***"
794         @echo "**************************************************"
795         @false
796
797 reconfigure reconf:
798         $(PERL) configdata.pm -r -v
799
800 {-
801   use File::Basename;
802   use File::Spec::Functions qw/:DEFAULT abs2rel rel2abs/;
803
804   # Helper function to figure out dependencies on libraries
805   # It takes a list of library names and outputs a list of dependencies
806   sub compute_lib_depends {
807       if ($disabled{shared}) {
808           return map { lib($_) } @_;
809       }
810
811       # Depending on shared libraries:
812       # On Windows POSIX layers, we depend on {libname}.dll.a
813       # On Unix platforms, we depend on {shlibname}.so
814       return map { $_ =~ /\.a$/ ? $`.$libext : shlib_simple($_) } @_;
815   }
816
817   sub generatesrc {
818       my %args = @_;
819       my $generator = join(" ", @{$args{generator}});
820       my $generator_incs = join("", map { " -I".$_ } @{$args{generator_incs}});
821       my $incs = join("", map { " -I".$_ } @{$args{incs}});
822       my $deps = join(" ", @{$args{generator_deps}}, @{$args{deps}});
823
824       if ($args{src} !~ /\.[sS]$/) {
825           if ($args{generator}->[0] =~ m|^.*\.in$|) {
826               my $dofile = abs2rel(rel2abs(catfile($config{sourcedir},
827                                                    "util", "dofile.pl")),
828                                    rel2abs($config{builddir}));
829               return <<"EOF";
830 $args{src}: $args{generator}->[0] $deps
831         \$(PERL) "-I\$(BLDDIR)" -Mconfigdata "$dofile" \\
832             "-o$target{build_file}" $generator > \$@
833 EOF
834           } else {
835               return <<"EOF";
836 $args{src}: $args{generator}->[0] $deps
837         \$(PERL)$generator_incs $generator > \$@
838 EOF
839           }
840       } else {
841           if ($args{generator}->[0] =~ /\.pl$/) {
842               $generator = 'CC="$(CC)" $(PERL)'.$generator_incs.' '.$generator;
843           } elsif ($args{generator}->[0] =~ /\.m4$/) {
844               $generator = 'm4 -B 8192'.$generator_incs.' '.$generator.' >'
845           } elsif ($args{generator}->[0] =~ /\.S$/) {
846               $generator = undef;
847           } else {
848               die "Generator type for $args{src} unknown: $generator\n";
849           }
850
851           if (defined($generator)) {
852               # If the target is named foo.S in build.info, we want to
853               # end up generating foo.s in two steps.
854               if ($args{src} =~ /\.S$/) {
855                    (my $target = $args{src}) =~ s|\.S$|.s|;
856                    return <<"EOF";
857 $target: $args{generator}->[0] $deps
858         ( trap "rm -f \$@.*" INT 0; \\
859           $generator \$@.S; \\
860           \$(CC) $incs \$(CFLAGS) \$(CPPFLAGS) -E \$@.S | \\
861           \$(PERL) -ne '/^#(line)?\\s*[0-9]+/ or print' > \$@.i && \\
862           mv -f \$@.i \$@ )
863 EOF
864               }
865               # Otherwise....
866               return <<"EOF";
867 $args{src}: $args{generator}->[0] $deps
868         $generator \$@
869 EOF
870           }
871           return <<"EOF";
872 $args{src}: $args{generator}->[0] $deps
873         \$(CC) $incs \$(CFLAGS) \$(CPPFLAGS) -E $args{generator}->[0] | \\
874         \$(PERL) -ne '/^#(line)?\\s*[0-9]+/ or print' > \$@
875 EOF
876       }
877   }
878
879   # Should one wonder about the end of the Perl snippet, it's because this
880   # second regexp eats up line endings as well, if the removed path is the
881   # last in the line.  We may therefore need to put back a line ending.
882   sub src2obj {
883       my %args = @_;
884       (my $obj = $args{obj}) =~ s|\.o$||;
885       my @srcs = map { if ($unified_info{generate}->{$_}) {
886                            (my $x = $_) =~ s/\.S$/.s/; $x
887                        } else {
888                            $_
889                        }
890                      } ( @{$args{srcs}} );
891       my $srcs = join(" ",  @srcs);
892       my $deps = join(" ", @srcs, @{$args{deps}});
893       my $incs = join("", map { " -I".$_ } @{$args{incs}});
894       unless ($disabled{zlib}) {
895           if ($withargs{zlib_include}) {
896               $incs .= " -I".$withargs{zlib_include};
897           }
898       }
899       my $cmd = '$(CC)';
900       my $cmdflags = '$(CFLAGS)';
901       my $cmdcompile = ' -c';
902       my $makedepprog = $disabled{makedepend} ? undef : $config{makedepprog};
903       if (grep /\.rc$/, @srcs) {
904           $cmd = '$(RC)';
905           $cmdflags = '$(RCFLAGS)';
906           $cmdcompile = '';
907           $makedepprog = undef;
908       } elsif (grep /\.(cc|cpp)$/, @srcs) {
909           $cmd = '$(CXX)';
910           $cmdflags = '$(CXXFLAGS)';
911           $cmdflags .= ' ' . { lib => '$(LIB_CXXFLAGS)',
912                                dso => '$(DSO_CXXFLAGS)',
913                                bin => '$(BIN_CXXFLAGS)' } -> {$args{intent}};
914           $cmdflags .= ' $(CPPFLAGS)';
915           $cmdflags .= ' ' . { lib => '$(LIB_CPPFLAGS)',
916                                dso => '$(DSO_CPPFLAGS)',
917                                bin => '$(BIN_CPPFLAGS)' } -> {$args{intent}};
918       } else {
919           $cmdflags .= ' ' . { lib => '$(LIB_CFLAGS)',
920                                dso => '$(DSO_CFLAGS)',
921                                bin => '$(BIN_CFLAGS)' } -> {$args{intent}};
922           $cmdflags .= ' $(CPPFLAGS)';
923           $cmdflags .= ' ' . { lib => '$(LIB_CPPFLAGS)',
924                                dso => '$(DSO_CPPFLAGS)',
925                                bin => '$(BIN_CPPFLAGS)' } -> {$args{intent}};
926       }
927       $cmdflags .= $cmdcompile;
928       my $recipe = <<"EOF";
929 $obj$objext: $deps
930 EOF
931       if (defined $makedepprog && $makedepprog !~ /\/makedepend/) {
932           $recipe .= <<"EOF";
933         $cmd $incs $cmdflags -MMD -MF $obj$depext.tmp -MT \$\@ -c -o \$\@ $srcs
934         \@touch $obj$depext.tmp
935         \@if cmp $obj$depext.tmp $obj$depext > /dev/null 2> /dev/null; then \\
936                 rm -f $obj$depext.tmp; \\
937         else \\
938                 mv $obj$depext.tmp $obj$depext; \\
939         fi
940 EOF
941       } else {
942           $recipe .= <<"EOF";
943         $cmd $incs $cmdflags -o \$\@ $srcs
944 EOF
945           if (defined $makedepprog  && $makedepprog =~ /\/makedepend/) {
946               $recipe .= <<"EOF";
947         -\$(MAKEDEPEND) -f- -o"|\$\@" -- $incs $cmdflags -- $srcs \\
948             >$obj$depext.tmp 2>/dev/null
949         -\$(PERL) -i -pe 's/^.*\\|//; s/ \\/(\\\\.|[^ ])*//; \$\$_ = undef if (/: *\$\$/ || /^(#.*| *)\$\$/); \$\$_.="\\n" unless !defined(\$\$_) or /\\R\$\$/g;' $obj$depext.tmp
950         \@if cmp $obj$depext.tmp $obj$depext > /dev/null 2> /dev/null; then \\
951                 rm -f $obj$depext.tmp; \\
952         else \\
953                 mv $obj$depext.tmp $obj$depext; \\
954         fi
955 EOF
956           }
957       }
958       return $recipe;
959   }
960   # On Unix, we build shlibs from static libs, so we're ignoring the
961   # object file array.  We *know* this routine is only called when we've
962   # configure 'shared'.
963   sub libobj2shlib {
964       my %args = @_;
965       my $lib = $args{lib};
966       my $shlib = $args{shlib};
967       my $libd = dirname($lib);
968       my $libn = basename($lib);
969       (my $libname = $libn) =~ s/^lib//;
970       my @linkdirs = ();
971       foreach (@{args{deps}}) {
972           my $d = dirname($_);
973           push @linkdirs, $d unless grep { $d eq $_ } @linkdirs;
974       }
975       my $linkflags = join("", map { "-L$_ " } @linkdirs);
976       my $linklibs = join("", map { my $f = basename($_);
977                                     (my $l = $f) =~ s/^lib//;
978                                     " -l$l" } @{$args{deps}});
979       my @objs = map { (my $x = $_) =~ s|\.o$|$objext|; $x }
980                  grep { $_ =~ m|\.o$| }
981                  @{$args{objs}};
982       my @defs = grep { $_ =~ /\.(def|map)$/ } @{$args{objs}};
983       my @deps = compute_lib_depends(@{$args{deps}});
984       die "More than one exported symbol map" if scalar @defs > 1;
985       my $objs = join(" ", @objs);
986       my $deps = join(" ", @objs, @defs, @deps);
987       my $target = shlib_simple($lib);
988       my $target_full = shlib($lib);
989       my $shared_soname = "";
990       $shared_soname .= ' '.$target{shared_sonameflag}.basename($target_full)
991           if defined $target{shared_sonameflag};
992       my $shared_imp = "";
993       $shared_imp .= ' '.$target{shared_impflag}.basename($target)
994           if defined $target{shared_impflag};
995       my $shared_def = join("", map { ' '.$target{shared_defflag}.$_ } @defs);
996       my $recipe = <<"EOF";
997 # When building on a Windows POSIX layer (Cygwin or Mingw), we know for a fact
998 # that two files get produced, {shlibname}.dll and {libname}.dll.a.
999 # With all other Unix platforms, we often build a shared library with the
1000 # SO version built into the file name and a symlink without the SO version
1001 # It's not necessary to have both as targets.  The choice falls on the
1002 # simplest, {libname}\$(SHLIB_EXT_IMPORT) for Windows POSIX layers and
1003 # {libname}\$(SHLIB_EXT_SIMPLE) for the Unix platforms.
1004 $target: $deps
1005         \$(CC) \$(CFLAGS) \$(LIB_CFLAGS) $linkflags\$(LIB_LDFLAGS)$shared_soname$shared_imp \\
1006                 -o $target_full$shared_def $objs \\
1007                 \$(PLIB_LDFLAGS) $linklibs \$(EX_LIBS)
1008 EOF
1009       if (windowsdll()) {
1010           $recipe .= <<"EOF";
1011         rm -f apps/$shlib'\$(SHLIB_EXT)'
1012         rm -f test/$shlib'\$(SHLIB_EXT)'
1013         rm -f fuzz/$shlib'\$(SHLIB_EXT)'
1014         cp -p $shlib'\$(SHLIB_EXT)' apps/
1015         cp -p $shlib'\$(SHLIB_EXT)' test/
1016         cp -p $shlib'\$(SHLIB_EXT)' fuzz/
1017 EOF
1018       } else {
1019           $recipe .= <<"EOF";
1020         if [ '$target' != '$target_full' ]; then \\
1021                 rm -f $target; \\
1022                 ln -s $target_full $target; \\
1023         fi
1024 EOF
1025       }
1026   }
1027   sub obj2dso {
1028       my %args = @_;
1029       my $dso = $args{lib};
1030       my $dsod = dirname($dso);
1031       my $dson = basename($dso);
1032       my @linkdirs = ();
1033       foreach (@{args{deps}}) {
1034           my $d = dirname($_);
1035           push @linkdirs, $d unless grep { $d eq $_ } @linkdirs;
1036       }
1037       my $linkflags = join("", map { "-L$_ " } @linkdirs);
1038       my $linklibs = join("", map { my $f = basename($_);
1039                                     (my $l = $f) =~ s/^lib//;
1040                                     " -l$l" } @{$args{deps}});
1041       my @objs = map { (my $x = $_) =~ s|\.o$|$objext|; $x } @{$args{objs}};
1042       my @deps = compute_lib_depends(@{$args{deps}});
1043       my $objs = join(" ", @objs);
1044       my $deps = join(" ", @deps);
1045       my $target = dso($dso);
1046       return <<"EOF";
1047 $target: $objs $deps
1048         \$(CC) \$(CFLAGS) \$(DSO_CFLAGS) $linkflags\$(DSO_LDFLAGS) \\
1049                 -o $target $objs \\
1050                 \$(PLIB_LDFLAGS) $linklibs \$(EX_LIBS)
1051 EOF
1052   }
1053   sub obj2lib {
1054       my %args = @_;
1055       (my $lib = $args{lib}) =~ s/\.a$//;
1056       my @objs = map { (my $x = $_) =~ s|\.o$|$objext|; $x } @{$args{objs}};
1057       my $objs = join(" ", @objs);
1058       return <<"EOF";
1059 $lib$libext: $objs
1060         \$(AR) \$(ARFLAGS) \$\@ \$\?
1061         \$(RANLIB) \$\@ || echo Never mind.
1062 EOF
1063   }
1064   sub obj2bin {
1065       my %args = @_;
1066       my $bin = $args{bin};
1067       my $bind = dirname($bin);
1068       my $binn = basename($bin);
1069       my $objs = join(" ", map { (my $x = $_) =~ s|\.o$|$objext|; $x }
1070                            @{$args{objs}});
1071       my $deps = join(" ",compute_lib_depends(@{$args{deps}}));
1072       my @linkdirs = ();
1073       foreach (@{args{deps}}) {
1074           next if $_ =~ /\.a$/;
1075           my $d = dirname($_);
1076           push @linkdirs, $d unless grep { $d eq $_ } @linkdirs;
1077       }
1078       my $linkflags = join("", map { "-L$_ " } @linkdirs);
1079       my $linklibs = join("", map { if ($_ =~ /\.a$/) {
1080                                         " $_";
1081                                     } else {
1082                                         my $f = basename($_);
1083                                         (my $l = $f) =~ s/^lib//;
1084                                         " -l$l"
1085                                     }
1086                                   } @{$args{deps}});
1087       my $cmd = '$(CC)';
1088       my $cmdflags = '$(CFLAGS) $(BIN_CFLAGS)';
1089       if (grep /_cc\.o$/, @{$args{objs}}) {
1090           $cmd = '$(CXX)';
1091           $cmdflags = '$(CXXFLAGS) $(BIN_CXXFLAGS)';
1092       }
1093       return <<"EOF";
1094 $bin$exeext: $objs $deps
1095         rm -f $bin$exeext
1096         \$\${LDCMD:-$cmd} $cmdflags $linkflags\$(LDFLAGS) \$(BIN_LDFLAGS) \\
1097                 -o $bin$exeext $objs \\
1098                 \$(PLIB_LDFLAGS) $linklibs \$(EX_LIBS)
1099 EOF
1100   }
1101   sub in2script {
1102       my %args = @_;
1103       my $script = $args{script};
1104       my $sources = join(" ", @{$args{sources}});
1105       my $dofile = abs2rel(rel2abs(catfile($config{sourcedir},
1106                                            "util", "dofile.pl")),
1107                            rel2abs($config{builddir}));
1108       return <<"EOF";
1109 $script: $sources
1110         \$(PERL) "-I\$(BLDDIR)" -Mconfigdata "$dofile" \\
1111             "-o$target{build_file}" $sources > "$script"
1112         chmod a+x $script
1113 EOF
1114   }
1115   sub generatedir {
1116       my %args = @_;
1117       my $dir = $args{dir};
1118       my @deps = map { s|\.o$|$objext|; $_ } @{$args{deps}};
1119       my @actions = ();
1120       my %extinfo = ( dso => $dsoext,
1121                       lib => $libext,
1122                       bin => $exeext );
1123
1124       foreach my $type (("dso", "lib", "bin", "script")) {
1125           next unless defined($unified_info{dirinfo}->{$dir}->{products}->{$type});
1126           # For lib object files, we could update the library.  However, it
1127           # was decided that it's enough to build the directory local object
1128           # files, so we don't need to add any actions, and the dependencies
1129           # are already taken care of.
1130           if ($type ne "lib") {
1131               foreach my $prod (@{$unified_info{dirinfo}->{$dir}->{products}->{$type}}) {
1132                   if (dirname($prod) eq $dir) {
1133                       push @deps, $prod.$extinfo{$type};
1134                   } else {
1135                       push @actions, "\t@ : No support to produce $type ".join(", ", @{$unified_info{dirinfo}->{$dir}->{products}->{$type}});
1136                   }
1137               }
1138           }
1139       }
1140
1141       my $deps = join(" ", @deps);
1142       my $actions = join("\n", "", @actions);
1143       return <<"EOF";
1144 $args{dir} $args{dir}/: $deps$actions
1145 EOF
1146   }
1147   ""    # Important!  This becomes part of the template result.
1148 -}