windows-makefile.tmpl 44 KB

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