unix-Makefile.tmpl 42.5 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
	( cd test; \
266
	  mkdir -p test-runs; \
267 268
	  SRCTOP=../$(SRCDIR) \
	  BLDTOP=../$(BLDDIR) \
269
	  RESULT_D=test-runs \
270
	  PERL="$(PERL)" \
B
Ben Laurie 已提交
271
	  EXE_EXT={- $exeext -} \
272
	  OPENSSL_ENGINES=`cd ../$(BLDDIR)/engines; pwd` \
273
	  OPENSSL_DEBUG_MEMORY=on \
274
	    $(PERL) ../$(SRCDIR)/test/run_tests.pl $(TESTS) )
M
Matt Caswell 已提交
275 276 277
	@ : {- if ($disabled{tests}) { output_on(); } else { output_off(); } "" -}
	@echo "Tests are not supported with your chosen Configure options"
	@ : {- output_on() if !$disabled{tests}; "" -}
278 279

list-tests:
280 281 282 283 284 285 286 287 288 289
	@ : {- 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
290 291

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

clean: libclean
306 307 308 309 310
	$(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 已提交
311
	$(RM) tags TAGS doc-nits
B
Bernd Edlinger 已提交
312
	$(RM) test/.rnd
313 314 315
	$(RM) openssl.pc libcrypto.pc libssl.pc
	-$(RM) `find . -type l -a \! -path "./.git/*"`
	$(RM) $(TARFILE)
316

317
distclean: clean
318 319
	$(RM) configdata.pm
	$(RM) Makefile
320

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

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

install_sw: all install_dev install_engines install_runtime

R
Richard Levitte 已提交
344
uninstall_sw: uninstall_runtime uninstall_engines uninstall_dev
345 346 347 348

install_docs: install_man_docs install_html_docs

uninstall_docs: uninstall_man_docs uninstall_html_docs
349
	$(RM) -r -v $(DESTDIR)$(DOCDIR)
350

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

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

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

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

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

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

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


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

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

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

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


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

612 613
update: generate errors ordinals

614 615
generate: generate_apps generate_crypto_bn generate_crypto_objects \
          generate_crypto_conf generate_crypto_asn1
616

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

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

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

628 629 630 631 632 633 634 635 636 637 638 639
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 )
640 641 642
	( cd $(SRCDIR); $(PERL) crypto/objects/obj_dat.pl \
				include/openssl/obj_mac.h \
				crypto/objects/obj_dat.h )
643 644 645 646
	( cd $(SRCDIR); $(PERL) crypto/objects/objxref.pl \
				crypto/objects/obj_mac.num \
				crypto/objects/obj_xref.txt \
				> crypto/objects/obj_xref.h )
647

648 649 650 651 652 653 654 655
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 )

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

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) #####################

684 685
# If your tar command doesn't support --owner and --group, make sure to
# use one that does, for example GNU tar
B
Ben Laurie 已提交
686
TAR_COMMAND=$(TAR) $(TARFLAGS) --owner 0 --group 0 -cvf -
687
PREPARE_CMD=:
688
tar:
689
	set -e; \
690
	TMPDIR=/var/tmp/openssl-copy.$$$$; \
691
	DISTDIR=$(NAME); \
692 693
	mkdir -p $$TMPDIR/$$DISTDIR; \
	(cd $(SRCDIR); \
694 695 696
	 excl_re=`git submodule status | sed -e 's/^.//' | cut -d' ' -f2`; \
	 excl_re="^(fuzz/corpora|`echo $$excl_re | sed -e 's/ /$$|/g'`\$$)"; \
	 echo "$$excl_re"; \
697
	 git ls-tree -r --name-only --full-tree HEAD \
698
	 | egrep -v "$$excl_re" \
699 700 701 702
	 | while read F; do \
	       mkdir -p $$TMPDIR/$$DISTDIR/`dirname $$F`; \
	       cp $$F $$TMPDIR/$$DISTDIR/$$F; \
	   done); \
703
	(cd $$TMPDIR/$$DISTDIR; \
704
	 $(PREPARE_CMD); \
705 706 707 708
	 find . -type d -print | xargs chmod 755; \
	 find . -type f -print | xargs chmod a+r; \
	 find . -type f -perm -0100 -print | xargs chmod a+x); \
	(cd $$TMPDIR; $(TAR_COMMAND) $$DISTDIR) \
709 710 711 712 713
	| (cd $(SRCDIR); gzip --best > $(TARFILE).gz); \
	rm -rf $$TMPDIR
	cd $(SRCDIR); ls -l $(TARFILE).gz

dist:
714
	@$(MAKE) PREPARE_CMD='$(PERL) ./Configure dist' TARFILE="$(TARFILE)" NAME="$(NAME)" tar
715 716 717

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

718
link-utils: $(BLDDIR)/util/opensslwrap.sh
719

720
$(BLDDIR)/util/opensslwrap.sh: configdata.pm
721 722 723 724
	@if [ "$(SRCDIR)" != "$(BLDDIR)" ]; then \
	    mkdir -p "$(BLDDIR)/util"; \
	    ln -sf "../$(SRCDIR)/util/opensslwrap.sh" "$(BLDDIR)/util"; \
	fi
725

726
FORCE:
727 728 729

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

730
libcrypto.pc libssl.pc openssl.pc: configdata.pm $(LIBS) {- join(" ",map { shlib_simple($_) } @{$unified_info{libraries}}) -}
731 732 733 734 735
libcrypto.pc:
	@ ( echo 'prefix=$(INSTALLTOP)'; \
	    echo 'exec_prefix=$${prefix}'; \
	    echo 'libdir=$${exec_prefix}/$(LIBDIR)'; \
	    echo 'includedir=$${prefix}/include'; \
736
	    echo 'enginesdir=$${libdir}/engines-{- $sover_dirname -}'; \
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 762 763 764 765 766 767 768 769
	    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

770
configdata.pm: $(SRCDIR)/Configure $(SRCDIR)/config {- join(" ", @{$config{build_file_templates}}, @{$config{build_infos}}, @{$config{conf_files}}) -}
771
	@echo "Detected changed: $?"
772
	@echo "Reconfiguring..."
773
	$(PERL) $(SRCDIR)/Configure reconf
774 775 776 777 778 779 780 781 782 783
	@echo "**************************************************"
	@echo "***                                            ***"
	@echo "***   Please run the same make command again   ***"
	@echo "***                                            ***"
	@echo "**************************************************"
	@false

{-
  use File::Basename;
  use File::Spec::Functions qw/:DEFAULT abs2rel rel2abs/;
784 785 786 787

  # 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 {
788
      if ($disabled{shared}) {
789
          return map { lib($_) } @_;
790 791 792 793 794
      }

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

798 799 800
  sub generatesrc {
      my %args = @_;
      my $generator = join(" ", @{$args{generator}});
801
      my $generator_incs = join("", map { " -I".$_ } @{$args{generator_incs}});
802
      my $incs = join("", map { " -I".$_ } @{$args{incs}});
803
      my $deps = join(" ", @{$args{generator_deps}}, @{$args{deps}});
804 805

      if ($args{src} !~ /\.[sS]$/) {
806 807 808 809 810 811 812 813 814 815 816
          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";
817
$args{src}: $args{generator}->[0] $deps
818
	\$(PERL)$generator_incs $generator > \$@
819
EOF
820
	  }
821
      } else {
822
          if ($args{generator}->[0] =~ /\.pl$/) {
823
              $generator = 'CC="$(CC)" $(PERL)'.$generator_incs.' '.$generator;
824
          } elsif ($args{generator}->[0] =~ /\.m4$/) {
825
              $generator = 'm4 -B 8192'.$generator_incs.' '.$generator.' >'
826 827 828 829 830 831 832 833 834 835 836 837
          } 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";
838
$target: $args{generator}->[0] $deps
839
	( trap "rm -f \$@.*" INT 0; \\
840
	  $generator \$@.S; \\
841
	  \$(CC) $incs \$(CFLAGS) -E \$@.S | \\
842 843
	  \$(PERL) -ne '/^#(line)?\\s*[0-9]+/ or print' > \$@.i && \\
	  mv -f \$@.i \$@ )
844
EOF
845 846
              }
              # Otherwise....
847
              return <<"EOF";
848
$args{src}: $args{generator}->[0] $deps
849
	$generator \$@
850 851
EOF
          }
852
          return <<"EOF";
853
$args{src}: $args{generator}->[0] $deps
854
	\$(CC) $incs \$(CFLAGS) -E \$< | \\
855
	\$(PERL) -ne '/^#(line)?\\s*[0-9]+/ or print' > \$@
856
EOF
857 858 859
      }
  }

860 861 862
  # 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.
863
  sub src2obj {
864
      my %args = @_;
865
      my $obj = $args{obj};
866 867 868 869 870 871
      my @srcs = map { if ($unified_info{generate}->{$_}) {
                           (my $x = $_) =~ s/\.S$/.s/; $x
                       } else {
                           $_
                       }
                     } ( @{$args{srcs}} );
872 873
      my $srcs = join(" ",  @srcs);
      my $deps = join(" ", @srcs, @{$args{deps}});
874
      my $incs = join("", map { " -I".$_ } @{$args{incs}});
875 876 877 878 879
      unless ($disabled{zlib}) {
          if ($withargs{zlib_include}) {
              $incs .= " -I".$withargs{zlib_include};
          }
      }
880 881 882 883 884 885 886 887 888 889 890 891 892
      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}};
      }
893
      my $makedepprog = $config{makedepprog};
894 895 896 897
      my $recipe = <<"EOF";
$obj$objext: $deps
EOF
      if (!$disabled{makedepend} && $makedepprog !~ /\/makedepend/) {
898
          $recipe .= <<"EOF";
899
	$cc $incs $cflags -MMD -MF $obj$depext.tmp -MT \$\@ -c -o \$\@ $srcs
900 901 902
	\@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 已提交
903
	else \\
904
		mv $obj$depext.tmp $obj$depext; \\
905
	fi
906
EOF
907
      } else {
908
          $recipe .= <<"EOF";
909
	$cc $incs $cflags -c -o \$\@ $srcs
910
EOF
911 912
          if (!$disabled{makedepend} && $makedepprog =~ /\/makedepend/) {
              $recipe .= <<"EOF";
913
	-\$(MAKEDEPEND) -f- -o"|\$\@" -- $incs $cflags -- $srcs \\
914 915
	    >$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 已提交
916
	\@if cmp $obj$depext.tmp $obj$depext > /dev/null 2> /dev/null; then \\
917
		rm -f $obj$depext.tmp; \\
R
Richard Levitte 已提交
918 919
	else \\
		mv $obj$depext.tmp $obj$depext; \\
920
	fi
921
EOF
922
          }
923 924
      }
      return $recipe;
925 926 927 928 929 930 931 932 933 934 935
  }
  # 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//;
936 937 938 939 940
      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}}));
941 942
      my $shlib_target = $target{shared_target};
      my $ordinalsfile = defined($args{ordinals}) ? $args{ordinals}->[1] : "";
943
      my $target = shlib_simple($lib);
R
Richard Levitte 已提交
944
      my $target_full = shlib($lib);
945
      return <<"EOF"
946 947 948 949 950
# 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
951 952
# simplest, {libname}\$(SHLIB_EXT_IMPORT) for Windows POSIX layers and
# {libname}\$(SHLIB_EXT_SIMPLE) for the Unix platforms.
B
Ben Laurie 已提交
953
$target: $lib$libext $deps $ordinalsfile
954
	\$(MAKE) -f \$(SRCDIR)/Makefile.shared -e \\
955
		ECHO=\$(ECHO) \\
956
		PLATFORM=\$(PLATFORM) \\
957
		PERL="\$(PERL)" SRCDIR='\$(SRCDIR)' DSTDIR="$libd" \\
958 959
		INSTALLTOP='\$(INSTALLTOP)' LIBDIR='\$(LIBDIR)' \\
		LIBDEPS='\$(PLIB_LDFLAGS) '"$linklibs"' \$(EX_LIBS)' \\
960
		LIBNAME=$libname SHLIBVERSION=\$(SHLIB_VERSION_NUMBER) \\
R
Richard Levitte 已提交
961 962
		STLIBNAME=$lib$libext \\
		SHLIBNAME=$target SHLIBNAME_FULL=$target_full \\
963
		CC='\$(CC)' CFLAGS='\$(CFLAGS) \$(LIB_CFLAGS)' \\
R
Richard Levitte 已提交
964
		LDFLAGS='\$(LDFLAGS)' SHARED_LDFLAGS='\$(LIB_LDFLAGS)' \\
965
		RC='\$(RC)' SHARED_RCFLAGS='\$(RCFLAGS)' \\
966
		link_shlib.$shlib_target
967 968
EOF
	  . (windowsdll() ? <<"EOF" : "");
969 970 971 972
	rm -f apps/$shlib'\$(SHLIB_EXT)'
	rm -f test/$shlib'\$(SHLIB_EXT)'
	cp -p $shlib'\$(SHLIB_EXT)' apps/
	cp -p $shlib'\$(SHLIB_EXT)' test/
973 974
EOF
  }
975
  sub obj2dso {
976
      my %args = @_;
R
Richard Levitte 已提交
977 978 979
      my $dso = $args{lib};
      my $dsod = dirname($dso);
      my $dson = basename($dso);
980 981 982 983
      my $shlibdeps = join("", map { my $d = dirname($_);
                                     my $f = basename($_);
                                     (my $l = $f) =~ s/^lib//;
                                     " -L$d -l$l" } @{$args{deps}});
984
      my $deps = join(" ",compute_lib_depends(@{$args{deps}}));
985
      my $shlib_target = $target{shared_target};
B
Ben Laurie 已提交
986
      my $objs = join(" ", map { $_.$objext } @{$args{objs}});
R
Richard Levitte 已提交
987
      my $target = dso($dso);
988
      return <<"EOF";
989
$target: $objs $deps
990
	\$(MAKE) -f \$(SRCDIR)/Makefile.shared -e \\
991
		PLATFORM=\$(PLATFORM) \\
R
Richard Levitte 已提交
992
		PERL="\$(PERL)" SRCDIR='\$(SRCDIR)' DSTDIR="$dsod" \\
993
		LIBDEPS='\$(PLIB_LDFLAGS) '"$shlibdeps"' \$(EX_LIBS)' \\
R
Richard Levitte 已提交
994
		SHLIBNAME_FULL=$target LDFLAGS='\$(LDFLAGS)' \\
995 996
		CC='\$(CC)' CFLAGS='\$(CFLAGS) \$(DSO_CFLAGS)' \\
		SHARED_LDFLAGS='\$(DSO_LDFLAGS)' \\
997
		LIBEXTRAS="$objs" \\
998
		link_dso.$shlib_target
999 1000 1001 1002
EOF
  }
  sub obj2lib {
      my %args = @_;
1003
      (my $lib = $args{lib}) =~ s/\.a$//;
B
Ben Laurie 已提交
1004
      my $objs = join(" ", map { $_.$objext } @{$args{objs}});
1005
      return <<"EOF";
B
Ben Laurie 已提交
1006
$lib$libext: $objs
1007
	\$(AR) \$\@ \$\?
1008 1009 1010 1011 1012 1013 1014 1015
	\$(RANLIB) \$\@ || echo Never mind.
EOF
  }
  sub obj2bin {
      my %args = @_;
      my $bin = $args{bin};
      my $bind = dirname($bin);
      my $binn = basename($bin);
B
Ben Laurie 已提交
1016
      my $objs = join(" ", map { $_.$objext } @{$args{objs}});
1017
      my $deps = join(" ",compute_lib_depends(@{$args{deps}}));
1018 1019 1020 1021 1022 1023 1024 1025 1026 1027
      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}});
1028
      my $shlib_target = $disabled{shared} ? "" : $target{shared_target};
1029 1030 1031 1032 1033 1034
      my $cc = '$(CC)';
      my $cflags = '$(CFLAGS) $(BIN_CFLAGS)';
      if (grep /_cc$/, @{$args{objs}}) {
          $cc = '$(CXX)';
          $cflags = '$(CXXFLAGS) $(BIN_CXXFLAGS)';
      }
1035
      return <<"EOF";
B
Ben Laurie 已提交
1036 1037
$bin$exeext: $objs $deps
	\$(RM) $bin$exeext
1038
	\$(MAKE) -f \$(SRCDIR)/Makefile.shared -e \\
1039
		PERL="\$(PERL)" SRCDIR=\$(SRCDIR) \\
B
Ben Laurie 已提交
1040
		APPNAME=$bin$exeext OBJECTS="$objs" \\
1041
		LIBDEPS='\$(PLIB_LDFLAGS) '"$linklibs"' \$(EX_LIBS)' \\
1042
		CC='$cc' CFLAGS='$cflags' \\
1043
		LDFLAGS='\$(LDFLAGS)' \\
1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054
		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";
1055
$script: $sources
1056
	\$(PERL) "-I\$(BLDDIR)" -Mconfigdata "$dofile" \\
1057
	    "-o$target{build_file}" $sources > "$script"
1058
	chmod a+x $script
1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071
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});
1072 1073 1074 1075 1076
          # 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") {
1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090
              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
1091 1092 1093 1094
EOF
  }
  ""    # Important!  This becomes part of the template result.
-}