5e9e10bcad6c0574f1ceb03494efea22b2076129
[openssl.git] / Configurations / unix-Makefile.tmpl
1 ##
2 ## Makefile for OpenSSL
3 ##
4 ## {- join("\n## ", @autowarntext) -}
5 {-
6      sub windowsdll { $config{target} =~ /^(?:Cygwin|mingw)/ }
7      sub shlib_ext { $target{shared_extension} || ".so" }
8      sub shlib_ext_simple { (my $x = $target{shared_extension})
9                                 =~ s/\.\$\(SHLIB_MAJOR\)\.\$\(SHLIB_MINOR\)//;
10                             $x }
11 -}
12 PLATFORM={- $config{target} -}
13 OPTIONS={- $config{options} -}
14 CONFIGURE_ARGS=({- join(", ",quotify_l(@{$config{perlargv}})) -})
15 SRCDIR={- $config{sourcedir} -}
16 BLDDIR={- $config{builddir} -}
17
18 VERSION={- $config{version} -}
19 MAJOR={- $config{major} -}
20 MINOR={- $config{minor} -}
21 SHLIB_VERSION_NUMBER={- $config{shlib_version_number} -}
22 SHLIB_VERSION_HISTORY={- $config{shlib_version_history} -}
23 SHLIB_MAJOR={- $config{shlib_major} -}
24 SHLIB_MINOR={- $config{shlib_minor} -}
25 SHLIB_TARGET={- $target{shared_target} -}
26
27 EXE_EXT={- $target{exe_extension} || "" -}
28 LIB_EXT={- $target{lib_extension} || ".a" -}
29 SHLIB_EXT={- shlib_ext() -}
30 SHLIB_EXT_SIMPLE={- shlib_ext_simple() -}
31 OBJ_EXT={- $target{obj_extension} || ".o" -}
32 DEP_EXT={- $target{dep_extension} || ".d" -}
33
34 LIBS={- join(" ", map { $_."\$(LIB_EXT)" } @{$unified_info{libraries}}) -}
35 SHLIBS={- join(" ", map { $_."\$(SHLIB_EXT)" } map { $unified_info{sharednames}->{$_} || () } @{$unified_info{libraries}}) -}
36 ENGINES={- join(" ", map { $_."\$(SHLIB_EXT_SIMPLE)" } @{$unified_info{engines}}) -}
37 PROGRAMS={- join(" ", map { $_."\$(EXE_EXT)" } grep { !m|^test/| } @{$unified_info{programs}}) -}
38 TESTPROGS={- join(" ", map { $_."\$(EXE_EXT)" } grep { m|^test/| } @{$unified_info{programs}}) -}
39 SCRIPTS={- join(" ", @{$unified_info{scripts}}) -}
40 BIN_SCRIPTS=$(BLDDIR)/tools/c_rehash
41 MISC_SCRIPTS=$(SRCDIR)/tools/c_hash $(SRCDIR)/tools/c_info \
42              $(SRCDIR)/tools/c_issuer $(SRCDIR)/tools/c_name \
43              $(BLDDIR)/apps/CA.pl $(SRCDIR)/apps/tsget
44
45 # INSTALL_PREFIX is for package builders so that they can configure
46 # for, say, /usr/ and yet have everything installed to /tmp/somedir/usr/.
47 # Normally it is left empty.
48 INSTALL_PREFIX={- $config{install_prefix} -}
49
50 # Do not edit these manually. Use Configure with --prefix or --openssldir
51 # to change this!  Short explanation in the top comment in Configure
52 INSTALLTOP={- # $prefix is used in the OPENSSLDIR perl snippet
53               #
54               our $prefix = $config{prefix} || "/usr/local";
55               $prefix -}
56 OPENSSLDIR={- #
57               # The logic here is that if no --openssldir was given,
58               # OPENSSLDIR will get the value from $prefix plus "/ssl".
59               # If --openssldir was given and the value is an absolute
60               # path, OPENSSLDIR will get its value without change.
61               # If the value from --openssldir is a relative path,
62               # OPENSSLDIR will get $prefix with the --openssldir
63               # value appended as a subdirectory.
64               #
65               use File::Spec::Functions;
66               our $openssldir =
67                   $config{openssldir} ?
68                       (file_name_is_absolute($config{openssldir}) ?
69                            $config{openssldir}
70                            : catdir($prefix, $config{openssldir}))
71                       : catdir($prefix, "ssl");
72               $openssldir -}
73 LIBDIR={- #
74           # if $prefix/lib$target{multilib} is not an existing
75           # directory, then assume that it's not searched by linker
76           # automatically, in which case adding $target{multilib} suffix
77           # causes more grief than we're ready to tolerate, so don't...
78           our $multilib =
79               -d "$prefix/lib$target{multilib}" ? $target{multilib} : "";
80           our $libdir = $config{libdir} || "lib$multilib";
81           $libdir -}
82 ENGINESDIR={- use File::Spec::Functions;
83               catdir($prefix,$libdir,"engines") -}
84
85 MANDIR=$(OPENSSLDIR)/man
86 HTMLDIR=$(OPENSSLDIR)/html
87
88 MANSUFFIX=ssl
89 HTMLSUFFIX=html
90
91
92
93 CROSS_COMPILE= {- $config{cross_compile_prefix} -}
94 CC= $(CROSS_COMPILE){- $target{cc} -}
95 CFLAGS={- join(" ",(map { "-D".$_} @{$config{defines}}),"-DOPENSSLDIR=\"\\\"\$(OPENSSLDIR)\\\"\"","-DENGINESDIR=\"\\\"\$(ENGINESDIR)\\\"\"") -} {- $config{cflags} -}
96 DEPFLAGS= {- join(" ",map { "-D".$_} @{$config{depdefines}}) -}
97 LDFLAGS= {- $config{lflags} -}
98 PLIB_LDFLAGS= {- $config{plib_lflags} -}
99 EX_LIBS= {- $config{ex_libs} -}
100 SHARED_LDFLAGS={- $target{shared_ldflag}
101                   # Unlike other OSes (like Solaris, Linux, Tru64,
102                   # IRIX) BSD run-time linkers (tested OpenBSD, NetBSD
103                   # and FreeBSD) "demand" RPATH set on .so objects.
104                   # Apparently application RPATH is not global and
105                   # does not apply to .so linked with other .so.
106                   # Problem manifests itself when libssl.so fails to
107                   # load libcrypto.so. One can argue that we should
108                   # engrave this into Makefile.shared rules or into
109                   # BSD-* config lines above. Meanwhile let's try to
110                   # be cautious and pass -rpath to linker only when
111                   # $prefix is not /usr.
112                   . ($config{target} =~ m|^BSD-| && $prefix !~ m|^/usr/.*$|
113                      ? " -Wl,-rpath,\$\$(LIBRPATH)" : "") -}
114
115 PERL={- $config{perl} -}
116
117 ARFLAGS= {- $target{arflags} -}
118 AR=$(CROSS_COMPILE){- $target{ar} || "ar" -} $(ARFLAGS) r
119 RANLIB= {- $target{ranlib} -}
120 NM= $(CROSS_COMPILE){- $target{nm} || "nm" -}
121 RM= rm -f
122 TAR= {- $target{tar} || "tar" -}
123 TARFLAGS= {- $target{tarflags} -}
124
125 BASENAME=       openssl
126 NAME=           $(BASENAME)-$(VERSION)
127 TARFILE=        ../$(NAME).tar
128
129 # We let the C compiler driver to take care of .s files. This is done in
130 # order to be excused from maintaining a separate set of architecture
131 # dependent assembler flags. E.g. if you throw -mcpu=ultrasparc at SPARC
132 # gcc, then the driver will automatically translate it to -xarch=v8plus
133 # and pass it down to assembler.
134 AS=$(CC) -c
135 ASFLAG=$(CFLAGS)
136 PERLASM_SCHEME= {- $target{perlasm_scheme} -}
137
138 # For x86 assembler: Set PROCESSOR to 386 if you want to support
139 # the 80386.
140 PROCESSOR= {- $config{processor} -}
141
142 # The main targets ###################################################
143
144 all: Makefile libcrypto.pc libssl.pc openssl.pc $(ENGINES) $(PROGRAMS) $(SCRIPTS) $(TESTPROGS)
145
146 test tests: $(TESTPROGS) rehash
147         ( cd test; \
148           SRCTOP=../$(SRCDIR) \
149           BLDTOP=../$(BLDDIR) \
150             $(PERL) ../$(SRCDIR)/test/run_tests.pl $(TESTS) )
151
152 list-tests:
153         @TOP=$(SRCDIR) PERL=$(PERL) $(PERL) $(SRCDIR)/test/run_tests.pl list
154
155 libclean:
156         -rm -f `find $(BLDDIR) -name '*$(LIB_EXT)' -o -name '*$(SHLIB_EXT)'`
157
158 install: install_sw install_docs
159
160 uninstall: uninstall_docs uninstall_sw
161
162 clean: libclean
163         rm -f $(PROGRAMS) $(TESTPROGS)
164         rm -f `find $(BLDDIR) -name '*$(DEP_EXT)'`
165         rm -f `find $(BLDDIR) -name '*$(OBJ_EXT)'`
166         rm -f $(BLDDIR)/core $(BLDDIR)/rehash.time
167         rm -f $(BLDDIR)/tags $(BLDDIR)/TAGS
168         rm -f $(BLDDIR)/openssl.pc $(BLDDIR)/libcrypto.pc $(BLDDIR)/libssl.pc
169         -rm -f `find $(BLDDIR) -type l`
170         rm -f $(TARFILE)
171
172 DCLEAN_CMD=sed -e '/^DO NOT DELETE.*/,$$d'
173 dclean:
174         $(DCLEAN_CMD) < Makefile >Makefile.new
175         mv -f Makefile.new Makefile
176
177 DEPS={- join(" ", map { (my $x = $_) =~ s|\.o$|\$(DEP_EXT)|; $x; }
178                   grep { $unified_info{sources}->{$_}->[0] =~ /\.c$/ }
179                   keys %{$unified_info{sources}}); -}
180 depend: $(DEPS)
181         ( $(DCLEAN_CMD) < Makefile; \
182           echo '# DO NOT DELETE THIS LINE -- make depend depends on it.'; \
183           echo; \
184           cat `find . -name '*$(DEP_EXT)'` ) > Makefile.new
185         mv -f Makefile.new Makefile
186
187 # Install helper targets #############################################
188
189 install_sw: all install_dev install_engines install_runtime
190
191 uninstall_sw: uninstall_dev uninstall_engines uninstall_runtime
192
193 install_docs: install_man_docs install_html_docs
194
195 uninstall_docs: uninstall_man_docs uninstall_html_docs
196
197 install_dev:
198         @[ -n "$(INSTALLTOP)" ] || (echo INSTALLTOP should not be empty; exit 1)
199         @echo "*** Installing development files"
200         @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl
201         @set -e; for i in $(SRCDIR)/include/openssl/*.h \
202                           $(BLDDIR)/include/openssl/*.h; do \
203                 fn=`basename $$i`; \
204                 echo "install $$i -> $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$fn"; \
205                 cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$fn; \
206                 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$fn; \
207         done
208         @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)
209         @set -e; for l in $(LIBS); do \
210                 fn=`basename $$l`; \
211                 echo "install $$l -> $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/$$fn"; \
212                 cp $$l $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/$$fn.new; \
213                 $(RANLIB) $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/$$fn.new; \
214                 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/$$fn.new; \
215                 mv -f $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/$$fn.new \
216                       $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/$$fn; \
217         done
218         @ : {- output_off() if $config{no_shared}; "" -}
219         @set -e; for s in $(SHLIBS); do \
220                 fn=`basename $$s`; \
221                 echo "install $$s -> $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/$$fn"; \
222                 cp $$s $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/$$fn.new; \
223                 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/$$fn.new; \
224                 mv -f $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/$$fn.new \
225                       $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/$$fn; \
226                 if [ "$(SHLIB_EXT)" != "$(SHLIB_EXT_SIMPLE)" ]; then \
227                         echo "link $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/$$fn2 -> $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/$$fn"; \
228                         fn2=`basename $$fn $(SHLIB_EXT)`$(SHLIB_EXT_SIMPLE); \
229                         ln -sf $$fn $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/$$fn2; \
230                 fi; \
231         done
232         @ : {- output_on() -}
233         @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/pkgconfig
234         @echo "install libcrypto.pc -> $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/libcrypto.pc"
235         @cp libcrypto.pc $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/pkgconfig
236         @chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/libcrypto.pc
237         @echo "install libssl.pc -> $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/libssl.pc"
238         @cp libssl.pc $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/pkgconfig
239         @chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/libssl.pc
240         @echo "install openssl.pc -> $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/openssl.pc"
241         @cp openssl.pc $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/pkgconfig
242         @chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/openssl.pc
243
244 uninstall_dev:
245         @echo "*** Uninstalling development files"
246         @set -e; for i in $(SRCDIR)/include/openssl/*.h \
247                           $(BLDDIR)/include/openssl/*.h; do \
248                 fn=`basename $$i`; \
249                 echo "$(RM) $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$fn"; \
250                 $(RM) $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$fn; \
251         done
252         @set -e; for l in $(LIBS); do \
253                 fn=`basename $$l`; \
254                 echo "$(RM) $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/$$fn"; \
255                 $(RM) $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/$$fn; \
256         done
257         @set -e; for s in $(SHLIBS); do \
258                 fn=`basename $$s`; \
259                 if [ "$(SHLIB_EXT)" != "$(SHLIB_EXT_SIMPLE)" ]; then \
260                         fn2=`basename $$fn $(SHLIB_EXT)`$(SHLIB_EXT_SIMPLE); \
261                         echo "$(RM) $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/$$fn2"; \
262                         $(RM) $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/$$fn2; \
263                 fi; \
264                 echo "$(RM) $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/$$fn"; \
265                 $(RM) $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/$$fn; \
266         done
267         @echo "$(RM) $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/libcrypto.pc"
268         @$(RM) $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/libcrypto.pc
269         @echo "$(RM) $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/libssl.pc"
270         @$(RM) $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/libssl.pc
271         @echo "$(RM) $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/openssl.pc"
272         @$(RM) $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/openssl.pc
273
274 install_engines:
275         @[ -n "$(INSTALLTOP)" ] || (echo INSTALLTOP should not be empty; exit 1)
276         @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/engines/
277         @echo "*** Installing engines"
278         @set -e; for e in $(ENGINES); do \
279                 fn=`basename $$e`; \
280                 echo "install $$e -> $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$fn"; \
281                 cp $$e $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/engines/$$fn.new; \
282                 chmod 755 $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/engines/$$fn.new; \
283                 mv -f $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/engines/$$fn.new \
284                       $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/engines/$$fn; \
285         done
286
287 uninstall_engines:
288         @echo "*** Uninstalling engines"
289         @set -e; for e in $(ENGINES); do \
290                 fn=`basename $$e`; \
291                 echo "$(RM) $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$fn"; \
292                 $(RM) $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/engines/$$fn; \
293         done
294
295 install_runtime:
296         @[ -n "$(INSTALLTOP)" ] || (echo INSTALLTOP should not be empty; exit 1)
297         @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(INSTALL_PREFIX)$(INSTALLTOP)/bin
298         @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(INSTALL_PREFIX)$(OPENSSLDIR)/misc
299         @echo "*** Installing runtime files"
300         @set -e; for x in $(PROGRAMS); do \
301                 fn=`basename $$x`; \
302                 echo "install $$x -> $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$fn"; \
303                 cp $$x $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$fn.new; \
304                 chmod 755 $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$fn.new; \
305                 mv -f $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$fn.new \
306                       $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$fn; \
307         done
308         @set -e; for x in $(BIN_SCRIPTS); do \
309                 fn=`basename $$x`; \
310                 echo "install $$x -> $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$fn"; \
311                 cp $$x $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$fn.new; \
312                 chmod 755 $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$fn.new; \
313                 mv -f $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$fn.new \
314                       $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$fn; \
315         done
316         @set -e; for x in $(MISC_SCRIPTS); do \
317                 fn=`basename $$x`; \
318                 echo "install $$x -> $(INSTALL_PREFIX)$(OPENSSLDIR)/misc/$$fn"; \
319                 cp $$x $(INSTALL_PREFIX)$(OPENSSLDIR)/misc/$$fn.new; \
320                 chmod 755 $(INSTALL_PREFIX)$(OPENSSLDIR)/misc/$$fn.new; \
321                 mv -f $(INSTALL_PREFIX)$(OPENSSLDIR)/misc/$$fn.new \
322                       $(INSTALL_PREFIX)$(OPENSSLDIR)/misc/$$fn; \
323         done
324         @echo "install $(SRCDIR)/apps/openssl.cnf -> $(INSTALL_PREFIX)$(OPENSSLDIR)/openssl.cnf"
325         @cp $(SRCDIR)/apps/openssl.cnf $(INSTALL_PREFIX)$(OPENSSLDIR)/openssl.cnf.new
326         @chmod 644 $(INSTALL_PREFIX)$(OPENSSLDIR)/openssl.cnf.new
327         @mv -f  $(INSTALL_PREFIX)$(OPENSSLDIR)/openssl.cnf.new $(INSTALL_PREFIX)$(OPENSSLDIR)/openssl.cnf
328
329 uninstall_runtime:
330         @echo "*** Uninstalling runtime files"
331         @set -e; for x in $(PROGRAMS); \
332         do  \
333                 fn=`basename $$x`; \
334                 echo "$(RM) $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$fn"; \
335                 $(RM) $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$fn; \
336         done;
337         @set -e; for x in $(BIN_SCRIPTS); \
338         do  \
339                 fn=`basename $$x`; \
340                 echo "$(RM) $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$fn"; \
341                 $(RM) $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$fn; \
342         done
343         @set -e; for x in $(MISC_SCRIPTS); \
344         do  \
345                 fn=`basename $$x`; \
346                 echo "$(RM) $(INSTALL_PREFIX)$(OPENSSLDIR)/misc/$$fn"; \
347                 $(RM) $(INSTALL_PREFIX)$(OPENSSLDIR)/misc/$$fn; \
348         done
349         $(RM) $(INSTALL_PREFIX)$(OPENSSLDIR)/openssl.cnf
350
351 # A method to extract all names from a .pod file
352 # The first sed extracts everything between "=head1 NAME" and the next =head1
353 # The second sed joins all the lines into one
354 # The third sed removes the description and turns all commas into spaces
355 # VoilĂ , you have a space separated list of names!
356 EXTRACT_NAMES=sed -e '1,/^=head1  *NAME *$$/d;/^=head1/,$$d' | \
357               sed -e ':a;{N;s/\n/ /;ba}' | \
358               sed -e 's/ - .*$$//;s/,/ /g'
359 PROCESS_PODS=\
360         set -e; \
361         here=`cd $(SRCDIR); pwd`; \
362         point=$$here/util/point.sh; \
363         for ds in apps:1 crypto:3 ssl:3; do \
364             defdir=`echo $$ds | cut -f1 -d:`; \
365             defsec=`echo $$ds | cut -f2 -d:`; \
366             for p in $(SRCDIR)/doc/$$defdir/*.pod; do \
367                 SEC=`sed -ne 's/^=for  *comment  *openssl_manual_section: *\([0-9]\) *$$/\1/p' $$p`; \
368                 [ -z "$$SEC" ] && SEC=$$defsec; \
369                 fn=`basename $$p .pod`; \
370                 NAME=`echo $$fn | tr [a-z] [A-Z]`; \
371                 suf=`eval "echo $$OUTSUFFIX"`; \
372                 top=`eval "echo $$OUTTOP"`; \
373                 $(PERL) $(SRCDIR)/util/mkdir-p.pl $$top/man$$SEC; \
374                 echo "install $$p -> $$top/man$$SEC/$$fn$$suf"; \
375                 cat $$p | eval "$$GENERATE" \
376                         >  $$top/man$$SEC/$$fn$$suf; \
377                 names=`cat $$p | $(EXTRACT_NAMES)`; \
378                 ( cd $$top/man$$SEC; \
379                   for n in $$names; do \
380                       if [ "$$n" != "$$fn" ]; then \
381                           echo "link $$top/man$$SEC/$$n$$suf -> $$top/man$$SEC/$$fn$$suf"; \
382                           PLATFORM=$(PLATFORM) $$point $$fn$$suf $$n$$suf; \
383                       fi; \
384                   done ); \
385             done; \
386         done
387 UNINSTALL_DOCS=\
388         set -e; \
389         here=`cd $(SRCDIR); pwd`; \
390         for ds in apps:1 crypto:3 ssl:3; do \
391             defdir=`echo $$ds | cut -f1 -d:`; \
392             defsec=`echo $$ds | cut -f2 -d:`; \
393             for p in $(SRCDIR)/doc/$$defdir/*.pod; do \
394                 SEC=`sed -ne 's/^=for  *comment  *openssl_manual_section: *\([0-9]\) *$$/\1/p' $$p`; \
395                 [ -z "$$SEC" ] && SEC=$$defsec; \
396                 fn=`basename $$p .pod`; \
397                 suf=`eval "echo $$OUTSUFFIX"`; \
398                 top=`eval "echo $$OUTTOP"`; \
399                 echo "$(RM) $$top/man$$SEC/$$fn$$suf"; \
400                 $(RM) $$top/man$$SEC/$$fn$$suf; \
401                 names=`cat $$p | $(EXTRACT_NAMES)`; \
402                 for n in $$names; do \
403                     if [ "$$n" != "$$fn" ]; then \
404                         echo "$(RM) $$top/man$$SEC/$$n$$suf"; \
405                         $(RM) $$top/man$$SEC/$$n$$suf; \
406                     fi; \
407                 done; \
408             done; \
409         done
410
411 install_man_docs:
412         @[ -n "$(INSTALLTOP)" ] || (echo INSTALLTOP should not be empty; exit 1)
413         @echo "*** Installing manpages"
414         @\
415         OUTSUFFIX='.$${SEC}$(MANSUFFIX)'; \
416         OUTTOP="$(INSTALL_PREFIX)$(MANDIR)"; \
417         GENERATE='pod2man --name=$$NAME --section=$$SEC --center=OpenSSL --release=$(VERSION)'; \
418         $(PROCESS_PODS)
419
420 uninstall_man_docs:
421         @echo "*** Uninstalling manpages"
422         @\
423         OUTSUFFIX='.$${SEC}$(MANSUFFIX)'; \
424         OUTTOP="$(INSTALL_PREFIX)$(MANDIR)"; \
425         $(UNINSTALL_DOCS)
426
427 install_html_docs:
428         @[ -n "$(INSTALLTOP)" ] || (echo INSTALLTOP should not be empty; exit 1)
429         @echo "*** Installing HTML manpages"
430         @\
431         OUTSUFFIX='.$(HTMLSUFFIX)'; \
432         OUTTOP="$(INSTALL_PREFIX)$(HTMLDIR)"; \
433         GENERATE="pod2html --podroot=$(SRCDIR)/doc --htmldir=.. \
434                            --podpath=apps:crypto:ssl \
435                   | sed -e 's|href=\"http://man.he.net/man|href=\"../man|g'"; \
436         $(PROCESS_PODS)
437
438 uninstall_html_docs:
439         @echo "*** Uninstalling manpages"
440         @\
441         OUTSUFFIX='.$(HTMLSUFFIX)'; \
442         OUTTOP="$(INSTALL_PREFIX)$(HTMLDIR)"; \
443         $(UNINSTALL_DOCS)
444
445
446 # Developer targets (note: these are only available on Unix) #########
447
448 update: errors ordinals tags test_ordinals
449
450 # Test coverage is a good idea for the future
451 #coverage: $(PROGRAMS) $(TESTPROGRAMS)
452 #       ...
453
454 # Currently disabled, util/selftest.pl needs a rewrite
455 #report:
456 #       SRCDIR=$(SRCDIR) @$(PERL) util/selftest.pl
457
458 lint:
459         lint -DLINT $(INCLUDES) $(SRCS)
460
461 errors:
462         ( cd $(SRCDIR); $(PERL) util/ck_errf.pl -strict */*.c */*/*.c )
463         ( cd $(SRCDIR); $(PERL) util/mkerr.pl -recurse -write )
464         ( cd $(SRCDIR)/engines; \
465           for e in *.ec; do \
466               $(PERL) ../util/mkerr.pl -conf $$e \
467                       -nostatic -staticloader -write *.c; \
468           done )
469         ( cd $(SRCDIR)/crypto/ct; \
470           $(PERL) ../../util/mkerr.pl -conf ct.ec -hprefix internal/ -write *.c )
471
472 ordinals:
473         ( b=`pwd`; cd $(SRCDIR); $(PERL) -I$$b util/mkdef.pl crypto update )
474         ( b=`pwd`; cd $(SRCDIR); $(PERL) -I$$b util/mkdef.pl ssl update )
475
476 test_ordinals:
477         ( cd test; \
478           SRCTOP=../$(SRCDIR) \
479           BLDTOP=../$(BLDDIR) \
480             $(PERL) ../$(SRCDIR)/test/run_tests.pl test_ordinals )
481
482 tags TAGS: FORCE
483         rm -f TAGS tags
484         -ctags -R .
485         -etags `find . -name '*.[ch]' -o -name '*.pm'`
486
487 # Release targets (note: only available on Unix) #####################
488
489 tar:
490         TMPDIR=/var/tmp/openssl-copy.$$$$; \
491         DISTDIR=openssl-$(VERSION); \
492         mkdir -p $$TMPDIR/$$DISTDIR; \
493         (cd $(SRCDIR); \
494          git ls-tree -r --name-only --full-tree HEAD \
495          | while read F; do \
496                mkdir -p $$TMPDIR/$$DISTDIR/`dirname $$F`; \
497                cp $$F $$TMPDIR/$$DISTDIR/$$F; \
498            done); \
499         (cd $$TMPDIR; \
500          [ -n "$(PREPARE_CMD)" ] && $(PREPARE_CMD); \
501          find $$TMPDIR/$$DISTDIR -type d -print | xargs chmod 755; \
502          find $$TMPDIR/$$DISTDIR -type f -print | xargs chmod a+r; \
503          find $$TMPDIR/$$DISTDIR -type f -perm -0100 -print | xargs chmod a+x; \
504          $(TAR) $(TARFLAGS) --owner 0 --group 0 -cvf - $$DISTDIR) \
505         | (cd $(SRCDIR); gzip --best > $(TARFILE).gz); \
506         rm -rf $$TMPDIR
507         cd $(SRCDIR); ls -l $(TARFILE).gz
508
509 dist:
510         @$(MAKE) PREPARE_CMD='./Configure dist' tar
511
512 # Helper targets #####################################################
513
514 rehash: link-utils copy-certs
515         @if [ -z "$(CROSS_COMPILE)" ]; then \
516                 (OPENSSL="$(BLDDIR)/util/shlib_wrap.sh apps/openssl"; \
517                 [ -x "$(BLDDIR)/openssl.exe" ] && OPENSSL="$(BLDDIR)/openssl.exe" || :; \
518                 OPENSSL_DEBUG_MEMORY=on; OPENSSL_CONF=/dev/null ; \
519                 export OPENSSL OPENSSL_DEBUG_MEMORY OPENSSL_CONF; \
520                 $$OPENSSL rehash certs/demo \
521                 || $(PERL) tools/c_rehash certs/demo) && \
522                 touch rehash.time; \
523         else :; fi
524
525 link-utils: $(BLDDIR)/util/opensslwrap.sh $(BLDDIR)/util/shlib_wrap.sh
526
527 $(BLDDIR)/util/opensslwrap.sh: Makefile
528         @if [ "$(SRCDIR)" != "$(BLDDIR)" ]; then \
529             mkdir -p "$(BLDDIR)/util"; \
530             ln -sf "../$(SRCDIR)/util/opensslwrap.sh" "$(BLDDIR)/util"; \
531         fi
532 $(BLDDIR)/util/shlib_wrap.sh: Makefile
533         @if [ "$(SRCDIR)" != "$(BLDDIR)" ]; then \
534             mkdir -p "$(BLDDIR)/util"; \
535             ln -sf "../$(SRCDIR)/util/shlib_wrap.sh" "$(BLDDIR)/util"; \
536         fi
537
538 copy-certs: FORCE
539         @if [ "$(SRCDIR)" != "$(BLDDIR)" ]; then \
540             cp -R "$(SRCDIR)/certs" "$(BLDDIR)/"; \
541         fi
542
543 FORCE :
544
545 # Building targets ###################################################
546
547 libcrypto.pc libssl.pc openssl.pc: Makefile $(LIBS)
548 libcrypto.pc:
549         @ ( echo 'prefix=$(INSTALLTOP)'; \
550             echo 'exec_prefix=$${prefix}'; \
551             echo 'libdir=$${exec_prefix}/$(LIBDIR)'; \
552             echo 'includedir=$${prefix}/include'; \
553             echo ''; \
554             echo 'Name: OpenSSL-libcrypto'; \
555             echo 'Description: OpenSSL cryptography library'; \
556             echo 'Version: '$(VERSION); \
557             echo 'Libs: -L$${libdir} -lcrypto'; \
558             echo 'Libs.private: $(EX_LIBS)'; \
559             echo 'Cflags: -I$${includedir}' ) > libcrypto.pc
560
561 libssl.pc:
562         @ ( echo 'prefix=$(INSTALLTOP)'; \
563             echo 'exec_prefix=$${prefix}'; \
564             echo 'libdir=$${exec_prefix}/$(LIBDIR)'; \
565             echo 'includedir=$${prefix}/include'; \
566             echo ''; \
567             echo 'Name: OpenSSL-libssl'; \
568             echo 'Description: Secure Sockets Layer and cryptography libraries'; \
569             echo 'Version: '$(VERSION); \
570             echo 'Requires.private: libcrypto'; \
571             echo 'Libs: -L$${libdir} -lssl'; \
572             echo 'Libs.private: $(EX_LIBS)'; \
573             echo 'Cflags: -I$${includedir}' ) > libssl.pc
574
575 openssl.pc:
576         @ ( echo 'prefix=$(INSTALLTOP)'; \
577             echo 'exec_prefix=$${prefix}'; \
578             echo 'libdir=$${exec_prefix}/$(LIBDIR)'; \
579             echo 'includedir=$${prefix}/include'; \
580             echo ''; \
581             echo 'Name: OpenSSL'; \
582             echo 'Description: Secure Sockets Layer and cryptography libraries and tools'; \
583             echo 'Version: '$(VERSION); \
584             echo 'Requires: libssl libcrypto' ) > openssl.pc
585
586 # Note on the use of $(MFLAGS): this was an older variant of MAKEFLAGS which
587 # wasn't passed down automatically.  It's quite safe to use it like we do
588 # below; if it doesn't exist, the result will be empty and 'make' will pick
589 # up $(MAKEFLAGS) which is passed down as an environment variable.
590 Makefile: {- $config{build_file_template} -} $(SRCDIR)/Configure $(SRCDIR)/config
591         @echo "Makefile is older than {- $config{build_file_template} -}, $(SRCDIR)/Configure or $(SRCDIR)/config."
592         @echo "Reconfiguring..."
593         $(SRCDIR)/Configure reconf
594         @echo "**************************************************"
595         @echo "***                                            ***"
596         @echo "***   Please run the same make command again   ***"
597         @echo "***                                            ***"
598         @echo "**************************************************"
599         @false
600
601 {-
602   use File::Basename;
603   use File::Spec::Functions qw/:DEFAULT abs2rel rel2abs/;
604   sub src2dep {
605       my %args = @_;
606       my $dep = $args{obj}.'$(DEP_EXT)';
607       my $obj = $args{obj}.'$(OBJ_EXT)';
608       my $srcs = join(" ", @{$args{srcs}});
609       my $incs = join(" ", map { " -I".$_ } @{$args{incs}});
610       my $makedepprog = $config{makedepprog};
611       if ($makedepprog eq "makedepend") {
612           return <<"EOF";
613 $dep : $srcs
614         rm -f \$\@.tmp; touch \$\@.tmp
615         \$(MAKEDEPEND) -f\$\@.tmp -o"|$obj"\
616             -- -DOPENSSL_DOING_MAKEDEPEND \$(DEPFLAGS)$incs \
617             -- $srcs
618         sed -e 's/^.*|//' -e 's/ \\/\\(\\\\.\\|[^ ]\\)*//g' -e '/: *\$/d' -e '/^\\(#.*\\| *\\)\$/d' \$\@.tmp > \$\@
619         rm \$\@.tmp
620 EOF
621       }
622       return <<"EOF";
623 $dep : $srcs Makefile
624         \$(CC) -DOPENSSL_DOING_MAKEDEPEND \$(DEPFLAGS)$incs -MM -MF \$\@ -MQ $obj $srcs
625 EOF
626   }
627   sub src2obj {
628       my %args = @_;
629       my $obj = $args{obj}.'$(OBJ_EXT)';
630       my $srcs = join(" ", @{$args{srcs}});
631       my $deps = join(" ", @{$args{srcs}}, @{$args{deps}});
632       my $incs = join(" ", map { " -I".$_ } @{$args{incs}});
633       return <<"EOF";
634 $obj : $deps
635         \$(CC) \$(CFLAGS)$incs -c -o \$\@ $srcs
636 EOF
637   }
638   # On Unix, we build shlibs from static libs, so we're ignoring the
639   # object file array.  We *know* this routine is only called when we've
640   # configure 'shared'.
641   sub libobj2shlib {
642       my %args = @_;
643       my $lib = $args{lib};
644       my $shlib = $args{shlib};
645       my $libd = dirname($lib);
646       my $libn = basename($lib);
647       (my $libname = $libn) =~ s/^lib//;
648       my $shlibdeps = join("", map { my $d = dirname($_);
649                                      my $f = basename($_);
650                                      (my $l = $f) =~ s/^lib//;
651                                      " -L$d -l$l" } @{$args{deps}});
652       my $deps = join(" ",map { $_."\$(SHLIB_EXT_SIMPLE)" } @{$args{deps}});
653       my $shlib_target = $target{shared_target};
654       my $ordinalsfile = defined($args{ordinals}) ? $args{ordinals}->[1] : "";
655       my $targets =
656          "$shlib".shlib_ext() .
657          (shlib_ext() ne shlib_ext_simple()
658           ? " $shlib".shlib_ext_simple() : "");
659       return <<"EOF"
660 $targets : $lib\$(LIB_EXT) $deps $ordinalsfile
661         \$(MAKE) -f \$(SRCDIR)/Makefile.shared -e \\
662                 PERL=\$(PERL) SRCDIR="\$(SRCDIR)" DSTDIR="$libd" \\
663                 INSTALLTOP="\$(INSTALLTOP)" LIBDIR="\$(LIBDIR)" \\
664                 LIBDEPS="\$(PLIB_LDFLAGS) $shlibdeps \$(EX_LIBS)" \\
665                 LIBNAME=$libname LIBVERSION=\$(SHLIB_MAJOR).\$(SHLIB_MINOR) \\
666                 LIBCOMPATVERSIONS=";\$(SHLIB_VERSION_HISTORY)" \\
667                 CC="\$(CC)" CFLAGS="\$(CFLAGS)" LDFLAGS="\$(LDFLAGS)" \\
668                 SHARED_LDFLAGS="\$(SHARED_LDFLAGS)" SHLIB_EXT=\$(SHLIB_EXT) \\
669                 link_a.$shlib_target
670 EOF
671   }
672   sub obj2dynlib {
673       my %args = @_;
674       my $lib = $args{lib};
675       my $libd = dirname($lib);
676       my $libn = basename($lib);
677       (my $libname = $libn) =~ s/^lib//;
678       my $shlibdeps = join("", map { my $d = dirname($_);
679                                      my $f = basename($_);
680                                      (my $l = $f) =~ s/^lib//;
681                                      " -L$d -l$l" } @{$args{deps}});
682       my $deps = join(" ",map { $_."\$(SHLIB_EXT_SIMPLE)" } @{$args{deps}});
683       my $shlib_target = $target{shared_target};
684       my $objs = join(" ", map { $_."\$(OBJ_EXT)" } @{$args{objs}});
685       return <<"EOF";
686 $lib\$(SHLIB_EXT_SIMPLE): $objs $deps
687         \$(MAKE) -f \$(SRCDIR)/Makefile.shared -e \\
688                 PERL=\$(PERL) SRCDIR="\$(SRCDIR)" DSTDIR="$libd" \\
689                 LIBDEPS="\$(PLIB_LDFLAGS) $shlibdeps \$(EX_LIBS)" \\
690                 LIBNAME=$libname LDFLAGS="\$(LDFLAGS)" \\
691                 CC="\$(CC)" CFLAGS="\$(CFLAGS)" \\
692                 SHARED_LDFLAGS="\$(SHARED_LDFLAGS)" \\
693                 SHLIB_EXT=\$(SHLIB_EXT_SIMPLE) \\
694                 LIBEXTRAS="$objs" \\
695                 link_o.$shlib_target
696 EOF
697   }
698   sub obj2lib {
699       my %args = @_;
700       my $lib = $args{lib};
701       my $objs = join(" ", map { $_."\$(OBJ_EXT)" } @{$args{objs}});
702       return <<"EOF";
703 $lib\$(LIB_EXT) : $objs
704         \$(AR) \$\@ $objs
705         \$(RANLIB) \$\@ || echo Never mind.
706 EOF
707   }
708   sub obj2bin {
709       my %args = @_;
710       my $bin = $args{bin};
711       my $bind = dirname($bin);
712       my $binn = basename($bin);
713       my $objs = join(" ", map { $_."\$(OBJ_EXT)" } @{$args{objs}});
714       my $deps = join(" ",
715                       (map { $_."\$(OBJ_EXT)" } @{$args{objs}}),
716                       (map { $_.($config{no_shared} ? "\$(LIB_EXT)" : "\$(SHLIB_EXT)" ) }
717                        @{$args{deps}}));
718       my $libdeps = join("", map { my $d = dirname($_);
719                                    my $f = basename($_);
720                                    $d = "." if $d eq $f;
721                                    (my $l = $f) =~ s/^lib//;
722                                    " -L$d -l$l" } @{$args{deps}});
723       my $shlib_target = $config{no_shared} ? "" : $target{shared_target};
724       return <<"EOF";
725 $bin\$(EXE_EXT) : $deps
726         \$(RM) $bin\$(EXE_EXT)
727         \$(MAKE) -f \$(SRCDIR)/Makefile.shared -e \\
728                 PERL=\$(PERL) SRCDIR=\$(SRCDIR) \\
729                 APPNAME=$bin OBJECTS="$objs" \\
730                 LIBDEPS="\$(PLIB_LDFLAGS) \$(LDFLAGS) $libdeps \$(EX_LIBS)" \\
731                 CC="\$(CC)" CFLAGS="\$(CFLAGS)" LDFLAGS="\$(LDFLAGS)" \\
732                 LIBRPATH="\$(INSTALLTOP)/\$(LIBDIR)" \\
733                 link_app.$shlib_target
734 EOF
735   }
736   sub in2script {
737       my %args = @_;
738       my $script = $args{script};
739       my $sources = join(" ", @{$args{sources}});
740       my $dofile = abs2rel(rel2abs(catfile($config{sourcedir},
741                                            "util", "dofile.pl")),
742                            rel2abs($config{builddir}));
743       return <<"EOF";
744 $script : $sources
745         \$(PERL) "-I\$(BLDDIR)" -Mconfigdata "$dofile" $sources > "$script"
746         chmod a+x $script
747 EOF
748   }
749   ""    # Important!  This becomes part of the template result.
750 -}