You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

129 lines
4.7 KiB

  1. #include <windows.h>
  2. #include <sys/types.h>
  3. #include <sys/stat.h>
  4. #include <stdio.h>
  5. #define CMD_SIZE 500
  6. /* This file creates the getbuildinfo.o object, by first
  7. invoking subwcrev.exe (if found), and then invoking cl.exe.
  8. As a side effect, it might generate PCBuild\getbuildinfo2.c
  9. also. If this isn't a subversion checkout, or subwcrev isn't
  10. found, it compiles ..\\Modules\\getbuildinfo.c instead.
  11. Currently, subwcrev.exe is found from the registry entries
  12. of TortoiseSVN.
  13. No attempt is made to place getbuildinfo.o into the proper
  14. binary directory. This isn't necessary, as this tool is
  15. invoked as a pre-link step for pythoncore, so that overwrites
  16. any previous getbuildinfo.o.
  17. However, if a second argument is provided, this will be used
  18. as a temporary directory where any getbuildinfo2.c and
  19. getbuildinfo.o files are put. This is useful if multiple
  20. configurations are being built in parallel, to avoid them
  21. trampling each other's files.
  22. */
  23. int make_buildinfo2(const char *tmppath)
  24. {
  25. struct _stat st;
  26. HKEY hTortoise;
  27. char command[CMD_SIZE+1];
  28. DWORD type, size;
  29. if (_stat(".svn", &st) < 0)
  30. return 0;
  31. /* Allow suppression of subwcrev.exe invocation if a no_subwcrev file is present. */
  32. if (_stat("no_subwcrev", &st) == 0)
  33. return 0;
  34. if (RegOpenKey(HKEY_LOCAL_MACHINE, "Software\\TortoiseSVN", &hTortoise) != ERROR_SUCCESS &&
  35. RegOpenKey(HKEY_CURRENT_USER, "Software\\TortoiseSVN", &hTortoise) != ERROR_SUCCESS)
  36. /* Tortoise not installed */
  37. return 0;
  38. command[0] = '"'; /* quote the path to the executable */
  39. size = sizeof(command) - 1;
  40. if (RegQueryValueEx(hTortoise, "Directory", 0, &type, command+1, &size) != ERROR_SUCCESS ||
  41. type != REG_SZ)
  42. /* Registry corrupted */
  43. return 0;
  44. strcat_s(command, CMD_SIZE, "bin\\subwcrev.exe");
  45. if (_stat(command+1, &st) < 0)
  46. /* subwcrev.exe not part of the release */
  47. return 0;
  48. strcat_s(command, CMD_SIZE, "\" .. ..\\Modules\\getbuildinfo.c \"");
  49. strcat_s(command, CMD_SIZE, tmppath); /* quoted tmppath */
  50. strcat_s(command, CMD_SIZE, "getbuildinfo2.c\"");
  51. puts(command); fflush(stdout);
  52. if (system(command) < 0)
  53. return 0;
  54. return 1;
  55. }
  56. int main(int argc, char*argv[])
  57. {
  58. char command[CMD_SIZE] = "cl.exe -c -D_WIN32 -DUSE_DL_EXPORT -D_WINDOWS -DWIN32 -D_WINDLL ";
  59. char tmppath[CMD_SIZE] = "";
  60. int do_unlink, result;
  61. char *tmpdir = NULL;
  62. if (argc <= 2 || argc > 3) {
  63. fprintf(stderr, "make_buildinfo $(ConfigurationName) [tmpdir]\n");
  64. return EXIT_FAILURE;
  65. }
  66. if (strcmp(argv[1], "Release") == 0) {
  67. strcat_s(command, CMD_SIZE, "-MD ");
  68. }
  69. else if (strcmp(argv[1], "Debug") == 0) {
  70. strcat_s(command, CMD_SIZE, "-D_DEBUG -MDd ");
  71. }
  72. else if (strcmp(argv[1], "ReleaseItanium") == 0) {
  73. strcat_s(command, CMD_SIZE, "-MD /USECL:MS_ITANIUM ");
  74. }
  75. else if (strcmp(argv[1], "ReleaseAMD64") == 0) {
  76. strcat_s(command, CMD_SIZE, "-MD ");
  77. strcat_s(command, CMD_SIZE, "-MD /USECL:MS_OPTERON ");
  78. }
  79. else {
  80. fprintf(stderr, "unsupported configuration %s\n", argv[1]);
  81. return EXIT_FAILURE;
  82. }
  83. if (argc > 2) {
  84. tmpdir = argv[2];
  85. strcat_s(tmppath, _countof(tmppath), tmpdir);
  86. /* Hack fix for bad command line: If the command is issued like this:
  87. * $(SolutionDir)make_buildinfo.exe" Debug "$(IntDir)"
  88. * we will get a trailing quote because IntDir ends with a backslash that then
  89. * escapes the final ". To simplify the life for developers, catch that problem
  90. * here by cutting it off.
  91. * The proper command line, btw is:
  92. * $(SolutionDir)make_buildinfo.exe" Debug "$(IntDir)\"
  93. * Hooray for command line parsing on windows.
  94. */
  95. if (strlen(tmppath) > 0 && tmppath[strlen(tmppath)-1] == '"')
  96. tmppath[strlen(tmppath)-1] = '\0';
  97. strcat_s(tmppath, _countof(tmppath), "\\");
  98. }
  99. if ((do_unlink = make_buildinfo2(tmppath))) {
  100. strcat_s(command, CMD_SIZE, "\"");
  101. strcat_s(command, CMD_SIZE, tmppath);
  102. strcat_s(command, CMD_SIZE, "getbuildinfo2.c\" -DSUBWCREV ");
  103. } else
  104. strcat_s(command, CMD_SIZE, "..\\Modules\\getbuildinfo.c");
  105. strcat_s(command, CMD_SIZE, " -Fo\"");
  106. strcat_s(command, CMD_SIZE, tmppath);
  107. strcat_s(command, CMD_SIZE, "getbuildinfo.o\" -I..\\Include -I..\\PC");
  108. puts(command); fflush(stdout);
  109. result = system(command);
  110. if (do_unlink) {
  111. command[0] = '\0';
  112. strcat_s(command, CMD_SIZE, "\"");
  113. strcat_s(command, CMD_SIZE, tmppath);
  114. strcat_s(command, CMD_SIZE, "getbuildinfo2.c\"");
  115. _unlink(command);
  116. }
  117. if (result < 0)
  118. return EXIT_FAILURE;
  119. return 0;
  120. }