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