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