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