unix-Makefile.tmpl 42.1 KB
Newer Older
1 2 3 4 5
##
## Makefile for OpenSSL
##
## {- join("\n## ", @autowarntext) -}
{-
B
Ben Laurie 已提交
6 7 8 9 10 11 12 13 14
     our $objext = $target{obj_extension} || ".o";
     our $depext = $target{dep_extension} || ".d";
     our $exeext = $target{exe_extension} || "";
     our $libext = $target{lib_extension} || ".a";
     our $shlibext = $target{shared_extension} || ".so";
     our $shlibextsimple = $target{shared_extension_simple} || ".so";
     our $shlibextimport = $target{shared_import_extension} || "";
     our $dsoext = $target{dso_extension} || ".so";

15
     sub windowsdll { $config{target} =~ /^(?:Cygwin|mingw)/ }
16

17 18 19
     our $sover_dirname = $config{shlib_version_number};
     $sover_dirname =~ s|\.|_|g
         if $config{target} =~ /^mingw/;
20

21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
     # shlib and shlib_simple both take a static library name and figure
     # out what the shlib name should be.
     #
     # When OpenSSL is configured "no-shared", these functions will just
     # return empty lists, making them suitable to join().
     #
     # With Windows DLL producers, shlib($libname) will return the shared
     # library name (which usually is different from the static library
     # name) with the default shared extension appended to it, while
     # shlib_simple($libname) will return the static library name with
     # the shared extension followed by ".a" appended to it.  The former
     # result is used as the runtime shared library while the latter is
     # used as the DLL import library.
     #
     # On all Unix systems, shlib($libname) will return the library name
     # with the default shared extension, while shlib_simple($libname)
     # will return the name from shlib($libname) with any SO version number
     # removed.  On some systems, they may therefore return the exact same
     # string.
     sub shlib {
         my $lib = shift;
42
         return () if $disabled{shared} || $lib =~ /\.a$/;
43
         return $unified_info{sharednames}->{$lib} . '$(SHLIB_EXT)';
44 45 46
     }
     sub shlib_simple {
         my $lib = shift;
47 48
         return () if $disabled{shared} || $lib =~ /\.a$/;

49
         if (windowsdll()) {
50
             return $lib . '$(SHLIB_EXT_IMPORT)';
51
         }
52
         return $lib .  '$(SHLIB_EXT_SIMPLE)';
53 54
     }

55 56 57 58 59 60
     # Easy fixing of static library names
     sub lib {
         (my $lib = shift) =~ s/\.a$//;
         return $lib . $libext;
     }

61 62 63 64 65 66
     # dso is a complement to shlib / shlib_simple that returns the
     # given libname with the simple shared extension (possible SO version
     # removed).  This differs from shlib_simple() by being unconditional.
     sub dso {
         my $engine = shift;

B
Ben Laurie 已提交
67
         return $engine . $dsoext;
68
     }
69 70 71 72 73 74 75
     # This makes sure things get built in the order they need
     # to. You're welcome.
     sub dependmagic {
         my $target = shift;

         return "$target: build_generated\n\t\$(MAKE) depend && \$(MAKE) _$target\n_$target";
     }
B
Ben Laurie 已提交
76
     '';
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
-}
PLATFORM={- $config{target} -}
OPTIONS={- $config{options} -}
CONFIGURE_ARGS=({- join(", ",quotify_l(@{$config{perlargv}})) -})
SRCDIR={- $config{sourcedir} -}
BLDDIR={- $config{builddir} -}

VERSION={- $config{version} -}
MAJOR={- $config{major} -}
MINOR={- $config{minor} -}
SHLIB_VERSION_NUMBER={- $config{shlib_version_number} -}
SHLIB_VERSION_HISTORY={- $config{shlib_version_history} -}
SHLIB_MAJOR={- $config{shlib_major} -}
SHLIB_MINOR={- $config{shlib_minor} -}
SHLIB_TARGET={- $target{shared_target} -}
92 93 94
SHLIB_EXT={- $shlibext -}
SHLIB_EXT_SIMPLE={- $shlibextsimple -}
SHLIB_EXT_IMPORT={- $shlibextimport -}
95

96
LIBS={- join(" ", map { lib($_) } @{$unified_info{libraries}}) -}
97
SHLIBS={- join(" ", map { shlib($_) } @{$unified_info{libraries}}) -}
98
SHLIB_INFO={- join(" ", map { "\"".shlib($_).";".shlib_simple($_)."\"" } @{$unified_info{libraries}}) -}
99
ENGINES={- join(" ", map { dso($_) } @{$unified_info{engines}}) -}
100
PROGRAMS={- join(" ", map { $_.$exeext } @{$unified_info{programs}}) -}
101
SCRIPTS={- join(" ", @{$unified_info{scripts}}) -}
102
{- output_off() if $disabled{makedepend}; "" -}
B
Ben Laurie 已提交
103
DEPS={- join(" ", map { (my $x = $_) =~ s|\.o$|$depext|; $x; }
104 105
                  grep { $unified_info{sources}->{$_}->[0] =~ /\.c$/ }
                  keys %{$unified_info{sources}}); -}
106
{- output_on() if $disabled{makedepend}; "" -}
107
GENERATED_MANDATORY={- join(" ", @{$unified_info{depends}->{""}} ) -}
108 109 110 111 112 113
GENERATED={- join(" ",
                  ( map { (my $x = $_) =~ s|\.S$|\.s|; $x }
                    grep { defined $unified_info{generate}->{$_} }
                    map { @{$unified_info{sources}->{$_}} }
                    grep { /\.o$/ } keys %{$unified_info{sources}} ),
                  ( grep { /\.h$/ } keys %{$unified_info{generate}} )) -}
114

115
INSTALL_LIBS={- join(" ", map { lib($_) } @{$unified_info{install}->{libraries}}) -}
116 117 118 119
INSTALL_SHLIBS={- join(" ", map { shlib($_) } @{$unified_info{install}->{libraries}}) -}
INSTALL_SHLIB_INFO={- join(" ", map { "\"".shlib($_).";".shlib_simple($_)."\"" } @{$unified_info{install}->{libraries}}) -}
INSTALL_ENGINES={- join(" ", map { dso($_) } @{$unified_info{install}->{engines}}) -}
INSTALL_PROGRAMS={- join(" ", map { $_.$exeext } @{$unified_info{install}->{programs}}) -}
120
{- output_off() if $disabled{apps}; "" -}
121
BIN_SCRIPTS=$(BLDDIR)/tools/c_rehash
R
Rich Salz 已提交
122
MISC_SCRIPTS=$(BLDDIR)/apps/CA.pl $(BLDDIR)/apps/tsget
123
{- output_on() if $disabled{apps}; "" -}
124

R
Richard Levitte 已提交
125 126 127
APPS_OPENSSL={- use File::Spec::Functions;
                catfile("apps","openssl") -}

128 129
# DESTDIR is for package builders so that they can configure for, say,
# /usr/ and yet have everything installed to /tmp/somedir/usr/.
130
# Normally it is left empty.
131
DESTDIR=
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165

# Do not edit these manually. Use Configure with --prefix or --openssldir
# to change this!  Short explanation in the top comment in Configure
INSTALLTOP={- # $prefix is used in the OPENSSLDIR perl snippet
	      #
	      our $prefix = $config{prefix} || "/usr/local";
              $prefix -}
OPENSSLDIR={- #
	      # The logic here is that if no --openssldir was given,
	      # OPENSSLDIR will get the value from $prefix plus "/ssl".
	      # If --openssldir was given and the value is an absolute
	      # path, OPENSSLDIR will get its value without change.
	      # If the value from --openssldir is a relative path,
	      # OPENSSLDIR will get $prefix with the --openssldir
	      # value appended as a subdirectory.
	      #
              use File::Spec::Functions;
              our $openssldir =
                  $config{openssldir} ?
                      (file_name_is_absolute($config{openssldir}) ?
                           $config{openssldir}
                           : catdir($prefix, $config{openssldir}))
                      : catdir($prefix, "ssl");
              $openssldir -}
LIBDIR={- #
          # if $prefix/lib$target{multilib} is not an existing
          # directory, then assume that it's not searched by linker
          # automatically, in which case adding $target{multilib} suffix
          # causes more grief than we're ready to tolerate, so don't...
          our $multilib =
              -d "$prefix/lib$target{multilib}" ? $target{multilib} : "";
          our $libdir = $config{libdir} || "lib$multilib";
          $libdir -}
ENGINESDIR={- use File::Spec::Functions;
166
              catdir($prefix,$libdir,"engines-$sover_dirname") -}
167

168 169 170 171
# Convenience variable for those who want to set the rpath in shared
# libraries and applications
LIBRPATH=$(INSTALLTOP)/$(LIBDIR)

172
MANDIR=$(INSTALLTOP)/share/man
173 174
DOCDIR=$(INSTALLTOP)/share/doc/$(BASENAME)
HTMLDIR=$(DOCDIR)/html
175

R
Richard Levitte 已提交
176 177 178 179
# MANSUFFIX is for the benefit of anyone who may want to have a suffix
# appended after the manpage file section number.  "ssl" is popular,
# resulting in files such as config.5ssl rather than config.5.
MANSUFFIX=
180 181
HTMLSUFFIX=html

182 183
# For "optional" echo messages, to get "real" silence
ECHO = echo
184 185 186

CROSS_COMPILE= {- $config{cross_compile_prefix} -}
CC= $(CROSS_COMPILE){- $target{cc} -}
187
CFLAGS={- our $cflags2 = join(" ",(map { "-D".$_} @{$target{defines}}, @{$config{defines}}),"-DOPENSSLDIR=\"\\\"\$(OPENSSLDIR)\\\"\"","-DENGINESDIR=\"\\\"\$(ENGINESDIR)\\\"\"") -} {- $target{cflags} -} {- $config{cflags} -}
188
CFLAGS_Q={- $cflags2 =~ s|([\\"])|\\$1|g; $cflags2 -} {- $config{cflags} -}
189
CXX= $(CROSS_COMPILE){- $target{cxx} -}
M
Matt Caswell 已提交
190
CXXFLAGS={- our $cxxflags2 = join(" ",(map { "-D".$_} @{$target{defines}}, @{$config{defines}}),"-DOPENSSLDIR=\"\\\"\$(OPENSSLDIR)\\\"\"","-DENGINESDIR=\"\\\"\$(ENGINESDIR)\\\"\"") -} {- $target{cxxflags} -} {- $config{cxxflags} -} -std=c++11
191 192
LDFLAGS= {- $target{lflags} -}
PLIB_LDFLAGS= {- $target{plib_lflags} -}
193
EX_LIBS= {- $target{ex_libs} -} {- $config{ex_libs} -}
194
LIB_CFLAGS={- $target{shared_cflag} || "" -}
195
LIB_CXXFLAGS={- $target{shared_cxxflag} || "" -}
R
Richard Levitte 已提交
196
LIB_LDFLAGS={- $target{shared_ldflag}." ".$config{shared_ldflag} -}
197
DSO_CFLAGS={- $target{shared_cflag} || "" -}
198
DSO_CXXFLAGS={- $target{shared_cxxflag} || "" -}
199
DSO_LDFLAGS=$(LIB_LDFLAGS)
A
Andy Polyakov 已提交
200
BIN_CFLAGS={- $target{bin_cflags} -}
201
BIN_CXXFLAGS={- $target{bin_cxxflag} || "" -}
202 203 204 205 206 207 208

PERL={- $config{perl} -}

ARFLAGS= {- $target{arflags} -}
AR=$(CROSS_COMPILE){- $target{ar} || "ar" -} $(ARFLAGS) r
RANLIB= {- $target{ranlib} -}
NM= $(CROSS_COMPILE){- $target{nm} || "nm" -}
209 210
RCFLAGS={- $target{shared_rcflag} -}
RC= $(CROSS_COMPILE){- $target{rc} || "windres" -}
211
RM= rm -f
212
RMDIR= rmdir
213 214
TAR= {- $target{tar} || "tar" -}
TARFLAGS= {- $target{tarflags} -}
215
MAKEDEPEND={- $config{makedepprog} -}
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233

BASENAME=       openssl
NAME=           $(BASENAME)-$(VERSION)
TARFILE=        ../$(NAME).tar

# We let the C compiler driver to take care of .s files. This is done in
# order to be excused from maintaining a separate set of architecture
# dependent assembler flags. E.g. if you throw -mcpu=ultrasparc at SPARC
# gcc, then the driver will automatically translate it to -xarch=v8plus
# and pass it down to assembler.
AS=$(CC) -c
ASFLAG=$(CFLAGS)
PERLASM_SCHEME= {- $target{perlasm_scheme} -}

# For x86 assembler: Set PROCESSOR to 386 if you want to support
# the 80386.
PROCESSOR= {- $config{processor} -}

234 235 236 237 238 239 240 241 242
# We want error [and other] messages in English. Trouble is that make(1)
# doesn't pass macros down as environment variables unless there already
# was corresponding variable originally set. In other words we can only
# reassign environment variables, but not set new ones, not in portable
# manner that is. That's why we reassign several, just to be sure...
LC_ALL=C
LC_MESSAGES=C
LANG=C

243 244
# The main targets ###################################################

245
{- dependmagic('all'); -}: build_libs_nodep build_engines_nodep build_programs_nodep link-utils
246 247
{- dependmagic('build_libs'); -}: build_libs_nodep
{- dependmagic('build_engines'); -}: build_engines_nodep
248
{- dependmagic('build_programs'); -}: build_programs_nodep
249

250
build_generated: $(GENERATED_MANDATORY)
251 252
build_libs_nodep: libcrypto.pc libssl.pc openssl.pc
build_engines_nodep: $(ENGINES)
253 254 255 256
build_programs_nodep: $(PROGRAMS) $(SCRIPTS)

# Kept around for backward compatibility
build_apps build_tests: build_programs
257

258 259 260 261
# Convenience target to prebuild all generated files, not just the mandatory
# ones
build_all_generated: $(GENERATED_MANDATORY) $(GENERATED)

262
test: tests
263
{- dependmagic('tests'); -}: build_programs_nodep build_engines_nodep link-utils
M
Matt Caswell 已提交
264
	@ : {- output_off() if $disabled{tests}; "" -}
265 266 267
	( cd test; \
	  SRCTOP=../$(SRCDIR) \
	  BLDTOP=../$(BLDDIR) \
268
	  PERL="$(PERL)" \
B
Ben Laurie 已提交
269
	  EXE_EXT={- $exeext -} \
270
	  OPENSSL_ENGINES=../$(BLDDIR)/engines \
271
	  OPENSSL_DEBUG_MEMORY=on \
272
	    $(PERL) ../$(SRCDIR)/test/run_tests.pl $(TESTS) )
M
Matt Caswell 已提交
273 274 275
	@ : {- if ($disabled{tests}) { output_on(); } else { output_off(); } "" -}
	@echo "Tests are not supported with your chosen Configure options"
	@ : {- output_on() if !$disabled{tests}; "" -}
276 277

list-tests:
278 279 280 281 282 283 284 285 286 287
	@ : {- output_off() if $disabled{tests}; "" -}
	@SRCTOP="$(SRCDIR)" \
	 $(PERL) $(SRCDIR)/test/run_tests.pl list
	@ : {- if ($disabled{tests}) { output_on(); } else { output_off(); } "" -}
	@echo "Tests are not supported with your chosen Configure options"
	@ : {- output_on() if !$disabled{tests}; "" -}

install: install_sw install_ssldirs install_docs

uninstall: uninstall_docs uninstall_sw
288 289

libclean:
R
Richard Levitte 已提交
290 291 292
	@set -e; for s in $(SHLIB_INFO); do \
		s1=`echo "$$s" | cut -f1 -d";"`; \
		s2=`echo "$$s" | cut -f2 -d";"`; \
293
		$(ECHO) $(RM) $$s1; \
R
Richard Levitte 已提交
294 295
		$(RM) $$s1; \
		if [ "$$s1" != "$$s2" ]; then \
296
			$(ECHO) $(RM) $$s2; \
R
Richard Levitte 已提交
297 298 299 300
			$(RM) $$s2; \
		fi; \
	done
	$(RM) $(LIBS)
301
	$(RM) *.map
302 303

clean: libclean
304 305 306 307 308
	$(RM) $(PROGRAMS) $(TESTPROGS) $(ENGINES) $(SCRIPTS)
	$(RM) $(GENERATED)
	-$(RM) `find . -name '*{- $depext -}' -a \! -path "./.git/*"`
	-$(RM) `find . -name '*{- $objext -}' -a \! -path "./.git/*"`
	$(RM) core
R
Rich Salz 已提交
309
	$(RM) tags TAGS doc-nits
B
Bernd Edlinger 已提交
310
	$(RM) test/.rnd
311 312 313
	$(RM) openssl.pc libcrypto.pc libssl.pc
	-$(RM) `find . -type l -a \! -path "./.git/*"`
	$(RM) $(TARFILE)
314

315
distclean: clean
316 317
	$(RM) configdata.pm
	$(RM) Makefile
318

319
# We check if any depfile is newer than Makefile and decide to
R
Richard Levitte 已提交
320
# concatenate only if that is true.
321
depend:
322
	@: {- output_off() if $disabled{makedepend}; "" -}
B
Ben Laurie 已提交
323
	@if egrep "^# DO NOT DELETE THIS LINE" Makefile >/dev/null && [ -z "`find $(DEPS) -newer Makefile 2>/dev/null; exit 0`" ]; then :; else \
324
	  ( $(PERL) -pe 'exit 0 if /^# DO NOT DELETE THIS LINE.*/' < Makefile; \
325 326
	    echo '# DO NOT DELETE THIS LINE -- make depend depends on it.'; \
	    echo; \
R
Richard Levitte 已提交
327 328
	    for f in $(DEPS); do \
	      if [ -f $$f ]; then cat $$f; fi; \
329
	    done ) > Makefile.new; \
R
Richard Levitte 已提交
330
	  if cmp Makefile.new Makefile >/dev/null 2>&1; then \
331
	    rm -f Makefile.new; \
R
Richard Levitte 已提交
332 333
	  else \
	    mv -f Makefile.new Makefile; \
334
	  fi; \
335
	fi
336
	@: {- output_on() if $disabled{makedepend}; "" -}
337 338 339 340 341

# Install helper targets #############################################

install_sw: all install_dev install_engines install_runtime

R
Richard Levitte 已提交
342
uninstall_sw: uninstall_runtime uninstall_engines uninstall_dev
343 344 345 346

install_docs: install_man_docs install_html_docs

uninstall_docs: uninstall_man_docs uninstall_html_docs
347
	$(RM) -r -v $(DESTDIR)$(DOCDIR)
348

349 350 351
install_ssldirs:
	@$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(OPENSSLDIR)/certs
	@$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(OPENSSLDIR)/private
352
	@$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(OPENSSLDIR)/misc
353 354 355
	@set -e; for x in dummy $(MISC_SCRIPTS); do \
		if [ "$$x" = "dummy" ]; then continue; fi; \
		fn=`basename $$x`; \
356
		$(ECHO) "install $$x -> $(DESTDIR)$(OPENSSLDIR)/misc/$$fn"; \
357 358 359 360 361
		cp $$x $(DESTDIR)$(OPENSSLDIR)/misc/$$fn.new; \
		chmod 755 $(DESTDIR)$(OPENSSLDIR)/misc/$$fn.new; \
		mv -f $(DESTDIR)$(OPENSSLDIR)/misc/$$fn.new \
		      $(DESTDIR)$(OPENSSLDIR)/misc/$$fn; \
	done
362
	@$(ECHO) "install $(SRCDIR)/apps/openssl.cnf -> $(DESTDIR)$(OPENSSLDIR)/openssl.cnf.dist"
363 364
	@cp $(SRCDIR)/apps/openssl.cnf $(DESTDIR)$(OPENSSLDIR)/openssl.cnf.new
	@chmod 644 $(DESTDIR)$(OPENSSLDIR)/openssl.cnf.new
365
	@mv -f  $(DESTDIR)$(OPENSSLDIR)/openssl.cnf.new $(DESTDIR)$(OPENSSLDIR)/openssl.cnf.dist
R
Rich Salz 已提交
366
	@if [ ! -f "$(DESTDIR)$(OPENSSLDIR)/openssl.cnf" ]; then \
367
		$(ECHO) "install $(SRCDIR)/apps/openssl.cnf -> $(DESTDIR)$(OPENSSLDIR)/openssl.cnf"; \
368 369 370
		cp $(SRCDIR)/apps/openssl.cnf $(DESTDIR)$(OPENSSLDIR)/openssl.cnf; \
		chmod 644 $(DESTDIR)$(OPENSSLDIR)/openssl.cnf; \
	fi
371
	@$(ECHO) "install $(SRCDIR)/apps/ct_log_list.cnf -> $(DESTDIR)$(OPENSSLDIR)/ct_log_list.cnf.dist"
R
Rich Salz 已提交
372 373 374 375
	@cp $(SRCDIR)/apps/ct_log_list.cnf $(DESTDIR)$(OPENSSLDIR)/ct_log_list.cnf.new
	@chmod 644 $(DESTDIR)$(OPENSSLDIR)/ct_log_list.cnf.new
	@mv -f  $(DESTDIR)$(OPENSSLDIR)/ct_log_list.cnf.new $(DESTDIR)$(OPENSSLDIR)/ct_log_list.cnf.dist
	@if [ ! -f "$(DESTDIR)$(OPENSSLDIR)/ct_log_list.cnf" ]; then \
376
		$(ECHO) "install $(SRCDIR)/apps/ct_log_list.cnf -> $(DESTDIR)$(OPENSSLDIR)/ct_log_list.cnf"; \
R
Rich Salz 已提交
377 378 379
		cp $(SRCDIR)/apps/ct_log_list.cnf $(DESTDIR)$(OPENSSLDIR)/ct_log_list.cnf; \
		chmod 644 $(DESTDIR)$(OPENSSLDIR)/ct_log_list.cnf; \
	fi
380

381 382
install_dev:
	@[ -n "$(INSTALLTOP)" ] || (echo INSTALLTOP should not be empty; exit 1)
383
	@$(ECHO) "*** Installing development files"
384
	@$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(INSTALLTOP)/include/openssl
385
	@ : {- output_off() unless grep { $_ eq "OPENSSL_USE_APPLINK" } @{$target{defines}}; "" -}
386
	@$(ECHO) "install $(SRCDIR)/ms/applink.c -> $(DESTDIR)$(INSTALLTOP)/include/openssl/applink.c"
387 388 389
	@cp $(SRCDIR)/ms/applink.c $(DESTDIR)$(INSTALLTOP)/include/openssl/applink.c
	@chmod 644 $(DESTDIR)$(INSTALLTOP)/include/openssl/applink.c
	@ : {- output_on() unless grep { $_ eq "OPENSSL_USE_APPLINK" } @{$target{defines}}; "" -}
390 391 392
	@set -e; for i in $(SRCDIR)/include/openssl/*.h \
			  $(BLDDIR)/include/openssl/*.h; do \
		fn=`basename $$i`; \
393
		$(ECHO) "install $$i -> $(DESTDIR)$(INSTALLTOP)/include/openssl/$$fn"; \
394 395
		cp $$i $(DESTDIR)$(INSTALLTOP)/include/openssl/$$fn; \
		chmod 644 $(DESTDIR)$(INSTALLTOP)/include/openssl/$$fn; \
396
	done
397
	@$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)
398
	@set -e; for l in $(INSTALL_LIBS); do \
399
		fn=`basename $$l`; \
400
		$(ECHO) "install $$l -> $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn"; \
401 402 403 404 405
		cp $$l $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn.new; \
		$(RANLIB) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn.new; \
		chmod 644 $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn.new; \
		mv -f $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn.new \
		      $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn; \
406
	done
407
	@ : {- output_off() if $disabled{shared}; "" -}
408
	@set -e; for s in $(INSTALL_SHLIB_INFO); do \
409 410 411 412 413
		s1=`echo "$$s" | cut -f1 -d";"`; \
		s2=`echo "$$s" | cut -f2 -d";"`; \
		fn1=`basename $$s1`; \
		fn2=`basename $$s2`; \
		: {- output_off() if windowsdll(); "" -}; \
414
		$(ECHO) "install $$s1 -> $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn1"; \
415
		cp $$s1 $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn1.new; \
416
		chmod 755 $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn1.new; \
417 418 419
		mv -f $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn1.new \
		      $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn1; \
		if [ "$$fn1" != "$$fn2" ]; then \
420
			$(ECHO) "link $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn2 -> $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn1"; \
421
			ln -sf $$fn1 $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn2; \
422
		fi; \
423
		: {- output_on() if windowsdll(); "" -}{- output_off() unless windowsdll(); "" -}; \
424
		$(ECHO) "install $$s2 -> $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn2"; \
425
		cp $$s2 $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn2.new; \
426
		chmod 755 $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn2.new; \
427 428
		mv -f $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn2.new \
		      $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn2; \
429
		: {- output_on() unless windowsdll(); "" -}; \
430
	done
431
	@ : {- output_on() if $disabled{shared}; "" -}
432
	@$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig
433
	@$(ECHO) "install libcrypto.pc -> $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/libcrypto.pc"
434 435
	@cp libcrypto.pc $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig
	@chmod 644 $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/libcrypto.pc
436
	@$(ECHO) "install libssl.pc -> $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/libssl.pc"
437 438
	@cp libssl.pc $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig
	@chmod 644 $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/libssl.pc
439
	@$(ECHO) "install openssl.pc -> $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/openssl.pc"
440 441
	@cp openssl.pc $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig
	@chmod 644 $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/openssl.pc
442 443

uninstall_dev:
444
	@$(ECHO) "*** Uninstalling development files"
445
	@ : {- output_off() unless grep { $_ eq "OPENSSL_USE_APPLINK" } @{$target{defines}}; "" -}
446
	@$(ECHO) "$(RM) $(DESTDIR)$(INSTALLTOP)/include/openssl/applink.c"
447 448
	@$(RM) $(DESTDIR)$(INSTALLTOP)/include/openssl/applink.c
	@ : {- output_on() unless grep { $_ eq "OPENSSL_USE_APPLINK" } @{$target{defines}}; "" -}
449 450 451
	@set -e; for i in $(SRCDIR)/include/openssl/*.h \
			  $(BLDDIR)/include/openssl/*.h; do \
		fn=`basename $$i`; \
452
		$(ECHO) "$(RM) $(DESTDIR)$(INSTALLTOP)/include/openssl/$$fn"; \
453
		$(RM) $(DESTDIR)$(INSTALLTOP)/include/openssl/$$fn; \
454
	done
455 456
	-$(RMDIR) $(DESTDIR)$(INSTALLTOP)/include/openssl
	-$(RMDIR) $(DESTDIR)$(INSTALLTOP)/include
457
	@set -e; for l in $(INSTALL_LIBS); do \
458
		fn=`basename $$l`; \
459
		$(ECHO) "$(RM) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn"; \
460
		$(RM) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn; \
461
	done
462
	@ : {- output_off() if $disabled{shared}; "" -}
463
	@set -e; for s in $(INSTALL_SHLIB_INFO); do \
464 465 466 467 468
		s1=`echo "$$s" | cut -f1 -d";"`; \
		s2=`echo "$$s" | cut -f2 -d";"`; \
		fn1=`basename $$s1`; \
		fn2=`basename $$s2`; \
		: {- output_off() if windowsdll(); "" -}; \
469
		$(ECHO) "$(RM) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn1"; \
470 471
		$(RM) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn1; \
		if [ "$$fn1" != "$$fn2" ]; then \
472
			$(ECHO) "$(RM) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn2"; \
473
			$(RM) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn2; \
474
		fi; \
475
		: {- output_on() if windowsdll(); "" -}{- output_off() unless windowsdll(); "" -}; \
476
		$(ECHO) "$(RM) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn2"; \
477
		$(RM) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn2; \
478
		: {- output_on() unless windowsdll(); "" -}; \
479
	done
480
	@ : {- output_on() if $disabled{shared}; "" -}
R
Richard Levitte 已提交
481 482 483 484 485
	$(RM) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/libcrypto.pc
	$(RM) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/libssl.pc
	$(RM) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/openssl.pc
	-$(RMDIR) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig
	-$(RMDIR) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)
486 487 488

install_engines:
	@[ -n "$(INSTALLTOP)" ] || (echo INSTALLTOP should not be empty; exit 1)
489
	@$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(ENGINESDIR)/
490
	@$(ECHO) "*** Installing engines"
491
	@set -e; for e in dummy $(INSTALL_ENGINES); do \
492
		if [ "$$e" = "dummy" ]; then continue; fi; \
493
		fn=`basename $$e`; \
494
		$(ECHO) "install $$e -> $(DESTDIR)$(ENGINESDIR)/$$fn"; \
495 496 497 498
		cp $$e $(DESTDIR)$(ENGINESDIR)/$$fn.new; \
		chmod 755 $(DESTDIR)$(ENGINESDIR)/$$fn.new; \
		mv -f $(DESTDIR)$(ENGINESDIR)/$$fn.new \
		      $(DESTDIR)$(ENGINESDIR)/$$fn; \
499 500 501
	done

uninstall_engines:
502
	@$(ECHO) "*** Uninstalling engines"
503
	@set -e; for e in dummy $(INSTALL_ENGINES); do \
504
		if [ "$$e" = "dummy" ]; then continue; fi; \
505
		fn=`basename $$e`; \
506 507 508
		if [ "$$fn" = '{- dso("ossltest") -}' ]; then \
			continue; \
		fi; \
509
		$(ECHO) "$(RM) $(DESTDIR)$(ENGINESDIR)/$$fn"; \
510
		$(RM) $(DESTDIR)$(ENGINESDIR)/$$fn; \
511
	done
512
	-$(RMDIR) $(DESTDIR)$(ENGINESDIR)
513 514 515

install_runtime:
	@[ -n "$(INSTALLTOP)" ] || (echo INSTALLTOP should not be empty; exit 1)
516
	@$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(INSTALLTOP)/bin
517 518 519
	@ : {- output_off() if windowsdll(); "" -}
	@$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)
	@ : {- output_on() if windowsdll(); "" -}
520
	@$(ECHO) "*** Installing runtime files"
521
	@set -e; for s in dummy $(INSTALL_SHLIBS); do \
522
		if [ "$$s" = "dummy" ]; then continue; fi; \
R
Richard Levitte 已提交
523
		fn=`basename $$s`; \
524
		: {- output_off() unless windowsdll(); "" -}; \
525
		$(ECHO) "install $$s -> $(DESTDIR)$(INSTALLTOP)/bin/$$fn"; \
526 527 528 529
		cp $$s $(DESTDIR)$(INSTALLTOP)/bin/$$fn.new; \
		chmod 644 $(DESTDIR)$(INSTALLTOP)/bin/$$fn.new; \
		mv -f $(DESTDIR)$(INSTALLTOP)/bin/$$fn.new \
		      $(DESTDIR)$(INSTALLTOP)/bin/$$fn; \
530
		: {- output_on() unless windowsdll(); "" -}{- output_off() if windowsdll(); "" -}; \
531
		$(ECHO) "install $$s -> $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn"; \
532 533 534 535 536
		cp $$s $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn.new; \
		chmod 755 $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn.new; \
		mv -f $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn.new \
		      $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn; \
		: {- output_on() if windowsdll(); "" -}; \
537
	done
538
	@set -e; for x in dummy $(INSTALL_PROGRAMS); do \
539
		if [ "$$x" = "dummy" ]; then continue; fi; \
540
		fn=`basename $$x`; \
541
		$(ECHO) "install $$x -> $(DESTDIR)$(INSTALLTOP)/bin/$$fn"; \
542 543 544 545
		cp $$x $(DESTDIR)$(INSTALLTOP)/bin/$$fn.new; \
		chmod 755 $(DESTDIR)$(INSTALLTOP)/bin/$$fn.new; \
		mv -f $(DESTDIR)$(INSTALLTOP)/bin/$$fn.new \
		      $(DESTDIR)$(INSTALLTOP)/bin/$$fn; \
546
	done
547 548
	@set -e; for x in dummy $(BIN_SCRIPTS); do \
		if [ "$$x" = "dummy" ]; then continue; fi; \
549
		fn=`basename $$x`; \
550
		$(ECHO) "install $$x -> $(DESTDIR)$(INSTALLTOP)/bin/$$fn"; \
551 552 553 554
		cp $$x $(DESTDIR)$(INSTALLTOP)/bin/$$fn.new; \
		chmod 755 $(DESTDIR)$(INSTALLTOP)/bin/$$fn.new; \
		mv -f $(DESTDIR)$(INSTALLTOP)/bin/$$fn.new \
		      $(DESTDIR)$(INSTALLTOP)/bin/$$fn; \
555 556 557
	done

uninstall_runtime:
558
	@$(ECHO) "*** Uninstalling runtime files"
559
	@set -e; for x in dummy $(INSTALL_PROGRAMS); \
560
	do  \
561
		if [ "$$x" = "dummy" ]; then continue; fi; \
562
		fn=`basename $$x`; \
563
		$(ECHO) "$(RM) $(DESTDIR)$(INSTALLTOP)/bin/$$fn"; \
564
		$(RM) $(DESTDIR)$(INSTALLTOP)/bin/$$fn; \
565
	done;
566
	@set -e; for x in dummy $(BIN_SCRIPTS); \
567
	do  \
568
		if [ "$$x" = "dummy" ]; then continue; fi; \
569
		fn=`basename $$x`; \
570
		$(ECHO) "$(RM) $(DESTDIR)$(INSTALLTOP)/bin/$$fn"; \
571
		$(RM) $(DESTDIR)$(INSTALLTOP)/bin/$$fn; \
572
	done
573
	@ : {- output_off() unless windowsdll(); "" -}
574
	@set -e; for s in dummy $(INSTALL_SHLIBS); do \
575
		if [ "$$s" = "dummy" ]; then continue; fi; \
R
Richard Levitte 已提交
576
		fn=`basename $$s`; \
577
		$(ECHO) "$(RM) $(DESTDIR)$(INSTALLTOP)/bin/$$fn"; \
578
		$(RM) $(DESTDIR)$(INSTALLTOP)/bin/$$fn; \
579
	done
580
	@ : {- output_on() unless windowsdll(); "" -}
R
Richard Levitte 已提交
581
	-$(RMDIR) $(DESTDIR)$(INSTALLTOP)/bin
582 583 584 585


install_man_docs:
	@[ -n "$(INSTALLTOP)" ] || (echo INSTALLTOP should not be empty; exit 1)
586
	@$(ECHO) "*** Installing manpages"
587 588
	$(PERL) $(SRCDIR)/util/process_docs.pl \
		--destdir=$(DESTDIR)$(MANDIR) --type=man --suffix=$(MANSUFFIX)
589 590

uninstall_man_docs:
591
	@$(ECHO) "*** Uninstalling manpages"
592 593 594
	$(PERL) $(SRCDIR)/util/process_docs.pl \
		--destdir=$(DESTDIR)$(MANDIR) --type=man --suffix=$(MANSUFFIX) \
		--remove
595 596 597

install_html_docs:
	@[ -n "$(INSTALLTOP)" ] || (echo INSTALLTOP should not be empty; exit 1)
598
	@$(ECHO) "*** Installing HTML manpages"
599 600
	$(PERL) $(SRCDIR)/util/process_docs.pl \
		--destdir=$(DESTDIR)$(HTMLDIR) --type=html
601 602

uninstall_html_docs:
603
	@$(ECHO) "*** Uninstalling manpages"
604 605
	$(PERL) $(SRCDIR)/util/process_docs.pl \
		--destdir=$(DESTDIR)$(HTMLDIR) --type=html --remove
606 607 608 609


# Developer targets (note: these are only available on Unix) #########

610 611
update: generate errors ordinals

612 613
generate: generate_apps generate_crypto_bn generate_crypto_objects \
          generate_crypto_conf generate_crypto_asn1
614

615
doc-nits:
R
Rich Salz 已提交
616
	(cd $(SRCDIR); $(PERL) util/find-doc-nits -n -p ) >doc-nits
R
Rich Salz 已提交
617
	if [ -s doc-nits ] ; then cat doc-nits; rm doc-nits ; exit 1; fi
618

619 620 621 622 623 624 625
# Test coverage is a good idea for the future
#coverage: $(PROGRAMS) $(TESTPROGRAMS)
#	...

lint:
	lint -DLINT $(INCLUDES) $(SRCS)

626 627 628 629 630 631 632 633 634 635 636 637
generate_apps:
	( cd $(SRCDIR); $(PERL) VMS/VMSify-conf.pl \
				< apps/openssl.cnf > apps/openssl-vms.cnf )

generate_crypto_bn:
	( cd $(SRCDIR); $(PERL) crypto/bn/bn_prime.pl > crypto/bn/bn_prime.h )

generate_crypto_objects:
	( cd $(SRCDIR); $(PERL) crypto/objects/objects.pl \
				crypto/objects/objects.txt \
				crypto/objects/obj_mac.num \
				include/openssl/obj_mac.h )
638 639 640
	( cd $(SRCDIR); $(PERL) crypto/objects/obj_dat.pl \
				include/openssl/obj_mac.h \
				crypto/objects/obj_dat.h )
641 642 643 644
	( cd $(SRCDIR); $(PERL) crypto/objects/objxref.pl \
				crypto/objects/obj_mac.num \
				crypto/objects/obj_xref.txt \
				> crypto/objects/obj_xref.h )
645

646 647 648 649 650 651 652 653
generate_crypto_conf:
	( cd $(SRCDIR); $(PERL) crypto/conf/keysets.pl \
			        > crypto/conf/conf_def.h )

generate_crypto_asn1:
	( cd $(SRCDIR); $(PERL) crypto/asn1/charmap.pl \
			        > crypto/asn1/charmap.h )

654 655
# Set to -force to force a rebuild
ERROR_REBUILD=
656 657
errors:
	( cd $(SRCDIR); $(PERL) util/ck_errf.pl -strict */*.c */*/*.c )
658
	( cd $(SRCDIR); $(PERL) util/mkerr.pl $(ERROR_REBUILD) -internal )
659
	( cd $(SRCDIR)/engines; \
660 661 662 663
          for E in *.ec ; do \
              $(PERL) ../util/mkerr.pl $(ERROR_REBUILD) -static \
                -conf $$E `basename $$E .ec`.c ; \
          done )
664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681

ordinals:
	( b=`pwd`; cd $(SRCDIR); $(PERL) -I$$b util/mkdef.pl crypto update )
	( b=`pwd`; cd $(SRCDIR); $(PERL) -I$$b util/mkdef.pl ssl update )

test_ordinals:
	( cd test; \
	  SRCTOP=../$(SRCDIR) \
	  BLDTOP=../$(BLDDIR) \
	    $(PERL) ../$(SRCDIR)/test/run_tests.pl test_ordinals )

tags TAGS: FORCE
	rm -f TAGS tags
	-ctags -R .
	-etags `find . -name '*.[ch]' -o -name '*.pm'`

# Release targets (note: only available on Unix) #####################

B
Ben Laurie 已提交
682
TAR_COMMAND=$(TAR) $(TARFLAGS) --owner 0 --group 0 -cvf -
683
PREPARE_CMD=:
684 685
tar:
	TMPDIR=/var/tmp/openssl-copy.$$$$; \
686
	DISTDIR=$(NAME); \
687 688 689
	mkdir -p $$TMPDIR/$$DISTDIR; \
	(cd $(SRCDIR); \
	 git ls-tree -r --name-only --full-tree HEAD \
B
Ben Laurie 已提交
690
         | grep -v '^fuzz/corpora' \
691 692 693 694 695
	 | while read F; do \
	       mkdir -p $$TMPDIR/$$DISTDIR/`dirname $$F`; \
	       cp $$F $$TMPDIR/$$DISTDIR/$$F; \
	   done); \
	(cd $$TMPDIR; \
696
	 $(PREPARE_CMD); \
697 698 699
	 find $$TMPDIR/$$DISTDIR -type d -print | xargs chmod 755; \
	 find $$TMPDIR/$$DISTDIR -type f -print | xargs chmod a+r; \
	 find $$TMPDIR/$$DISTDIR -type f -perm -0100 -print | xargs chmod a+x; \
700
	 $(TAR_COMMAND) $$DISTDIR) \
701 702 703 704 705
	| (cd $(SRCDIR); gzip --best > $(TARFILE).gz); \
	rm -rf $$TMPDIR
	cd $(SRCDIR); ls -l $(TARFILE).gz

dist:
706
	@$(MAKE) PREPARE_CMD='$(PERL) ./Configure dist' tar
707 708 709

# Helper targets #####################################################

710
link-utils: $(BLDDIR)/util/opensslwrap.sh
711

712
$(BLDDIR)/util/opensslwrap.sh: configdata.pm
713 714 715 716
	@if [ "$(SRCDIR)" != "$(BLDDIR)" ]; then \
	    mkdir -p "$(BLDDIR)/util"; \
	    ln -sf "../$(SRCDIR)/util/opensslwrap.sh" "$(BLDDIR)/util"; \
	fi
717

718
FORCE:
719 720 721

# Building targets ###################################################

722
libcrypto.pc libssl.pc openssl.pc: configdata.pm $(LIBS) {- join(" ",map { shlib_simple($_) } @{$unified_info{libraries}}) -}
723 724 725 726 727
libcrypto.pc:
	@ ( echo 'prefix=$(INSTALLTOP)'; \
	    echo 'exec_prefix=$${prefix}'; \
	    echo 'libdir=$${exec_prefix}/$(LIBDIR)'; \
	    echo 'includedir=$${prefix}/include'; \
728
	    echo 'enginesdir=$${libdir}/engines-{- $sover_dirname -}'; \
729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761
	    echo ''; \
	    echo 'Name: OpenSSL-libcrypto'; \
	    echo 'Description: OpenSSL cryptography library'; \
	    echo 'Version: '$(VERSION); \
	    echo 'Libs: -L$${libdir} -lcrypto'; \
	    echo 'Libs.private: $(EX_LIBS)'; \
	    echo 'Cflags: -I$${includedir}' ) > libcrypto.pc

libssl.pc:
	@ ( echo 'prefix=$(INSTALLTOP)'; \
	    echo 'exec_prefix=$${prefix}'; \
	    echo 'libdir=$${exec_prefix}/$(LIBDIR)'; \
	    echo 'includedir=$${prefix}/include'; \
	    echo ''; \
	    echo 'Name: OpenSSL-libssl'; \
	    echo 'Description: Secure Sockets Layer and cryptography libraries'; \
	    echo 'Version: '$(VERSION); \
	    echo 'Requires.private: libcrypto'; \
	    echo 'Libs: -L$${libdir} -lssl'; \
	    echo 'Libs.private: $(EX_LIBS)'; \
	    echo 'Cflags: -I$${includedir}' ) > libssl.pc

openssl.pc:
	@ ( echo 'prefix=$(INSTALLTOP)'; \
	    echo 'exec_prefix=$${prefix}'; \
	    echo 'libdir=$${exec_prefix}/$(LIBDIR)'; \
	    echo 'includedir=$${prefix}/include'; \
	    echo ''; \
	    echo 'Name: OpenSSL'; \
	    echo 'Description: Secure Sockets Layer and cryptography libraries and tools'; \
	    echo 'Version: '$(VERSION); \
	    echo 'Requires: libssl libcrypto' ) > openssl.pc

762
configdata.pm: $(SRCDIR)/Configure $(SRCDIR)/config {- join(" ", @{$config{build_file_templates}}, @{$config{build_infos}}, @{$config{conf_files}}) -}
763
	@echo "Detected changed: $?"
764
	@echo "Reconfiguring..."
765
	$(PERL) $(SRCDIR)/Configure reconf
766 767 768 769 770 771 772 773 774 775
	@echo "**************************************************"
	@echo "***                                            ***"
	@echo "***   Please run the same make command again   ***"
	@echo "***                                            ***"
	@echo "**************************************************"
	@false

{-
  use File::Basename;
  use File::Spec::Functions qw/:DEFAULT abs2rel rel2abs/;
776 777 778 779

  # Helper function to figure out dependencies on libraries
  # It takes a list of library names and outputs a list of dependencies
  sub compute_lib_depends {
780
      if ($disabled{shared}) {
781
          return map { lib($_) } @_;
782 783 784 785 786
      }

      # Depending on shared libraries:
      # On Windows POSIX layers, we depend on {libname}.dll.a
      # On Unix platforms, we depend on {shlibname}.so
787
      return map { $_ =~ /\.a$/ ? $`.$libext : shlib_simple($_) } @_;
788 789
  }

790 791 792
  sub generatesrc {
      my %args = @_;
      my $generator = join(" ", @{$args{generator}});
793
      my $generator_incs = join("", map { " -I".$_ } @{$args{generator_incs}});
794
      my $incs = join("", map { " -I".$_ } @{$args{incs}});
795
      my $deps = join(" ", @{$args{generator_deps}}, @{$args{deps}});
796 797

      if ($args{src} !~ /\.[sS]$/) {
798 799 800 801 802 803 804 805 806 807 808
          if ($args{generator}->[0] =~ m|^.*\.in$|) {
              my $dofile = abs2rel(rel2abs(catfile($config{sourcedir},
                                                   "util", "dofile.pl")),
                                   rel2abs($config{builddir}));
              return <<"EOF";
$args{src}: $args{generator}->[0] $deps
	\$(PERL) "-I\$(BLDDIR)" -Mconfigdata "$dofile" \\
	    "-o$target{build_file}" $generator > \$@
EOF
	  } else {
              return <<"EOF";
809
$args{src}: $args{generator}->[0] $deps
810
	\$(PERL)$generator_incs $generator > \$@
811
EOF
812
	  }
813
      } else {
814
          if ($args{generator}->[0] =~ /\.pl$/) {
815
              $generator = 'CC="$(CC)" $(PERL)'.$generator_incs.' '.$generator;
816
          } elsif ($args{generator}->[0] =~ /\.m4$/) {
817
              $generator = 'm4 -B 8192'.$generator_incs.' '.$generator.' >'
818 819 820 821 822 823 824 825 826 827 828 829
          } elsif ($args{generator}->[0] =~ /\.S$/) {
              $generator = undef;
          } else {
              die "Generator type for $args{src} unknown: $generator\n";
          }

          if (defined($generator)) {
              # If the target is named foo.S in build.info, we want to
              # end up generating foo.s in two steps.
              if ($args{src} =~ /\.S$/) {
                   (my $target = $args{src}) =~ s|\.S$|.s|;
                   return <<"EOF";
830
$target: $args{generator}->[0] $deps
831
	( trap "rm -f \$@.*" INT 0; \\
832
	  $generator \$@.S; \\
833
	  \$(CC) $incs \$(CFLAGS) -E \$@.S | \\
834 835
	  \$(PERL) -ne '/^#(line)?\\s*[0-9]+/ or print' > \$@.i && \\
	  mv -f \$@.i \$@ )
836
EOF
837 838
              }
              # Otherwise....
839
              return <<"EOF";
840
$args{src}: $args{generator}->[0] $deps
841
	$generator \$@
842 843
EOF
          }
844
          return <<"EOF";
845
$args{src}: $args{generator}->[0] $deps
846
	\$(CC) $incs \$(CFLAGS) -E \$< | \\
847
	\$(PERL) -ne '/^#(line)?\\s*[0-9]+/ or print' > \$@
848
EOF
849 850 851
      }
  }

852 853 854
  # Should one wonder about the end of the Perl snippet, it's because this
  # second regexp eats up line endings as well, if the removed path is the
  # last in the line.  We may therefore need to put back a line ending.
855
  sub src2obj {
856
      my %args = @_;
857
      my $obj = $args{obj};
858 859 860 861 862 863
      my @srcs = map { if ($unified_info{generate}->{$_}) {
                           (my $x = $_) =~ s/\.S$/.s/; $x
                       } else {
                           $_
                       }
                     } ( @{$args{srcs}} );
864 865
      my $srcs = join(" ",  @srcs);
      my $deps = join(" ", @srcs, @{$args{deps}});
866
      my $incs = join("", map { " -I".$_ } @{$args{incs}});
867 868 869 870 871
      unless ($disabled{zlib}) {
          if ($withargs{zlib_include}) {
              $incs .= " -I".$withargs{zlib_include};
          }
      }
872 873 874 875 876 877 878 879 880 881 882 883 884
      my $cc = '$(CC)';
      my $cflags = '$(CFLAGS)';
      if (grep /\.(cc|cpp)$/, @srcs) {
          $cc = '$(CXX)';
          $cflags = '$(CXXFLAGS)';
          $cflags .= ' ' . { lib => '$(LIB_CXXFLAGS)',
                             dso => '$(DSO_CXXFLAGS)',
                             bin => '$(BIN_CXXFLAGS)' } -> {$args{intent}};
      } else {
          $cflags .= ' ' . { lib => '$(LIB_CFLAGS)',
                             dso => '$(DSO_CFLAGS)',
                             bin => '$(BIN_CFLAGS)' } -> {$args{intent}};
      }
885
      my $makedepprog = $config{makedepprog};
886 887 888 889
      my $recipe = <<"EOF";
$obj$objext: $deps
EOF
      if (!$disabled{makedepend} && $makedepprog !~ /\/makedepend/) {
890
          $recipe .= <<"EOF";
891
	$cc $incs $cflags -MMD -MF $obj$depext.tmp -MT \$\@ -c -o \$\@ $srcs
892 893 894
	\@touch $obj$depext.tmp
	\@if cmp $obj$depext.tmp $obj$depext > /dev/null 2> /dev/null; then \\
		rm -f $obj$depext.tmp; \\
R
Richard Levitte 已提交
895
	else \\
896
		mv $obj$depext.tmp $obj$depext; \\
897
	fi
898
EOF
899
      } else {
900
          $recipe .= <<"EOF";
901
	$cc $incs $cflags -c -o \$\@ $srcs
902
EOF
903 904
          if (!$disabled{makedepend} && $makedepprog =~ /\/makedepend/) {
              $recipe .= <<"EOF";
905
	-\$(MAKEDEPEND) -f- -o"|\$\@" -- $incs $cflags -- $srcs \\
906 907
	    >$obj$depext.tmp 2>/dev/null
	-\$(PERL) -i -pe 's/^.*\\|//; s/ \\/(\\\\.|[^ ])*//; \$\$_ = undef if (/: *\$\$/ || /^(#.*| *)\$\$/); \$\$_.="\\n" unless !defined(\$\$_) or /\\R\$\$/g;' $obj$depext.tmp
R
Richard Levitte 已提交
908
	\@if cmp $obj$depext.tmp $obj$depext > /dev/null 2> /dev/null; then \\
909
		rm -f $obj$depext.tmp; \\
R
Richard Levitte 已提交
910 911
	else \\
		mv $obj$depext.tmp $obj$depext; \\
912
	fi
913
EOF
914
          }
915 916
      }
      return $recipe;
917 918 919 920 921 922 923 924 925 926 927
  }
  # On Unix, we build shlibs from static libs, so we're ignoring the
  # object file array.  We *know* this routine is only called when we've
  # configure 'shared'.
  sub libobj2shlib {
      my %args = @_;
      my $lib = $args{lib};
      my $shlib = $args{shlib};
      my $libd = dirname($lib);
      my $libn = basename($lib);
      (my $libname = $libn) =~ s/^lib//;
928 929 930 931 932
      my $linklibs = join("", map { my $d = dirname($_);
                                    my $f = basename($_);
                                    (my $l = $f) =~ s/^lib//;
                                    " -L$d -l$l" } @{$args{deps}});
      my $deps = join(" ",compute_lib_depends(@{$args{deps}}));
933 934
      my $shlib_target = $target{shared_target};
      my $ordinalsfile = defined($args{ordinals}) ? $args{ordinals}->[1] : "";
935
      my $target = shlib_simple($lib);
R
Richard Levitte 已提交
936
      my $target_full = shlib($lib);
937
      return <<"EOF"
938 939 940 941 942
# With a build on a Windows POSIX layer (Cygwin or Mingw), we know for a fact
# that two files get produced, {shlibname}.dll and {libname}.dll.a.
# With all other Unix platforms, we often build a shared library with the
# SO version built into the file name and a symlink without the SO version
# It's not necessary to have both as targets.  The choice falls on the
943 944
# simplest, {libname}\$(SHLIB_EXT_IMPORT) for Windows POSIX layers and
# {libname}\$(SHLIB_EXT_SIMPLE) for the Unix platforms.
B
Ben Laurie 已提交
945
$target: $lib$libext $deps $ordinalsfile
946
	\$(MAKE) -f \$(SRCDIR)/Makefile.shared -e \\
947
		ECHO=\$(ECHO) \\
948
		PLATFORM=\$(PLATFORM) \\
949
		PERL="\$(PERL)" SRCDIR='\$(SRCDIR)' DSTDIR="$libd" \\
950 951
		INSTALLTOP='\$(INSTALLTOP)' LIBDIR='\$(LIBDIR)' \\
		LIBDEPS='\$(PLIB_LDFLAGS) '"$linklibs"' \$(EX_LIBS)' \\
952
		LIBNAME=$libname SHLIBVERSION=\$(SHLIB_VERSION_NUMBER) \\
R
Richard Levitte 已提交
953 954
		STLIBNAME=$lib$libext \\
		SHLIBNAME=$target SHLIBNAME_FULL=$target_full \\
955
		CC='\$(CC)' CFLAGS='\$(CFLAGS) \$(LIB_CFLAGS)' \\
R
Richard Levitte 已提交
956
		LDFLAGS='\$(LDFLAGS)' SHARED_LDFLAGS='\$(LIB_LDFLAGS)' \\
957
		RC='\$(RC)' SHARED_RCFLAGS='\$(RCFLAGS)' \\
958
		link_shlib.$shlib_target
959 960
EOF
	  . (windowsdll() ? <<"EOF" : "");
961 962 963 964
	rm -f apps/$shlib'\$(SHLIB_EXT)'
	rm -f test/$shlib'\$(SHLIB_EXT)'
	cp -p $shlib'\$(SHLIB_EXT)' apps/
	cp -p $shlib'\$(SHLIB_EXT)' test/
965 966
EOF
  }
967
  sub obj2dso {
968
      my %args = @_;
R
Richard Levitte 已提交
969 970 971
      my $dso = $args{lib};
      my $dsod = dirname($dso);
      my $dson = basename($dso);
972 973 974 975
      my $shlibdeps = join("", map { my $d = dirname($_);
                                     my $f = basename($_);
                                     (my $l = $f) =~ s/^lib//;
                                     " -L$d -l$l" } @{$args{deps}});
976
      my $deps = join(" ",compute_lib_depends(@{$args{deps}}));
977
      my $shlib_target = $target{shared_target};
B
Ben Laurie 已提交
978
      my $objs = join(" ", map { $_.$objext } @{$args{objs}});
R
Richard Levitte 已提交
979
      my $target = dso($dso);
980
      return <<"EOF";
981
$target: $objs $deps
982
	\$(MAKE) -f \$(SRCDIR)/Makefile.shared -e \\
983
		PLATFORM=\$(PLATFORM) \\
R
Richard Levitte 已提交
984
		PERL="\$(PERL)" SRCDIR='\$(SRCDIR)' DSTDIR="$dsod" \\
985
		LIBDEPS='\$(PLIB_LDFLAGS) '"$shlibdeps"' \$(EX_LIBS)' \\
R
Richard Levitte 已提交
986
		SHLIBNAME_FULL=$target LDFLAGS='\$(LDFLAGS)' \\
987 988
		CC='\$(CC)' CFLAGS='\$(CFLAGS) \$(DSO_CFLAGS)' \\
		SHARED_LDFLAGS='\$(DSO_LDFLAGS)' \\
989
		LIBEXTRAS="$objs" \\
990
		link_dso.$shlib_target
991 992 993 994
EOF
  }
  sub obj2lib {
      my %args = @_;
995
      (my $lib = $args{lib}) =~ s/\.a$//;
B
Ben Laurie 已提交
996
      my $objs = join(" ", map { $_.$objext } @{$args{objs}});
997
      return <<"EOF";
B
Ben Laurie 已提交
998
$lib$libext: $objs
999
	\$(AR) \$\@ \$\?
1000 1001 1002 1003 1004 1005 1006 1007
	\$(RANLIB) \$\@ || echo Never mind.
EOF
  }
  sub obj2bin {
      my %args = @_;
      my $bin = $args{bin};
      my $bind = dirname($bin);
      my $binn = basename($bin);
B
Ben Laurie 已提交
1008
      my $objs = join(" ", map { $_.$objext } @{$args{objs}});
1009
      my $deps = join(" ",compute_lib_depends(@{$args{deps}}));
1010 1011 1012 1013 1014 1015 1016 1017 1018 1019
      my $linklibs = join("", map { if ($_ =~ /\.a$/) {
                                        " $_";
                                    } else {
                                        my $d = dirname($_);
                                        my $f = basename($_);
                                        $d = "." if $d eq $f;
                                        (my $l = $f) =~ s/^lib//;
                                        " -L$d -l$l"
                                    }
                                  } @{$args{deps}});
1020
      my $shlib_target = $disabled{shared} ? "" : $target{shared_target};
1021 1022 1023 1024 1025 1026
      my $cc = '$(CC)';
      my $cflags = '$(CFLAGS) $(BIN_CFLAGS)';
      if (grep /_cc$/, @{$args{objs}}) {
          $cc = '$(CXX)';
          $cflags = '$(CXXFLAGS) $(BIN_CXXFLAGS)';
      }
1027
      return <<"EOF";
B
Ben Laurie 已提交
1028 1029
$bin$exeext: $objs $deps
	\$(RM) $bin$exeext
1030
	\$(MAKE) -f \$(SRCDIR)/Makefile.shared -e \\
1031
		PERL="\$(PERL)" SRCDIR=\$(SRCDIR) \\
B
Ben Laurie 已提交
1032
		APPNAME=$bin$exeext OBJECTS="$objs" \\
1033
		LIBDEPS='\$(PLIB_LDFLAGS) '"$linklibs"' \$(EX_LIBS)' \\
1034
		CC='$cc' CFLAGS='$cflags' \\
1035
		LDFLAGS='\$(LDFLAGS)' \\
1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046
		link_app.$shlib_target
EOF
  }
  sub in2script {
      my %args = @_;
      my $script = $args{script};
      my $sources = join(" ", @{$args{sources}});
      my $dofile = abs2rel(rel2abs(catfile($config{sourcedir},
                                           "util", "dofile.pl")),
                           rel2abs($config{builddir}));
      return <<"EOF";
1047
$script: $sources
1048
	\$(PERL) "-I\$(BLDDIR)" -Mconfigdata "$dofile" \\
1049
	    "-o$target{build_file}" $sources > "$script"
1050
	chmod a+x $script
1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063
EOF
  }
  sub generatedir {
      my %args = @_;
      my $dir = $args{dir};
      my @deps = map { s|\.o$|$objext|; $_ } @{$args{deps}};
      my @actions = ();
      my %extinfo = ( dso => $dsoext,
                      lib => $libext,
                      bin => $exeext );

      foreach my $type (("dso", "lib", "bin", "script")) {
          next unless defined($unified_info{dirinfo}->{$dir}->{products}->{$type});
1064 1065 1066 1067 1068
          # For lib object files, we could update the library.  However, it
          # was decided that it's enough to build the directory local object
          # files, so we don't need to add any actions, and the dependencies
          # are already taken care of.
          if ($type ne "lib") {
1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082
              foreach my $prod (@{$unified_info{dirinfo}->{$dir}->{products}->{$type}}) {
                  if (dirname($prod) eq $dir) {
                      push @deps, $prod.$extinfo{$type};
                  } else {
                      push @actions, "\t@ : No support to produce $type ".join(", ", @{$unified_info{dirinfo}->{$dir}->{products}->{$type}});
                  }
              }
          }
      }

      my $deps = join(" ", @deps);
      my $actions = join("\n", "", @actions);
      return <<"EOF";
$args{dir} $args{dir}/: $deps$actions
1083 1084 1085 1086
EOF
  }
  ""    # Important!  This becomes part of the template result.
-}