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