unix-Makefile.tmpl 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083
  1. ##
  2. ## Makefile for OpenSSL
  3. ##
  4. ## {- join("\n## ", @autowarntext) -}
  5. {-
  6. our $objext = $target{obj_extension} || ".o";
  7. our $depext = $target{dep_extension} || ".d";
  8. our $exeext = $target{exe_extension} || "";
  9. our $libext = $target{lib_extension} || ".a";
  10. our $shlibext = $target{shared_extension} || ".so";
  11. our $shlibextsimple = $target{shared_extension_simple} || ".so";
  12. our $shlibextimport = $target{shared_import_extension} || "";
  13. our $dsoext = $target{dso_extension} || ".so";
  14. sub windowsdll { $config{target} =~ /^(?:Cygwin|mingw)/ }
  15. our $sover = $config{target} =~ /^mingw/
  16. ? $config{shlib_major}."_".$config{shlib_minor}
  17. : $config{shlib_major}.".".$config{shlib_minor};
  18. # shlib and shlib_simple both take a static library name and figure
  19. # out what the shlib name should be.
  20. #
  21. # When OpenSSL is configured "no-shared", these functions will just
  22. # return empty lists, making them suitable to join().
  23. #
  24. # With Windows DLL producers, shlib($libname) will return the shared
  25. # library name (which usually is different from the static library
  26. # name) with the default shared extension appended to it, while
  27. # shlib_simple($libname) will return the static library name with
  28. # the shared extension followed by ".a" appended to it. The former
  29. # result is used as the runtime shared library while the latter is
  30. # used as the DLL import library.
  31. #
  32. # On all Unix systems, shlib($libname) will return the library name
  33. # with the default shared extension, while shlib_simple($libname)
  34. # will return the name from shlib($libname) with any SO version number
  35. # removed. On some systems, they may therefore return the exact same
  36. # string.
  37. sub shlib {
  38. my $lib = shift;
  39. return () if $disabled{shared} || $lib =~ /\.a$/;
  40. return $unified_info{sharednames}->{$lib} . $shlibext;
  41. }
  42. sub shlib_simple {
  43. my $lib = shift;
  44. return () if $disabled{shared} || $lib =~ /\.a$/;
  45. if (windowsdll()) {
  46. return $lib . $shlibextimport;
  47. }
  48. return $lib . $shlibextsimple;
  49. }
  50. # Easy fixing of static library names
  51. sub lib {
  52. (my $lib = shift) =~ s/\.a$//;
  53. return $lib . $libext;
  54. }
  55. # dso is a complement to shlib / shlib_simple that returns the
  56. # given libname with the simple shared extension (possible SO version
  57. # removed). This differs from shlib_simple() by being unconditional.
  58. sub dso {
  59. my $engine = shift;
  60. return $engine . $dsoext;
  61. }
  62. # This makes sure things get built in the order they need
  63. # to. You're welcome.
  64. sub dependmagic {
  65. my $target = shift;
  66. return "$target: build_generated\n\t\$(MAKE) depend && \$(MAKE) _$target\n_$target";
  67. }
  68. '';
  69. -}
  70. PLATFORM={- $config{target} -}
  71. OPTIONS={- $config{options} -}
  72. CONFIGURE_ARGS=({- join(", ",quotify_l(@{$config{perlargv}})) -})
  73. SRCDIR={- $config{sourcedir} -}
  74. BLDDIR={- $config{builddir} -}
  75. VERSION={- $config{version} -}
  76. MAJOR={- $config{major} -}
  77. MINOR={- $config{minor} -}
  78. SHLIB_VERSION_NUMBER={- $config{shlib_version_number} -}
  79. SHLIB_VERSION_HISTORY={- $config{shlib_version_history} -}
  80. SHLIB_MAJOR={- $config{shlib_major} -}
  81. SHLIB_MINOR={- $config{shlib_minor} -}
  82. SHLIB_TARGET={- $target{shared_target} -}
  83. LIBS={- join(" ", map { lib($_) } @{$unified_info{libraries}}) -}
  84. SHLIBS={- join(" ", map { shlib($_) } @{$unified_info{libraries}}) -}
  85. SHLIB_INFO={- join(" ", map { "\"".shlib($_).";".shlib_simple($_)."\"" } @{$unified_info{libraries}}) -}
  86. ENGINES={- join(" ", map { dso($_) } @{$unified_info{engines}}) -}
  87. PROGRAMS={- join(" ", map { $_.$exeext } @{$unified_info{programs}}) -}
  88. SCRIPTS={- join(" ", @{$unified_info{scripts}}) -}
  89. {- output_off() if $disabled{makedepend}; "" -}
  90. DEPS={- join(" ", map { (my $x = $_) =~ s|\.o$|$depext|; $x; }
  91. grep { $unified_info{sources}->{$_}->[0] =~ /\.c$/ }
  92. keys %{$unified_info{sources}}); -}
  93. {- output_on() if $disabled{makedepend}; "" -}
  94. GENERATED_MANDATORY={- join(" ", @{$unified_info{depends}->{""}} ) -}
  95. GENERATED={- join(" ",
  96. ( map { (my $x = $_) =~ s|\.S$|\.s|; $x }
  97. grep { defined $unified_info{generate}->{$_} }
  98. map { @{$unified_info{sources}->{$_}} }
  99. grep { /\.o$/ } keys %{$unified_info{sources}} ),
  100. ( grep { /\.h$/ } keys %{$unified_info{generate}} )) -}
  101. INSTALL_LIBS={- join(" ", map { lib($_) } @{$unified_info{install}->{libraries}}) -}
  102. INSTALL_SHLIBS={- join(" ", map { shlib($_) } @{$unified_info{install}->{libraries}}) -}
  103. INSTALL_SHLIB_INFO={- join(" ", map { "\"".shlib($_).";".shlib_simple($_)."\"" } @{$unified_info{install}->{libraries}}) -}
  104. INSTALL_ENGINES={- join(" ", map { dso($_) } @{$unified_info{install}->{engines}}) -}
  105. INSTALL_PROGRAMS={- join(" ", map { $_.$exeext } @{$unified_info{install}->{programs}}) -}
  106. {- output_off() if $disabled{apps}; "" -}
  107. BIN_SCRIPTS=$(BLDDIR)/tools/c_rehash
  108. MISC_SCRIPTS=$(BLDDIR)/apps/CA.pl $(BLDDIR)/apps/tsget
  109. {- output_on() if $disabled{apps}; "" -}
  110. # DESTDIR is for package builders so that they can configure for, say,
  111. # /usr/ and yet have everything installed to /tmp/somedir/usr/.
  112. # Normally it is left empty.
  113. DESTDIR=
  114. # Do not edit these manually. Use Configure with --prefix or --openssldir
  115. # to change this! Short explanation in the top comment in Configure
  116. INSTALLTOP={- # $prefix is used in the OPENSSLDIR perl snippet
  117. #
  118. our $prefix = $config{prefix} || "/usr/local";
  119. $prefix -}
  120. OPENSSLDIR={- #
  121. # The logic here is that if no --openssldir was given,
  122. # OPENSSLDIR will get the value from $prefix plus "/ssl".
  123. # If --openssldir was given and the value is an absolute
  124. # path, OPENSSLDIR will get its value without change.
  125. # If the value from --openssldir is a relative path,
  126. # OPENSSLDIR will get $prefix with the --openssldir
  127. # value appended as a subdirectory.
  128. #
  129. use File::Spec::Functions;
  130. our $openssldir =
  131. $config{openssldir} ?
  132. (file_name_is_absolute($config{openssldir}) ?
  133. $config{openssldir}
  134. : catdir($prefix, $config{openssldir}))
  135. : catdir($prefix, "ssl");
  136. $openssldir -}
  137. LIBDIR={- #
  138. # if $prefix/lib$target{multilib} is not an existing
  139. # directory, then assume that it's not searched by linker
  140. # automatically, in which case adding $target{multilib} suffix
  141. # causes more grief than we're ready to tolerate, so don't...
  142. our $multilib =
  143. -d "$prefix/lib$target{multilib}" ? $target{multilib} : "";
  144. our $libdir = $config{libdir} || "lib$multilib";
  145. $libdir -}
  146. ENGINESDIR={- use File::Spec::Functions;
  147. catdir($prefix,$libdir,"engines-$sover") -}
  148. # Convenience variable for those who want to set the rpath in shared
  149. # libraries and applications
  150. LIBRPATH=$(INSTALLTOP)/$(LIBDIR)
  151. MANDIR=$(INSTALLTOP)/share/man
  152. DOCDIR=$(INSTALLTOP)/share/doc/$(BASENAME)
  153. HTMLDIR=$(DOCDIR)/html
  154. # MANSUFFIX is for the benefit of anyone who may want to have a suffix
  155. # appended after the manpage file section number. "ssl" is popular,
  156. # resulting in files such as config.5ssl rather than config.5.
  157. MANSUFFIX=
  158. HTMLSUFFIX=html
  159. CROSS_COMPILE= {- $config{cross_compile_prefix} -}
  160. CC= $(CROSS_COMPILE){- $target{cc} -}
  161. CFLAGS={- our $cflags2 = join(" ",(map { "-D".$_} @{$target{defines}}, @{$config{defines}}),"-DOPENSSLDIR=\"\\\"\$(OPENSSLDIR)\\\"\"","-DENGINESDIR=\"\\\"\$(ENGINESDIR)\\\"\"") -} {- $target{cflags} -} {- $config{cflags} -}
  162. CFLAGS_Q={- $cflags2 =~ s|([\\"])|\\$1|g; $cflags2 -} {- $config{cflags} -}
  163. CXX= $(CROSS_COMPILE){- $target{cxx} -}
  164. CXXFLAGS={- our $cxxflags2 = join(" ",(map { "-D".$_} @{$target{defines}}, @{$config{defines}}),"-DOPENSSLDIR=\"\\\"\$(OPENSSLDIR)\\\"\"","-DENGINESDIR=\"\\\"\$(ENGINESDIR)\\\"\"") -} {- $target{cxxflags} -} {- $config{cxxflags} -} -std=c++11
  165. LDFLAGS= {- $target{lflags} -}
  166. PLIB_LDFLAGS= {- $target{plib_lflags} -}
  167. EX_LIBS= {- $target{ex_libs} -} {- $config{ex_libs} -}
  168. LIB_CFLAGS={- $target{shared_cflag} || "" -}
  169. LIB_CXXFLAGS={- $target{shared_cxxflag} || "" -}
  170. LIB_LDFLAGS={- $target{shared_ldflag}." ".$config{shared_ldflag} -}
  171. DSO_CFLAGS={- $target{shared_cflag} || "" -}
  172. DSO_CXXFLAGS={- $target{shared_cxxflag} || "" -}
  173. DSO_LDFLAGS=$(LIB_LDFLAGS)
  174. BIN_CFLAGS={- $target{bin_cflags} -}
  175. BIN_CXXFLAGS={- $target{bin_cxxflag} || "" -}
  176. PERL={- $config{perl} -}
  177. ARFLAGS= {- $target{arflags} -}
  178. AR=$(CROSS_COMPILE){- $target{ar} || "ar" -} $(ARFLAGS) r
  179. RANLIB= {- $target{ranlib} -}
  180. NM= $(CROSS_COMPILE){- $target{nm} || "nm" -}
  181. RCFLAGS={- $target{shared_rcflag} -}
  182. RC= $(CROSS_COMPILE){- $target{rc} || "windres" -}
  183. RM= rm -f
  184. RMDIR= rmdir
  185. TAR= {- $target{tar} || "tar" -}
  186. TARFLAGS= {- $target{tarflags} -}
  187. MAKEDEPEND={- $config{makedepprog} -}
  188. BASENAME= openssl
  189. NAME= $(BASENAME)-$(VERSION)
  190. TARFILE= ../$(NAME).tar
  191. # We let the C compiler driver to take care of .s files. This is done in
  192. # order to be excused from maintaining a separate set of architecture
  193. # dependent assembler flags. E.g. if you throw -mcpu=ultrasparc at SPARC
  194. # gcc, then the driver will automatically translate it to -xarch=v8plus
  195. # and pass it down to assembler.
  196. AS=$(CC) -c
  197. ASFLAG=$(CFLAGS)
  198. PERLASM_SCHEME= {- $target{perlasm_scheme} -}
  199. # For x86 assembler: Set PROCESSOR to 386 if you want to support
  200. # the 80386.
  201. PROCESSOR= {- $config{processor} -}
  202. # We want error [and other] messages in English. Trouble is that make(1)
  203. # doesn't pass macros down as environment variables unless there already
  204. # was corresponding variable originally set. In other words we can only
  205. # reassign environment variables, but not set new ones, not in portable
  206. # manner that is. That's why we reassign several, just to be sure...
  207. LC_ALL=C
  208. LC_MESSAGES=C
  209. LANG=C
  210. # The main targets ###################################################
  211. {- dependmagic('all'); -}: build_libs_nodep build_engines_nodep build_programs_nodep link-utils
  212. {- dependmagic('build_libs'); -}: build_libs_nodep
  213. {- dependmagic('build_engines'); -}: build_engines_nodep
  214. {- dependmagic('build_programs'); -}: build_programs_nodep
  215. build_generated: $(GENERATED_MANDATORY)
  216. build_libs_nodep: libcrypto.pc libssl.pc openssl.pc
  217. build_engines_nodep: $(ENGINES)
  218. build_programs_nodep: $(PROGRAMS) $(SCRIPTS)
  219. # Kept around for backward compatibility
  220. build_apps build_tests: build_programs
  221. test: tests
  222. {- dependmagic('tests'); -}: build_programs_nodep build_engines_nodep link-utils
  223. @ : {- output_off() if $disabled{tests}; "" -}
  224. ( cd test; \
  225. SRCTOP=../$(SRCDIR) \
  226. BLDTOP=../$(BLDDIR) \
  227. PERL="$(PERL)" \
  228. EXE_EXT={- $exeext -} \
  229. OPENSSL_ENGINES=../$(BLDDIR)/engines \
  230. OPENSSL_DEBUG_MEMORY=on \
  231. $(PERL) ../$(SRCDIR)/test/run_tests.pl $(TESTS) )
  232. @ : {- if ($disabled{tests}) { output_on(); } else { output_off(); } "" -}
  233. @echo "Tests are not supported with your chosen Configure options"
  234. @ : {- output_on() if !$disabled{tests}; "" -}
  235. list-tests:
  236. @ : {- output_off() if $disabled{tests}; "" -}
  237. @SRCTOP="$(SRCDIR)" \
  238. $(PERL) $(SRCDIR)/test/run_tests.pl list
  239. @ : {- if ($disabled{tests}) { output_on(); } else { output_off(); } "" -}
  240. @echo "Tests are not supported with your chosen Configure options"
  241. @ : {- output_on() if !$disabled{tests}; "" -}
  242. install: install_sw install_ssldirs install_docs
  243. uninstall: uninstall_docs uninstall_sw
  244. libclean:
  245. @set -e; for s in $(SHLIB_INFO); do \
  246. s1=`echo "$$s" | cut -f1 -d";"`; \
  247. s2=`echo "$$s" | cut -f2 -d";"`; \
  248. echo $(RM) $$s1; \
  249. $(RM) $$s1; \
  250. if [ "$$s1" != "$$s2" ]; then \
  251. echo $(RM) $$s2; \
  252. $(RM) $$s2; \
  253. fi; \
  254. done
  255. $(RM) $(LIBS)
  256. $(RM) *.map
  257. clean: libclean
  258. $(RM) $(PROGRAMS) $(TESTPROGS) $(ENGINES) $(SCRIPTS)
  259. $(RM) $(GENERATED)
  260. -$(RM) `find . -name '*{- $depext -}' -a \! -path "./.git/*"`
  261. -$(RM) `find . -name '*{- $objext -}' -a \! -path "./.git/*"`
  262. $(RM) core
  263. $(RM) tags TAGS doc-nits
  264. $(RM) test/.rnd
  265. $(RM) openssl.pc libcrypto.pc libssl.pc
  266. -$(RM) `find . -type l -a \! -path "./.git/*"`
  267. $(RM) $(TARFILE)
  268. distclean: clean
  269. $(RM) configdata.pm
  270. $(RM) Makefile
  271. # We check if any depfile is newer than Makefile and decide to
  272. # concatenate only if that is true.
  273. depend:
  274. @: {- output_off() if $disabled{makedepend}; "" -}
  275. @if egrep "^# DO NOT DELETE THIS LINE" Makefile >/dev/null && [ -z "`find $(DEPS) -newer Makefile 2>/dev/null; exit 0`" ]; then :; else \
  276. ( $(PERL) -pe 'exit 0 if /^# DO NOT DELETE THIS LINE.*/' < Makefile; \
  277. echo '# DO NOT DELETE THIS LINE -- make depend depends on it.'; \
  278. echo; \
  279. for f in $(DEPS); do \
  280. if [ -f $$f ]; then cat $$f; fi; \
  281. done ) > Makefile.new; \
  282. if cmp Makefile.new Makefile >/dev/null 2>&1; then \
  283. rm -f Makefile.new; \
  284. else \
  285. mv -f Makefile.new Makefile; \
  286. fi; \
  287. fi
  288. @: {- output_on() if $disabled{makedepend}; "" -}
  289. # Install helper targets #############################################
  290. install_sw: all install_dev install_engines install_runtime
  291. uninstall_sw: uninstall_runtime uninstall_engines uninstall_dev
  292. install_docs: install_man_docs install_html_docs
  293. uninstall_docs: uninstall_man_docs uninstall_html_docs
  294. $(RM) -r -v $(DESTDIR)$(DOCDIR)
  295. install_ssldirs:
  296. @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(OPENSSLDIR)/certs
  297. @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(OPENSSLDIR)/private
  298. @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(OPENSSLDIR)/misc
  299. @set -e; for x in dummy $(MISC_SCRIPTS); do \
  300. if [ "$$x" = "dummy" ]; then continue; fi; \
  301. fn=`basename $$x`; \
  302. echo "install $$x -> $(DESTDIR)$(OPENSSLDIR)/misc/$$fn"; \
  303. cp $$x $(DESTDIR)$(OPENSSLDIR)/misc/$$fn.new; \
  304. chmod 755 $(DESTDIR)$(OPENSSLDIR)/misc/$$fn.new; \
  305. mv -f $(DESTDIR)$(OPENSSLDIR)/misc/$$fn.new \
  306. $(DESTDIR)$(OPENSSLDIR)/misc/$$fn; \
  307. done
  308. @echo "install $(SRCDIR)/apps/openssl.cnf -> $(DESTDIR)$(OPENSSLDIR)/openssl.cnf.dist"
  309. @cp $(SRCDIR)/apps/openssl.cnf $(DESTDIR)$(OPENSSLDIR)/openssl.cnf.new
  310. @chmod 644 $(DESTDIR)$(OPENSSLDIR)/openssl.cnf.new
  311. @mv -f $(DESTDIR)$(OPENSSLDIR)/openssl.cnf.new $(DESTDIR)$(OPENSSLDIR)/openssl.cnf.dist
  312. @if [ ! -f "$(DESTDIR)$(OPENSSLDIR)/openssl.cnf" ]; then \
  313. echo "install $(SRCDIR)/apps/openssl.cnf -> $(DESTDIR)$(OPENSSLDIR)/openssl.cnf"; \
  314. cp $(SRCDIR)/apps/openssl.cnf $(DESTDIR)$(OPENSSLDIR)/openssl.cnf; \
  315. chmod 644 $(DESTDIR)$(OPENSSLDIR)/openssl.cnf; \
  316. fi
  317. @echo "install $(SRCDIR)/apps/ct_log_list.cnf -> $(DESTDIR)$(OPENSSLDIR)/ct_log_list.cnf.dist"
  318. @cp $(SRCDIR)/apps/ct_log_list.cnf $(DESTDIR)$(OPENSSLDIR)/ct_log_list.cnf.new
  319. @chmod 644 $(DESTDIR)$(OPENSSLDIR)/ct_log_list.cnf.new
  320. @mv -f $(DESTDIR)$(OPENSSLDIR)/ct_log_list.cnf.new $(DESTDIR)$(OPENSSLDIR)/ct_log_list.cnf.dist
  321. @if [ ! -f "$(DESTDIR)$(OPENSSLDIR)/ct_log_list.cnf" ]; then \
  322. echo "install $(SRCDIR)/apps/ct_log_list.cnf -> $(DESTDIR)$(OPENSSLDIR)/ct_log_list.cnf"; \
  323. cp $(SRCDIR)/apps/ct_log_list.cnf $(DESTDIR)$(OPENSSLDIR)/ct_log_list.cnf; \
  324. chmod 644 $(DESTDIR)$(OPENSSLDIR)/ct_log_list.cnf; \
  325. fi
  326. install_dev:
  327. @[ -n "$(INSTALLTOP)" ] || (echo INSTALLTOP should not be empty; exit 1)
  328. @echo "*** Installing development files"
  329. @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(INSTALLTOP)/include/openssl
  330. @ : {- output_off() unless grep { $_ eq "OPENSSL_USE_APPLINK" } @{$target{defines}}; "" -}
  331. @echo "install $(SRCDIR)/ms/applink.c -> $(DESTDIR)$(INSTALLTOP)/include/openssl/applink.c"
  332. @cp $(SRCDIR)/ms/applink.c $(DESTDIR)$(INSTALLTOP)/include/openssl/applink.c
  333. @chmod 644 $(DESTDIR)$(INSTALLTOP)/include/openssl/applink.c
  334. @ : {- output_on() unless grep { $_ eq "OPENSSL_USE_APPLINK" } @{$target{defines}}; "" -}
  335. @set -e; for i in $(SRCDIR)/include/openssl/*.h \
  336. $(BLDDIR)/include/openssl/*.h; do \
  337. fn=`basename $$i`; \
  338. echo "install $$i -> $(DESTDIR)$(INSTALLTOP)/include/openssl/$$fn"; \
  339. cp $$i $(DESTDIR)$(INSTALLTOP)/include/openssl/$$fn; \
  340. chmod 644 $(DESTDIR)$(INSTALLTOP)/include/openssl/$$fn; \
  341. done
  342. @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)
  343. @set -e; for l in $(INSTALL_LIBS); do \
  344. fn=`basename $$l`; \
  345. echo "install $$l -> $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn"; \
  346. cp $$l $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn.new; \
  347. $(RANLIB) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn.new; \
  348. chmod 644 $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn.new; \
  349. mv -f $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn.new \
  350. $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn; \
  351. done
  352. @ : {- output_off() if $disabled{shared}; "" -}
  353. @set -e; for s in $(INSTALL_SHLIB_INFO); do \
  354. s1=`echo "$$s" | cut -f1 -d";"`; \
  355. s2=`echo "$$s" | cut -f2 -d";"`; \
  356. fn1=`basename $$s1`; \
  357. fn2=`basename $$s2`; \
  358. : {- output_off() if windowsdll(); "" -}; \
  359. echo "install $$s1 -> $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn1"; \
  360. cp $$s1 $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn1.new; \
  361. chmod 755 $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn1.new; \
  362. mv -f $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn1.new \
  363. $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn1; \
  364. if [ "$$fn1" != "$$fn2" ]; then \
  365. echo "link $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn2 -> $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn1"; \
  366. ln -sf $$fn1 $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn2; \
  367. fi; \
  368. : {- output_on() if windowsdll(); "" -}{- output_off() unless windowsdll(); "" -}; \
  369. echo "install $$s2 -> $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn2"; \
  370. cp $$s2 $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn2.new; \
  371. chmod 755 $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn2.new; \
  372. mv -f $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn2.new \
  373. $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn2; \
  374. : {- output_on() unless windowsdll(); "" -}; \
  375. done
  376. @ : {- output_on() if $disabled{shared}; "" -}
  377. @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig
  378. @echo "install libcrypto.pc -> $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/libcrypto.pc"
  379. @cp libcrypto.pc $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig
  380. @chmod 644 $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/libcrypto.pc
  381. @echo "install libssl.pc -> $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/libssl.pc"
  382. @cp libssl.pc $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig
  383. @chmod 644 $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/libssl.pc
  384. @echo "install openssl.pc -> $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/openssl.pc"
  385. @cp openssl.pc $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig
  386. @chmod 644 $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/openssl.pc
  387. uninstall_dev:
  388. @echo "*** Uninstalling development files"
  389. @ : {- output_off() unless grep { $_ eq "OPENSSL_USE_APPLINK" } @{$target{defines}}; "" -}
  390. @echo "$(RM) $(DESTDIR)$(INSTALLTOP)/include/openssl/applink.c"
  391. @$(RM) $(DESTDIR)$(INSTALLTOP)/include/openssl/applink.c
  392. @ : {- output_on() unless grep { $_ eq "OPENSSL_USE_APPLINK" } @{$target{defines}}; "" -}
  393. @set -e; for i in $(SRCDIR)/include/openssl/*.h \
  394. $(BLDDIR)/include/openssl/*.h; do \
  395. fn=`basename $$i`; \
  396. echo "$(RM) $(DESTDIR)$(INSTALLTOP)/include/openssl/$$fn"; \
  397. $(RM) $(DESTDIR)$(INSTALLTOP)/include/openssl/$$fn; \
  398. done
  399. -$(RMDIR) $(DESTDIR)$(INSTALLTOP)/include/openssl
  400. -$(RMDIR) $(DESTDIR)$(INSTALLTOP)/include
  401. @set -e; for l in $(INSTALL_LIBS); do \
  402. fn=`basename $$l`; \
  403. echo "$(RM) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn"; \
  404. $(RM) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn; \
  405. done
  406. @ : {- output_off() if $disabled{shared}; "" -}
  407. @set -e; for s in $(INSTALL_SHLIB_INFO); do \
  408. s1=`echo "$$s" | cut -f1 -d";"`; \
  409. s2=`echo "$$s" | cut -f2 -d";"`; \
  410. fn1=`basename $$s1`; \
  411. fn2=`basename $$s2`; \
  412. : {- output_off() if windowsdll(); "" -}; \
  413. echo "$(RM) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn1"; \
  414. $(RM) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn1; \
  415. if [ "$$fn1" != "$$fn2" ]; then \
  416. echo "$(RM) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn2"; \
  417. $(RM) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn2; \
  418. fi; \
  419. : {- output_on() if windowsdll(); "" -}{- output_off() unless windowsdll(); "" -}; \
  420. echo "$(RM) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn2"; \
  421. $(RM) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn2; \
  422. : {- output_on() unless windowsdll(); "" -}; \
  423. done
  424. @ : {- output_on() if $disabled{shared}; "" -}
  425. $(RM) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/libcrypto.pc
  426. $(RM) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/libssl.pc
  427. $(RM) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/openssl.pc
  428. -$(RMDIR) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig
  429. -$(RMDIR) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)
  430. install_engines:
  431. @[ -n "$(INSTALLTOP)" ] || (echo INSTALLTOP should not be empty; exit 1)
  432. @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(ENGINESDIR)/
  433. @echo "*** Installing engines"
  434. @set -e; for e in dummy $(INSTALL_ENGINES); do \
  435. if [ "$$e" = "dummy" ]; then continue; fi; \
  436. fn=`basename $$e`; \
  437. echo "install $$e -> $(DESTDIR)$(ENGINESDIR)/$$fn"; \
  438. cp $$e $(DESTDIR)$(ENGINESDIR)/$$fn.new; \
  439. chmod 755 $(DESTDIR)$(ENGINESDIR)/$$fn.new; \
  440. mv -f $(DESTDIR)$(ENGINESDIR)/$$fn.new \
  441. $(DESTDIR)$(ENGINESDIR)/$$fn; \
  442. done
  443. uninstall_engines:
  444. @echo "*** Uninstalling engines"
  445. @set -e; for e in dummy $(INSTALL_ENGINES); do \
  446. if [ "$$e" = "dummy" ]; then continue; fi; \
  447. fn=`basename $$e`; \
  448. if [ "$$fn" = '{- dso("ossltest") -}' ]; then \
  449. continue; \
  450. fi; \
  451. echo "$(RM) $(DESTDIR)$(ENGINESDIR)/$$fn"; \
  452. $(RM) $(DESTDIR)$(ENGINESDIR)/$$fn; \
  453. done
  454. -$(RMDIR) $(DESTDIR)$(ENGINESDIR)
  455. install_runtime:
  456. @[ -n "$(INSTALLTOP)" ] || (echo INSTALLTOP should not be empty; exit 1)
  457. @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(INSTALLTOP)/bin
  458. @ : {- output_off() if windowsdll(); "" -}
  459. @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)
  460. @ : {- output_on() if windowsdll(); "" -}
  461. @echo "*** Installing runtime files"
  462. @set -e; for s in dummy $(INSTALL_SHLIBS); do \
  463. if [ "$$s" = "dummy" ]; then continue; fi; \
  464. fn=`basename $$s`; \
  465. : {- output_off() unless windowsdll(); "" -}; \
  466. echo "install $$s -> $(DESTDIR)$(INSTALLTOP)/bin/$$fn"; \
  467. cp $$s $(DESTDIR)$(INSTALLTOP)/bin/$$fn.new; \
  468. chmod 644 $(DESTDIR)$(INSTALLTOP)/bin/$$fn.new; \
  469. mv -f $(DESTDIR)$(INSTALLTOP)/bin/$$fn.new \
  470. $(DESTDIR)$(INSTALLTOP)/bin/$$fn; \
  471. : {- output_on() unless windowsdll(); "" -}{- output_off() if windowsdll(); "" -}; \
  472. echo "install $$s -> $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn"; \
  473. cp $$s $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn.new; \
  474. chmod 755 $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn.new; \
  475. mv -f $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn.new \
  476. $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn; \
  477. : {- output_on() if windowsdll(); "" -}; \
  478. done
  479. @set -e; for x in dummy $(INSTALL_PROGRAMS); do \
  480. if [ "$$x" = "dummy" ]; then continue; fi; \
  481. fn=`basename $$x`; \
  482. echo "install $$x -> $(DESTDIR)$(INSTALLTOP)/bin/$$fn"; \
  483. cp $$x $(DESTDIR)$(INSTALLTOP)/bin/$$fn.new; \
  484. chmod 755 $(DESTDIR)$(INSTALLTOP)/bin/$$fn.new; \
  485. mv -f $(DESTDIR)$(INSTALLTOP)/bin/$$fn.new \
  486. $(DESTDIR)$(INSTALLTOP)/bin/$$fn; \
  487. done
  488. @set -e; for x in dummy $(BIN_SCRIPTS); do \
  489. if [ "$$x" = "dummy" ]; then continue; fi; \
  490. fn=`basename $$x`; \
  491. echo "install $$x -> $(DESTDIR)$(INSTALLTOP)/bin/$$fn"; \
  492. cp $$x $(DESTDIR)$(INSTALLTOP)/bin/$$fn.new; \
  493. chmod 755 $(DESTDIR)$(INSTALLTOP)/bin/$$fn.new; \
  494. mv -f $(DESTDIR)$(INSTALLTOP)/bin/$$fn.new \
  495. $(DESTDIR)$(INSTALLTOP)/bin/$$fn; \
  496. done
  497. uninstall_runtime:
  498. @echo "*** Uninstalling runtime files"
  499. @set -e; for x in dummy $(INSTALL_PROGRAMS); \
  500. do \
  501. if [ "$$x" = "dummy" ]; then continue; fi; \
  502. fn=`basename $$x`; \
  503. echo "$(RM) $(DESTDIR)$(INSTALLTOP)/bin/$$fn"; \
  504. $(RM) $(DESTDIR)$(INSTALLTOP)/bin/$$fn; \
  505. done;
  506. @set -e; for x in dummy $(BIN_SCRIPTS); \
  507. do \
  508. if [ "$$x" = "dummy" ]; then continue; fi; \
  509. fn=`basename $$x`; \
  510. echo "$(RM) $(DESTDIR)$(INSTALLTOP)/bin/$$fn"; \
  511. $(RM) $(DESTDIR)$(INSTALLTOP)/bin/$$fn; \
  512. done
  513. @ : {- output_off() unless windowsdll(); "" -}
  514. @set -e; for s in dummy $(INSTALL_SHLIBS); do \
  515. if [ "$$s" = "dummy" ]; then continue; fi; \
  516. fn=`basename $$s`; \
  517. echo "$(RM) $(DESTDIR)$(INSTALLTOP)/bin/$$fn"; \
  518. $(RM) $(DESTDIR)$(INSTALLTOP)/bin/$$fn; \
  519. done
  520. @ : {- output_on() unless windowsdll(); "" -}
  521. -$(RMDIR) $(DESTDIR)$(INSTALLTOP)/bin
  522. install_man_docs:
  523. @[ -n "$(INSTALLTOP)" ] || (echo INSTALLTOP should not be empty; exit 1)
  524. @echo "*** Installing manpages"
  525. $(PERL) $(SRCDIR)/util/process_docs.pl \
  526. --destdir=$(DESTDIR)$(MANDIR) --type=man --suffix=$(MANSUFFIX)
  527. uninstall_man_docs:
  528. @echo "*** Uninstalling manpages"
  529. $(PERL) $(SRCDIR)/util/process_docs.pl \
  530. --destdir=$(DESTDIR)$(MANDIR) --type=man --suffix=$(MANSUFFIX) \
  531. --remove
  532. install_html_docs:
  533. @[ -n "$(INSTALLTOP)" ] || (echo INSTALLTOP should not be empty; exit 1)
  534. @echo "*** Installing HTML manpages"
  535. $(PERL) $(SRCDIR)/util/process_docs.pl \
  536. --destdir=$(DESTDIR)$(HTMLDIR) --type=html
  537. uninstall_html_docs:
  538. @echo "*** Uninstalling manpages"
  539. $(PERL) $(SRCDIR)/util/process_docs.pl \
  540. --destdir=$(DESTDIR)$(HTMLDIR) --type=html --remove
  541. # Developer targets (note: these are only available on Unix) #########
  542. update: generate errors ordinals
  543. generate: generate_apps generate_crypto_bn generate_crypto_objects \
  544. generate_crypto_conf generate_crypto_asn1
  545. doc-nits:
  546. (cd $(SRCDIR); $(PERL) util/find-doc-nits -n ) >doc-nits
  547. if [ -s doc-nits ] ; then cat doc-nits; rm doc-nits ; exit 1; fi
  548. # Test coverage is a good idea for the future
  549. #coverage: $(PROGRAMS) $(TESTPROGRAMS)
  550. # ...
  551. lint:
  552. lint -DLINT $(INCLUDES) $(SRCS)
  553. {- # because the program apps/openssl has object files as sources, and
  554. # they then have the corresponding C files as source, we need to chain
  555. # the lookups in %unified_info
  556. my $apps_openssl = catfile("apps","openssl");
  557. our @openssl_source = map { @{$unified_info{sources}->{$_}} }
  558. @{$unified_info{sources}->{$apps_openssl}};
  559. ""; -}
  560. generate_apps:
  561. ( cd $(SRCDIR); $(PERL) VMS/VMSify-conf.pl \
  562. < apps/openssl.cnf > apps/openssl-vms.cnf )
  563. ( b=`pwd`; cd $(SRCDIR); $(PERL) -I$$b apps/progs.pl \
  564. {- join(" ", @openssl_source) -} \
  565. > apps/progs.h )
  566. generate_crypto_bn:
  567. ( cd $(SRCDIR); $(PERL) crypto/bn/bn_prime.pl > crypto/bn/bn_prime.h )
  568. generate_crypto_objects:
  569. ( cd $(SRCDIR); $(PERL) crypto/objects/objects.pl \
  570. crypto/objects/objects.txt \
  571. crypto/objects/obj_mac.num \
  572. include/openssl/obj_mac.h )
  573. ( cd $(SRCDIR); $(PERL) crypto/objects/obj_dat.pl \
  574. include/openssl/obj_mac.h \
  575. crypto/objects/obj_dat.h )
  576. ( cd $(SRCDIR); $(PERL) crypto/objects/objxref.pl \
  577. crypto/objects/obj_mac.num \
  578. crypto/objects/obj_xref.txt \
  579. > crypto/objects/obj_xref.h )
  580. generate_crypto_conf:
  581. ( cd $(SRCDIR); $(PERL) crypto/conf/keysets.pl \
  582. > crypto/conf/conf_def.h )
  583. generate_crypto_asn1:
  584. ( cd $(SRCDIR); $(PERL) crypto/asn1/charmap.pl \
  585. > crypto/asn1/charmap.h )
  586. errors:
  587. ( cd $(SRCDIR); $(PERL) util/ck_errf.pl -strict */*.c */*/*.c )
  588. ( cd $(SRCDIR); $(PERL) util/mkerr.pl -recurse -write )
  589. ( cd $(SRCDIR)/engines; \
  590. for e in *.ec; do \
  591. $(PERL) ../util/mkerr.pl -conf $$e \
  592. -nostatic -staticloader -write *.c; \
  593. done )
  594. ordinals:
  595. ( b=`pwd`; cd $(SRCDIR); $(PERL) -I$$b util/mkdef.pl crypto update )
  596. ( b=`pwd`; cd $(SRCDIR); $(PERL) -I$$b util/mkdef.pl ssl update )
  597. test_ordinals:
  598. ( cd test; \
  599. SRCTOP=../$(SRCDIR) \
  600. BLDTOP=../$(BLDDIR) \
  601. $(PERL) ../$(SRCDIR)/test/run_tests.pl test_ordinals )
  602. tags TAGS: FORCE
  603. rm -f TAGS tags
  604. -ctags -R .
  605. -etags `find . -name '*.[ch]' -o -name '*.pm'`
  606. # Release targets (note: only available on Unix) #####################
  607. TAR_COMMAND=$(TAR) $(TARFLAGS) --owner 0 --group 0 -cvf -
  608. PREPARE_CMD=:
  609. tar:
  610. TMPDIR=/var/tmp/openssl-copy.$$$$; \
  611. DISTDIR=$(NAME); \
  612. mkdir -p $$TMPDIR/$$DISTDIR; \
  613. (cd $(SRCDIR); \
  614. git ls-tree -r --name-only --full-tree HEAD \
  615. | grep -v '^fuzz/corpora' \
  616. | while read F; do \
  617. mkdir -p $$TMPDIR/$$DISTDIR/`dirname $$F`; \
  618. cp $$F $$TMPDIR/$$DISTDIR/$$F; \
  619. done); \
  620. (cd $$TMPDIR; \
  621. $(PREPARE_CMD); \
  622. find $$TMPDIR/$$DISTDIR -type d -print | xargs chmod 755; \
  623. find $$TMPDIR/$$DISTDIR -type f -print | xargs chmod a+r; \
  624. find $$TMPDIR/$$DISTDIR -type f -perm -0100 -print | xargs chmod a+x; \
  625. $(TAR_COMMAND) $$DISTDIR) \
  626. | (cd $(SRCDIR); gzip --best > $(TARFILE).gz); \
  627. rm -rf $$TMPDIR
  628. cd $(SRCDIR); ls -l $(TARFILE).gz
  629. dist:
  630. @$(MAKE) PREPARE_CMD='$(PERL) ./Configure dist' tar
  631. # Helper targets #####################################################
  632. link-utils: $(BLDDIR)/util/opensslwrap.sh
  633. $(BLDDIR)/util/opensslwrap.sh: configdata.pm
  634. @if [ "$(SRCDIR)" != "$(BLDDIR)" ]; then \
  635. mkdir -p "$(BLDDIR)/util"; \
  636. ln -sf "../$(SRCDIR)/util/opensslwrap.sh" "$(BLDDIR)/util"; \
  637. fi
  638. FORCE:
  639. # Building targets ###################################################
  640. libcrypto.pc libssl.pc openssl.pc: configdata.pm $(LIBS) {- join(" ",map { shlib_simple($_) } @{$unified_info{libraries}}) -}
  641. libcrypto.pc:
  642. @ ( echo 'prefix=$(INSTALLTOP)'; \
  643. echo 'exec_prefix=$${prefix}'; \
  644. echo 'libdir=$${exec_prefix}/$(LIBDIR)'; \
  645. echo 'includedir=$${prefix}/include'; \
  646. echo 'enginesdir=$${libdir}/engines-{- $sover -}'; \
  647. echo ''; \
  648. echo 'Name: OpenSSL-libcrypto'; \
  649. echo 'Description: OpenSSL cryptography library'; \
  650. echo 'Version: '$(VERSION); \
  651. echo 'Libs: -L$${libdir} -lcrypto'; \
  652. echo 'Libs.private: $(EX_LIBS)'; \
  653. echo 'Cflags: -I$${includedir}' ) > libcrypto.pc
  654. libssl.pc:
  655. @ ( echo 'prefix=$(INSTALLTOP)'; \
  656. echo 'exec_prefix=$${prefix}'; \
  657. echo 'libdir=$${exec_prefix}/$(LIBDIR)'; \
  658. echo 'includedir=$${prefix}/include'; \
  659. echo ''; \
  660. echo 'Name: OpenSSL-libssl'; \
  661. echo 'Description: Secure Sockets Layer and cryptography libraries'; \
  662. echo 'Version: '$(VERSION); \
  663. echo 'Requires.private: libcrypto'; \
  664. echo 'Libs: -L$${libdir} -lssl'; \
  665. echo 'Libs.private: $(EX_LIBS)'; \
  666. echo 'Cflags: -I$${includedir}' ) > libssl.pc
  667. openssl.pc:
  668. @ ( echo 'prefix=$(INSTALLTOP)'; \
  669. echo 'exec_prefix=$${prefix}'; \
  670. echo 'libdir=$${exec_prefix}/$(LIBDIR)'; \
  671. echo 'includedir=$${prefix}/include'; \
  672. echo ''; \
  673. echo 'Name: OpenSSL'; \
  674. echo 'Description: Secure Sockets Layer and cryptography libraries and tools'; \
  675. echo 'Version: '$(VERSION); \
  676. echo 'Requires: libssl libcrypto' ) > openssl.pc
  677. configdata.pm: $(SRCDIR)/Configure $(SRCDIR)/config {- join(" ", @{$config{build_file_templates}}, @{$config{build_infos}}, @{$config{conf_files}}) -}
  678. @echo "Detected changed: $?"
  679. @echo "Reconfiguring..."
  680. $(PERL) $(SRCDIR)/Configure reconf
  681. @echo "**************************************************"
  682. @echo "*** ***"
  683. @echo "*** Please run the same make command again ***"
  684. @echo "*** ***"
  685. @echo "**************************************************"
  686. @false
  687. {-
  688. use File::Basename;
  689. use File::Spec::Functions qw/:DEFAULT abs2rel rel2abs/;
  690. # Helper function to figure out dependencies on libraries
  691. # It takes a list of library names and outputs a list of dependencies
  692. sub compute_lib_depends {
  693. if ($disabled{shared}) {
  694. return map { lib($_) } @_;
  695. }
  696. # Depending on shared libraries:
  697. # On Windows POSIX layers, we depend on {libname}.dll.a
  698. # On Unix platforms, we depend on {shlibname}.so
  699. return map { $_ =~ /\.a$/ ? $`.$libext : shlib_simple($_) } @_;
  700. }
  701. sub generatesrc {
  702. my %args = @_;
  703. my $generator = join(" ", @{$args{generator}});
  704. my $generator_incs = join("", map { " -I".$_ } @{$args{generator_incs}});
  705. my $incs = join("", map { " -I".$_ } @{$args{incs}});
  706. my $deps = join(" ", @{$args{generator_deps}}, @{$args{deps}});
  707. if ($args{src} !~ /\.[sS]$/) {
  708. if ($args{generator}->[0] =~ m|^.*\.in$|) {
  709. my $dofile = abs2rel(rel2abs(catfile($config{sourcedir},
  710. "util", "dofile.pl")),
  711. rel2abs($config{builddir}));
  712. return <<"EOF";
  713. $args{src}: $args{generator}->[0] $deps
  714. \$(PERL) "-I\$(BLDDIR)" -Mconfigdata "$dofile" \\
  715. "-o$target{build_file}" $generator > \$@
  716. EOF
  717. } else {
  718. return <<"EOF";
  719. $args{src}: $args{generator}->[0] $deps
  720. \$(PERL)$generator_incs $generator > \$@
  721. EOF
  722. }
  723. } else {
  724. if ($args{generator}->[0] =~ /\.pl$/) {
  725. $generator = 'CC="$(CC)" $(PERL)'.$generator_incs.' '.$generator;
  726. } elsif ($args{generator}->[0] =~ /\.m4$/) {
  727. $generator = 'm4 -B 8192'.$generator_incs.' '.$generator.' >'
  728. } elsif ($args{generator}->[0] =~ /\.S$/) {
  729. $generator = undef;
  730. } else {
  731. die "Generator type for $args{src} unknown: $generator\n";
  732. }
  733. if (defined($generator)) {
  734. # If the target is named foo.S in build.info, we want to
  735. # end up generating foo.s in two steps.
  736. if ($args{src} =~ /\.S$/) {
  737. (my $target = $args{src}) =~ s|\.S$|.s|;
  738. return <<"EOF";
  739. $target: $args{generator}->[0] $deps
  740. ( trap "rm -f \$@.*" INT 0; \\
  741. $generator \$@.S; \\
  742. \$(CC) $incs \$(CFLAGS) -E \$@.S | \\
  743. \$(PERL) -ne '/^#(line)?\\s*[0-9]+/ or print' > \$@.i && \\
  744. mv -f \$@.i \$@ )
  745. EOF
  746. }
  747. # Otherwise....
  748. return <<"EOF";
  749. $args{src}: $args{generator}->[0] $deps
  750. $generator \$@
  751. EOF
  752. }
  753. return <<"EOF";
  754. $args{src}: $args{generator}->[0] $deps
  755. \$(CC) $incs \$(CFLAGS) -E \$< | \\
  756. \$(PERL) -ne '/^#(line)?\\s*[0-9]+/ or print' > \$@
  757. EOF
  758. }
  759. }
  760. # Should one wonder about the end of the Perl snippet, it's because this
  761. # second regexp eats up line endings as well, if the removed path is the
  762. # last in the line. We may therefore need to put back a line ending.
  763. sub src2obj {
  764. my %args = @_;
  765. my $obj = $args{obj};
  766. my @srcs = map { if ($unified_info{generate}->{$_}) {
  767. (my $x = $_) =~ s/\.S$/.s/; $x
  768. } else {
  769. $_
  770. }
  771. } ( @{$args{srcs}} );
  772. my $srcs = join(" ", @srcs);
  773. my $deps = join(" ", @srcs, @{$args{deps}});
  774. my $incs = join("", map { " -I".$_ } @{$args{incs}});
  775. unless ($disabled{zlib}) {
  776. if ($withargs{zlib_include}) {
  777. $incs .= " -I".$withargs{zlib_include};
  778. }
  779. }
  780. my $cc = '$(CC)';
  781. my $cflags = '$(CFLAGS)';
  782. if (grep /\.(cc|cpp)$/, @srcs) {
  783. $cc = '$(CXX)';
  784. $cflags = '$(CXXFLAGS)';
  785. $cflags .= ' ' . { lib => '$(LIB_CXXFLAGS)',
  786. dso => '$(DSO_CXXFLAGS)',
  787. bin => '$(BIN_CXXFLAGS)' } -> {$args{intent}};
  788. } else {
  789. $cflags .= ' ' . { lib => '$(LIB_CFLAGS)',
  790. dso => '$(DSO_CFLAGS)',
  791. bin => '$(BIN_CFLAGS)' } -> {$args{intent}};
  792. }
  793. my $makedepprog = $config{makedepprog};
  794. my $recipe = <<"EOF";
  795. $obj$objext: $deps
  796. EOF
  797. if (!$disabled{makedepend} && $makedepprog !~ /\/makedepend/) {
  798. $recipe .= <<"EOF";
  799. $cc $incs $cflags -MMD -MF $obj$depext.tmp -MT \$\@ -c -o \$\@ $srcs
  800. \@touch $obj$depext.tmp
  801. \@if cmp $obj$depext.tmp $obj$depext > /dev/null 2> /dev/null; then \\
  802. rm -f $obj$depext.tmp; \\
  803. else \\
  804. mv $obj$depext.tmp $obj$depext; \\
  805. fi
  806. EOF
  807. } else {
  808. $recipe .= <<"EOF";
  809. $cc $incs $cflags -c -o \$\@ $srcs
  810. EOF
  811. if (!$disabled{makedepend} && $makedepprog =~ /\/makedepend/) {
  812. $recipe .= <<"EOF";
  813. -\$(MAKEDEPEND) -f- -o"|\$\@" -- $incs $cflags -- $srcs \\
  814. >$obj$depext.tmp 2>/dev/null
  815. -\$(PERL) -i -pe 's/^.*\\|//; s/ \\/(\\\\.|[^ ])*//; \$\$_ = undef if (/: *\$\$/ || /^(#.*| *)\$\$/); \$\$_.="\\n" unless !defined(\$\$_) or /\\R\$\$/g;' $obj$depext.tmp
  816. \@if cmp $obj$depext.tmp $obj$depext > /dev/null 2> /dev/null; then \\
  817. rm -f $obj$depext.tmp; \\
  818. else \\
  819. mv $obj$depext.tmp $obj$depext; \\
  820. fi
  821. EOF
  822. }
  823. }
  824. return $recipe;
  825. }
  826. # On Unix, we build shlibs from static libs, so we're ignoring the
  827. # object file array. We *know* this routine is only called when we've
  828. # configure 'shared'.
  829. sub libobj2shlib {
  830. my %args = @_;
  831. my $lib = $args{lib};
  832. my $shlib = $args{shlib};
  833. my $libd = dirname($lib);
  834. my $libn = basename($lib);
  835. (my $libname = $libn) =~ s/^lib//;
  836. my $linklibs = join("", map { my $d = dirname($_);
  837. my $f = basename($_);
  838. (my $l = $f) =~ s/^lib//;
  839. " -L$d -l$l" } @{$args{deps}});
  840. my $deps = join(" ",compute_lib_depends(@{$args{deps}}));
  841. my $shlib_target = $target{shared_target};
  842. my $ordinalsfile = defined($args{ordinals}) ? $args{ordinals}->[1] : "";
  843. my $target = shlib_simple($lib);
  844. return <<"EOF"
  845. # With a build on a Windows POSIX layer (Cygwin or Mingw), we know for a fact
  846. # that two files get produced, {shlibname}.dll and {libname}.dll.a.
  847. # With all other Unix platforms, we often build a shared library with the
  848. # SO version built into the file name and a symlink without the SO version
  849. # It's not necessary to have both as targets. The choice falls on the
  850. # simplest, {libname}$shlibextimport for Windows POSIX layers and
  851. # {libname}$shlibextsimple for the Unix platforms.
  852. $target: $lib$libext $deps $ordinalsfile
  853. \$(MAKE) -f \$(SRCDIR)/Makefile.shared -e \\
  854. PLATFORM=\$(PLATFORM) \\
  855. PERL="\$(PERL)" SRCDIR='\$(SRCDIR)' DSTDIR="$libd" \\
  856. INSTALLTOP='\$(INSTALLTOP)' LIBDIR='\$(LIBDIR)' \\
  857. LIBDEPS='\$(PLIB_LDFLAGS) '"$linklibs"' \$(EX_LIBS)' \\
  858. LIBNAME=$libname LIBVERSION=\$(SHLIB_MAJOR).\$(SHLIB_MINOR) \\
  859. LIBCOMPATVERSIONS=';\$(SHLIB_VERSION_HISTORY)' \\
  860. CC='\$(CC)' CFLAGS='\$(CFLAGS) \$(LIB_CFLAGS)' \\
  861. LDFLAGS='\$(LDFLAGS)' \\
  862. SHARED_LDFLAGS='\$(LIB_LDFLAGS)' SHLIB_EXT=$shlibext \\
  863. RC='\$(RC)' SHARED_RCFLAGS='\$(RCFLAGS)' \\
  864. link_shlib.$shlib_target
  865. EOF
  866. . (windowsdll() ? <<"EOF" : "");
  867. rm -f apps/$shlib$shlibext
  868. rm -f test/$shlib$shlibext
  869. cp -p $shlib$shlibext apps/
  870. cp -p $shlib$shlibext test/
  871. EOF
  872. }
  873. sub obj2dso {
  874. my %args = @_;
  875. my $lib = $args{lib};
  876. my $libd = dirname($lib);
  877. my $libn = basename($lib);
  878. (my $libname = $libn) =~ s/^lib//;
  879. my $shlibdeps = join("", map { my $d = dirname($_);
  880. my $f = basename($_);
  881. (my $l = $f) =~ s/^lib//;
  882. " -L$d -l$l" } @{$args{deps}});
  883. my $deps = join(" ",compute_lib_depends(@{$args{deps}}));
  884. my $shlib_target = $target{shared_target};
  885. my $objs = join(" ", map { $_.$objext } @{$args{objs}});
  886. my $target = dso($lib);
  887. return <<"EOF";
  888. $target: $objs $deps
  889. \$(MAKE) -f \$(SRCDIR)/Makefile.shared -e \\
  890. PLATFORM=\$(PLATFORM) \\
  891. PERL="\$(PERL)" SRCDIR='\$(SRCDIR)' DSTDIR="$libd" \\
  892. LIBDEPS='\$(PLIB_LDFLAGS) '"$shlibdeps"' \$(EX_LIBS)' \\
  893. LIBNAME=$libname LDFLAGS='\$(LDFLAGS)' \\
  894. CC='\$(CC)' CFLAGS='\$(CFLAGS) \$(DSO_CFLAGS)' \\
  895. SHARED_LDFLAGS='\$(DSO_LDFLAGS)' \\
  896. SHLIB_EXT=$dsoext \\
  897. LIBEXTRAS="$objs" \\
  898. link_dso.$shlib_target
  899. EOF
  900. }
  901. sub obj2lib {
  902. my %args = @_;
  903. (my $lib = $args{lib}) =~ s/\.a$//;
  904. my $objs = join(" ", map { $_.$objext } @{$args{objs}});
  905. return <<"EOF";
  906. $lib$libext: $objs
  907. \$(AR) \$\@ \$\?
  908. \$(RANLIB) \$\@ || echo Never mind.
  909. EOF
  910. }
  911. sub obj2bin {
  912. my %args = @_;
  913. my $bin = $args{bin};
  914. my $bind = dirname($bin);
  915. my $binn = basename($bin);
  916. my $objs = join(" ", map { $_.$objext } @{$args{objs}});
  917. my $deps = join(" ",compute_lib_depends(@{$args{deps}}));
  918. my $linklibs = join("", map { if ($_ =~ /\.a$/) {
  919. " $_";
  920. } else {
  921. my $d = dirname($_);
  922. my $f = basename($_);
  923. $d = "." if $d eq $f;
  924. (my $l = $f) =~ s/^lib//;
  925. " -L$d -l$l"
  926. }
  927. } @{$args{deps}});
  928. my $shlib_target = $disabled{shared} ? "" : $target{shared_target};
  929. my $cc = '$(CC)';
  930. my $cflags = '$(CFLAGS) $(BIN_CFLAGS)';
  931. if (grep /_cc$/, @{$args{objs}}) {
  932. $cc = '$(CXX)';
  933. $cflags = '$(CXXFLAGS) $(BIN_CXXFLAGS)';
  934. }
  935. return <<"EOF";
  936. $bin$exeext: $objs $deps
  937. \$(RM) $bin$exeext
  938. \$(MAKE) -f \$(SRCDIR)/Makefile.shared -e \\
  939. PERL="\$(PERL)" SRCDIR=\$(SRCDIR) \\
  940. APPNAME=$bin$exeext OBJECTS="$objs" \\
  941. LIBDEPS='\$(PLIB_LDFLAGS) '"$linklibs"' \$(EX_LIBS)' \\
  942. CC='$cc' CFLAGS='$cflags' \\
  943. LDFLAGS='\$(LDFLAGS)' \\
  944. link_app.$shlib_target
  945. EOF
  946. }
  947. sub in2script {
  948. my %args = @_;
  949. my $script = $args{script};
  950. my $sources = join(" ", @{$args{sources}});
  951. my $dofile = abs2rel(rel2abs(catfile($config{sourcedir},
  952. "util", "dofile.pl")),
  953. rel2abs($config{builddir}));
  954. return <<"EOF";
  955. $script: $sources
  956. \$(PERL) "-I\$(BLDDIR)" -Mconfigdata "$dofile" \\
  957. "-o$target{build_file}" $sources > "$script"
  958. chmod a+x $script
  959. EOF
  960. }
  961. sub generatedir {
  962. my %args = @_;
  963. my $dir = $args{dir};
  964. my @deps = map { s|\.o$|$objext|; $_ } @{$args{deps}};
  965. my @actions = ();
  966. my %extinfo = ( dso => $dsoext,
  967. lib => $libext,
  968. bin => $exeext );
  969. foreach my $type (("dso", "lib", "bin", "script")) {
  970. next unless defined($unified_info{dirinfo}->{$dir}->{products}->{$type});
  971. # For lib object files, we could update the library. However, it
  972. # was decided that it's enough to build the directory local object
  973. # files, so we don't need to add any actions, and the dependencies
  974. # are already taken care of.
  975. if ($type ne "lib") {
  976. foreach my $prod (@{$unified_info{dirinfo}->{$dir}->{products}->{$type}}) {
  977. if (dirname($prod) eq $dir) {
  978. push @deps, $prod.$extinfo{$type};
  979. } else {
  980. push @actions, "\t@ : No support to produce $type ".join(", ", @{$unified_info{dirinfo}->{$dir}->{products}->{$type}});
  981. }
  982. }
  983. }
  984. }
  985. my $deps = join(" ", @deps);
  986. my $actions = join("\n", "", @actions);
  987. return <<"EOF";
  988. $args{dir} $args{dir}/: $deps$actions
  989. EOF
  990. }
  991. "" # Important! This becomes part of the template result.
  992. -}