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