unified build scheme: add the tweaks to build on Cygwin & Mingw
[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                 : {- output_off() unless windowsdll(); "" -}; \
232                 echo "install $$s.a -> $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/$$fn.a"; \
233                 cp $$s.a $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/$$fn.a.new; \
234                 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/$$fn.a.new; \
235                 mv -f $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/$$fn.a.new \
236                       $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/$$fn.a; \
237                 : {- output_on() -}; \
238         done
239         @ : {- output_on() -}
240         @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/pkgconfig
241         @echo "install libcrypto.pc -> $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/libcrypto.pc"
242         @cp libcrypto.pc $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/pkgconfig
243         @chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/libcrypto.pc
244         @echo "install libssl.pc -> $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/libssl.pc"
245         @cp libssl.pc $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/pkgconfig
246         @chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/libssl.pc
247         @echo "install openssl.pc -> $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/openssl.pc"
248         @cp openssl.pc $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/pkgconfig
249         @chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/openssl.pc
250
251 uninstall_dev:
252         @echo "*** Uninstalling development files"
253         @set -e; for i in $(SRCDIR)/include/openssl/*.h \
254                           $(BLDDIR)/include/openssl/*.h; do \
255                 fn=`basename $$i`; \
256                 echo "$(RM) $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$fn"; \
257                 $(RM) $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$fn; \
258         done
259         @set -e; for l in $(LIBS); do \
260                 fn=`basename $$l`; \
261                 echo "$(RM) $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/$$fn"; \
262                 $(RM) $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/$$fn; \
263         done
264         @set -e; for s in $(SHLIBS); do \
265                 fn=`basename $$s`; \
266                 if [ "$(SHLIB_EXT)" != "$(SHLIB_EXT_SIMPLE)" ]; then \
267                         fn2=`basename $$fn $(SHLIB_EXT)`$(SHLIB_EXT_SIMPLE); \
268                         echo "$(RM) $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/$$fn2"; \
269                         $(RM) $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/$$fn2; \
270                 fi; \
271                 echo "$(RM) $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/$$fn"; \
272                 $(RM) $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/$$fn; \
273                 : {- output_off() unless windowsdll(); "" -}; \
274                 echo "$(RM) $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/$$fn.a"; \
275                 $(RM) $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/$$fn.a; \
276                 : {- output_on() -}; \
277         done
278         @echo "$(RM) $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/libcrypto.pc"
279         @$(RM) $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/libcrypto.pc
280         @echo "$(RM) $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/libssl.pc"
281         @$(RM) $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/libssl.pc
282         @echo "$(RM) $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/openssl.pc"
283         @$(RM) $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/openssl.pc
284
285 install_engines:
286         @[ -n "$(INSTALLTOP)" ] || (echo INSTALLTOP should not be empty; exit 1)
287         @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/engines/
288         @echo "*** Installing engines"
289         @set -e; for e in $(ENGINES); do \
290                 fn=`basename $$e`; \
291                 echo "install $$e -> $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$fn"; \
292                 cp $$e $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/engines/$$fn.new; \
293                 chmod 755 $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/engines/$$fn.new; \
294                 mv -f $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/engines/$$fn.new \
295                       $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/engines/$$fn; \
296         done
297
298 uninstall_engines:
299         @echo "*** Uninstalling engines"
300         @set -e; for e in $(ENGINES); do \
301                 fn=`basename $$e`; \
302                 echo "$(RM) $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$fn"; \
303                 $(RM) $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/engines/$$fn; \
304         done
305
306 install_runtime:
307         @[ -n "$(INSTALLTOP)" ] || (echo INSTALLTOP should not be empty; exit 1)
308         @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(INSTALL_PREFIX)$(INSTALLTOP)/bin
309         @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(INSTALL_PREFIX)$(OPENSSLDIR)/misc
310         @echo "*** Installing runtime files"
311         : {- output_off() unless windowsdll(); "" -};
312         @set -e; for s in $(SHLIBS); do \
313                 fn=`basename $$i`; \
314                 echo "install $$s -> $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$fn"; \
315                 cp $$s $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$fn.new; \
316                 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$fn.new; \
317                 mv -f $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$fn.new \
318                       $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$fn; \
319         done
320         : {- output_on() -};
321         @set -e; for x in $(PROGRAMS); do \
322                 fn=`basename $$x`; \
323                 echo "install $$x -> $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$fn"; \
324                 cp $$x $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$fn.new; \
325                 chmod 755 $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$fn.new; \
326                 mv -f $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$fn.new \
327                       $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$fn; \
328         done
329         @set -e; for x in $(BIN_SCRIPTS); do \
330                 fn=`basename $$x`; \
331                 echo "install $$x -> $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$fn"; \
332                 cp $$x $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$fn.new; \
333                 chmod 755 $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$fn.new; \
334                 mv -f $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$fn.new \
335                       $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$fn; \
336         done
337         @set -e; for x in $(MISC_SCRIPTS); do \
338                 fn=`basename $$x`; \
339                 echo "install $$x -> $(INSTALL_PREFIX)$(OPENSSLDIR)/misc/$$fn"; \
340                 cp $$x $(INSTALL_PREFIX)$(OPENSSLDIR)/misc/$$fn.new; \
341                 chmod 755 $(INSTALL_PREFIX)$(OPENSSLDIR)/misc/$$fn.new; \
342                 mv -f $(INSTALL_PREFIX)$(OPENSSLDIR)/misc/$$fn.new \
343                       $(INSTALL_PREFIX)$(OPENSSLDIR)/misc/$$fn; \
344         done
345         @echo "install $(SRCDIR)/apps/openssl.cnf -> $(INSTALL_PREFIX)$(OPENSSLDIR)/openssl.cnf"
346         @cp $(SRCDIR)/apps/openssl.cnf $(INSTALL_PREFIX)$(OPENSSLDIR)/openssl.cnf.new
347         @chmod 644 $(INSTALL_PREFIX)$(OPENSSLDIR)/openssl.cnf.new
348         @mv -f  $(INSTALL_PREFIX)$(OPENSSLDIR)/openssl.cnf.new $(INSTALL_PREFIX)$(OPENSSLDIR)/openssl.cnf
349
350 uninstall_runtime:
351         @echo "*** Uninstalling runtime files"
352         @set -e; for x in $(PROGRAMS); \
353         do  \
354                 fn=`basename $$x`; \
355                 echo "$(RM) $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$fn"; \
356                 $(RM) $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$fn; \
357         done;
358         @set -e; for x in $(BIN_SCRIPTS); \
359         do  \
360                 fn=`basename $$x`; \
361                 echo "$(RM) $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$fn"; \
362                 $(RM) $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$fn; \
363         done
364         @set -e; for x in $(MISC_SCRIPTS); \
365         do  \
366                 fn=`basename $$x`; \
367                 echo "$(RM) $(INSTALL_PREFIX)$(OPENSSLDIR)/misc/$$fn"; \
368                 $(RM) $(INSTALL_PREFIX)$(OPENSSLDIR)/misc/$$fn; \
369         done
370         : {- output_off() unless windowsdll(); "" -};
371         @set -e; for s in $(SHLIBS); do \
372                 fn=`basename $$i`; \
373                 echo "$(RM) $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$fn"; \
374                 $(RM) $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$fn; \
375         done
376         : {- output_on() -};
377         $(RM) $(INSTALL_PREFIX)$(OPENSSLDIR)/openssl.cnf
378
379 # A method to extract all names from a .pod file
380 # The first sed extracts everything between "=head1 NAME" and the next =head1
381 # The second sed joins all the lines into one
382 # The third sed removes the description and turns all commas into spaces
383 # VoilĂ , you have a space separated list of names!
384 EXTRACT_NAMES=sed -e '1,/^=head1  *NAME *$$/d;/^=head1/,$$d' | \
385               sed -e ':a;{N;s/\n/ /;ba}' | \
386               sed -e 's/ - .*$$//;s/,/ /g'
387 PROCESS_PODS=\
388         set -e; \
389         here=`cd $(SRCDIR); pwd`; \
390         point=$$here/util/point.sh; \
391         for ds in apps:1 crypto:3 ssl:3; do \
392             defdir=`echo $$ds | cut -f1 -d:`; \
393             defsec=`echo $$ds | cut -f2 -d:`; \
394             for p in $(SRCDIR)/doc/$$defdir/*.pod; do \
395                 SEC=`sed -ne 's/^=for  *comment  *openssl_manual_section: *\([0-9]\) *$$/\1/p' $$p`; \
396                 [ -z "$$SEC" ] && SEC=$$defsec; \
397                 fn=`basename $$p .pod`; \
398                 NAME=`echo $$fn | tr [a-z] [A-Z]`; \
399                 suf=`eval "echo $$OUTSUFFIX"`; \
400                 top=`eval "echo $$OUTTOP"`; \
401                 $(PERL) $(SRCDIR)/util/mkdir-p.pl $$top/man$$SEC; \
402                 echo "install $$p -> $$top/man$$SEC/$$fn$$suf"; \
403                 cat $$p | eval "$$GENERATE" \
404                         >  $$top/man$$SEC/$$fn$$suf; \
405                 names=`cat $$p | $(EXTRACT_NAMES)`; \
406                 ( cd $$top/man$$SEC; \
407                   for n in $$names; do \
408                       if [ "$$n" != "$$fn" ]; then \
409                           echo "link $$top/man$$SEC/$$n$$suf -> $$top/man$$SEC/$$fn$$suf"; \
410                           PLATFORM=$(PLATFORM) $$point $$fn$$suf $$n$$suf; \
411                       fi; \
412                   done ); \
413             done; \
414         done
415 UNINSTALL_DOCS=\
416         set -e; \
417         here=`cd $(SRCDIR); pwd`; \
418         for ds in apps:1 crypto:3 ssl:3; do \
419             defdir=`echo $$ds | cut -f1 -d:`; \
420             defsec=`echo $$ds | cut -f2 -d:`; \
421             for p in $(SRCDIR)/doc/$$defdir/*.pod; do \
422                 SEC=`sed -ne 's/^=for  *comment  *openssl_manual_section: *\([0-9]\) *$$/\1/p' $$p`; \
423                 [ -z "$$SEC" ] && SEC=$$defsec; \
424                 fn=`basename $$p .pod`; \
425                 suf=`eval "echo $$OUTSUFFIX"`; \
426                 top=`eval "echo $$OUTTOP"`; \
427                 echo "$(RM) $$top/man$$SEC/$$fn$$suf"; \
428                 $(RM) $$top/man$$SEC/$$fn$$suf; \
429                 names=`cat $$p | $(EXTRACT_NAMES)`; \
430                 for n in $$names; do \
431                     if [ "$$n" != "$$fn" ]; then \
432                         echo "$(RM) $$top/man$$SEC/$$n$$suf"; \
433                         $(RM) $$top/man$$SEC/$$n$$suf; \
434                     fi; \
435                 done; \
436             done; \
437         done
438
439 install_man_docs:
440         @[ -n "$(INSTALLTOP)" ] || (echo INSTALLTOP should not be empty; exit 1)
441         @echo "*** Installing manpages"
442         @\
443         OUTSUFFIX='.$${SEC}$(MANSUFFIX)'; \
444         OUTTOP="$(INSTALL_PREFIX)$(MANDIR)"; \
445         GENERATE='pod2man --name=$$NAME --section=$$SEC --center=OpenSSL --release=$(VERSION)'; \
446         $(PROCESS_PODS)
447
448 uninstall_man_docs:
449         @echo "*** Uninstalling manpages"
450         @\
451         OUTSUFFIX='.$${SEC}$(MANSUFFIX)'; \
452         OUTTOP="$(INSTALL_PREFIX)$(MANDIR)"; \
453         $(UNINSTALL_DOCS)
454
455 install_html_docs:
456         @[ -n "$(INSTALLTOP)" ] || (echo INSTALLTOP should not be empty; exit 1)
457         @echo "*** Installing HTML manpages"
458         @\
459         OUTSUFFIX='.$(HTMLSUFFIX)'; \
460         OUTTOP="$(INSTALL_PREFIX)$(HTMLDIR)"; \
461         GENERATE="pod2html --podroot=$(SRCDIR)/doc --htmldir=.. \
462                            --podpath=apps:crypto:ssl \
463                   | sed -e 's|href=\"http://man.he.net/man|href=\"../man|g'"; \
464         $(PROCESS_PODS)
465
466 uninstall_html_docs:
467         @echo "*** Uninstalling manpages"
468         @\
469         OUTSUFFIX='.$(HTMLSUFFIX)'; \
470         OUTTOP="$(INSTALL_PREFIX)$(HTMLDIR)"; \
471         $(UNINSTALL_DOCS)
472
473
474 # Developer targets (note: these are only available on Unix) #########
475
476 update: errors ordinals tags test_ordinals
477
478 # Test coverage is a good idea for the future
479 #coverage: $(PROGRAMS) $(TESTPROGRAMS)
480 #       ...
481
482 # Currently disabled, util/selftest.pl needs a rewrite
483 #report:
484 #       SRCDIR=$(SRCDIR) @$(PERL) util/selftest.pl
485
486 lint:
487         lint -DLINT $(INCLUDES) $(SRCS)
488
489 errors:
490         ( cd $(SRCDIR); $(PERL) util/ck_errf.pl -strict */*.c */*/*.c )
491         ( cd $(SRCDIR); $(PERL) util/mkerr.pl -recurse -write )
492         ( cd $(SRCDIR)/engines; \
493           for e in *.ec; do \
494               $(PERL) ../util/mkerr.pl -conf $$e \
495                       -nostatic -staticloader -write *.c; \
496           done )
497         ( cd $(SRCDIR)/crypto/ct; \
498           $(PERL) ../../util/mkerr.pl -conf ct.ec -hprefix internal/ -write *.c )
499
500 ordinals:
501         ( b=`pwd`; cd $(SRCDIR); $(PERL) -I$$b util/mkdef.pl crypto update )
502         ( b=`pwd`; cd $(SRCDIR); $(PERL) -I$$b util/mkdef.pl ssl update )
503
504 test_ordinals:
505         ( cd test; \
506           SRCTOP=../$(SRCDIR) \
507           BLDTOP=../$(BLDDIR) \
508             $(PERL) ../$(SRCDIR)/test/run_tests.pl test_ordinals )
509
510 tags TAGS: FORCE
511         rm -f TAGS tags
512         -ctags -R .
513         -etags `find . -name '*.[ch]' -o -name '*.pm'`
514
515 # Release targets (note: only available on Unix) #####################
516
517 tar:
518         TMPDIR=/var/tmp/openssl-copy.$$$$; \
519         DISTDIR=openssl-$(VERSION); \
520         mkdir -p $$TMPDIR/$$DISTDIR; \
521         (cd $(SRCDIR); \
522          git ls-tree -r --name-only --full-tree HEAD \
523          | while read F; do \
524                mkdir -p $$TMPDIR/$$DISTDIR/`dirname $$F`; \
525                cp $$F $$TMPDIR/$$DISTDIR/$$F; \
526            done); \
527         (cd $$TMPDIR; \
528          [ -n "$(PREPARE_CMD)" ] && $(PREPARE_CMD); \
529          find $$TMPDIR/$$DISTDIR -type d -print | xargs chmod 755; \
530          find $$TMPDIR/$$DISTDIR -type f -print | xargs chmod a+r; \
531          find $$TMPDIR/$$DISTDIR -type f -perm -0100 -print | xargs chmod a+x; \
532          $(TAR) $(TARFLAGS) --owner 0 --group 0 -cvf - $$DISTDIR) \
533         | (cd $(SRCDIR); gzip --best > $(TARFILE).gz); \
534         rm -rf $$TMPDIR
535         cd $(SRCDIR); ls -l $(TARFILE).gz
536
537 dist:
538         @$(MAKE) PREPARE_CMD='./Configure dist' tar
539
540 # Helper targets #####################################################
541
542 rehash: link-utils copy-certs
543         @if [ -z "$(CROSS_COMPILE)" ]; then \
544                 (OPENSSL="$(BLDDIR)/util/shlib_wrap.sh apps/openssl"; \
545                 [ -x "$(BLDDIR)/openssl.exe" ] && OPENSSL="$(BLDDIR)/openssl.exe" || :; \
546                 OPENSSL_DEBUG_MEMORY=on; OPENSSL_CONF=/dev/null ; \
547                 export OPENSSL OPENSSL_DEBUG_MEMORY OPENSSL_CONF; \
548                 $$OPENSSL rehash certs/demo \
549                 || $(PERL) tools/c_rehash certs/demo) && \
550                 touch rehash.time; \
551         else :; fi
552
553 link-utils: $(BLDDIR)/util/opensslwrap.sh $(BLDDIR)/util/shlib_wrap.sh
554
555 $(BLDDIR)/util/opensslwrap.sh: Makefile
556         @if [ "$(SRCDIR)" != "$(BLDDIR)" ]; then \
557             mkdir -p "$(BLDDIR)/util"; \
558             ln -sf "../$(SRCDIR)/util/opensslwrap.sh" "$(BLDDIR)/util"; \
559         fi
560 $(BLDDIR)/util/shlib_wrap.sh: Makefile
561         @if [ "$(SRCDIR)" != "$(BLDDIR)" ]; then \
562             mkdir -p "$(BLDDIR)/util"; \
563             ln -sf "../$(SRCDIR)/util/shlib_wrap.sh" "$(BLDDIR)/util"; \
564         fi
565
566 copy-certs: FORCE
567         @if [ "$(SRCDIR)" != "$(BLDDIR)" ]; then \
568             cp -R "$(SRCDIR)/certs" "$(BLDDIR)/"; \
569         fi
570
571 FORCE :
572
573 # Building targets ###################################################
574
575 libcrypto.pc libssl.pc openssl.pc: Makefile $(LIBS)
576 libcrypto.pc:
577         @ ( echo 'prefix=$(INSTALLTOP)'; \
578             echo 'exec_prefix=$${prefix}'; \
579             echo 'libdir=$${exec_prefix}/$(LIBDIR)'; \
580             echo 'includedir=$${prefix}/include'; \
581             echo ''; \
582             echo 'Name: OpenSSL-libcrypto'; \
583             echo 'Description: OpenSSL cryptography library'; \
584             echo 'Version: '$(VERSION); \
585             echo 'Libs: -L$${libdir} -lcrypto'; \
586             echo 'Libs.private: $(EX_LIBS)'; \
587             echo 'Cflags: -I$${includedir}' ) > libcrypto.pc
588
589 libssl.pc:
590         @ ( echo 'prefix=$(INSTALLTOP)'; \
591             echo 'exec_prefix=$${prefix}'; \
592             echo 'libdir=$${exec_prefix}/$(LIBDIR)'; \
593             echo 'includedir=$${prefix}/include'; \
594             echo ''; \
595             echo 'Name: OpenSSL-libssl'; \
596             echo 'Description: Secure Sockets Layer and cryptography libraries'; \
597             echo 'Version: '$(VERSION); \
598             echo 'Requires.private: libcrypto'; \
599             echo 'Libs: -L$${libdir} -lssl'; \
600             echo 'Libs.private: $(EX_LIBS)'; \
601             echo 'Cflags: -I$${includedir}' ) > libssl.pc
602
603 openssl.pc:
604         @ ( echo 'prefix=$(INSTALLTOP)'; \
605             echo 'exec_prefix=$${prefix}'; \
606             echo 'libdir=$${exec_prefix}/$(LIBDIR)'; \
607             echo 'includedir=$${prefix}/include'; \
608             echo ''; \
609             echo 'Name: OpenSSL'; \
610             echo 'Description: Secure Sockets Layer and cryptography libraries and tools'; \
611             echo 'Version: '$(VERSION); \
612             echo 'Requires: libssl libcrypto' ) > openssl.pc
613
614 # Note on the use of $(MFLAGS): this was an older variant of MAKEFLAGS which
615 # wasn't passed down automatically.  It's quite safe to use it like we do
616 # below; if it doesn't exist, the result will be empty and 'make' will pick
617 # up $(MAKEFLAGS) which is passed down as an environment variable.
618 Makefile: {- $config{build_file_template} -} $(SRCDIR)/Configure $(SRCDIR)/config
619         @echo "Makefile is older than {- $config{build_file_template} -}, $(SRCDIR)/Configure or $(SRCDIR)/config."
620         @echo "Reconfiguring..."
621         $(SRCDIR)/Configure reconf
622         @echo "**************************************************"
623         @echo "***                                            ***"
624         @echo "***   Please run the same make command again   ***"
625         @echo "***                                            ***"
626         @echo "**************************************************"
627         @false
628
629 {-
630   use File::Basename;
631   use File::Spec::Functions qw/:DEFAULT abs2rel rel2abs/;
632   sub src2dep {
633       my %args = @_;
634       my $dep = $args{obj}.'$(DEP_EXT)';
635       my $obj = $args{obj}.'$(OBJ_EXT)';
636       my $srcs = join(" ", @{$args{srcs}});
637       my $incs = join(" ", map { " -I".$_ } @{$args{incs}});
638       my $makedepprog = $config{makedepprog};
639       if ($makedepprog eq "makedepend") {
640           return <<"EOF";
641 $dep : $srcs
642         rm -f \$\@.tmp; touch \$\@.tmp
643         \$(MAKEDEPEND) -f\$\@.tmp -o"|$obj"\
644             -- -DOPENSSL_DOING_MAKEDEPEND \$(DEPFLAGS)$incs \
645             -- $srcs
646         sed -e 's/^.*|//' -e 's/ \\/\\(\\\\.\\|[^ ]\\)*//g' -e '/: *\$/d' -e '/^\\(#.*\\| *\\)\$/d' \$\@.tmp > \$\@
647         rm \$\@.tmp
648 EOF
649       }
650       return <<"EOF";
651 $dep : $srcs Makefile
652         \$(CC) -DOPENSSL_DOING_MAKEDEPEND \$(DEPFLAGS)$incs -MM -MF \$\@ -MQ $obj $srcs
653 EOF
654   }
655   sub src2obj {
656       my %args = @_;
657       my $obj = $args{obj}.'$(OBJ_EXT)';
658       my $srcs = join(" ", @{$args{srcs}});
659       my $deps = join(" ", @{$args{srcs}}, @{$args{deps}});
660       my $incs = join(" ", map { " -I".$_ } @{$args{incs}});
661       return <<"EOF";
662 $obj : $deps
663         \$(CC) \$(CFLAGS)$incs -c -o \$\@ $srcs
664 EOF
665   }
666   # On Unix, we build shlibs from static libs, so we're ignoring the
667   # object file array.  We *know* this routine is only called when we've
668   # configure 'shared'.
669   sub libobj2shlib {
670       my %args = @_;
671       my $lib = $args{lib};
672       my $shlib = $args{shlib};
673       my $libd = dirname($lib);
674       my $libn = basename($lib);
675       (my $libname = $libn) =~ s/^lib//;
676       my $shlibdeps = join("", map { my $d = dirname($_);
677                                      my $f = basename($_);
678                                      (my $l = $f) =~ s/^lib//;
679                                      " -L$d -l$l" } @{$args{deps}});
680       my $deps = join(" ",map { $_."\$(SHLIB_EXT_SIMPLE)" } @{$args{deps}});
681       my $shlib_target = $target{shared_target};
682       my $ordinalsfile = defined($args{ordinals}) ? $args{ordinals}->[1] : "";
683       my $targets =
684          "$shlib".shlib_ext() .
685          (shlib_ext() ne shlib_ext_simple()
686           ? " $shlib".shlib_ext_simple() : "");
687       return <<"EOF"
688 $targets : $lib\$(LIB_EXT) $deps $ordinalsfile
689         \$(MAKE) -f \$(SRCDIR)/Makefile.shared -e \\
690                 PERL=\$(PERL) SRCDIR="\$(SRCDIR)" DSTDIR="$libd" \\
691                 INSTALLTOP="\$(INSTALLTOP)" LIBDIR="\$(LIBDIR)" \\
692                 LIBDEPS="\$(PLIB_LDFLAGS) $shlibdeps \$(EX_LIBS)" \\
693                 LIBNAME=$libname LIBVERSION=\$(SHLIB_MAJOR).\$(SHLIB_MINOR) \\
694                 LIBCOMPATVERSIONS=";\$(SHLIB_VERSION_HISTORY)" \\
695                 CC="\$(CC)" CFLAGS="\$(CFLAGS)" LDFLAGS="\$(LDFLAGS)" \\
696                 SHARED_LDFLAGS="\$(SHARED_LDFLAGS)" SHLIB_EXT=\$(SHLIB_EXT) \\
697                 link_a.$shlib_target
698 EOF
699           . (windowsdll() ? <<"EOF" : "");
700         rm -f apps/$shlib\$(SHLIB_EXT)
701         rm -f test/$shlib\$(SHLIB_EXT)
702         cp -p $shlib\$(SHLIB_EXT) apps/
703         cp -p $shlib\$(SHLIB_EXT) test/
704 EOF
705   }
706   sub obj2dynlib {
707       my %args = @_;
708       my $lib = $args{lib};
709       my $libd = dirname($lib);
710       my $libn = basename($lib);
711       (my $libname = $libn) =~ s/^lib//;
712       my $shlibdeps = join("", map { my $d = dirname($_);
713                                      my $f = basename($_);
714                                      (my $l = $f) =~ s/^lib//;
715                                      " -L$d -l$l" } @{$args{deps}});
716       my $deps = join(" ",map { $_."\$(SHLIB_EXT_SIMPLE)" } @{$args{deps}});
717       my $shlib_target = $target{shared_target};
718       my $objs = join(" ", map { $_."\$(OBJ_EXT)" } @{$args{objs}});
719       return <<"EOF";
720 $lib\$(SHLIB_EXT_SIMPLE): $objs $deps
721         \$(MAKE) -f \$(SRCDIR)/Makefile.shared -e \\
722                 PERL=\$(PERL) SRCDIR="\$(SRCDIR)" DSTDIR="$libd" \\
723                 LIBDEPS="\$(PLIB_LDFLAGS) $shlibdeps \$(EX_LIBS)" \\
724                 LIBNAME=$libname LDFLAGS="\$(LDFLAGS)" \\
725                 CC="\$(CC)" CFLAGS="\$(CFLAGS)" \\
726                 SHARED_LDFLAGS="\$(SHARED_LDFLAGS)" \\
727                 SHLIB_EXT=\$(SHLIB_EXT_SIMPLE) \\
728                 LIBEXTRAS="$objs" \\
729                 link_o.$shlib_target
730 EOF
731   }
732   sub obj2lib {
733       my %args = @_;
734       my $lib = $args{lib};
735       my $objs = join(" ", map { $_."\$(OBJ_EXT)" } @{$args{objs}});
736       return <<"EOF";
737 $lib\$(LIB_EXT) : $objs
738         \$(AR) \$\@ $objs
739         \$(RANLIB) \$\@ || echo Never mind.
740 EOF
741   }
742   sub obj2bin {
743       my %args = @_;
744       my $bin = $args{bin};
745       my $bind = dirname($bin);
746       my $binn = basename($bin);
747       my $objs = join(" ", map { $_."\$(OBJ_EXT)" } @{$args{objs}});
748       my $deps = join(" ",
749                       (map { $_."\$(OBJ_EXT)" } @{$args{objs}}),
750                       (map { $_.($config{no_shared} ? "\$(LIB_EXT)" : "\$(SHLIB_EXT)" ) }
751                        @{$args{deps}}));
752       my $libdeps = join("", map { my $d = dirname($_);
753                                    my $f = basename($_);
754                                    $d = "." if $d eq $f;
755                                    (my $l = $f) =~ s/^lib//;
756                                    " -L$d -l$l" } @{$args{deps}});
757       my $shlib_target = $config{no_shared} ? "" : $target{shared_target};
758       return <<"EOF";
759 $bin\$(EXE_EXT) : $deps
760         \$(RM) $bin\$(EXE_EXT)
761         \$(MAKE) -f \$(SRCDIR)/Makefile.shared -e \\
762                 PERL=\$(PERL) SRCDIR=\$(SRCDIR) \\
763                 APPNAME=$bin OBJECTS="$objs" \\
764                 LIBDEPS="\$(PLIB_LDFLAGS) \$(LDFLAGS) $libdeps \$(EX_LIBS)" \\
765                 CC="\$(CC)" CFLAGS="\$(CFLAGS)" LDFLAGS="\$(LDFLAGS)" \\
766                 LIBRPATH="\$(INSTALLTOP)/\$(LIBDIR)" \\
767                 link_app.$shlib_target
768 EOF
769   }
770   sub in2script {
771       my %args = @_;
772       my $script = $args{script};
773       my $sources = join(" ", @{$args{sources}});
774       my $dofile = abs2rel(rel2abs(catfile($config{sourcedir},
775                                            "util", "dofile.pl")),
776                            rel2abs($config{builddir}));
777       return <<"EOF";
778 $script : $sources
779         \$(PERL) "-I\$(BLDDIR)" -Mconfigdata "$dofile" $sources > "$script"
780         chmod a+x $script
781 EOF
782   }
783   ""    # Important!  This becomes part of the template result.
784 -}