windows-makefile.tmpl 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628
  1. ##
  2. ## Makefile for OpenSSL
  3. ##
  4. ## {- join("\n## ", @autowarntext) -}
  5. {-
  6. our $objext = $target{obj_extension} || ".obj";
  7. our $depext = $target{dep_extension} || ".d";
  8. our $exeext = $target{exe_extension} || ".exe";
  9. our $libext = $target{lib_extension} || ".lib";
  10. our $shlibext = $target{shared_extension} || ".dll";
  11. our $shlibextimport = $target{shared_import_extension} || ".lib";
  12. our $dsoext = $target{dso_extension} || ".dll";
  13. our $sover = $config{shlib_major}."_".$config{shlib_minor};
  14. my $win_installenv =
  15. $target{build_scheme}->[2] eq "VC-W32" ?
  16. "ProgramFiles(x86)" : "ProgramW6432";
  17. my $win_commonenv =
  18. $target{build_scheme}->[2] eq "VC-W32"
  19. ? "CommonProgramFiles(x86)" : "CommonProgramW6432";
  20. our $win_installroot =
  21. defined($ENV{$win_installenv})
  22. ? $win_installenv : 'ProgramFiles';
  23. our $win_commonroot =
  24. defined($ENV{$win_commonenv})
  25. ? $win_commonenv : 'CommonProgramFiles';
  26. # expand variables early
  27. $win_installroot = $ENV{$win_installroot};
  28. $win_commonroot = $ENV{$win_commonroot};
  29. sub shlib {
  30. return () if $disabled{shared};
  31. my $lib = shift;
  32. return $unified_info{sharednames}->{$lib} . $shlibext;
  33. }
  34. sub shlib_import {
  35. return () if $disabled{shared};
  36. my $lib = shift;
  37. return $lib . $shlibextimport;
  38. }
  39. sub dso {
  40. my $dso = shift;
  41. return $dso . $dsoext;
  42. }
  43. # This makes sure things get built in the order they need
  44. # to. You're welcome.
  45. sub dependmagic {
  46. my $target = shift;
  47. return "$target: build_generated\n\t\$(MAKE) depend && \$(MAKE) _$target\n_$target";
  48. }
  49. '';
  50. -}
  51. PLATFORM={- $config{target} -}
  52. SRCDIR={- $config{sourcedir} -}
  53. BLDDIR={- $config{builddir} -}
  54. VERSION={- $config{version} -}
  55. MAJOR={- $config{major} -}
  56. MINOR={- $config{minor} -}
  57. SHLIB_VERSION_NUMBER={- $config{shlib_version_number} -}
  58. LIBS={- join(" ", map { $_.$libext } @{$unified_info{libraries}}) -}
  59. SHLIBS={- join(" ", map { shlib($_) } @{$unified_info{libraries}}) -}
  60. SHLIBPDBS={- join(" ", map { local $shlibext = ".pdb"; shlib($_) } @{$unified_info{libraries}}) -}
  61. ENGINES={- join(" ", map { dso($_) } @{$unified_info{engines}}) -}
  62. ENGINEPDBS={- join(" ", map { local $dsoext = ".pdb"; dso($_) } @{$unified_info{engines}}) -}
  63. PROGRAMS={- our @PROGRAMS = map { $_.$exeext } @{$unified_info{programs}}; join(" ", @PROGRAMS) -}
  64. PROGRAMPDBS={- join(" ", map { $_.".pdb" } @{$unified_info{programs}}) -}
  65. SCRIPTS={- join(" ", @{$unified_info{scripts}}) -}
  66. {- output_off() if $disabled{makedepend}; "" -}
  67. DEPS={- join(" ", map { (my $x = $_) =~ s|\.o$|$depext|; $x; }
  68. grep { $unified_info{sources}->{$_}->[0] =~ /\.c$/ }
  69. keys %{$unified_info{sources}}); -}
  70. {- output_on() if $disabled{makedepend}; "" -}
  71. GENERATED_MANDATORY={- join(" ", @{$unified_info{depends}->{""}} ) -}
  72. GENERATED={- join(" ",
  73. ( map { (my $x = $_) =~ s|\.[sS]$|\.asm|; $x }
  74. grep { defined $unified_info{generate}->{$_} }
  75. map { @{$unified_info{sources}->{$_}} }
  76. grep { /\.o$/ } keys %{$unified_info{sources}} ),
  77. ( grep { /\.h$/ } keys %{$unified_info{generate}} )) -}
  78. INSTALL_LIBS={- join(" ", map { quotify1($_.$libext) } @{$unified_info{install}->{libraries}}) -}
  79. INSTALL_SHLIBS={- join(" ", map { quotify_l(shlib($_)) } @{$unified_info{install}->{libraries}}) -}
  80. INSTALL_SHLIBPDBS={- join(" ", map { local $shlibext = ".pdb"; quotify_l(shlib($_)) } @{$unified_info{install}->{libraries}}) -}
  81. INSTALL_ENGINES={- join(" ", map { quotify1(dso($_)) } @{$unified_info{install}->{engines}}) -}
  82. INSTALL_ENGINEPDBS={- join(" ", map { local $dsoext = ".pdb"; quotify1(dso($_)) } @{$unified_info{install}->{engines}}) -}
  83. INSTALL_PROGRAMS={- join(" ", map { quotify1($_.$exeext) } grep { !m|^test\\| } @{$unified_info{install}->{programs}}) -}
  84. INSTALL_PROGRAMPDBS={- join(" ", map { quotify1($_.".pdb") } grep { !m|^test\\| } @{$unified_info{install}->{programs}}) -}
  85. {- output_off() if $disabled{apps}; "" -}
  86. BIN_SCRIPTS="$(BLDDIR)\tools\c_rehash.pl"
  87. MISC_SCRIPTS="$(BLDDIR)\apps\CA.pl" "$(BLDDIR)\apps\tsget.pl"
  88. {- output_on() if $disabled{apps}; "" -}
  89. APPS_OPENSSL={- use File::Spec::Functions;
  90. "\"".catfile("apps","openssl")."\"" -}
  91. # Do not edit these manually. Use Configure with --prefix or --openssldir
  92. # to change this! Short explanation in the top comment in Configure
  93. INSTALLTOP_dev={- # $prefix is used in the OPENSSLDIR perl snippet
  94. #
  95. use File::Spec::Functions qw(:DEFAULT splitpath);
  96. our $prefix = canonpath($config{prefix}
  97. || "$win_installroot\\OpenSSL");
  98. our ($prefix_dev, $prefix_dir, $prefix_file) =
  99. splitpath($prefix, 1);
  100. $prefix_dev -}
  101. INSTALLTOP_dir={- canonpath($prefix_dir) -}
  102. OPENSSLDIR_dev={- #
  103. # The logic here is that if no --openssldir was given,
  104. # OPENSSLDIR will get the value from $prefix plus "/ssl".
  105. # If --openssldir was given and the value is an absolute
  106. # path, OPENSSLDIR will get its value without change.
  107. # If the value from --openssldir is a relative path,
  108. # OPENSSLDIR will get $prefix with the --openssldir
  109. # value appended as a subdirectory.
  110. #
  111. use File::Spec::Functions qw(:DEFAULT splitpath);
  112. our $openssldir =
  113. $config{openssldir} ?
  114. (file_name_is_absolute($config{openssldir}) ?
  115. canonpath($config{openssldir})
  116. : catdir($prefix, $config{openssldir}))
  117. : canonpath("$win_commonroot\\SSL");
  118. our ($openssldir_dev, $openssldir_dir, $openssldir_file) =
  119. splitpath($openssldir, 1);
  120. $openssldir_dev -}
  121. OPENSSLDIR_dir={- canonpath($openssldir_dir) -}
  122. LIBDIR={- our $libdir = $config{libdir} || "lib";
  123. $libdir -}
  124. ENGINESDIR_dev={- use File::Spec::Functions qw(:DEFAULT splitpath);
  125. our $enginesdir = catdir($prefix,$libdir,"engines-$sover");
  126. our ($enginesdir_dev, $enginesdir_dir, $enginesdir_file) =
  127. splitpath($enginesdir, 1);
  128. $enginesdir_dev -}
  129. ENGINESDIR_dir={- canonpath($enginesdir_dir) -}
  130. !IF "$(DESTDIR)" != ""
  131. INSTALLTOP=$(DESTDIR)$(INSTALLTOP_dir)
  132. OPENSSLDIR=$(DESTDIR)$(OPENSSLDIR_dir)
  133. ENGINESDIR=$(DESTDIR)$(ENGINESDIR_dir)
  134. !ELSE
  135. INSTALLTOP=$(INSTALLTOP_dev)$(INSTALLTOP_dir)
  136. OPENSSLDIR=$(OPENSSLDIR_dev)$(OPENSSLDIR_dir)
  137. ENGINESDIR=$(ENGINESDIR_dev)$(ENGINESDIR_dir)
  138. !ENDIF
  139. CC={- $target{cc} -}
  140. CFLAGS={- join(" ",(map { "-D".$_} @{$target{defines}}, @{$config{defines}})) -} {- join(" ", quotify_l("-DENGINESDIR=\"$enginesdir\"", "-DOPENSSLDIR=\"$openssldir\"")) -} {- $target{cflags} -} {- $config{cflags} -}
  141. COUTFLAG={- $target{coutflag} || "/Fo" -}$(OSSL_EMPTY)
  142. RC={- $target{rc} || "rc" -}
  143. RCOUTFLAG={- $target{rcoutflag} || "/fo" -}$(OSSL_EMPTY)
  144. LD={- $target{ld} || "link" -}
  145. LDFLAGS={- $target{lflags} -}
  146. LDOUTFLAG={- $target{loutflag} || "/out:" -}$(OSSL_EMPTY)
  147. EX_LIBS={- $target{ex_libs} -}
  148. LIB_CFLAGS={- join(" ", $target{lib_cflags}, $target{shared_cflag}) || "" -}
  149. LIB_LDFLAGS={- $target{shared_ldflag} || "" -}
  150. DSO_CFLAGS={- join(" ", $target{dso_cflags}, $target{shared_cflag}) || "" -}
  151. DSO_LDFLAGS={- join(" ", $target{dso_lflags}, $target{shared_ldflag}) || "" -}
  152. BIN_CFLAGS={- $target{bin_cflags} -}
  153. BIN_LDFLAGS={- $target{bin_lflags} -}
  154. PERL={- $config{perl} -}
  155. AR={- $target{ar} -}
  156. ARFLAGS= {- $target{arflags} -}
  157. AROUTFLAG={- $target{aroutflag} || "/out:" -}$(OSSL_EMPTY)
  158. MT={- $target{mt} -}
  159. MTFLAGS= {- $target{mtflags} -}
  160. MTINFLAG={- $target{mtinflag} || "-manifest " -}$(OSSL_EMPTY)
  161. MTOUTFLAG={- $target{mtoutflag} || "-outputresource:" -}$(OSSL_EMPTY)
  162. AS={- $target{as} -}
  163. ASFLAGS={- $target{asflags} -}
  164. ASOUTFLAG={- $target{asoutflag} -}$(OSSL_EMPTY)
  165. ECHO="$(PERL)" "$(SRCDIR)\util\echo.pl"
  166. PERLASM_SCHEME= {- $target{perlasm_scheme} -}
  167. PROCESSOR= {- $config{processor} -}
  168. # The main targets ###################################################
  169. {- dependmagic('all'); -}: build_libs_nodep build_engines_nodep build_programs_nodep
  170. {- dependmagic('build_libs'); -}: build_libs_nodep
  171. {- dependmagic('build_engines'); -}: build_engines_nodep
  172. {- dependmagic('build_programs'); -}: build_programs_nodep
  173. build_generated: $(GENERATED_MANDATORY)
  174. build_libs_nodep: $(LIBS) {- join(" ",map { shlib_import($_) } @{$unified_info{libraries}}) -}
  175. build_engines_nodep: $(ENGINES)
  176. build_programs_nodep: $(PROGRAMS) $(SCRIPTS)
  177. # Kept around for backward compatibility
  178. build_apps build_tests: build_programs
  179. # Convenience target to prebuild all generated files, not just the mandatory
  180. # ones
  181. build_all_generated: $(GENERATED_MANDATORY) $(GENERATED)
  182. test: tests
  183. {- dependmagic('tests'); -}: build_programs_nodep build_engines_nodep
  184. @{- output_off() if $disabled{tests}; "" -}
  185. -mkdir $(BLDDIR)\test\test-runs
  186. set SRCTOP=$(SRCDIR)
  187. set BLDTOP=$(BLDDIR)
  188. set RESULT_D=$(BLDDIR)\test\test-runs
  189. set PERL=$(PERL)
  190. set OPENSSL_ENGINES=$(MAKEDIR)\engines
  191. set OPENSSL_DEBUG_MEMORY=on
  192. "$(PERL)" "$(SRCDIR)\test\run_tests.pl" $(TESTS)
  193. @{- if ($disabled{tests}) { output_on(); } else { output_off(); } "" -}
  194. @$(ECHO) "Tests are not supported with your chosen Configure options"
  195. @{- output_on() if !$disabled{tests}; "" -}
  196. list-tests:
  197. @{- output_off() if $disabled{tests}; "" -}
  198. @set SRCTOP=$(SRCDIR)
  199. @"$(PERL)" "$(SRCDIR)\test\run_tests.pl" list
  200. @{- if ($disabled{tests}) { output_on(); } else { output_off(); } "" -}
  201. @$(ECHO) "Tests are not supported with your chosen Configure options"
  202. @{- output_on() if !$disabled{tests}; "" -}
  203. install: install_sw install_ssldirs install_docs
  204. uninstall: uninstall_docs uninstall_sw
  205. libclean:
  206. "$(PERL)" -e "map { m/(.*)\.dll$$/; unlink glob """$$1.*"""; } @ARGV" $(SHLIBS)
  207. "$(PERL)" -e "map { m/(.*)\.dll$$/; unlink glob """apps/$$1.*"""; } @ARGV" $(SHLIBS)
  208. "$(PERL)" -e "map { m/(.*)\.dll$$/; unlink glob """test/$$1.*"""; } @ARGV" $(SHLIBS)
  209. "$(PERL)" -e "map { m/(.*)\.dll$$/; unlink glob """fuzz/$$1.*"""; } @ARGV" $(SHLIBS)
  210. -del /Q /F $(LIBS)
  211. -del /Q ossl_static.pdb
  212. clean: libclean
  213. {- join("\n\t", map { "-del /Q /F $_" } @PROGRAMS) -}
  214. -del /Q /F $(ENGINES)
  215. -del /Q /F $(SCRIPTS)
  216. -del /Q /F $(GENERATED)
  217. -del /Q /S /F *.d
  218. -del /Q /S /F *.obj
  219. -del /Q /S /F *.pdb
  220. -del /Q /S /F *.exp
  221. -del /Q /S /F engines\*.ilk
  222. -del /Q /S /F engines\*.lib
  223. -del /Q /S /F apps\*.lib
  224. -del /Q /S /F engines\*.manifest
  225. -del /Q /S /F apps\*.manifest
  226. -del /Q /S /F test\*.manifest
  227. distclean: clean
  228. -del /Q /F configdata.pm
  229. -del /Q /F makefile
  230. depend:
  231. # Install helper targets #############################################
  232. install_sw: install_dev install_engines install_runtime
  233. uninstall_sw: uninstall_runtime uninstall_engines uninstall_dev
  234. install_docs: install_html_docs
  235. uninstall_docs: uninstall_html_docs
  236. install_ssldirs:
  237. @"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(OPENSSLDIR)\certs"
  238. @"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(OPENSSLDIR)\private"
  239. @"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(OPENSSLDIR)\misc"
  240. @"$(PERL)" "$(SRCDIR)\util\copy.pl" "$(SRCDIR)\apps\openssl.cnf" \
  241. "$(OPENSSLDIR)\openssl.cnf.dist"
  242. @IF NOT EXIST "$(OPENSSLDIR)\openssl.cnf" \
  243. "$(PERL)" "$(SRCDIR)\util\copy.pl" "$(SRCDIR)\apps\openssl.cnf" \
  244. "$(OPENSSLDIR)\openssl.cnf"
  245. @"$(PERL)" "$(SRCDIR)\util\copy.pl" $(MISC_SCRIPTS) \
  246. "$(OPENSSLDIR)\misc"
  247. install_dev: install_runtime_libs
  248. @if "$(INSTALLTOP)"=="" ( $(ECHO) "INSTALLTOP should not be empty" & exit 1 )
  249. @$(ECHO) "*** Installing development files"
  250. @"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(INSTALLTOP)\include\openssl"
  251. @{- output_off() unless grep { $_ eq "OPENSSL_USE_APPLINK" } @{$target{defines}}; "" -}
  252. @"$(PERL)" "$(SRCDIR)\util\copy.pl" "$(SRCDIR)\ms\applink.c" \
  253. "$(INSTALLTOP)\include\openssl"
  254. @{- output_on() unless grep { $_ eq "OPENSSL_USE_APPLINK" } @{$target{defines}}; "" -}
  255. @"$(PERL)" "$(SRCDIR)\util\copy.pl" "-exclude_re=/__DECC_" \
  256. "$(SRCDIR)\include\openssl\*.h" \
  257. "$(INSTALLTOP)\include\openssl"
  258. @"$(PERL)" "$(SRCDIR)\util\copy.pl" "$(BLDDIR)\include\openssl\*.h" \
  259. "$(INSTALLTOP)\include\openssl"
  260. @"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(INSTALLTOP)\$(LIBDIR)"
  261. @"$(PERL)" "$(SRCDIR)\util\copy.pl" $(INSTALL_LIBS) \
  262. "$(INSTALLTOP)\$(LIBDIR)"
  263. @if "$(SHLIBS)"=="" \
  264. "$(PERL)" "$(SRCDIR)\util\copy.pl" ossl_static.pdb \
  265. "$(INSTALLTOP)\$(LIBDIR)"
  266. uninstall_dev:
  267. install_engines: install_runtime_libs build_engines
  268. @if "$(INSTALLTOP)"=="" ( $(ECHO) "INSTALLTOP should not be empty" & exit 1 )
  269. @$(ECHO) "*** Installing engines"
  270. @"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(ENGINESDIR)"
  271. @if not "$(ENGINES)"=="" \
  272. "$(PERL)" "$(SRCDIR)\util\copy.pl" $(INSTALL_ENGINES) "$(ENGINESDIR)"
  273. @if not "$(ENGINES)"=="" \
  274. "$(PERL)" "$(SRCDIR)\util\copy.pl" $(INSTALL_ENGINEPDBS) "$(ENGINESDIR)"
  275. uninstall_engines:
  276. install_runtime: install_programs
  277. install_runtime_libs: build_libs
  278. @if "$(INSTALLTOP)"=="" ( $(ECHO) "INSTALLTOP should not be empty" & exit 1 )
  279. @$(ECHO) "*** Installing runtime libraries"
  280. @"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(INSTALLTOP)\bin"
  281. @if not "$(SHLIBS)"=="" \
  282. "$(PERL)" "$(SRCDIR)\util\copy.pl" $(INSTALL_SHLIBS) "$(INSTALLTOP)\bin"
  283. @if not "$(SHLIBS)"=="" \
  284. "$(PERL)" "$(SRCDIR)\util\copy.pl" $(INSTALL_SHLIBPDBS) \
  285. "$(INSTALLTOP)\bin"
  286. install_programs: install_runtime_libs build_programs
  287. @if "$(INSTALLTOP)"=="" ( $(ECHO) "INSTALLTOP should not be empty" & exit 1 )
  288. @$(ECHO) "*** Installing runtime programs"
  289. @"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(INSTALLTOP)\bin"
  290. @"$(PERL)" "$(SRCDIR)\util\copy.pl" $(INSTALL_PROGRAMS) \
  291. "$(INSTALLTOP)\bin"
  292. @"$(PERL)" "$(SRCDIR)\util\copy.pl" $(INSTALL_PROGRAMPDBS) \
  293. "$(INSTALLTOP)\bin"
  294. @"$(PERL)" "$(SRCDIR)\util\copy.pl" $(BIN_SCRIPTS) \
  295. "$(INSTALLTOP)\bin"
  296. uninstall_runtime:
  297. install_html_docs:
  298. "$(PERL)" "$(SRCDIR)\util\process_docs.pl" \
  299. "--destdir=$(INSTALLTOP)\html" --type=html
  300. uninstall_html_docs:
  301. # Building targets ###################################################
  302. configdata.pm: "$(SRCDIR)\Configure" {- join(" ", map { '"'.$_.'"' } @{$config{build_file_templates}}, @{$config{build_infos}}, @{$config{conf_files}}) -}
  303. @$(ECHO) "Detected changed: $?"
  304. @$(ECHO) "Reconfiguring..."
  305. "$(PERL)" "$(SRCDIR)\Configure" reconf
  306. @$(ECHO) "**************************************************"
  307. @$(ECHO) "*** ***"
  308. @$(ECHO) "*** Please run the same make command again ***"
  309. @$(ECHO) "*** ***"
  310. @$(ECHO) "**************************************************"
  311. @exit 1
  312. {-
  313. use File::Basename;
  314. use File::Spec::Functions qw/:DEFAULT abs2rel rel2abs/;
  315. # Helper function to figure out dependencies on libraries
  316. # It takes a list of library names and outputs a list of dependencies
  317. sub compute_lib_depends {
  318. if ($disabled{shared}) {
  319. return map { $_.$libext } @_;
  320. }
  321. return map { shlib_import($_) } @_;
  322. }
  323. sub generatesrc {
  324. my %args = @_;
  325. (my $target = $args{src}) =~ s/\.[sS]$/.asm/;
  326. my ($gen0, @gens) = @{$args{generator}};
  327. my $generator = '"'.$gen0.'"'.join('', map { " $_" } @gens);
  328. my $generator_incs = join("", map { " -I \"$_\"" } @{$args{generator_incs}});
  329. my $incs = join("", map { " /I \"$_\"" } @{$args{incs}});
  330. my $deps = @{$args{deps}} ?
  331. '"'.join('" "', @{$args{generator_deps}}, @{$args{deps}}).'"' : '';
  332. if ($target !~ /\.asm$/) {
  333. if ($args{generator}->[0] =~ m|^.*\.in$|) {
  334. my $dofile = abs2rel(rel2abs(catfile($config{sourcedir},
  335. "util", "dofile.pl")),
  336. rel2abs($config{builddir}));
  337. return <<"EOF";
  338. $target: "$args{generator}->[0]" $deps
  339. "\$(PERL)" "-I\$(BLDDIR)" -Mconfigdata "$dofile" \\
  340. "-o$target{build_file}" $generator > \$@
  341. EOF
  342. } else {
  343. return <<"EOF";
  344. $target: "$args{generator}->[0]" $deps
  345. "\$(PERL)"$generator_incs $generator > \$@
  346. EOF
  347. }
  348. } else {
  349. if ($args{generator}->[0] =~ /\.pl$/) {
  350. $generator = '"$(PERL)"'.$generator_incs.' '.$generator;
  351. } elsif ($args{generator}->[0] =~ /\.S$/) {
  352. $generator = undef;
  353. } else {
  354. die "Generator type for $src unknown: $generator\n";
  355. }
  356. if (defined($generator)) {
  357. # If the target is named foo.S in build.info, we want to
  358. # end up generating foo.s in two steps.
  359. if ($args{src} =~ /\.S$/) {
  360. return <<"EOF";
  361. $target: "$args{generator}->[0]" $deps
  362. set ASM=\$(AS)
  363. $generator \$@.S
  364. \$(CC) $incs \$(CFLAGS) /EP /C \$@.S > \$@.i && move /Y \$@.i \$@
  365. del /Q \$@.S
  366. EOF
  367. }
  368. # Otherwise....
  369. return <<"EOF";
  370. $target: "$args{generator}->[0]" $deps
  371. set ASM=\$(AS)
  372. $generator \$@
  373. EOF
  374. }
  375. return <<"EOF";
  376. $target: "$args{generator}->[0]" $deps
  377. \$(CC) $incs \$(CFLAGS) /EP /C "$args{generator}->[0]" > \$@.i && move /Y \$@.i \$@
  378. EOF
  379. }
  380. }
  381. sub src2obj {
  382. my %args = @_;
  383. my $obj = $args{obj};
  384. my @srcs = map { (my $x = $_) =~ s/\.s$/.asm/; $x
  385. } ( @{$args{srcs}} );
  386. my $srcs = '"'.join('" "', @srcs).'"';
  387. my $deps = '"'.join('" "', @srcs, @{$args{deps}}).'"';
  388. my $incs = join("", map { ' /I "'.$_.'"' } @{$args{incs}});
  389. unless ($disabled{zlib}) {
  390. if ($withargs{zlib_include}) {
  391. $incs .= ' /I "'.$withargs{zlib_include}.'"';
  392. }
  393. }
  394. my $ecflags = { lib => '$(LIB_CFLAGS)',
  395. dso => '$(DSO_CFLAGS)',
  396. bin => '$(BIN_CFLAGS)' } -> {$args{intent}};
  397. my $makedepprog = $config{makedepprog};
  398. if ($srcs[0] =~ /\.asm$/) {
  399. return <<"EOF";
  400. $obj$objext: $deps
  401. \$(AS) \$(ASFLAGS) \$(ASOUTFLAG)\$\@ $srcs
  402. EOF
  403. }
  404. my $recipe = <<"EOF";
  405. $obj$objext: $deps
  406. \$(CC) $incs \$(CFLAGS) $ecflags -c \$(COUTFLAG)\$\@ $srcs
  407. EOF
  408. $recipe .= <<"EOF" unless $disabled{makedepend};
  409. \$(CC) $incs \$(CFLAGS) $ecflags /Zs /showIncludes $srcs 2>&1 | \\
  410. "\$(PERL)" -n << > $obj$depext
  411. chomp;
  412. s/^Note: including file: *//;
  413. \$\$collect{\$\$_} = 1;
  414. END { print '$obj$objext: ',join(" ", sort keys \%collect),"\\n" }
  415. <<
  416. EOF
  417. return $recipe;
  418. }
  419. # On Unix, we build shlibs from static libs, so we're ignoring the
  420. # object file array. We *know* this routine is only called when we've
  421. # configure 'shared'.
  422. sub libobj2shlib {
  423. my %args = @_;
  424. my $lib = $args{lib};
  425. my $shlib = $args{shlib};
  426. (my $mkdef_key = $lib) =~ s/^lib//i;
  427. my $objs = join("\n", map { $_.$objext } @{$args{objs}});
  428. my $linklibs = join("",
  429. map { "\n$_" } compute_lib_depends(@{$args{deps}}));
  430. my $deps = join(" ",
  431. (map { $_.$objext } @{$args{objs}}),
  432. compute_lib_depends(@{$args{deps}}));
  433. my $ordinalsfile = defined($args{ordinals}) ? $args{ordinals}->[1] : "";
  434. my $mkdef_pl = abs2rel(rel2abs(catfile($config{sourcedir},
  435. "util", "mkdef.pl")),
  436. rel2abs($config{builddir}));
  437. my $mkrc_pl = abs2rel(rel2abs(catfile($config{sourcedir},
  438. "util", "mkrc.pl")),
  439. rel2abs($config{builddir}));
  440. my $target = shlib_import($lib);
  441. return <<"EOF"
  442. $target: $deps "$ordinalsfile" "$mkdef_pl"
  443. "\$(PERL)" "$mkdef_pl" "$mkdef_key" 32 > $shlib.def
  444. "\$(PERL)" -i.tmp -pe "s|^LIBRARY\\s+${mkdef_key}32|LIBRARY $shlib|;" $shlib.def
  445. DEL $shlib.def.tmp
  446. "\$(PERL)" "$mkrc_pl" $shlib$shlibext > $shlib.rc
  447. \$(RC) \$(RCOUTFLAG)$shlib.res $shlib.rc
  448. IF EXIST $shlib$shlibext.manifest DEL /F /Q $shlib$shlibext.manifest
  449. \$(LD) \$(LDFLAGS) \$(LIB_LDFLAGS) \\
  450. /implib:\$@ \$(LDOUTFLAG)$shlib$shlibext /def:$shlib.def @<< || (DEL /Q \$(\@B).* $shlib.* && EXIT 1)
  451. $objs $shlib.res$linklibs \$(EX_LIBS)
  452. <<
  453. IF EXIST $shlib$shlibext.manifest \\
  454. \$(MT) \$(MTFLAGS) \$(MTINFLAG)$shlib$shlibext.manifest \$(MTOUTFLAG)$shlib$shlibext
  455. IF EXIST apps\\$shlib$shlibext DEL /Q /F apps\\$shlib$shlibext
  456. IF EXIST test\\$shlib$shlibext DEL /Q /F test\\$shlib$shlibext
  457. IF EXIST fuzz\\$shlib$shlibext DEL /Q /F fuzz\\$shlib$shlibext
  458. COPY $shlib$shlibext apps
  459. COPY $shlib$shlibext test
  460. COPY $shlib$shlibext fuzz
  461. EOF
  462. }
  463. sub obj2dso {
  464. my %args = @_;
  465. my $dso = $args{lib};
  466. my $dso_n = basename($dso);
  467. my $objs = join("\n", map { $_.$objext } @{$args{objs}});
  468. my $linklibs = join("",
  469. map { "\n$_" } compute_lib_depends(@{$args{deps}}));
  470. my $deps = join(" ",
  471. (map { $_.$objext } @{$args{objs}}),
  472. compute_lib_depends(@{$args{deps}}));
  473. return <<"EOF";
  474. $dso$dsoext: $deps
  475. IF EXIST $dso$dsoext.manifest DEL /F /Q $dso$dsoext.manifest
  476. \$(LD) \$(LDFLAGS) \$(DSO_LDFLAGS) \$(LDOUTFLAG)$dso$dsoext /def:<< @<<
  477. LIBRARY $dso_n
  478. EXPORTS
  479. bind_engine @1
  480. v_check @2
  481. <<
  482. $objs$linklibs \$(EX_LIBS)
  483. <<
  484. IF EXIST $dso$dsoext.manifest \\
  485. \$(MT) \$(MTFLAGS) \$(MTINFLAG)$dso$dsoext.manifest \$(MTOUTFLAG)$dso$dsoext
  486. EOF
  487. }
  488. sub obj2lib {
  489. # Because static libs and import libs are both named the same in native
  490. # Windows, we can't have both. We skip the static lib in that case,
  491. # as the shared libs are what we use anyway.
  492. return "" unless $disabled{"shared"};
  493. my %args = @_;
  494. my $lib = $args{lib};
  495. my $objs = join("\n", map { $_.$objext } @{$args{objs}});
  496. my $deps = join(" ", map { $_.$objext } @{$args{objs}});
  497. return <<"EOF";
  498. $lib$libext: $deps
  499. \$(AR) \$(ARFLAGS) \$(AROUTFLAG)$lib$libext @<<
  500. \$**
  501. <<
  502. EOF
  503. }
  504. sub obj2bin {
  505. my %args = @_;
  506. my $bin = $args{bin};
  507. my $objs = join("\n", map { $_.$objext } @{$args{objs}});
  508. my $linklibs = join("",
  509. map { "\n$_" } compute_lib_depends(@{$args{deps}}));
  510. my $deps = join(" ",
  511. (map { $_.$objext } @{$args{objs}}),
  512. compute_lib_depends(@{$args{deps}}));
  513. return <<"EOF";
  514. $bin$exeext: $deps
  515. IF EXIST $bin$exeext.manifest DEL /F /Q $bin$exeext.manifest
  516. \$(LD) \$(LDFLAGS) \$(BIN_LDFLAGS) \$(LDOUTFLAG)$bin$exeext @<<
  517. $objs setargv.obj$linklibs \$(EX_LIBS)
  518. <<
  519. IF EXIST $bin$exeext.manifest \\
  520. \$(MT) \$(MTFLAGS) \$(MTINFLAG)$bin$exeext.manifest \$(MTOUTFLAG)$bin$exeext
  521. EOF
  522. }
  523. sub in2script {
  524. my %args = @_;
  525. my $script = $args{script};
  526. my $sources = '"'.join('" "', @{$args{sources}}).'"';
  527. my $dofile = abs2rel(rel2abs(catfile($config{sourcedir},
  528. "util", "dofile.pl")),
  529. rel2abs($config{builddir}));
  530. return <<"EOF";
  531. $script: $sources
  532. "\$(PERL)" "-I\$(BLDDIR)" -Mconfigdata "$dofile" \\
  533. "-o$target{build_file}" $sources > "$script"
  534. EOF
  535. }
  536. sub generatedir {
  537. my %args = @_;
  538. my $dir = $args{dir};
  539. my @deps = map { s|\.o$|$objext|; $_ } @{$args{deps}};
  540. my @actions = ();
  541. my %extinfo = ( dso => $dsoext,
  542. lib => $libext,
  543. bin => $exeext );
  544. foreach my $type (("dso", "lib", "bin", "script")) {
  545. next unless defined($unified_info{dirinfo}->{$dir}->{products}->{$type});
  546. # For lib object files, we could update the library. However,
  547. # LIB on Windows doesn't work that way, so we won't create any
  548. # actions for it, and the dependencies are already taken care of.
  549. if ($type ne "lib") {
  550. foreach my $prod (@{$unified_info{dirinfo}->{$dir}->{products}->{$type}}) {
  551. if (dirname($prod) eq $dir) {
  552. push @deps, $prod.$extinfo{$type};
  553. }
  554. }
  555. }
  556. }
  557. my $deps = join(" ", @deps);
  558. my $actions = join("\n", "", @actions);
  559. return <<"EOF";
  560. $args{dir} $args{dir}\\ : $deps$actions
  561. EOF
  562. }
  563. "" # Important! This becomes part of the template result.
  564. -}