windows-makefile.tmpl 23 KB

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