windows-makefile.tmpl 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049
  1. ##
  2. ## Makefile for OpenSSL
  3. ##
  4. ## {- join("\n## ", @autowarntext) -}
  5. {-
  6. use File::Basename;
  7. use OpenSSL::Util;
  8. our $sover_dirname = platform->shlib_version_as_filename();
  9. my $build_scheme = $target{build_scheme};
  10. my $install_flavour = $build_scheme->[$#$build_scheme]; # last element
  11. my $win_installenv =
  12. $install_flavour eq "VC-WOW" ? "ProgramFiles(x86)"
  13. : "ProgramW6432";
  14. my $win_commonenv =
  15. $install_flavour eq "VC-WOW" ? "CommonProgramFiles(x86)"
  16. : "CommonProgramW6432";
  17. our $win_installroot =
  18. defined($ENV{$win_installenv}) ? $win_installenv : 'ProgramFiles';
  19. our $win_commonroot =
  20. defined($ENV{$win_commonenv}) ? $win_commonenv : 'CommonProgramFiles';
  21. # expand variables early
  22. $win_installroot = $ENV{$win_installroot};
  23. $win_commonroot = $ENV{$win_commonroot};
  24. # This makes sure things get built in the order they need
  25. # to. You're welcome.
  26. sub dependmagic {
  27. my $target = shift;
  28. return "$target: build_generated\n\t\$(MAKE) /\$(MAKEFLAGS) depend\n\t\$(MAKE) /\$(MAKEFLAGS) _$target\n_$target";
  29. }
  30. '';
  31. -}
  32. PLATFORM={- $config{target} -}
  33. SRCDIR={- $config{sourcedir} -}
  34. BLDDIR={- $config{builddir} -}
  35. FIPSKEY={- $config{FIPSKEY} -}
  36. VERSION={- "$config{full_version}" -}
  37. MAJOR={- $config{major} -}
  38. MINOR={- $config{minor} -}
  39. SHLIB_VERSION_NUMBER={- $config{shlib_version} -}
  40. LIBS={- join(" ", map { ( platform->sharedlib_import($_), platform->staticlib($_) ) } @{$unified_info{libraries}}) -}
  41. SHLIBS={- join(" ", map { platform->sharedlib($_) // () } @{$unified_info{libraries}}) -}
  42. SHLIBPDBS={- join(" ", map { platform->sharedlibpdb($_) // () } @{$unified_info{libraries}}) -}
  43. MODULES={- our @MODULES = map { platform->dso($_) }
  44. # Drop all modules that are dependencies, they will
  45. # be processed through their dependents
  46. grep { my $x = $_;
  47. !grep { grep { $_ eq $x } @$_ }
  48. values %{$unified_info{depends}} }
  49. @{$unified_info{modules}};
  50. join(" ", @MODULES) -}
  51. MODULEPDBS={- join(" ", map { platform->dsopdb($_) } @{$unified_info{modules}}) -}
  52. FIPSMODULE={- # We do some extra checking here, as there should be only one
  53. use File::Basename;
  54. our @fipsmodules =
  55. grep { !$unified_info{attributes}->{modules}->{$_}->{noinst}
  56. && $unified_info{attributes}->{modules}->{$_}->{fips} }
  57. @{$unified_info{modules}};
  58. die "More that one FIPS module" if scalar @fipsmodules > 1;
  59. join(" ", map { platform->dso($_) } @fipsmodules) -}
  60. FIPSMODULENAME={- die "More that one FIPS module" if scalar @fipsmodules > 1;
  61. join(", ", map { basename(platform->dso($_)) } @fipsmodules) -}
  62. PROGRAMS={- our @PROGRAMS = map { platform->bin($_) } @{$unified_info{programs}}; join(" ", @PROGRAMS) -}
  63. PROGRAMPDBS={- join(" ", map { $_.".pdb" } @{$unified_info{programs}}) -}
  64. SCRIPTS={- our @SCRIPTS = @{$unified_info{scripts}}; join(" ", @SCRIPTS) -}
  65. {- output_off() if $disabled{makedepend}; "" -}
  66. DEPS={- join(" ", map { platform->isobj($_) ? platform->dep($_) : () }
  67. grep { $unified_info{sources}->{$_}->[0] =~ /\.c$/ }
  68. keys %{$unified_info{sources}}); -}
  69. {- output_on() if $disabled{makedepend}; "" -}
  70. GENERATED_MANDATORY={- our @GENERATED_MANDATORY = @{$unified_info{depends}->{""}};
  71. join(" ", @GENERATED_MANDATORY) -}
  72. GENERATED={- # common0.tmpl provides @generated
  73. our @GENERATED = map { platform->convertext($_) } @generated;
  74. join(" ", @GENERATED) -}
  75. INSTALL_LIBS={-
  76. join(" ", map { quotify1(platform->sharedlib_import($_)
  77. // platform->staticlib($_)) }
  78. grep { !$unified_info{attributes}->{libraries}->{$_}->{noinst} }
  79. @{$unified_info{libraries}})
  80. -}
  81. INSTALL_SHLIBS={-
  82. join(" ", map { my $x = platform->sharedlib($_);
  83. $x ? quotify_l($x) : () }
  84. grep { !$unified_info{attributes}->{libraries}->{$_}->{noinst} }
  85. @{$unified_info{libraries}})
  86. -}
  87. INSTALL_SHLIBPDBS={-
  88. join(" ", map { my $x = platform->sharedlibpdb($_);
  89. $x ? quotify_l($x) : () }
  90. grep { !$unified_info{attributes}->{libraries}->{$_}->{noinst} }
  91. @{$unified_info{libraries}})
  92. -}
  93. INSTALL_ENGINES={-
  94. join(" ", map { quotify1(platform->dso($_)) }
  95. grep { !$unified_info{attributes}->{modules}->{$_}->{noinst}
  96. && $unified_info{attributes}->{modules}->{$_}->{engine} }
  97. @{$unified_info{modules}})
  98. -}
  99. INSTALL_ENGINEPDBS={-
  100. join(" ", map { quotify1(platform->dsopdb($_)) }
  101. grep { !$unified_info{attributes}->{modules}->{$_}->{noinst}
  102. && $unified_info{attributes}->{modules}->{$_}->{engine} }
  103. @{$unified_info{modules}})
  104. -}
  105. INSTALL_MODULES={-
  106. join(" ", map { quotify1(platform->dso($_)) }
  107. grep { !$unified_info{attributes}->{modules}->{$_}->{noinst}
  108. && !$unified_info{attributes}->{modules}->{$_}->{engine}
  109. && !$unified_info{attributes}->{modules}->{$_}->{fips} }
  110. @{$unified_info{modules}})
  111. -}
  112. INSTALL_MODULEPDBS={-
  113. join(" ", map { quotify1(platform->dsopdb($_)) }
  114. grep { !$unified_info{attributes}->{modules}->{$_}->{noinst}
  115. && !$unified_info{attributes}->{modules}->{$_}->{engine} }
  116. @{$unified_info{modules}})
  117. -}
  118. INSTALL_FIPSMODULE={-
  119. join(" ", map { quotify1(platform->dso($_)) }
  120. grep { !$unified_info{attributes}->{modules}->{$_}->{noinst}
  121. && $unified_info{attributes}->{modules}->{$_}->{fips} }
  122. @{$unified_info{modules}})
  123. -}
  124. INSTALL_FIPSMODULECONF=providers\fipsmodule.cnf
  125. INSTALL_PROGRAMS={-
  126. join(" ", map { quotify1(platform->bin($_)) }
  127. grep { !$unified_info{attributes}->{programs}->{$_}->{noinst} }
  128. @{$unified_info{programs}})
  129. -}
  130. INSTALL_PROGRAMPDBS={-
  131. join(" ", map { quotify1(platform->binpdb($_)) }
  132. grep { !$unified_info{attributes}->{programs}->{$_}->{noinst} }
  133. @{$unified_info{programs}})
  134. -}
  135. BIN_SCRIPTS={-
  136. join(" ", map { quotify1($_) }
  137. grep { !$unified_info{attributes}->{scripts}->{$_}->{noinst}
  138. && !$unified_info{attributes}->{scripts}->{$_}->{misc} }
  139. @{$unified_info{scripts}})
  140. -}
  141. MISC_SCRIPTS={-
  142. join(" ", map { quotify1($_) }
  143. grep { !$unified_info{attributes}->{scripts}->{$_}->{noinst}
  144. && $unified_info{attributes}->{scripts}->{$_}->{misc} }
  145. @{$unified_info{scripts}})
  146. -}
  147. IMAGEDOCS1={- our @IMAGEDOCS1 = @{$unified_info{imagedocs}->{man1}};
  148. join(" ", @IMAGEDOCS1) -}
  149. IMAGEDOCS3={- our @IMAGEDOCS3 = @{$unified_info{imagedocs}->{man3}};
  150. join(" ", @IMAGEDOCS3) -}
  151. IMAGEDOCS5={- our @IMAGEDOCS5 = @{$unified_info{imagedocs}->{man5}};
  152. join(" ", @IMAGEDOCS5) -}
  153. IMAGEDOCS7={- our @IMAGEDOCS7 = @{$unified_info{imagedocs}->{man7}};
  154. join(" ", @IMAGEDOCS7) -}
  155. HTMLDOCS1={- our @HTMLDOCS1 = @{$unified_info{htmldocs}->{man1}};
  156. join(" ", @HTMLDOCS1) -}
  157. HTMLDOCS3={- our @HTMLDOCS3 = @{$unified_info{htmldocs}->{man3}};
  158. join(" ", @HTMLDOCS3) -}
  159. HTMLDOCS5={- our @HTMLDOCS5 = @{$unified_info{htmldocs}->{man5}};
  160. join(" ", @HTMLDOCS5) -}
  161. HTMLDOCS7={- our @HTMLDOCS7 = @{$unified_info{htmldocs}->{man7}};
  162. join(" ", @HTMLDOCS7) -}
  163. HTMLDOCS1_BLDDIRS={- my %dirs = map { dirname($_) => 1 } @HTMLDOCS1;
  164. join(' ', sort keys %dirs) -}
  165. HTMLDOCS3_BLDDIRS={- my %dirs = map { dirname($_) => 1 } @HTMLDOCS3;
  166. join(' ', sort keys %dirs) -}
  167. HTMLDOCS5_BLDDIRS={- my %dirs = map { dirname($_) => 1 } @HTMLDOCS5;
  168. join(' ', sort keys %dirs) -}
  169. HTMLDOCS7_BLDDIRS={- my %dirs = map { dirname($_) => 1 } @HTMLDOCS7;
  170. join(' ', sort keys %dirs) -}
  171. APPS_OPENSSL="{- use File::Spec::Functions;
  172. catfile("apps","openssl") -}"
  173. # Do not edit these manually. Use Configure with --prefix or --openssldir
  174. # to change this! Short explanation in the top comment in Configure
  175. INSTALLTOP_dev={- # $prefix is used in the OPENSSLDIR perl snippet
  176. #
  177. use File::Spec::Functions qw(:DEFAULT splitpath);
  178. our $prefix = canonpath($config{prefix}
  179. || "$win_installroot\\OpenSSL");
  180. our ($prefix_dev, $prefix_dir, $prefix_file) =
  181. splitpath($prefix, 1);
  182. $prefix_dev -}
  183. INSTALLTOP_dir={- canonpath($prefix_dir) -}
  184. OPENSSLDIR_dev={- #
  185. # The logic here is that if no --openssldir was given,
  186. # OPENSSLDIR will get the value "$win_commonroot\\SSL".
  187. # If --openssldir was given and the value is an absolute
  188. # path, OPENSSLDIR will get its value without change.
  189. # If the value from --openssldir is a relative path,
  190. # OPENSSLDIR will get $prefix with the --openssldir
  191. # value appended as a subdirectory.
  192. #
  193. use File::Spec::Functions qw(:DEFAULT splitpath);
  194. our $openssldir =
  195. $config{openssldir} ?
  196. (file_name_is_absolute($config{openssldir}) ?
  197. canonpath($config{openssldir})
  198. : catdir($prefix, $config{openssldir}))
  199. : canonpath("$win_commonroot\\SSL");
  200. our ($openssldir_dev, $openssldir_dir, $openssldir_file) =
  201. splitpath($openssldir, 1);
  202. $openssldir_dev -}
  203. OPENSSLDIR_dir={- canonpath($openssldir_dir) -}
  204. LIBDIR={- our $libdir = $config{libdir} || "lib";
  205. file_name_is_absolute($libdir) ? "" : $libdir -}
  206. MODULESDIR_dev={- use File::Spec::Functions qw(:DEFAULT splitpath catpath);
  207. our $modulesprefix = catdir($prefix,$libdir);
  208. our ($modulesprefix_dev, $modulesprefix_dir,
  209. $modulesprefix_file) =
  210. splitpath($modulesprefix, 1);
  211. our $modulesdir_dev = $modulesprefix_dev;
  212. our $modulesdir_dir =
  213. catdir($modulesprefix_dir, "ossl-modules");
  214. our $modulesdir = catpath($modulesdir_dev, $modulesdir_dir);
  215. our $enginesdir_dev = $modulesprefix_dev;
  216. our $enginesdir_dir =
  217. catdir($modulesprefix_dir, "engines-$sover_dirname");
  218. our $enginesdir = catpath($enginesdir_dev, $enginesdir_dir);
  219. $modulesdir_dev -}
  220. MODULESDIR_dir={- canonpath($modulesdir_dir) -}
  221. ENGINESDIR_dev={- $enginesdir_dev -}
  222. ENGINESDIR_dir={- canonpath($enginesdir_dir) -}
  223. !IF "$(DESTDIR)" != ""
  224. INSTALLTOP=$(DESTDIR)$(INSTALLTOP_dir)
  225. OPENSSLDIR=$(DESTDIR)$(OPENSSLDIR_dir)
  226. ENGINESDIR=$(DESTDIR)$(ENGINESDIR_dir)
  227. MODULESDIR=$(DESTDIR)$(MODULESDIR_dir)
  228. !ELSE
  229. INSTALLTOP=$(INSTALLTOP_dev)$(INSTALLTOP_dir)
  230. OPENSSLDIR=$(OPENSSLDIR_dev)$(OPENSSLDIR_dir)
  231. ENGINESDIR=$(ENGINESDIR_dev)$(ENGINESDIR_dir)
  232. MODULESDIR=$(MODULESDIR_dev)$(MODULESDIR_dir)
  233. !ENDIF
  234. # $(libdir) is chosen to be compatible with the GNU coding standards
  235. libdir={- file_name_is_absolute($libdir)
  236. ? $libdir : '$(INSTALLTOP)\$(LIBDIR)' -}
  237. ##### User defined commands and flags ################################
  238. CC="{- $config{CC} -}"
  239. CPP={- $config{CPP} -}
  240. CPPFLAGS={- our $cppflags1 = join(" ",
  241. (map { "-D".$_} @{$config{CPPDEFINES}}),
  242. (map { " -I".$_} @{$config{CPPINCLUDES}}),
  243. @{$config{CPPFLAGS}}) -}
  244. CFLAGS={- join(' ', @{$config{CFLAGS}}) -}
  245. LD="{- $config{LD} -}"
  246. LDFLAGS={- join(' ', @{$config{LDFLAGS}}) -}
  247. EX_LIBS={- join(' ', @{$config{LDLIBS}}) -}
  248. PERL={- $config{PERL} -}
  249. AR="{- $config{AR} -}"
  250. ARFLAGS= {- join(' ', @{$config{ARFLAGS}}) -}
  251. MT="{- $config{MT} -}"
  252. MTFLAGS= {- join(' ', @{$config{MTFLAGS}}) -}
  253. AS="{- $config{AS} -}"
  254. ASFLAGS={- join(' ', @{$config{ASFLAGS}}) -}
  255. RC="{- $config{RC} -}"
  256. RCFLAGS={- join(' ', @{$config{RCFLAGS}}) -}
  257. ECHO="$(PERL)" "$(SRCDIR)\util\echo.pl"
  258. ##### Special command flags ##########################################
  259. COUTFLAG={- $target{coutflag} -}$(OSSL_EMPTY)
  260. LDOUTFLAG={- $target{ldoutflag} -}$(OSSL_EMPTY)
  261. AROUTFLAG={- $target{aroutflag} -}$(OSSL_EMPTY)
  262. MTINFLAG={- $target{mtinflag} -}$(OSSL_EMPTY)
  263. MTOUTFLAG={- $target{mtoutflag} -}$(OSSL_EMPTY)
  264. ASOUTFLAG={- $target{asoutflag} -}$(OSSL_EMPTY)
  265. RCOUTFLAG={- $target{rcoutflag} -}$(OSSL_EMPTY)
  266. ##### Project flags ##################################################
  267. # Variables starting with CNF_ are common variables for all product types
  268. CNF_ASFLAGS={- join(' ', $target{asflags} || (),
  269. @{$config{asflags}}) -}
  270. CNF_CPPFLAGS={- our $cppfags2 =
  271. join(' ', $target{cppflags} || (),
  272. (map { '-D'.quotify1($_) } @{$target{defines}},
  273. @{$config{defines}}),
  274. (map { '-I'.'"'.$_.'"' } @{$target{includes}},
  275. @{$config{includes}}),
  276. @{$config{cppflags}}) -}
  277. CNF_CFLAGS={- join(' ', $target{cflags} || (),
  278. @{$config{cflags}}) -}
  279. CNF_CXXFLAGS={- join(' ', $target{cxxflags} || (),
  280. @{$config{cxxflags}}) -}
  281. CNF_LDFLAGS={- join(' ', $target{lflags} || (),
  282. @{$config{lflags}}) -}
  283. CNF_EX_LIBS={- join(' ', $target{ex_libs} || (),
  284. @{$config{ex_libs}}) -}
  285. # Variables starting with LIB_ are used to build library object files
  286. # and shared libraries.
  287. # Variables starting with DSO_ are used to build DSOs and their object files.
  288. # Variables starting with BIN_ are used to build programs and their object
  289. # files.
  290. LIB_ASFLAGS={- join(' ', $target{lib_asflags} || (),
  291. @{$config{lib_asflags}},
  292. '$(CNF_ASFLAGS)', '$(ASFLAGS)') -}
  293. LIB_CPPFLAGS={- our $lib_cppflags =
  294. join(' ', $target{lib_cppflags} || (),
  295. $target{shared_cppflag} || (),
  296. (map { '-D'.quotify1($_) }
  297. @{$target{lib_defines}},
  298. @{$target{shared_defines}},
  299. @{$config{lib_defines}},
  300. @{$config{shared_defines}}),
  301. (map { '-I'.quotify1($_) }
  302. @{$target{lib_includes}},
  303. @{$target{shared_includes}},
  304. @{$config{lib_includes}},
  305. @{$config{shared_includes}}),
  306. @{$config{lib_cppflags}},
  307. @{$config{shared_cppflag}});
  308. join(' ', $lib_cppflags,
  309. (map { '-D'.quotify1($_) }
  310. "OPENSSLDIR=\"$openssldir\"",
  311. "ENGINESDIR=\"$enginesdir\"",
  312. "MODULESDIR=\"$modulesdir\""),
  313. '$(CNF_CPPFLAGS)', '$(CPPFLAGS)') -}
  314. LIB_CFLAGS={- join(' ', $target{lib_cflags} || (),
  315. $target{shared_cflag} || (),
  316. @{$config{lib_cflags}},
  317. @{$config{shared_cflag}},
  318. '$(CNF_CFLAGS)', '$(CFLAGS)') -}
  319. LIB_LDFLAGS={- join(' ', $target{shared_ldflag} || (),
  320. $config{shared_ldflag} || (),
  321. '$(CNF_LDFLAGS)', '$(LDFLAGS)') -}
  322. LIB_EX_LIBS=$(CNF_EX_LIBS) $(EX_LIBS)
  323. DSO_ASFLAGS={- join(' ', $target{dso_asflags} || (),
  324. $target{module_asflags} || (),
  325. @{$config{dso_asflags}},
  326. @{$config{module_asflags}},
  327. '$(CNF_ASFLAGS)', '$(ASFLAGS)') -}
  328. DSO_CPPFLAGS={- join(' ', $target{dso_cppflags} || (),
  329. $target{module_cppflag} || (),
  330. (map { '-D'.quotify1($_) }
  331. @{$target{dso_defines}},
  332. @{$target{module_defines}},
  333. @{$config{dso_defines}},
  334. @{$config{module_defines}}),
  335. (map { '-I'.quotify1($_) }
  336. @{$target{dso_includes}},
  337. @{$target{module_includes}},
  338. @{$config{dso_includes}},
  339. @{$config{module_includes}}),
  340. @{$config{dso_cppflags}},
  341. @{$config{module_cppflags}},
  342. '$(CNF_CPPFLAGS)', '$(CPPFLAGS)') -}
  343. DSO_CFLAGS={- join(' ', $target{dso_cflags} || (),
  344. $target{module_cflags} || (),
  345. @{$config{dso_cflags}},
  346. @{$config{module_cflags}},
  347. '$(CNF_CFLAGS)', '$(CFLAGS)') -}
  348. DSO_LDFLAGS={- join(' ', $target{dso_lflags} || (),
  349. $target{module_ldflags} || (),
  350. @{$config{dso_lflags}},
  351. @{$config{module_ldflags}},
  352. '$(CNF_LDFLAGS)', '$(LDFLAGS)') -}
  353. DSO_EX_LIBS=$(CNF_EX_LIBS) $(EX_LIBS)
  354. BIN_ASFLAGS={- join(' ', $target{bin_asflags} || (),
  355. @{$config{bin_asflags}},
  356. '$(CNF_ASFLAGS)', '$(ASFLAGS)') -}
  357. BIN_CPPFLAGS={- join(' ', $target{bin_cppflags} || (),
  358. (map { '-D'.$_ } @{$config{bin_defines} || ()}),
  359. @{$config{bin_cppflags}},
  360. '$(CNF_CPPFLAGS)', '$(CPPFLAGS)') -}
  361. BIN_CFLAGS={- join(' ', $target{bin_cflags} || (),
  362. @{$config{bin_cflags}},
  363. '$(CNF_CFLAGS)', '$(CFLAGS)') -}
  364. BIN_LDFLAGS={- join(' ', $target{bin_lflags} || (),
  365. @{$config{bin_lflags}},
  366. '$(CNF_LDFLAGS)', '$(LDFLAGS)') -}
  367. BIN_EX_LIBS=$(CNF_EX_LIBS) $(EX_LIBS)
  368. # CPPFLAGS_Q is used for one thing only: to build up buildinf.h
  369. CPPFLAGS_Q={- $cppflags1 =~ s|([\\"])|\\$1|g;
  370. $cppflags2 =~ s|([\\"])|\\$1|g;
  371. join(' ', $lib_cppflags || (), $cppflags2 || (),
  372. $cppflags1 || ()) -}
  373. PERLASM_SCHEME= {- $target{perlasm_scheme} -}
  374. PROCESSOR= {- $config{processor} -}
  375. # The main targets ###################################################
  376. {- dependmagic('build_sw'); -}: build_libs_nodep build_modules_nodep build_programs_nodep copy-utils
  377. {- dependmagic('build_libs'); -}: build_libs_nodep
  378. {- dependmagic('build_modules'); -}: build_modules_nodep
  379. {- dependmagic('build_programs'); -}: build_programs_nodep
  380. build_docs: build_html_docs
  381. build_html_docs: $(HTMLDOCS1) $(HTMLDOCS3) $(HTMLDOCS5) $(HTMLDOCS7)
  382. @
  383. build_generated: $(GENERATED_MANDATORY)
  384. @
  385. build_libs_nodep: $(LIBS) {- join(" ",map { platform->sharedlib_import($_) // () } @{$unified_info{libraries}}) -}
  386. @
  387. build_modules_nodep: $(MODULES)
  388. @
  389. build_programs_nodep: $(PROGRAMS) $(SCRIPTS)
  390. @
  391. # Kept around for backward compatibility
  392. build_apps build_tests: build_programs
  393. # Convenience target to prebuild all generated files, not just the mandatory
  394. # ones
  395. build_all_generated: $(GENERATED_MANDATORY) $(GENERATED) build_docs
  396. @{- output_off() if $disabled{makedepend}; "" -}
  397. @$(ECHO) "Warning: consider configuring with no-makedepend, because if"
  398. @$(ECHO) " target system doesn't have $(PERL),"
  399. @$(ECHO) " then make will fail..."
  400. @{- output_on() if $disabled{makedepend}; "" -}
  401. all: build_sw build_docs
  402. test: tests
  403. {- dependmagic('tests'); -}: build_programs_nodep build_modules_nodep copy-utils
  404. @{- output_off() if $disabled{tests}; "" -}
  405. cmd /C "set "SRCTOP=$(SRCDIR)" & set "BLDTOP=$(BLDDIR)" & set "PERL=$(PERL)" & set "FIPSKEY=$(FIPSKEY)" & "$(PERL)" "$(SRCDIR)\test\run_tests.pl" $(TESTS)"
  406. @{- if ($disabled{tests}) { output_on(); } else { output_off(); } "" -}
  407. @$(ECHO) "Tests are not supported with your chosen Configure options"
  408. @{- output_on() if !$disabled{tests}; "" -}
  409. list-tests:
  410. @{- output_off() if $disabled{tests}; "" -}
  411. @cmd /C "set "SRCTOP=$(SRCDIR)" & "$(PERL)" "$(SRCDIR)\test\run_tests.pl" list"
  412. @{- if ($disabled{tests}) { output_on(); } else { output_off(); } "" -}
  413. @$(ECHO) "Tests are not supported with your chosen Configure options"
  414. @{- output_on() if !$disabled{tests}; "" -}
  415. install: install_sw install_ssldirs install_docs
  416. uninstall: uninstall_docs uninstall_sw
  417. libclean:
  418. "$(PERL)" -e "map { m/(.*)\.dll$$/; unlink glob """{.,apps,test,fuzz}/$$1.*"""; } @ARGV" $(SHLIBS)
  419. -del /Q /F $(LIBS) libcrypto.* libssl.* ossl_static.pdb
  420. clean: libclean
  421. -rd /Q /S $(HTMLDOCS1_BLDDIRS)
  422. -rd /Q /S $(HTMLDOCS3_BLDDIRS)
  423. -rd /Q /S $(HTMLDOCS5_BLDDIRS)
  424. -rd /Q /S $(HTMLDOCS7_BLDDIRS)
  425. {- join("\n\t", map { "-del /Q /F $_" } @PROGRAMS) -}
  426. {- join("\n\t", map { "-del /Q /F $_" } @MODULES) -}
  427. {- join("\n\t", map { "-del /Q /F $_" } @SCRIPTS) -}
  428. {- join("\n\t", map { "-del /Q /F $_" } @GENERATED_MANDATORY) -}
  429. {- join("\n\t", map { "-del /Q /F $_" } @GENERATED) -}
  430. -del /Q /S /F *.d *.obj *.pdb *.ilk *.manifest
  431. -del /Q /S /F engines\*.lib engines\*.exp
  432. -del /Q /S /F apps\*.lib apps\*.rc apps\*.res apps\*.exp
  433. -del /Q /S /F test\*.exp
  434. -rd /Q /S test\test-runs
  435. distclean: clean
  436. -del /Q /F configdata.pm
  437. -del /Q /F makefile
  438. depend:
  439. @ {- output_off() if $disabled{makedepend}; "" -}
  440. @ "$(PERL)" "$(SRCDIR)\util\add-depends.pl" "{- $target{makedep_scheme} -}"
  441. @ {- output_on() if $disabled{makedepend}; "" -}
  442. # Install helper targets #############################################
  443. install_sw: install_dev install_engines install_modules install_runtime
  444. uninstall_sw: uninstall_runtime uninstall_modules uninstall_engines uninstall_dev
  445. install_docs: install_html_docs
  446. uninstall_docs: uninstall_html_docs
  447. {- output_off() if $disabled{fips}; "" -}
  448. install_fips: build_sw providers\fipsmodule.cnf
  449. # @[ -n "$(INSTALLTOP)" ] || (echo INSTALLTOP should not be empty; exit 1)
  450. @$(PERL) $(SRCDIR)\util\mkdir-p.pl $(MODULESDIR)
  451. @$(ECHO) "*** Installing FIPS module"
  452. @$(ECHO) "install $(INSTALL_FIPSMODULE) -> $(MODULESDIR)\$(FIPSMODULENAME)"
  453. @copy "$(INSTALL_FIPSMODULE)" $(MODULESDIR)\$(FIPSMODULENAME).new
  454. @move /Y $(MODULESDIR)\$(FIPSMODULENAME).new \
  455. $(MODULESDIR)\$(FIPSMODULENAME)
  456. @$(ECHO) "*** Installing FIPS module configuration"
  457. @$(ECHO) "install $(INSTALL_FIPSMODULECONF) -> $(OPENSSLDIR)\fipsmodule.cnf"
  458. @copy $(INSTALL_FIPSMODULECONF) "$(OPENSSLDIR)\fipsmodule.cnf"
  459. uninstall_fips:
  460. @$(ECHO) "*** Uninstalling FIPS module configuration"
  461. $(RM) "$(OPENSSLDIR)\fipsmodule.cnf"
  462. @$(ECHO) "*** Uninstalling FIPS module"
  463. $(RM) "$(MODULESDIR)\$(FIPSMODULENAME)"
  464. {- if ($disabled{fips}) { output_on(); } else { output_off(); } "" -}
  465. install_fips:
  466. @$(ECHO) "The 'install_fips' target requires the 'enable-fips' option"
  467. uninstall_fips:
  468. @$(ECHO) "The 'uninstall_fips' target requires the 'enable-fips' option"
  469. {- output_on() if !$disabled{fips}; "" -}
  470. install_ssldirs:
  471. @"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(OPENSSLDIR)\certs"
  472. @"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(OPENSSLDIR)\private"
  473. @"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(OPENSSLDIR)\misc"
  474. @"$(PERL)" "$(SRCDIR)\util\copy.pl" "$(SRCDIR)\apps\openssl.cnf" \
  475. "$(OPENSSLDIR)\openssl.cnf.dist"
  476. @IF NOT EXIST "$(OPENSSLDIR)\openssl.cnf" \
  477. "$(PERL)" "$(SRCDIR)\util\copy.pl" "$(SRCDIR)\apps\openssl.cnf" \
  478. "$(OPENSSLDIR)\openssl.cnf"
  479. @if not "$(MISC_SCRIPTS)"=="" \
  480. "$(PERL)" "$(SRCDIR)\util\copy.pl" $(MISC_SCRIPTS) \
  481. "$(OPENSSLDIR)\misc"
  482. @"$(PERL)" "$(SRCDIR)\util\copy.pl" "$(SRCDIR)\apps\ct_log_list.cnf" \
  483. "$(OPENSSLDIR)\ct_log_list.cnf.dist"
  484. @IF NOT EXIST "$(OPENSSLDIR)\ct_log_list.cnf" \
  485. "$(PERL)" "$(SRCDIR)\util\copy.pl" "$(SRCDIR)\apps\ct_log_list.cnf" \
  486. "$(OPENSSLDIR)\ct_log_list.cnf"
  487. install_dev: install_runtime_libs
  488. @if "$(INSTALLTOP)"=="" ( $(ECHO) "INSTALLTOP should not be empty" & exit 1 )
  489. @$(ECHO) "*** Installing development files"
  490. @"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(INSTALLTOP)\include\openssl"
  491. @{- output_off() unless grep { $_ eq "OPENSSL_USE_APPLINK" } (@{$target{defines}}, @{$config{defines}}); "" -}
  492. @"$(PERL)" "$(SRCDIR)\util\copy.pl" "$(SRCDIR)\ms\applink.c" \
  493. "$(INSTALLTOP)\include\openssl"
  494. @{- output_on() unless grep { $_ eq "OPENSSL_USE_APPLINK" } (@{$target{defines}}, @{$config{defines}}); "" -}
  495. @"$(PERL)" "$(SRCDIR)\util\copy.pl" "-exclude_re=/__DECC_" \
  496. "$(SRCDIR)\include\openssl\*.h" \
  497. "$(INSTALLTOP)\include\openssl"
  498. @"$(PERL)" "$(SRCDIR)\util\copy.pl" "$(BLDDIR)\include\openssl\*.h" \
  499. "$(INSTALLTOP)\include\openssl"
  500. @"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(libdir)"
  501. @"$(PERL)" "$(SRCDIR)\util\copy.pl" $(INSTALL_LIBS) "$(libdir)"
  502. @if "$(SHLIBS)"=="" \
  503. "$(PERL)" "$(SRCDIR)\util\copy.pl" ossl_static.pdb "$(libdir)"
  504. uninstall_dev:
  505. _install_modules_deps: install_runtime_libs build_modules
  506. install_engines: _install_modules_deps
  507. @if "$(INSTALLTOP)"=="" ( $(ECHO) "INSTALLTOP should not be empty" & exit 1 )
  508. @$(ECHO) "*** Installing engines"
  509. @"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(ENGINESDIR)"
  510. @if not "$(INSTALL_ENGINES)"=="" \
  511. "$(PERL)" "$(SRCDIR)\util\copy.pl" $(INSTALL_ENGINES) "$(ENGINESDIR)"
  512. @if not "$(INSTALL_ENGINES)"=="" \
  513. "$(PERL)" "$(SRCDIR)\util\copy.pl" $(INSTALL_ENGINEPDBS) "$(ENGINESDIR)"
  514. uninstall_engines:
  515. install_modules: _install_modules_deps
  516. @if "$(INSTALLTOP)"=="" ( $(ECHO) "INSTALLTOP should not be empty" & exit 1 )
  517. @$(ECHO) "*** Installing modules"
  518. @"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(MODULESDIR)"
  519. @if not "$(INSTALL_MODULES)"=="" \
  520. "$(PERL)" "$(SRCDIR)\util\copy.pl" $(INSTALL_MODULES) "$(MODULESDIR)"
  521. @if not "$(INSTALL_MODULES)"=="" \
  522. "$(PERL)" "$(SRCDIR)\util\copy.pl" $(INSTALL_MODULEPDBS) "$(MODULESDIR)"
  523. uninstall_modules:
  524. install_runtime: install_programs
  525. install_runtime_libs: build_libs
  526. @if "$(INSTALLTOP)"=="" ( $(ECHO) "INSTALLTOP should not be empty" & exit 1 )
  527. @$(ECHO) "*** Installing runtime libraries"
  528. @"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(INSTALLTOP)\bin"
  529. @if not "$(SHLIBS)"=="" \
  530. "$(PERL)" "$(SRCDIR)\util\copy.pl" $(INSTALL_SHLIBS) "$(INSTALLTOP)\bin"
  531. @if not "$(SHLIBS)"=="" \
  532. "$(PERL)" "$(SRCDIR)\util\copy.pl" $(INSTALL_SHLIBPDBS) \
  533. "$(INSTALLTOP)\bin"
  534. install_programs: install_runtime_libs build_programs
  535. @if "$(INSTALLTOP)"=="" ( $(ECHO) "INSTALLTOP should not be empty" & exit 1 )
  536. @$(ECHO) "*** Installing runtime programs"
  537. @if not "$(INSTALL_PROGRAMS)"=="" \
  538. "$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(INSTALLTOP)\bin"
  539. @if not "$(INSTALL_PROGRAMS)"=="" \
  540. "$(PERL)" "$(SRCDIR)\util\copy.pl" $(INSTALL_PROGRAMS) \
  541. "$(INSTALLTOP)\bin"
  542. @if not "$(INSTALL_PROGRAMS)"=="" \
  543. "$(PERL)" "$(SRCDIR)\util\copy.pl" $(INSTALL_PROGRAMPDBS) \
  544. "$(INSTALLTOP)\bin"
  545. @if not "$(INSTALL_PROGRAMS)"=="" \
  546. "$(PERL)" "$(SRCDIR)\util\copy.pl" $(BIN_SCRIPTS) \
  547. "$(INSTALLTOP)\bin"
  548. uninstall_runtime:
  549. install_html_docs: install_image_docs build_html_docs
  550. @if "$(INSTALLTOP)"=="" ( echo INSTALLTOP should not be empty & exit 1 )
  551. @echo *** Installing HTML docs
  552. @"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(INSTALLTOP)\html\man1"
  553. @"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(INSTALLTOP)\html\man3"
  554. @"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(INSTALLTOP)\html\man5"
  555. @"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(INSTALLTOP)\html\man7"
  556. @"$(PERL)" "$(SRCDIR)\util\copy.pl" $(BLDDIR)\doc\html\man1\*.html \
  557. "$(INSTALLTOP)\html\man1"
  558. @"$(PERL)" "$(SRCDIR)\util\copy.pl" $(BLDDIR)\doc\html\man3\*.html \
  559. "$(INSTALLTOP)\html\man3"
  560. @"$(PERL)" "$(SRCDIR)\util\copy.pl" $(BLDDIR)\doc\html\man5\*.html \
  561. "$(INSTALLTOP)\html\man5"
  562. @"$(PERL)" "$(SRCDIR)\util\copy.pl" $(BLDDIR)\doc\html\man7\*.html \
  563. "$(INSTALLTOP)\html\man7"
  564. uninstall_html_docs: uninstall_image_docs
  565. install_image_docs:
  566. @if "$(INSTALLTOP)"=="" ( echo INSTALLTOP should not be empty & exit 1 )
  567. @echo *** Installing HTML images
  568. @"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(INSTALLTOP)\html\man7\img"
  569. @"$(PERL)" "$(SRCDIR)\util\copy.pl" $(SRCDIR)\doc\man7\img\*.png \
  570. "$(INSTALLTOP)\html\man7\img"
  571. uninstall_image_docs:
  572. # Helper targets #####################################################
  573. copy-utils: $(BLDDIR)\util\wrap.pl $(BLDDIR)\apps\openssl.cnf
  574. $(BLDDIR)\util\wrap.pl: configdata.pm
  575. @if NOT EXIST "$(BLDDIR)\util" mkdir "$(BLDDIR)\util"
  576. @if NOT "$(SRCDIR)"=="$(BLDDIR)" copy "$(SRCDIR)\util\$(@F)" "$(BLDDIR)\util"
  577. $(BLDDIR)\apps\openssl.cnf: configdata.pm
  578. @if NOT EXIST "$(BLDDIR)\apps" mkdir "$(BLDDIR)\apps"
  579. @if NOT "$(SRCDIR)"=="$(BLDDIR)" copy "$(SRCDIR)\apps\$(@F)" "$(BLDDIR)\apps"
  580. # Building targets ###################################################
  581. configdata.pm: "$(SRCDIR)\Configure" {- join(" ", map { '"'.$_.'"' } @{$config{build_file_templates}}, @{$config{build_infos}}, @{$config{conf_files}}) -}
  582. @$(ECHO) "Detected changed: $?"
  583. "$(PERL)" configdata.pm -r
  584. @$(ECHO) "**************************************************"
  585. @$(ECHO) "*** ***"
  586. @$(ECHO) "*** Please run the same make command again ***"
  587. @$(ECHO) "*** ***"
  588. @$(ECHO) "**************************************************"
  589. @exit 1
  590. reconfigure reconf:
  591. "$(PERL)" configdata.pm -r
  592. {-
  593. use File::Basename;
  594. use File::Spec::Functions qw/:DEFAULT abs2rel rel2abs file_name_is_absolute/;
  595. # Helper function to convert dependencies in platform agnostic form to
  596. # dependencies in platform form.
  597. sub compute_platform_depends {
  598. map { my $x = $_;
  599. grep { $x eq $_ } @{$unified_info{programs}} and platform->bin($x)
  600. or grep { $x eq $_ } @{$unified_info{modules}} and platform->dso($x)
  601. or grep { $x eq $_ } @{$unified_info{libraries}} and platform->lib($x)
  602. or platform->convertext($x); } @_;
  603. }
  604. # Helper function to figure out dependencies on libraries
  605. # It takes a list of library names and outputs a list of dependencies
  606. sub compute_lib_depends {
  607. if ($disabled{shared}) {
  608. return map { platform->staticlib($_) } @_;
  609. }
  610. return map { platform->sharedlib_import($_) // platform->staticlib($_) } @_;
  611. }
  612. sub generatetarget {
  613. my %args = @_;
  614. my $deps = join(" ", compute_platform_depends(@{$args{deps}}));
  615. return <<"EOF";
  616. $args{target}: $deps
  617. EOF
  618. }
  619. # This function (and the next) avoids quoting paths of generated dependencies
  620. # (in the build tree), but quotes paths of non-generated dependencies (in the
  621. # source tree). This is a workaround for a limitation of C++Builder's make.exe
  622. # in handling quoted paths: https://quality.embarcadero.com/browse/RSP-31756
  623. sub generatesrc {
  624. my %args = @_;
  625. my $gen0 = $args{generator}->[0];
  626. my $gen_args = join('', map { " $_" }
  627. @{$args{generator}}[1..$#{$args{generator}}]);
  628. my $gen_incs = join("", map { " -I\"$_\"" } @{$args{generator_incs}});
  629. my $incs = join("", map { " -I\"$_\"" } @{$args{incs}});
  630. my $defs = join("", map { " -D".$_ } @{$args{defs}});
  631. my $deps = join(' ',
  632. map { file_name_is_absolute($_) || ($_ =~ m|^../|) ? "\"$_\"" : $_ }
  633. compute_platform_depends(@{$args{generator_deps}},
  634. @{$args{deps}}));
  635. if ($args{src} =~ /\.html$/) {
  636. #
  637. # HTML generator
  638. #
  639. my $title = basename($args{src}, ".html");
  640. my $pod = $gen0;
  641. return <<"EOF";
  642. $args{src}: "$pod"
  643. "\$(PERL)" "\$(SRCDIR)/util/mkpod2html.pl" -i "$pod" -o \$\@ -t "$title" -r "\$(SRCDIR)/doc"
  644. EOF
  645. } elsif (platform->isdef($args{src})) {
  646. #
  647. # Linker script-ish generator
  648. #
  649. my $target = platform->def($args{src});
  650. my $mkdef = abs2rel(rel2abs(catfile($config{sourcedir},
  651. "util", "mkdef.pl")),
  652. rel2abs($config{builddir}));
  653. my $ord_ver = $args{intent} eq 'lib' ? ' --version $(VERSION)' : '';
  654. my $ord_name =
  655. $args{generator}->[1] || platform->dsoname($args{product});
  656. return <<"EOF";
  657. $target: $gen0 $deps $mkdef
  658. "\$(PERL)" $mkdef$ord_ver --ordinals $gen0 --name $ord_name --OS windows > $target
  659. EOF
  660. } elsif (platform->isasm($args{src})) {
  661. #
  662. # Assembler generator
  663. #
  664. my $cppflags = {
  665. shlib => '$(LIB_CFLAGS) $(LIB_CPPFLAGS)',
  666. lib => '$(LIB_CFLAGS) $(LIB_CPPFLAGS)',
  667. dso => '$(DSO_CFLAGS) $(DSO_CPPFLAGS)',
  668. bin => '$(BIN_CFLAGS) $(BIN_CPPFLAGS)'
  669. } -> {$args{intent}};
  670. my $target = platform->asm($args{src});
  671. my $generator;
  672. if ($gen0 =~ /\.pl$/) {
  673. $generator = '"$(PERL)"'.$gen_incs.' '.$gen0.$gen_args
  674. .' "$(PERLASM_SCHEME)"'.$incs.' '.$cppflags.$defs.' $(PROCESSSOR)';
  675. } elsif ($gen0 =~ /\.S$/) {
  676. $generator = undef;
  677. } else {
  678. die "Generator type for $src unknown: $gen0\n";
  679. }
  680. if (defined($generator)) {
  681. # If the target is named foo.S in build.info, we want to
  682. # end up generating foo.s in two steps.
  683. if ($args{src} =~ /\.S$/) {
  684. return <<"EOF";
  685. $target: "$gen0" $deps
  686. cmd /C "set "ASM=\$(AS)" & $generator \$@.S"
  687. \$(CPP) $incs $cppflags $defs \$@.S > \$@.i
  688. move /Y \$@.i \$@
  689. del /Q \$@.S
  690. EOF
  691. }
  692. # Otherwise....
  693. return <<"EOF";
  694. $target: "$gen0" $deps
  695. cmd /C "set "ASM=\$(AS)" & $generator \$@"
  696. EOF
  697. }
  698. return <<"EOF";
  699. $target: "$gen0" $deps
  700. \$(CPP) $incs $cppflags $defs "$gen0" > \$@.i
  701. move /Y \$@.i \$@
  702. EOF
  703. } elsif ($gen0 =~ m|^.*\.in$|) {
  704. #
  705. # "dofile" generator (file.in -> file)
  706. #
  707. my $dofile = abs2rel(rel2abs(catfile($config{sourcedir},
  708. "util", "dofile.pl")),
  709. rel2abs($config{builddir}));
  710. my @perlmodules = ( 'configdata.pm',
  711. grep { $_ =~ m|\.pm$| } @{$args{deps}} );
  712. my %perlmoduleincs = map { '"-I'.dirname($_).'"' => 1 } @perlmodules;
  713. $deps = join(' ', $deps, compute_platform_depends(@perlmodules));
  714. @perlmodules = map { "-M".basename($_, '.pm') } @perlmodules;
  715. my $perlmodules = join(' ', '', sort keys %perlmoduleincs, @perlmodules);
  716. return <<"EOF";
  717. $args{src}: "$gen0" $deps
  718. "\$(PERL)"$perlmodules "$dofile" "-o$target{build_file}" "$gen0"$gen_args > \$@
  719. EOF
  720. } elsif (grep { $_ eq $gen0 } @{$unified_info{programs}}) {
  721. #
  722. # Generic generator using OpenSSL programs
  723. #
  724. # Redo $gen0, to ensure that we have the proper extension.
  725. $gen0 = platform->bin($gen0);
  726. return <<"EOF";
  727. $args{src}: $gen0 $deps "\$(BLDDIR)\\util\\wrap.pl"
  728. "\$(PERL)" "\$(BLDDIR)\\util\\wrap.pl" $gen0$gen_args > \$@
  729. EOF
  730. } else {
  731. #
  732. # Generic generator using Perl
  733. #
  734. return <<"EOF";
  735. $args{src}: "$gen0" $deps
  736. "\$(PERL)"$gen_incs $gen0$gen_args > \$@
  737. EOF
  738. }
  739. }
  740. sub src2obj {
  741. my $asmext = platform->asmext();
  742. my %args = @_;
  743. my @srcs =
  744. map { my $x = $_;
  745. (platform->isasm($x) && grep { $x eq $_ } @generated)
  746. ? platform->asm($x) : $x }
  747. ( @{$args{srcs}} );
  748. my $srcs = '"'.join('" "', @srcs).'"';
  749. my $deps = join(' ',
  750. map { file_name_is_absolute($_) || ($_ =~ m|^../|) ? "\"$_\"" : $_ }
  751. (@srcs, @{$args{deps}}));
  752. my $incs = join("", map { ' -I"'.$_.'"' } @{$args{incs}});
  753. my $defs = join("", map { " -D".$_ } @{$args{defs}});
  754. my $cflags = { shlib => ' $(LIB_CFLAGS)',
  755. lib => ' $(LIB_CFLAGS)',
  756. dso => ' $(DSO_CFLAGS)',
  757. bin => ' $(BIN_CFLAGS)' } -> {$args{intent}};
  758. $cflags .= $incs;
  759. $cflags .= { shlib => ' $(LIB_CPPFLAGS)',
  760. lib => ' $(LIB_CPPFLAGS)',
  761. dso => ' $(DSO_CPPFLAGS)',
  762. bin => ' $(BIN_CPPFLAGS)' } -> {$args{intent}};
  763. my $asflags = { shlib => ' $(LIB_ASFLAGS)',
  764. lib => ' $(LIB_ASFLAGS)',
  765. dso => ' $(DSO_ASFLAGS)',
  766. bin => ' $(BIN_ASFLAGS)' } -> {$args{intent}};
  767. my $makedepcmd = $config{makedepcmd} unless $disabled{makedepend};
  768. if ($srcs[0] =~ /\.rc$/) {
  769. my $res = platform->res($args{obj});
  770. return <<"EOF";
  771. $res: $deps
  772. \$(RC) \$(RCFLAGS) \$(RCOUTFLAG)\$\@ $srcs
  773. EOF
  774. }
  775. my $obj = platform->obj($args{obj});
  776. my $dep = platform->dep($args{obj});
  777. if ($srcs[0] =~ /\Q${asmext}\E$/) {
  778. return <<"EOF";
  779. $obj: $deps
  780. \$(AS) $asflags \$(ASOUTFLAG)\$\@ $srcs
  781. EOF
  782. } elsif ($srcs[0] =~ /.S$/) {
  783. return <<"EOF";
  784. $obj: $deps
  785. \$(CC) /EP -D__ASSEMBLER__ $cflags $defs $srcs > \$@.asm
  786. \$(AS) $asflags \$(ASOUTFLAG)\$\@ \$@.asm
  787. EOF
  788. }
  789. my $recipe = <<"EOF";
  790. $obj: $deps
  791. \$(CC) $cflags $defs -c \$(COUTFLAG)\$\@ $srcs
  792. EOF
  793. $recipe .= <<"EOF" unless $disabled{makedepend};
  794. cmd /C "$makedepcmd $cflags $defs $srcs > $dep 2>&1"
  795. EOF
  796. return $recipe;
  797. }
  798. # We *know* this routine is only called when we've configure 'shared'.
  799. # Also, note that even though the import library built here looks like
  800. # a static library, it really isn't.
  801. sub obj2shlib {
  802. my %args = @_;
  803. my $lib = $args{lib};
  804. my @objs = map { platform->convertext($_) }
  805. grep { platform->isobj($_) }
  806. @{$args{objs}};
  807. my @ress = map { platform->convertext($_) }
  808. grep { platform->isres($_) }
  809. @{$args{objs}};
  810. my @defs = map { platform->def($_) }
  811. grep { platform->isdef($_) }
  812. @{$args{objs}};
  813. my @deps = compute_lib_depends(@{$args{deps}});
  814. die "More than one exported symbols list" if scalar @defs > 1;
  815. my $linklibs = join("", map { "$_$target{ld_resp_delim}" } @deps);
  816. my $objs = join($target{ld_resp_delim}, @objs);
  817. my $ress = join($target{ld_resp_delim}, @ress);
  818. my $deps = join(" ", @objs, @ress, @defs, @deps);
  819. my $import = platform->sharedlib_import($lib);
  820. my $dll = platform->sharedlib($lib);
  821. my $shared_def = $target{lddefflag} . join("", @defs);
  822. my $implib_rule = $target{ld_implib_rule} || "";
  823. my $implib_flag = $target{ld_implib_flag}
  824. ? "$target{ld_implib_flag}$import"
  825. : "";
  826. return <<"EOF"
  827. # The import library may look like a static library, but it is not.
  828. # We MUST make the import library depend on the DLL, in case someone
  829. # mistakenly removes the latter.
  830. $import: $dll
  831. $implib_rule
  832. $dll: $deps
  833. IF EXIST $full.manifest DEL /F /Q $full.manifest
  834. IF EXIST \$@ DEL /F /Q \$@
  835. cmd /C "\$(LD) \$(LDFLAGS) \$(LIB_LDFLAGS) @<< $implib_flag || (DEL /Q \$(\@B).* $import & EXIT 1)"
  836. $objs$target{ld_resp_delim}\$(LDOUTFLAG)$dll$target{ldpostoutflag}$target{ld_resp_delim}$linklibs\$(LIB_EX_LIBS)$target{ld_resp_delim}$shared_def$target{ldresflag}$ress
  837. <<
  838. IF EXIST $dll.manifest \\
  839. \$(MT) \$(MTFLAGS) \$(MTINFLAG)$dll.manifest \$(MTOUTFLAG)$dll
  840. IF EXIST apps\\$dll DEL /Q /F apps\\$dll
  841. IF EXIST test\\$dll DEL /Q /F test\\$dll
  842. IF EXIST fuzz\\$dll DEL /Q /F fuzz\\$dll
  843. COPY $dll apps
  844. COPY $dll test
  845. COPY $dll fuzz
  846. EOF
  847. }
  848. sub obj2dso {
  849. my %args = @_;
  850. my $dso = platform->dso($args{module});
  851. my $dso_n = platform->dsoname($args{module});
  852. my @objs = map { platform->convertext($_) }
  853. grep { platform->isobj($_) }
  854. @{$args{objs}};
  855. my @ress = map { platform->convertext($_) }
  856. grep { platform->isres($_) }
  857. @{$args{objs}};
  858. my @defs = map { platform->def($_) }
  859. grep { platform->isdef($_) }
  860. @{$args{objs}};
  861. my @deps = compute_lib_depends(@{$args{deps}});
  862. die "More than one exported symbols list" if scalar @defs > 1;
  863. my $objs = join($target{ld_resp_delim}, @objs);
  864. my $ress = join($target{ld_resp_delim}, @ress);
  865. my $linklibs = join("", map { "$_$target{ld_resp_delim}" } @deps);
  866. my $deps = join(" ", @objs, @ress, @defs, @deps);
  867. my $shared_def = $target{lddefflag} . join("", @defs);
  868. return <<"EOF";
  869. $dso: $deps
  870. IF EXIST $dso.manifest DEL /F /Q $dso.manifest
  871. cmd /C "\$(LD) \$(LDFLAGS) \$(DSO_LDFLAGS) @<< || (DEL /Q \$(\@B).* $dso_n.* & EXIT 1)"
  872. $objs$target{ld_resp_delim}\$(LDOUTFLAG)$dso$target{ldpostoutflag}$target{ld_resp_delim}$linklibs \$(DSO_EX_LIBS)$target{ld_resp_delim}$shared_def$target{ldresflag}$ress
  873. <<
  874. IF EXIST $dso.manifest \\
  875. \$(MT) \$(MTFLAGS) \$(MTINFLAG)$dso.manifest \$(MTOUTFLAG)$dso
  876. EOF
  877. }
  878. sub obj2lib {
  879. my %args = @_;
  880. my $lib = platform->staticlib($args{lib});
  881. my @objs = map { platform->obj($_) } @{$args{objs}};
  882. my $objs = join($target{ar_resp_delim}, @objs);
  883. my $deps = join(" ", @objs);
  884. return <<"EOF";
  885. $lib: $deps
  886. \$(AR) \$(ARFLAGS) \$(AROUTFLAG)$lib @<<
  887. $objs
  888. <<
  889. EOF
  890. }
  891. sub obj2bin {
  892. my %args = @_;
  893. my $bin = platform->bin($args{bin});
  894. my @objs = map { platform->convertext($_) }
  895. grep { platform->isobj($_) }
  896. @{$args{objs}};
  897. my @ress = map { platform->convertext($_) }
  898. grep { platform->isres($_) }
  899. @{$args{objs}};
  900. my @deps = compute_lib_depends(@{$args{deps}});
  901. my $objs = join($target{ld_resp_delim}, @objs);
  902. my $linklibs = join("", map { "$_$target{ld_resp_delim}" } @deps);
  903. my $deps = join(" ", @objs, @ress, @deps);
  904. return <<"EOF";
  905. $bin: $deps
  906. IF EXIST $bin.manifest DEL /F /Q $bin.manifest
  907. \$(LD) \$(LDFLAGS) \$(BIN_LDFLAGS) @<<
  908. $objs$target{ld_resp_delim}\$(LDOUTFLAG)$bin$target{ldpostoutflag}$target{ld_resp_delim}$linklibs\$(BIN_EX_LIBS)$target{ldresflag}$target{ldresflag}$ress
  909. <<
  910. IF EXIST $bin.manifest \\
  911. \$(MT) \$(MTFLAGS) \$(MTINFLAG)$bin.manifest \$(MTOUTFLAG)$bin
  912. EOF
  913. }
  914. sub in2script {
  915. my %args = @_;
  916. my $script = $args{script};
  917. my $sources = '"'.join('" "', @{$args{sources}}).'"';
  918. my $dofile = abs2rel(rel2abs(catfile($config{sourcedir},
  919. "util", "dofile.pl")),
  920. rel2abs($config{builddir}));
  921. return <<"EOF";
  922. $script: $sources
  923. "\$(PERL)" "-I\$(BLDDIR)" -Mconfigdata "$dofile" \\
  924. "-o$target{build_file}" $sources > \$@
  925. EOF
  926. }
  927. sub generatedir {
  928. my %args = @_;
  929. my $dir = $args{dir};
  930. my @deps = map { platform->convertext($_) } @{$args{deps}};
  931. my @actions = ();
  932. my %extinfo = ( dso => platform->dsoext(),
  933. lib => platform->libext(),
  934. bin => platform->binext() );
  935. # We already have a 'test' target, and the top directory is just plain
  936. # silly
  937. return if $dir eq "test" || $dir eq ".";
  938. foreach my $type (("dso", "lib", "bin", "script")) {
  939. next unless defined($unified_info{dirinfo}->{$dir}->{products}->{$type});
  940. # For lib object files, we could update the library. However,
  941. # LIB on Windows doesn't work that way, so we won't create any
  942. # actions for it, and the dependencies are already taken care of.
  943. if ($type ne "lib") {
  944. foreach my $prod (@{$unified_info{dirinfo}->{$dir}->{products}->{$type}}) {
  945. if (dirname($prod) eq $dir) {
  946. push @deps, $prod.$extinfo{$type};
  947. }
  948. }
  949. }
  950. }
  951. my $deps = join(" ", @deps);
  952. my $actions = join("\n", "", @actions);
  953. return <<"EOF";
  954. $dir $dir\\ : $deps$actions
  955. EOF
  956. }
  957. "" # Important! This becomes part of the template result.
  958. -}