2
0

cvtdsp.pl 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502
  1. use IO::File;
  2. use File::Find;
  3. if ($ARGV[0] eq '-6') {
  4. find(\&tovc6, '.');
  5. }
  6. elsif ($ARGV[0] eq '-5') {
  7. find(\&tovc5, '.');
  8. }
  9. elsif ($ARGV[0] eq '-w3') {
  10. find(\&tow3, '.');
  11. }
  12. elsif ($ARGV[0] eq '-w4') {
  13. find(\&tow4, '.');
  14. }
  15. elsif ($ARGV[0] eq '-ia64') {
  16. find(\&tovc64, '.');
  17. }
  18. elsif ($ARGV[0] eq '-d') {
  19. find(\&todebugpools, '.');
  20. }
  21. elsif ($ARGV[0] eq '-b') {
  22. find(\&tobrowse, '.');
  23. }
  24. elsif ($ARGV[0] eq '-m') {
  25. ## 0 - conapp, 1 - dll lib, 2 - static lib
  26. $dsptype = 2;
  27. $name = "apr";
  28. onemake();
  29. }
  30. else {
  31. print "Specify -5 or -6 for Visual Studio 5 or 6 (98) .dsp format\n";
  32. print "Specify -w3 or -w4 for .dsp build with warning level 3 or 4 (strict)\n\n";
  33. print "Specify -ia64 for build targeted at Itanium (req's psdk tools)\n\n";
  34. print "Specify -p for extreme pool debugging\n\n";
  35. die "Missing argument";
  36. }
  37. sub tovc5 {
  38. if (m|\.dsp$|) {
  39. $oname = $_;
  40. $tname = '.#' . $_;
  41. $verchg = 0;
  42. $srcfl = new IO::File $oname, "r" || die;
  43. $dstfl = new IO::File $tname, "w" || die;
  44. while ($src = <$srcfl>) {
  45. if ($src =~ s|Format Version 6\.00|Format Version 5\.00|) {
  46. $verchg = -1;
  47. }
  48. if ($src =~ s|^(# ADD CPP .*)/ZI (.*)|$1/Zi $2|) {
  49. $verchg = -1;
  50. }
  51. if ($src =~ s|^(# ADD BASE CPP .*)/ZI (.*)|$1/Zi $2|) {
  52. $verchg = -1;
  53. }
  54. if ($src =~ s|^(# ADD CPP .*)/EHsc (.*)|$1/GX $2|) {
  55. $verchg = -1;
  56. }
  57. if ($src =~ s|^(# ADD BASE CPP .*)/EHsc (.*)|$1/GX $2|) {
  58. $verchg = -1;
  59. }
  60. if ($src !~ m|^# PROP AllowPerConfigDependencies|) {
  61. print $dstfl $src; }
  62. else {
  63. $verchg = -1;
  64. }
  65. }
  66. undef $srcfl;
  67. undef $dstfl;
  68. if ($verchg) {
  69. unlink $oname || die;
  70. rename $tname, $oname || die;
  71. print "Converted VC6 project " . $oname . " to VC5 in " . $File::Find::dir . "\n";
  72. }
  73. else {
  74. unlink $tname;
  75. }
  76. }
  77. }
  78. sub tovc6 {
  79. if (m|\.dsp$|) {
  80. $oname = $_;
  81. $tname = '.#' . $_;
  82. $verchg = 0;
  83. $srcfl = new IO::File $_, "r" || die;
  84. $dstfl = new IO::File $tname, "w" || die;
  85. while ($src = <$srcfl>) {
  86. if ($src =~ s|Format Version 5\.00|Format Version 6\.00|) {
  87. $verchg = -1;
  88. }
  89. if ($src =~ s|^(!MESSAGE .*)\\\n|$1|) {
  90. $cont = <$srcfl>;
  91. $src = $src . $cont;
  92. $verchg = -1;
  93. }
  94. if ($src =~ s|^(# ADD CPP .*)/GX (.*)|$1/EHsc $2|) {
  95. $verchg = -1;
  96. }
  97. if ($src =~ s|^(# ADD BASE CPP .*)/GX (.*)|$1/EHsc $2|) {
  98. $verchg = -1;
  99. }
  100. print $dstfl $src;
  101. if ($verchg && $src =~ m|^# Begin Project|) {
  102. print $dstfl "# PROP AllowPerConfigDependencies 0\n";
  103. }
  104. }
  105. undef $srcfl;
  106. undef $dstfl;
  107. if ($verchg) {
  108. unlink $oname || die;
  109. rename $tname, $oname || die;
  110. print "Converted VC5 project " . $oname . " to VC6 in " . $File::Find::dir . "\n";
  111. }
  112. else {
  113. unlink $tname;
  114. }
  115. }
  116. }
  117. sub tow3 {
  118. if (m|\.dsp$| || m|\.mak$|) {
  119. $oname = $_;
  120. $tname = '.#' . $_;
  121. $verchg = 0;
  122. $srcfl = new IO::File $_, "r" || die;
  123. $dstfl = new IO::File $tname, "w" || die;
  124. while ($src = <$srcfl>) {
  125. while ($src =~ m|\\\n$|) {
  126. $src = $src . <$srcfl>
  127. }
  128. if ($src =~ s|(\bCPP.*) /W4(.*)|$1 /W3$2|) {
  129. $verchg = -1;
  130. }
  131. print $dstfl $src;
  132. }
  133. undef $srcfl;
  134. undef $dstfl;
  135. if ($verchg) {
  136. unlink $oname || die;
  137. rename $tname, $oname || die;
  138. print "Converted project " . $oname . " to warn:3 in " . $File::Find::dir . "\n";
  139. }
  140. else {
  141. unlink $tname;
  142. }
  143. }
  144. }
  145. sub tow4 {
  146. if (m|\.dsp$| || m|\.mak$|) {
  147. $oname = $_;
  148. $tname = '.#' . $_;
  149. $verchg = 0;
  150. $srcfl = new IO::File $_, "r" || die;
  151. $dstfl = new IO::File $tname, "w" || die;
  152. while ($src = <$srcfl>) {
  153. while ($src =~ m|\\\n$|) {
  154. $src = $src . <$srcfl>
  155. }
  156. if ($src =~ s|(\bCPP.*) /W3(.*)|$1 /W4$2|) {
  157. $verchg = -1;
  158. }
  159. print $dstfl $src;
  160. }
  161. undef $srcfl;
  162. undef $dstfl;
  163. if ($verchg) {
  164. unlink $oname || die;
  165. rename $tname, $oname || die;
  166. print "Converted project " . $oname . " to warn:4 " . $File::Find::dir . "\n";
  167. }
  168. else {
  169. unlink $tname;
  170. }
  171. }
  172. }
  173. sub tovc64 {
  174. if (m|\.dsp$| || m|\.mak$|) {
  175. $oname = $_;
  176. $tname = '.#' . $_;
  177. $verchg = 0;
  178. $srcfl = new IO::File $_, "r" || die;
  179. $dstfl = new IO::File $tname, "w" || die;
  180. while ($src = <$srcfl>) {
  181. while ($src =~ m|\\\n$|) {
  182. $src = $src . <$srcfl>
  183. }
  184. if ($src =~ s|Win32 \(x86\) (Release)|Win32 (IA64) $1|s) {
  185. $verchg = -1;
  186. }
  187. if ($src =~ s|Win32 \(x86\) (Debug)|Win32 (IA64) $1|s) {
  188. $verchg = -1;
  189. }
  190. if ($src =~ s| - Win32 (Release)| - Win32 (IA64) $1|s) {
  191. $verchg = -1;
  192. }
  193. if ($src =~ s| - Win32 (Debug)| - Win32 (IA64) $1|s) {
  194. $verchg = -1;
  195. }
  196. # Cross compilation exceptions
  197. if (!(m|gen[^/]*$| || m|dftables[^/]*$|)) {
  198. if ($src =~ s|(\bCPP.* /W3)(.*) /FD(.*)|$1 /As64 /Wp64$2$3|s) {
  199. $verchg = -1;
  200. }
  201. if ($src =~ s|(\bLINK.*/machine):I386(.*)|$1:IA64$2|s) {
  202. $verchg = -1;
  203. }
  204. }
  205. else {
  206. if ($src =~ s|(\bCPP.* /W3)(.*) /FD(.*)|$1 /As32 /Wp64$2$3|s) {
  207. $verchg = -1;
  208. }
  209. }
  210. print $dstfl $src;
  211. }
  212. undef $srcfl;
  213. undef $dstfl;
  214. if ($verchg) {
  215. unlink $oname || die;
  216. rename $tname, $oname || die;
  217. print "Converted build file " . $oname . " to Win64 in " . $File::Find::dir . "\n";
  218. }
  219. else {
  220. unlink $tname;
  221. }
  222. }
  223. }
  224. sub todebugpools {
  225. if (m|\.dsp$|) {
  226. $oname = $_;
  227. $tname = '.#' . $_;
  228. $verchg = 0;
  229. $srcfl = new IO::File $oname, "r" || die;
  230. $dstfl = new IO::File $tname, "w" || die;
  231. while ($src = <$srcfl>) {
  232. if ($src =~ s|^(# ADD CPP .* /D "_DEBUG" )|$1/D "APR_POOL_DEBUG" |) {
  233. $verchg = -1;
  234. if ($oname =~ /apr\.dsp$/) {
  235. $src =~ s|^(# ADD CPP .* /D "_DEBUG" )|$1/D "POOL_DEBUG" |;
  236. }
  237. }
  238. print $dstfl $src;
  239. }
  240. undef $srcfl;
  241. undef $dstfl;
  242. if ($verchg) {
  243. unlink $oname || die;
  244. rename $tname, $oname || die;
  245. print "Converted project " . $oname . " to debug pools in " . $File::Find::dir . "\n";
  246. }
  247. else {
  248. unlink $tname;
  249. }
  250. }
  251. }
  252. sub tobrowsesources {
  253. if (m|\.dsp$|) {
  254. $oname = $_;
  255. $tname = '.#' . $_;
  256. $verchg = 0;
  257. $srcfl = new IO::File $oname, "r" || die;
  258. $dstfl = new IO::File $tname, "w" || die;
  259. while ($src = <$srcfl>) {
  260. if ($src =~ s|^(# ADD CPP .*)( /Fd)|$1 /Fr "/httpd-2.0/srclib/apr"$2|) {
  261. $verchg = -1;
  262. }
  263. print $dstfl $src;
  264. }
  265. undef $srcfl;
  266. undef $dstfl;
  267. if ($verchg) {
  268. unlink $oname || die;
  269. rename $tname, $oname || die;
  270. print "Converted project " . $oname . " to browse sources in " . $File::Find::dir . "\n";
  271. }
  272. else {
  273. unlink $tname;
  274. }
  275. }
  276. }
  277. sub frommakefiles {
  278. if (m|\.mak\.in$|) {
  279. $oname = $_;
  280. $dname = $_;
  281. $_ =~ s/\.mak\.in/.dsp/;
  282. $verchg = 0;
  283. $srcfl = new IO::File $oname, "r" || die;
  284. $dstfl = new IO::File $tname, "w" || die;
  285. while ($src = <$srcfl>) {
  286. if ($src =~ s|^(# ADD CPP .*)( /Fd)|$1 /Fr "/httpd-2.0/srclib/apr"$2|) {
  287. $verchg = -1;
  288. }
  289. print $dstfl $src;
  290. }
  291. undef $srcfl;
  292. undef $dstfl;
  293. if ($verchg) {
  294. unlink $oname || die;
  295. rename $tname, $oname || die;
  296. print "Converted project " . $oname . " to browse sources in " . $File::Find::dir . "\n";
  297. }
  298. else {
  299. unlink $tname;
  300. }
  301. }
  302. }
  303. sub onemake {
  304. if ($dsptype == 0) {
  305. $cdefs = qq{/D "WIN32" /D "_CONSOLE"};
  306. $lmodel = qq{/subsystem:console};
  307. $targname = "Win32 (x86) Console Application";
  308. $targid = "0x0103";
  309. $debpath = "Debug"; $relpath = "Release";
  310. } elsif ($dsptype == 1) {
  311. $cdefs = qq{/D "WIN32" /D "_WINDOWS"};
  312. $lmodel = qq{/subsystem:windows /dll};
  313. $targname = "Win32 (x86) Dynamic-Link Library";
  314. $targid = "0x0102";
  315. $debpath = "Debug"; $relpath = "Release";
  316. } elsif($dsptype == 2) {
  317. $cdefs = qq{/D "WIN32" /D "_CONSOLE"};
  318. $lmodel = qq{/subsystem:console};
  319. $targname = "Win32 (x86) Static Library";
  320. $targid = "0x0104";
  321. $debpath = "LibD"; $relpath = "LibR";
  322. }
  323. $file = dspheader();
  324. $second = "";
  325. $model = "Release";
  326. $usedebuglib = "0";
  327. $debugdef = "NDEBUG";
  328. $cflags = "/MD /W3 /O2";
  329. $cincl = qq{/I "./include" /I "./os/win32" /I "./srclib/apr/include" /I "./srclib/apr-util/include"};
  330. $lflags = qq{/map};
  331. $file .= dsponemodel();
  332. $second = "ELSE";
  333. $model = "Debug";
  334. $usedebuglib = "1";
  335. $debugdef = "_DEBUG";
  336. $cflags = "/MDd /W3 /GX /Zi /Od";
  337. $cincl = qq{/I "./include" /I "./os/win32" /I "./srclib/apr/include" /I "./srclib/apr-util/include"};
  338. $lflags = qq{/incremental:no /debug};
  339. $file .= dsponemodel();
  340. $file .= qq{
  341. !ENDIF
  342. # Begin Target
  343. # Name "$name - Win32 Release"
  344. # Name "$name - Win32 Debug"
  345. };
  346. $toroot = ".";
  347. #HERE IS OUR FOREACH!
  348. $file .= qq{# Begin Source File
  349. SOURCE=./server/main.c
  350. # End Source File
  351. };
  352. if ($dsptype == 0) {
  353. #HERE IS OUR ICON!
  354. $icon="$toroot/build/win32/apache.ico";
  355. $file .= qq{# Begin Source File
  356. SOURCE=$icon
  357. # End Source File
  358. };
  359. $icon = "icon=" . $icon . " ";
  360. }
  361. if ($dsptype == 0 || $dsptype == 1) {
  362. $file .= qq{
  363. # Begin Source File
  364. SOURCE=./$name.rc
  365. # End Source File
  366. # Begin Source File
  367. SOURCE=$toroot/include/ap_release.h
  368. # PROP Ignore_Default_Tool 1
  369. # Begin Custom Build - Creating Version Resource
  370. InputPath=$toroot/include/ap_release.h $toroot/build/win32/win32ver.awk
  371. "./$name.rc" : \$(SOURCE) "\$(INTDIR)" "\$(OUTDIR)"
  372. awk -f $toroot/build/win32/win32ver.awk $name "Apache HTTP Server" $toroot/include/ap_release.h $icon> ./Apache.rc
  373. # End Custom Build
  374. # End Source File
  375. };
  376. }
  377. $file .= qq{
  378. # End Target
  379. # End Project
  380. };
  381. print $file;
  382. }
  383. sub dspheader {
  384. if ($dsptype == 1) {
  385. $midl = "MTL=midl.exe\n";
  386. } else {
  387. $midl = ""
  388. }
  389. qq{# Microsoft Developer Studio Project File - Name="$name" - Package Owner=<4>
  390. # Microsoft Developer Studio Generated Build File, Format Version 6.00
  391. # ** DO NOT EDIT **
  392. # TARGTYPE "$targname" $targid
  393. CFG=$name - Win32 Release
  394. !MESSAGE This is not a valid makefile. To build this project using NMAKE,
  395. !MESSAGE use the Export Makefile command and run
  396. !MESSAGE
  397. !MESSAGE NMAKE /f "$name.mak".
  398. !MESSAGE
  399. !MESSAGE You can specify a configuration when running NMAKE
  400. !MESSAGE by defining the macro CFG on the command line. For example:
  401. !MESSAGE
  402. !MESSAGE NMAKE /f "$name.mak" CFG="$name - Win32 Release"
  403. !MESSAGE
  404. !MESSAGE Possible choices for configuration are:
  405. !MESSAGE
  406. !MESSAGE "$name - Win32 Release" (based on "$targname")
  407. !MESSAGE "$name - Win32 Debug" (based on "$targname")
  408. !MESSAGE
  409. # Begin Project
  410. # PROP AllowPerConfigDependencies 0
  411. # PROP Scc_ProjName ""
  412. # PROP Scc_LocalPath ""
  413. CPP=cl.exe
  414. ${midl}RSC=rc.exe
  415. };
  416. }
  417. sub dsponemodel {
  418. if ($model eq "Release") {
  419. $targpath = $relpath;
  420. } else {
  421. $targpath = $debpath;
  422. }
  423. if ($dsptype == 1) {
  424. $midl =
  425. qq{# ADD BASE MTL /nologo /D "$debugdef" /win32
  426. # ADD MTL /nologo /D "$debugdef" /mktyplib203 /win32
  427. }; }
  428. if ($dsptype == 2) {
  429. $linkop = qq{LIB32=link.exe -lib
  430. # ADD BASE LIB32 /nologo
  431. # ADD LIB32 /nologo
  432. };
  433. } else {
  434. $linkop = qq{LINK32=link.exe
  435. # ADD BASE LINK32 kernel32.lib user32.lib advapi32.lib ws2_32.lib mswsock.lib /nologo $lmodel $lflags /machine:I386
  436. # ADD LINK32 kernel32.lib user32.lib advapi32.lib ws2_32.lib mswsock.lib /nologo $lmodel $lflags /machine:I386
  437. };
  438. }
  439. qq{
  440. !${second}IF "\$(CFG)" == "$name - Win32 $model"
  441. # PROP BASE Use_MFC 0
  442. # PROP BASE Use_Debug_Libraries $usedebuglib
  443. # PROP BASE Output_Dir "$targpath"
  444. # PROP BASE Intermediate_Dir "$targpath"
  445. # PROP BASE Target_Dir ""
  446. # PROP Use_MFC 0
  447. # PROP Use_Debug_Libraries $usedebuglib
  448. # PROP Output_Dir "$targpath"
  449. # PROP Intermediate_Dir "$targpath"
  450. # PROP Ignore_Export_Lib 0
  451. # PROP Target_Dir ""
  452. # ADD BASE CPP /nologo $cflags $cincl /D "$debugdef" $cdefs /FD /c
  453. # ADD CPP /nologo $cflags $cincl /D "$debugdef" $cdefs /Fd"$targpath/$name" /FD /c
  454. ${midl}# ADD BASE RSC /l 0x409 /d "$debugdef"
  455. # ADD RSC /l 0x409 /d "$debugdef"
  456. BSC32=bscmake.exe
  457. # ADD BASE BSC32 /nologo
  458. # ADD BSC32 /nologo
  459. $linkop};
  460. }