unix-Makefile.tmpl 44.4 KB
Newer Older
1 2 3 4 5
##
## Makefile for OpenSSL
##
## {- join("\n## ", @autowarntext) -}
{-
B
Ben Laurie 已提交
6 7 8 9 10
     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";
11
     our $shlibvariant = $target{shlib_variant} || "";
B
Ben Laurie 已提交
12 13 14 15
     our $shlibextsimple = $target{shared_extension_simple} || ".so";
     our $shlibextimport = $target{shared_import_extension} || "";
     our $dsoext = $target{dso_extension} || ".so";

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

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

22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
     # 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;
43
         return () if $disabled{shared} || $lib =~ /\.a$/;
44
         return $unified_info{sharednames}->{$lib}. $shlibvariant. '$(SHLIB_EXT)';
45 46 47
     }
     sub shlib_simple {
         my $lib = shift;
48 49
         return () if $disabled{shared} || $lib =~ /\.a$/;

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

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

62 63 64 65 66 67
     # 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 已提交
68
         return $engine . $dsoext;
69
     }
70 71 72 73 74 75 76
     # 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 已提交
77
     '';
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
-}
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} -}
93 94 95
SHLIB_EXT={- $shlibext -}
SHLIB_EXT_SIMPLE={- $shlibextsimple -}
SHLIB_EXT_IMPORT={- $shlibextimport -}
96

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

116
INSTALL_LIBS={- join(" ", map { lib($_) } @{$unified_info{install}->{libraries}}) -}
117 118 119 120
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}}) -}
121
{- output_off() if $disabled{apps}; "" -}
122
BIN_SCRIPTS=$(BLDDIR)/tools/c_rehash
R
Rich Salz 已提交
123
MISC_SCRIPTS=$(BLDDIR)/apps/CA.pl $(BLDDIR)/apps/tsget
124
{- output_on() if $disabled{apps}; "" -}
125

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

129 130
# DESTDIR is for package builders so that they can configure for, say,
# /usr/ and yet have everything installed to /tmp/somedir/usr/.
131
# Normally it is left empty.
132
DESTDIR=
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 166

# 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;
167
              catdir($prefix,$libdir,"engines-$sover_dirname") -}
168

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

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

R
Richard Levitte 已提交
177 178 179 180
# 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=
181 182
HTMLSUFFIX=html

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

CROSS_COMPILE= {- $config{cross_compile_prefix} -}
187
CPPFLAGS={- our $cppflags = join(" ",
188 189 190
                                 (map { "-D".$_} @{$config{defines}}),
                                 (map { "-I".$_} @{$config{includes}}),
                                 @{$config{cppflags}}) -}
191
CPPFLAGS_Q={- $cppflags =~ s|([\\"])|\\$1|g; $cppflags -}
192 193
CC= $(CROSS_COMPILE){- $config{cc} -}
CFLAGS={- join(' ', @{$config{cflags}}) -}
194
CXX={- $config{cxx} ? "\$(CROSS_COMPILE)$config{cxx}" : '' -}
195
CXXFLAGS={- join(' ', @{$config{cxxflags}}) -}
196 197 198
LDFLAGS= {- join(' ', @{$config{lflags}}) -}
PLIB_LDFLAGS= {- join(' ', @{$config{plib_lflags}}) -}
EX_LIBS= {- join(' ', @{$config{ex_libs}}) -}
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215

LIB_CPPFLAGS={- join(' ', '$(CPPFLAGS)',
                          $target{shared_cppflag} || (),
                          (map { '-D'.$_ }
                               ('OPENSSLDIR="\"$(OPENSSLDIR)\""',
                                'ENGINESDIR="\"$(ENGINESDIR)\""'))) -}
LIB_CFLAGS={- join(' ', '$(CFLAGS)', $target{shared_cflag} || ()) -}
LIB_CXXFLAGS={- join(' ', '$(CXXFLAGS)', $target{shared_cxxflag} || ()) -}
LIB_LDFLAGS={- join(' ', '$(LDFLAGS)', $target{shared_ldflag} || (), $config{shared_ldflag} || ()) -}
DSO_CPPFLAGS={- join(' ', '$(CPPFLAGS)', $target{dso_cppflags} || ()) -}
DSO_CFLAGS={- join(' ', '$(CFLAGS)', $target{dso_cflags} || ()) -}
DSO_CXXFLAGS={- join(' ', '$(CXXFLAGS)', $target{dso_cxxflags} || ()) -}
DSO_LDFLAGS={- join(' ', '$(LDFLAGS)', $target{dso_lflags} || ()) -}
BIN_CPPFLAGS={- join(' ', '$(CPPFLAGS)', $target{bin_cppflags} || ()) -}
BIN_CFLAGS={- join(' ', '$(CFLAGS)', $target{bin_cflags} || ()) -}
BIN_CXXFLAGS={- join(' ', '$(CXXFLAGS)', $target{bin_cxxflags} || ()) -}
BIN_LDFLAGS={- join(' ', '$(LDFLAGS)', $target{bin_lflags} || ()) -}
216 217 218

PERL={- $config{perl} -}

219 220
AR=$(CROSS_COMPILE){- $config{ar} -}
ARFLAGS= {- join(' ', @{$config{arflags}}) -}
R
Richard Levitte 已提交
221
RANLIB={- $config{ranlib} ? "\$(CROSS_COMPILE)$config{ranlib}" : "true"; -}
222
RC= $(CROSS_COMPILE){- $target{rc} || "windres" -}
223
RCFLAGS={- join(' ', @{$config{rcflags}}) -} {- $target{shared_rcflag} -}
224
RM= rm -f
225
RMDIR= rmdir
226 227
TAR= {- $target{tar} || "tar" -}
TARFLAGS= {- $target{tarflags} -}
228
MAKEDEPEND={- $config{makedepprog} -}
229 230 231 232 233 234 235 236 237 238

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.
239
AS={- $config{as} ? "\$(CROSS_COMPILE)$config{as}" : '$(CC) -c' -}
240
ASFLAGS={- join(' ', @{$config{asflags}}) || '$(CFLAGS)' -}
241 242 243 244 245 246
PERLASM_SCHEME= {- $target{perlasm_scheme} -}

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

247 248 249 250 251 252 253 254 255
# 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

256 257
# The main targets ###################################################

258
{- dependmagic('all'); -}: build_libs_nodep build_engines_nodep build_programs_nodep link-utils
259 260
{- dependmagic('build_libs'); -}: build_libs_nodep
{- dependmagic('build_engines'); -}: build_engines_nodep
261
{- dependmagic('build_programs'); -}: build_programs_nodep
262

263
build_generated: $(GENERATED_MANDATORY)
264 265
build_libs_nodep: libcrypto.pc libssl.pc openssl.pc
build_engines_nodep: $(ENGINES)
266 267 268 269
build_programs_nodep: $(PROGRAMS) $(SCRIPTS)

# Kept around for backward compatibility
build_apps build_tests: build_programs
270

271 272 273 274
# Convenience target to prebuild all generated files, not just the mandatory
# ones
build_all_generated: $(GENERATED_MANDATORY) $(GENERATED)

275
test: tests
276
{- dependmagic('tests'); -}: build_programs_nodep build_engines_nodep link-utils
M
Matt Caswell 已提交
277
	@ : {- output_off() if $disabled{tests}; "" -}
278
	( cd test; \
279
	  mkdir -p test-runs; \
280 281
	  SRCTOP=../$(SRCDIR) \
	  BLDTOP=../$(BLDDIR) \
282
	  RESULT_D=test-runs \
283
	  PERL="$(PERL)" \
B
Ben Laurie 已提交
284
	  EXE_EXT={- $exeext -} \
285
	  OPENSSL_ENGINES=`cd ../$(BLDDIR)/engines; pwd` \
286
	  OPENSSL_DEBUG_MEMORY=on \
287
	    $(PERL) ../$(SRCDIR)/test/run_tests.pl $(TESTS) )
M
Matt Caswell 已提交
288 289 290
	@ : {- if ($disabled{tests}) { output_on(); } else { output_off(); } "" -}
	@echo "Tests are not supported with your chosen Configure options"
	@ : {- output_on() if !$disabled{tests}; "" -}
291 292

list-tests:
293 294 295 296 297 298 299 300 301 302
	@ : {- 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
303 304

libclean:
R
Richard Levitte 已提交
305 306 307
	@set -e; for s in $(SHLIB_INFO); do \
		s1=`echo "$$s" | cut -f1 -d";"`; \
		s2=`echo "$$s" | cut -f2 -d";"`; \
308
		$(ECHO) $(RM) $$s1; \
R
Richard Levitte 已提交
309 310
		$(RM) $$s1; \
		if [ "$$s1" != "$$s2" ]; then \
311
			$(ECHO) $(RM) $$s2; \
R
Richard Levitte 已提交
312 313 314 315
			$(RM) $$s2; \
		fi; \
	done
	$(RM) $(LIBS)
316
	$(RM) *.map
317 318

clean: libclean
319 320 321 322 323
	$(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 已提交
324
	$(RM) tags TAGS doc-nits
325
	$(RM) -r test/test-runs
326 327 328
	$(RM) openssl.pc libcrypto.pc libssl.pc
	-$(RM) `find . -type l -a \! -path "./.git/*"`
	$(RM) $(TARFILE)
329

330
distclean: clean
331 332
	$(RM) configdata.pm
	$(RM) Makefile
333

334
# We check if any depfile is newer than Makefile and decide to
R
Richard Levitte 已提交
335
# concatenate only if that is true.
336
depend:
337
	@: {- output_off() if $disabled{makedepend}; "" -}
B
Ben Laurie 已提交
338
	@if egrep "^# DO NOT DELETE THIS LINE" Makefile >/dev/null && [ -z "`find $(DEPS) -newer Makefile 2>/dev/null; exit 0`" ]; then :; else \
339
	  ( $(PERL) -pe 'exit 0 if /^# DO NOT DELETE THIS LINE.*/' < Makefile; \
340 341
	    echo '# DO NOT DELETE THIS LINE -- make depend depends on it.'; \
	    echo; \
R
Richard Levitte 已提交
342 343
	    for f in $(DEPS); do \
	      if [ -f $$f ]; then cat $$f; fi; \
344
	    done ) > Makefile.new; \
R
Richard Levitte 已提交
345
	  if cmp Makefile.new Makefile >/dev/null 2>&1; then \
346
	    rm -f Makefile.new; \
R
Richard Levitte 已提交
347 348
	  else \
	    mv -f Makefile.new Makefile; \
349
	  fi; \
350
	fi
351
	@: {- output_on() if $disabled{makedepend}; "" -}
352 353 354 355 356

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

install_sw: all install_dev install_engines install_runtime

R
Richard Levitte 已提交
357
uninstall_sw: uninstall_runtime uninstall_engines uninstall_dev
358 359 360 361

install_docs: install_man_docs install_html_docs

uninstall_docs: uninstall_man_docs uninstall_html_docs
362
	$(RM) -r -v $(DESTDIR)$(DOCDIR)
363

364 365 366
install_ssldirs:
	@$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(OPENSSLDIR)/certs
	@$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(OPENSSLDIR)/private
367
	@$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(OPENSSLDIR)/misc
368 369 370
	@set -e; for x in dummy $(MISC_SCRIPTS); do \
		if [ "$$x" = "dummy" ]; then continue; fi; \
		fn=`basename $$x`; \
371
		$(ECHO) "install $$x -> $(DESTDIR)$(OPENSSLDIR)/misc/$$fn"; \
372 373 374 375 376
		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
377
	@$(ECHO) "install $(SRCDIR)/apps/openssl.cnf -> $(DESTDIR)$(OPENSSLDIR)/openssl.cnf.dist"
378 379
	@cp $(SRCDIR)/apps/openssl.cnf $(DESTDIR)$(OPENSSLDIR)/openssl.cnf.new
	@chmod 644 $(DESTDIR)$(OPENSSLDIR)/openssl.cnf.new
380
	@mv -f  $(DESTDIR)$(OPENSSLDIR)/openssl.cnf.new $(DESTDIR)$(OPENSSLDIR)/openssl.cnf.dist
R
Rich Salz 已提交
381
	@if [ ! -f "$(DESTDIR)$(OPENSSLDIR)/openssl.cnf" ]; then \
382
		$(ECHO) "install $(SRCDIR)/apps/openssl.cnf -> $(DESTDIR)$(OPENSSLDIR)/openssl.cnf"; \
383 384 385
		cp $(SRCDIR)/apps/openssl.cnf $(DESTDIR)$(OPENSSLDIR)/openssl.cnf; \
		chmod 644 $(DESTDIR)$(OPENSSLDIR)/openssl.cnf; \
	fi
386
	@$(ECHO) "install $(SRCDIR)/apps/ct_log_list.cnf -> $(DESTDIR)$(OPENSSLDIR)/ct_log_list.cnf.dist"
R
Rich Salz 已提交
387 388 389 390
	@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 \
391
		$(ECHO) "install $(SRCDIR)/apps/ct_log_list.cnf -> $(DESTDIR)$(OPENSSLDIR)/ct_log_list.cnf"; \
R
Rich Salz 已提交
392 393 394
		cp $(SRCDIR)/apps/ct_log_list.cnf $(DESTDIR)$(OPENSSLDIR)/ct_log_list.cnf; \
		chmod 644 $(DESTDIR)$(OPENSSLDIR)/ct_log_list.cnf; \
	fi
395

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

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

install_engines:
	@[ -n "$(INSTALLTOP)" ] || (echo INSTALLTOP should not be empty; exit 1)
504
	@$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(ENGINESDIR)/
505
	@$(ECHO) "*** Installing engines"
506
	@set -e; for e in dummy $(INSTALL_ENGINES); do \
507
		if [ "$$e" = "dummy" ]; then continue; fi; \
508
		fn=`basename $$e`; \
509
		$(ECHO) "install $$e -> $(DESTDIR)$(ENGINESDIR)/$$fn"; \
510 511 512 513
		cp $$e $(DESTDIR)$(ENGINESDIR)/$$fn.new; \
		chmod 755 $(DESTDIR)$(ENGINESDIR)/$$fn.new; \
		mv -f $(DESTDIR)$(ENGINESDIR)/$$fn.new \
		      $(DESTDIR)$(ENGINESDIR)/$$fn; \
514 515 516
	done

uninstall_engines:
517
	@$(ECHO) "*** Uninstalling engines"
518
	@set -e; for e in dummy $(INSTALL_ENGINES); do \
519
		if [ "$$e" = "dummy" ]; then continue; fi; \
520
		fn=`basename $$e`; \
521 522 523
		if [ "$$fn" = '{- dso("ossltest") -}' ]; then \
			continue; \
		fi; \
524
		$(ECHO) "$(RM) $(DESTDIR)$(ENGINESDIR)/$$fn"; \
525
		$(RM) $(DESTDIR)$(ENGINESDIR)/$$fn; \
526
	done
527
	-$(RMDIR) $(DESTDIR)$(ENGINESDIR)
528 529 530

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

uninstall_runtime:
573
	@$(ECHO) "*** Uninstalling runtime files"
574
	@set -e; for x in dummy $(INSTALL_PROGRAMS); \
575
	do  \
576
		if [ "$$x" = "dummy" ]; then continue; fi; \
577
		fn=`basename $$x`; \
578
		$(ECHO) "$(RM) $(DESTDIR)$(INSTALLTOP)/bin/$$fn"; \
579
		$(RM) $(DESTDIR)$(INSTALLTOP)/bin/$$fn; \
580
	done;
581
	@set -e; for x in dummy $(BIN_SCRIPTS); \
582
	do  \
583
		if [ "$$x" = "dummy" ]; then continue; fi; \
584
		fn=`basename $$x`; \
585
		$(ECHO) "$(RM) $(DESTDIR)$(INSTALLTOP)/bin/$$fn"; \
586
		$(RM) $(DESTDIR)$(INSTALLTOP)/bin/$$fn; \
587
	done
588
	@ : {- output_off() unless windowsdll(); "" -}
589
	@set -e; for s in dummy $(INSTALL_SHLIBS); do \
590
		if [ "$$s" = "dummy" ]; then continue; fi; \
R
Richard Levitte 已提交
591
		fn=`basename $$s`; \
592
		$(ECHO) "$(RM) $(DESTDIR)$(INSTALLTOP)/bin/$$fn"; \
593
		$(RM) $(DESTDIR)$(INSTALLTOP)/bin/$$fn; \
594
	done
595
	@ : {- output_on() unless windowsdll(); "" -}
R
Richard Levitte 已提交
596
	-$(RMDIR) $(DESTDIR)$(INSTALLTOP)/bin
597 598 599 600


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

uninstall_man_docs:
606
	@$(ECHO) "*** Uninstalling manpages"
607 608 609
	$(PERL) $(SRCDIR)/util/process_docs.pl \
		--destdir=$(DESTDIR)$(MANDIR) --type=man --suffix=$(MANSUFFIX) \
		--remove
610 611 612

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

uninstall_html_docs:
618
	@$(ECHO) "*** Uninstalling manpages"
619 620
	$(PERL) $(SRCDIR)/util/process_docs.pl \
		--destdir=$(DESTDIR)$(HTMLDIR) --type=html --remove
621 622 623 624


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

625 626
update: generate errors ordinals

627
generate: generate_apps generate_crypto_bn generate_crypto_objects \
628
          generate_crypto_conf generate_crypto_asn1 generate_fuzz_oids
629

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

634 635 636 637 638 639 640
# Test coverage is a good idea for the future
#coverage: $(PROGRAMS) $(TESTPROGRAMS)
#	...

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

641 642 643 644 645 646 647 648 649 650 651 652
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 )
653 654 655
	( cd $(SRCDIR); $(PERL) crypto/objects/obj_dat.pl \
				include/openssl/obj_mac.h \
				crypto/objects/obj_dat.h )
656 657 658 659
	( cd $(SRCDIR); $(PERL) crypto/objects/objxref.pl \
				crypto/objects/obj_mac.num \
				crypto/objects/obj_xref.txt \
				> crypto/objects/obj_xref.h )
660

661 662 663 664 665 666 667 668
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 )

669 670 671 672 673
generate_fuzz_oids:
	( cd $(SRCDIR); $(PERL) fuzz/mkfuzzoids.pl \
				crypto/objects/obj_dat.h \
				> fuzz/oids.txt )

674 675
# Set to -force to force a rebuild
ERROR_REBUILD=
676 677
errors:
	( cd $(SRCDIR); $(PERL) util/ck_errf.pl -strict */*.c */*/*.c )
678 679 680
	( b=`pwd`; cd $(SRCDIR); \
          $(PERL) -I$$b util/mkerr.pl $(ERROR_REBUILD) -internal )
	( b=`pwd`; cd $(SRCDIR)/engines; \
681
          for E in *.ec ; do \
682
              $(PERL) -I$$b ../util/mkerr.pl $(ERROR_REBUILD) -static \
683 684
                -conf $$E `basename $$E .ec`.c ; \
          done )
685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702

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

703 704
# If your tar command doesn't support --owner and --group, make sure to
# use one that does, for example GNU tar
B
Ben Laurie 已提交
705
TAR_COMMAND=$(TAR) $(TARFLAGS) --owner 0 --group 0 -cvf -
706
PREPARE_CMD=:
707
tar:
708
	set -e; \
709
	TMPDIR=/var/tmp/openssl-copy.$$$$; \
710
	DISTDIR=$(NAME); \
711 712
	mkdir -p $$TMPDIR/$$DISTDIR; \
	(cd $(SRCDIR); \
713 714 715
	 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"; \
716
	 git ls-tree -r --name-only --full-tree HEAD \
717
	 | egrep -v "$$excl_re" \
718 719 720 721
	 | while read F; do \
	       mkdir -p $$TMPDIR/$$DISTDIR/`dirname $$F`; \
	       cp $$F $$TMPDIR/$$DISTDIR/$$F; \
	   done); \
722
	(cd $$TMPDIR/$$DISTDIR; \
723
	 $(PREPARE_CMD); \
724 725 726 727
	 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) \
728 729 730 731 732
	| (cd $(SRCDIR); gzip --best > $(TARFILE).gz); \
	rm -rf $$TMPDIR
	cd $(SRCDIR); ls -l $(TARFILE).gz

dist:
733
	@$(MAKE) PREPARE_CMD='$(PERL) ./Configure dist' TARFILE="$(TARFILE)" NAME="$(NAME)" tar
734 735 736

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

737
link-utils: $(BLDDIR)/util/opensslwrap.sh
738

739
$(BLDDIR)/util/opensslwrap.sh: configdata.pm
740 741 742 743
	@if [ "$(SRCDIR)" != "$(BLDDIR)" ]; then \
	    mkdir -p "$(BLDDIR)/util"; \
	    ln -sf "../$(SRCDIR)/util/opensslwrap.sh" "$(BLDDIR)/util"; \
	fi
744

745
FORCE:
746 747 748

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

749
libcrypto.pc libssl.pc openssl.pc: configdata.pm $(LIBS) {- join(" ",map { shlib_simple($_) } @{$unified_info{libraries}}) -}
750 751 752 753 754
libcrypto.pc:
	@ ( echo 'prefix=$(INSTALLTOP)'; \
	    echo 'exec_prefix=$${prefix}'; \
	    echo 'libdir=$${exec_prefix}/$(LIBDIR)'; \
	    echo 'includedir=$${prefix}/include'; \
755
	    echo 'enginesdir=$${libdir}/engines-{- $sover_dirname -}'; \
756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787
	    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 '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

788
configdata.pm: $(SRCDIR)/Configure $(SRCDIR)/config {- join(" ", @{$config{build_file_templates}}, @{$config{build_infos}}, @{$config{conf_files}}) -}
789
	@echo "Detected changed: $?"
790
	$(PERL) configdata.pm -r
791 792 793 794 795 796 797
	@echo "**************************************************"
	@echo "***                                            ***"
	@echo "***   Please run the same make command again   ***"
	@echo "***                                            ***"
	@echo "**************************************************"
	@false

798
reconfigure reconf:
799
	$(PERL) configdata.pm -r
800

801 802 803
{-
  use File::Basename;
  use File::Spec::Functions qw/:DEFAULT abs2rel rel2abs/;
804 805 806 807

  # 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 {
808
      if ($disabled{shared}) {
809
          return map { lib($_) } @_;
810 811 812 813 814
      }

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

818 819 820
  sub generatesrc {
      my %args = @_;
      my $generator = join(" ", @{$args{generator}});
821
      my $generator_incs = join("", map { " -I".$_ } @{$args{generator_incs}});
822
      my $incs = join("", map { " -I".$_ } @{$args{incs}});
823
      my $deps = join(" ", @{$args{generator_deps}}, @{$args{deps}});
824 825

      if ($args{src} !~ /\.[sS]$/) {
826 827 828 829 830 831 832 833 834 835 836
          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";
837
$args{src}: $args{generator}->[0] $deps
838
	\$(PERL)$generator_incs $generator > \$@
839
EOF
840
	  }
841
      } else {
842
          if ($args{generator}->[0] =~ /\.pl$/) {
843
              $generator = 'CC="$(CC)" $(PERL)'.$generator_incs.' '.$generator;
844
          } elsif ($args{generator}->[0] =~ /\.m4$/) {
845
              $generator = 'm4 -B 8192'.$generator_incs.' '.$generator.' >'
846 847 848 849 850 851
          } elsif ($args{generator}->[0] =~ /\.S$/) {
              $generator = undef;
          } else {
              die "Generator type for $args{src} unknown: $generator\n";
          }

852
          my $cppflags = {
853 854 855
              lib => '$(LIB_CFLAGS) $(LIB_CPPFLAGS)',
              dso => '$(DSO_CFLAGS) $(DSO_CPPFLAGS)',
              bin => '$(BIN_CFLAGS) $(BIN_CPPFLAGS)'
856
          } -> {$args{intent}};
857 858 859 860 861 862
          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";
863
$target: $args{generator}->[0] $deps
864
	( trap "rm -f \$@.*" INT 0; \\
865
	  $generator \$@.S; \\
R
Richard Levitte 已提交
866
	  \$(CPP) $incs $cppflags \$@.S | \\
867 868
	  \$(PERL) -ne '/^#(line)?\\s*[0-9]+/ or print' > \$@.i && \\
	  mv -f \$@.i \$@ )
869
EOF
870 871
              }
              # Otherwise....
872
              return <<"EOF";
873
$args{src}: $args{generator}->[0] $deps
874
	$generator \$@
875 876
EOF
          }
877
          return <<"EOF";
878
$args{src}: $args{generator}->[0] $deps
R
Richard Levitte 已提交
879
	\$(CPP) $incs $cppflags $args{generator}->[0] | \\
880
	\$(PERL) -ne '/^#(line)?\\s*[0-9]+/ or print' > \$@
881
EOF
882 883 884
      }
  }

885 886 887
  # 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.
888
  sub src2obj {
889
      my %args = @_;
890
      (my $obj = $args{obj}) =~ s|\.o$||;
891 892 893 894 895 896
      my @srcs = map { if ($unified_info{generate}->{$_}) {
                           (my $x = $_) =~ s/\.S$/.s/; $x
                       } else {
                           $_
                       }
                     } ( @{$args{srcs}} );
897 898
      my $srcs = join(" ",  @srcs);
      my $deps = join(" ", @srcs, @{$args{deps}});
899
      my $incs = join("", map { " -I".$_ } @{$args{incs}});
900 901 902
      my $cmd;
      my $cmdflags;
      my $cmdcompile;
903 904 905 906
      my $makedepprog = $disabled{makedepend} ? undef : $config{makedepprog};
      if (grep /\.rc$/, @srcs) {
          $cmd = '$(RC)';
          $cmdflags = '$(RCFLAGS)';
907
          $cmdcompile = '';
908 909 910
          $makedepprog = undef;
      } elsif (grep /\.(cc|cpp)$/, @srcs) {
          $cmd = '$(CXX)';
911 912 913 914 915 916
          $cmdcompile = ' -c';
          $cmdflags = {
              lib => '$(LIB_CXXFLAGS) $(LIB_CPPFLAGS)',
              dso => '$(DSO_CXXFLAGS) $(DSO_CPPFLAGS)',
              bin => '$(BIN_CXXFLAGS) $(BIN_CPPFLAGS)'
          } -> {$args{intent}};
917
      } else {
918 919 920 921 922 923 924
          $cmd = '$(CC)';
          $cmdcompile = ' -c';
          $cmdflags = {
              lib => '$(LIB_CFLAGS) $(LIB_CPPFLAGS)',
              dso => '$(DSO_CFLAGS) $(DSO_CPPFLAGS)',
              bin => '$(BIN_CFLAGS) $(BIN_CPPFLAGS)'
          } -> {$args{intent}};
925
      }
926
      $cmdflags .= $cmdcompile;
927 928 929
      my $recipe = <<"EOF";
$obj$objext: $deps
EOF
930
      if (defined $makedepprog && $makedepprog !~ /\/makedepend/) {
931
          $recipe .= <<"EOF";
932
	$cmd $incs $cmdflags -MMD -MF $obj$depext.tmp -MT \$\@ -c -o \$\@ $srcs
933 934 935
	\@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 已提交
936
	else \\
937
		mv $obj$depext.tmp $obj$depext; \\
938
	fi
939
EOF
940
      } else {
941
          $recipe .= <<"EOF";
942
	$cmd $incs $cmdflags -o \$\@ $srcs
943
EOF
944
          if (defined $makedepprog  && $makedepprog =~ /\/makedepend/) {
945
              $recipe .= <<"EOF";
946
	-\$(MAKEDEPEND) -f- -o"|\$\@" -- $incs $cmdflags -- $srcs \\
947 948
	    >$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 已提交
949
	\@if cmp $obj$depext.tmp $obj$depext > /dev/null 2> /dev/null; then \\
950
		rm -f $obj$depext.tmp; \\
R
Richard Levitte 已提交
951 952
	else \\
		mv $obj$depext.tmp $obj$depext; \\
953
	fi
954
EOF
955
          }
956 957
      }
      return $recipe;
958 959 960 961 962 963 964 965 966 967 968
  }
  # 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//;
969 970 971 972 973 974 975
      my @linkdirs = ();
      foreach (@{args{deps}}) {
          my $d = dirname($_);
          push @linkdirs, $d unless grep { $d eq $_ } @linkdirs;
      }
      my $linkflags = join("", map { "-L$_ " } @linkdirs);
      my $linklibs = join("", map { my $f = basename($_);
976
                                    (my $l = $f) =~ s/^lib//;
977
                                    " -l$l" } @{$args{deps}});
978 979 980 981 982 983 984 985
      my @objs = map { (my $x = $_) =~ s|\.o$|$objext|; $x }
                 grep { $_ =~ m|\.o$| }
                 @{$args{objs}};
      my @defs = grep { $_ =~ /\.(def|map)$/ } @{$args{objs}};
      my @deps = compute_lib_depends(@{$args{deps}});
      die "More than one exported symbol map" if scalar @defs > 1;
      my $objs = join(" ", @objs);
      my $deps = join(" ", @objs, @defs, @deps);
986
      my $target = shlib_simple($lib);
R
Richard Levitte 已提交
987
      my $target_full = shlib($lib);
988 989 990 991 992 993 994 995 996
      my $shared_soname = "";
      $shared_soname .= ' '.$target{shared_sonameflag}.basename($target_full)
          if defined $target{shared_sonameflag};
      my $shared_imp = "";
      $shared_imp .= ' '.$target{shared_impflag}.basename($target)
          if defined $target{shared_impflag};
      my $shared_def = join("", map { ' '.$target{shared_defflag}.$_ } @defs);
      my $recipe = <<"EOF";
# When building on a Windows POSIX layer (Cygwin or Mingw), we know for a fact
997 998 999 1000
# 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
1001 1002
# simplest, {libname}\$(SHLIB_EXT_IMPORT) for Windows POSIX layers and
# {libname}\$(SHLIB_EXT_SIMPLE) for the Unix platforms.
1003
$target: $deps
1004
	\$(CC) \$(LIB_CFLAGS) $linkflags\$(LIB_LDFLAGS)$shared_soname$shared_imp \\
1005 1006
		-o $target_full$shared_def $objs \\
                \$(PLIB_LDFLAGS) $linklibs \$(EX_LIBS)
1007
EOF
1008 1009
      if (windowsdll()) {
          $recipe .= <<"EOF";
1010 1011
	rm -f apps/$shlib'\$(SHLIB_EXT)'
	rm -f test/$shlib'\$(SHLIB_EXT)'
1012
	rm -f fuzz/$shlib'\$(SHLIB_EXT)'
1013 1014
	cp -p $shlib'\$(SHLIB_EXT)' apps/
	cp -p $shlib'\$(SHLIB_EXT)' test/
1015 1016 1017 1018
	cp -p $shlib'\$(SHLIB_EXT)' fuzz/
EOF
      } else {
          $recipe .= <<"EOF";
1019 1020 1021 1022
	if [ '$target' != '$target_full' ]; then \\
		rm -f $target; \\
		ln -s $target_full $target; \\
	fi
1023
EOF
1024
      }
1025
  }
1026
  sub obj2dso {
1027
      my %args = @_;
R
Richard Levitte 已提交
1028 1029 1030
      my $dso = $args{lib};
      my $dsod = dirname($dso);
      my $dson = basename($dso);
1031 1032 1033 1034 1035 1036 1037
      my @linkdirs = ();
      foreach (@{args{deps}}) {
          my $d = dirname($_);
          push @linkdirs, $d unless grep { $d eq $_ } @linkdirs;
      }
      my $linkflags = join("", map { "-L$_ " } @linkdirs);
      my $linklibs = join("", map { my $f = basename($_);
1038
                                    (my $l = $f) =~ s/^lib//;
1039
                                    " -l$l" } @{$args{deps}});
1040 1041 1042 1043
      my @objs = map { (my $x = $_) =~ s|\.o$|$objext|; $x } @{$args{objs}};
      my @deps = compute_lib_depends(@{$args{deps}});
      my $objs = join(" ", @objs);
      my $deps = join(" ", @deps);
R
Richard Levitte 已提交
1044
      my $target = dso($dso);
1045
      return <<"EOF";
1046
$target: $objs $deps
1047
	\$(CC) \$(DSO_CFLAGS) $linkflags\$(DSO_LDFLAGS) \\
1048 1049
		-o $target $objs \\
                \$(PLIB_LDFLAGS) $linklibs \$(EX_LIBS)
1050 1051 1052 1053
EOF
  }
  sub obj2lib {
      my %args = @_;
1054
      (my $lib = $args{lib}) =~ s/\.a$//;
1055 1056
      my @objs = map { (my $x = $_) =~ s|\.o$|$objext|; $x } @{$args{objs}};
      my $objs = join(" ", @objs);
1057
      return <<"EOF";
B
Ben Laurie 已提交
1058
$lib$libext: $objs
1059
	\$(AR) \$(ARFLAGS) \$\@ \$\?
1060 1061 1062 1063 1064 1065 1066 1067
	\$(RANLIB) \$\@ || echo Never mind.
EOF
  }
  sub obj2bin {
      my %args = @_;
      my $bin = $args{bin};
      my $bind = dirname($bin);
      my $binn = basename($bin);
1068 1069
      my $objs = join(" ", map { (my $x = $_) =~ s|\.o$|$objext|; $x }
                           @{$args{objs}});
1070
      my $deps = join(" ",compute_lib_depends(@{$args{deps}}));
1071 1072 1073 1074 1075 1076 1077
      my @linkdirs = ();
      foreach (@{args{deps}}) {
          next if $_ =~ /\.a$/;
          my $d = dirname($_);
          push @linkdirs, $d unless grep { $d eq $_ } @linkdirs;
      }
      my $linkflags = join("", map { "-L$_ " } @linkdirs);
1078 1079 1080 1081 1082
      my $linklibs = join("", map { if ($_ =~ /\.a$/) {
                                        " $_";
                                    } else {
                                        my $f = basename($_);
                                        (my $l = $f) =~ s/^lib//;
1083
                                        " -l$l"
1084 1085
                                    }
                                  } @{$args{deps}});
1086
      my $cmd = '$(CC)';
1087
      my $cmdflags = '$(BIN_CFLAGS)';
1088 1089
      if (grep /_cc\.o$/, @{$args{objs}}) {
          $cmd = '$(CXX)';
1090
          $cmdflags = '$(BIN_CXXFLAGS)';
1091
      }
1092
      return <<"EOF";
B
Ben Laurie 已提交
1093
$bin$exeext: $objs $deps
1094
	rm -f $bin$exeext
1095
	\$\${LDCMD:-$cmd} $cmdflags $linkflags\$(BIN_LDFLAGS) \\
1096
		-o $bin$exeext $objs \\
1097
		\$(PLIB_LDFLAGS) $linklibs \$(EX_LIBS)
1098 1099 1100 1101 1102 1103 1104 1105 1106 1107
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";
1108
$script: $sources
1109
	\$(PERL) "-I\$(BLDDIR)" -Mconfigdata "$dofile" \\
1110
	    "-o$target{build_file}" $sources > "$script"
1111
	chmod a+x $script
1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124
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});
1125 1126 1127 1128 1129
          # 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") {
1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143
              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
1144 1145 1146 1147
EOF
  }
  ""    # Important!  This becomes part of the template result.
-}