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