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