/PC/VS8.0/make_buildinfo.c

http://unladen-swallow.googlecode.com/ · C · 94 lines · 74 code · 3 blank · 17 comment · 6 complexity · 3301a8e830d27b7a968076520325524f MD5 · raw file

  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. */
  18. int make_buildinfo2()
  19. {
  20. struct _stat st;
  21. HKEY hTortoise;
  22. char command[CMD_SIZE+1];
  23. DWORD type, size;
  24. if (_stat(".svn", &st) < 0)
  25. return 0;
  26. /* Allow suppression of subwcrev.exe invocation if a no_subwcrev file is present. */
  27. if (_stat("no_subwcrev", &st) == 0)
  28. return 0;
  29. if (RegOpenKey(HKEY_LOCAL_MACHINE, "Software\\TortoiseSVN", &hTortoise) != ERROR_SUCCESS &&
  30. RegOpenKey(HKEY_CURRENT_USER, "Software\\TortoiseSVN", &hTortoise) != ERROR_SUCCESS)
  31. /* Tortoise not installed */
  32. return 0;
  33. command[0] = '"'; /* quote the path to the executable */
  34. size = sizeof(command) - 1;
  35. if (RegQueryValueEx(hTortoise, "Directory", 0, &type, command+1, &size) != ERROR_SUCCESS ||
  36. type != REG_SZ)
  37. /* Registry corrupted */
  38. return 0;
  39. strcat_s(command, CMD_SIZE, "bin\\subwcrev.exe");
  40. if (_stat(command+1, &st) < 0)
  41. /* subwcrev.exe not part of the release */
  42. return 0;
  43. strcat_s(command, CMD_SIZE, "\" ..\\.. ..\\..\\Modules\\getbuildinfo.c getbuildinfo2.c");
  44. puts(command); fflush(stdout);
  45. if (system(command) < 0)
  46. return 0;
  47. return 1;
  48. }
  49. int main(int argc, char*argv[])
  50. {
  51. char command[500] = "cl.exe -c -D_WIN32 -DUSE_DL_EXPORT -D_WINDOWS -DWIN32 -D_WINDLL ";
  52. int do_unlink, result;
  53. if (argc != 2) {
  54. fprintf(stderr, "make_buildinfo $(ConfigurationName)\n");
  55. return EXIT_FAILURE;
  56. }
  57. if (strcmp(argv[1], "Release") == 0) {
  58. strcat_s(command, CMD_SIZE, "-MD ");
  59. }
  60. else if (strcmp(argv[1], "Debug") == 0) {
  61. strcat_s(command, CMD_SIZE, "-D_DEBUG -MDd ");
  62. }
  63. else if (strcmp(argv[1], "ReleaseItanium") == 0) {
  64. strcat_s(command, CMD_SIZE, "-MD /USECL:MS_ITANIUM ");
  65. }
  66. else if (strcmp(argv[1], "ReleaseAMD64") == 0) {
  67. strcat_s(command, CMD_SIZE, "-MD ");
  68. strcat_s(command, CMD_SIZE, "-MD /USECL:MS_OPTERON ");
  69. }
  70. else {
  71. fprintf(stderr, "unsupported configuration %s\n", argv[1]);
  72. return EXIT_FAILURE;
  73. }
  74. if ((do_unlink = make_buildinfo2()))
  75. strcat_s(command, CMD_SIZE, "getbuildinfo2.c -DSUBWCREV ");
  76. else
  77. strcat_s(command, CMD_SIZE, "..\\..\\Modules\\getbuildinfo.c");
  78. strcat_s(command, CMD_SIZE, " -Fogetbuildinfo.o -I..\\..\\Include -I..\\..\\PC");
  79. puts(command); fflush(stdout);
  80. result = system(command);
  81. if (do_unlink)
  82. _unlink("getbuildinfo2.c");
  83. if (result < 0)
  84. return EXIT_FAILURE;
  85. return 0;
  86. }