/PC/VS7.1/make_buildinfo.c

http://unladen-swallow.googlecode.com/ · C · 92 lines · 73 code · 2 blank · 17 comment · 6 complexity · d5aac08014da4bc82f90b0888355412f MD5 · raw file

  1. #include <windows.h>
  2. #include <sys/types.h>
  3. #include <sys/stat.h>
  4. #include <stdio.h>
  5. /* This file creates the getbuildinfo.o object, by first
  6. invoking subwcrev.exe (if found), and then invoking cl.exe.
  7. As a side effect, it might generate PC\VS7.1\getbuildinfo2.c
  8. also. If this isn't a subversion checkout, or subwcrev isn't
  9. found, it compiles ..\\..\\Modules\\getbuildinfo.c instead.
  10. Currently, subwcrev.exe is found from the registry entries
  11. of TortoiseSVN.
  12. No attempt is made to place getbuildinfo.o into the proper
  13. binary directory. This isn't necessary, as this tool is
  14. invoked as a pre-link step for pythoncore, so that overwrites
  15. any previous getbuildinfo.o.
  16. */
  17. int make_buildinfo2()
  18. {
  19. struct _stat st;
  20. HKEY hTortoise;
  21. char command[500];
  22. DWORD type, size;
  23. if (_stat(".svn", &st) < 0)
  24. return 0;
  25. /* Allow suppression of subwcrev.exe invocation if a no_subwcrev file is present. */
  26. if (_stat("no_subwcrev", &st) == 0)
  27. return 0;
  28. if (RegOpenKey(HKEY_LOCAL_MACHINE, "Software\\TortoiseSVN", &hTortoise) != ERROR_SUCCESS &&
  29. RegOpenKey(HKEY_CURRENT_USER, "Software\\TortoiseSVN", &hTortoise) != ERROR_SUCCESS)
  30. /* Tortoise not installed */
  31. return 0;
  32. command[0] = '"'; /* quote the path to the executable */
  33. size = sizeof(command) - 1;
  34. if (RegQueryValueEx(hTortoise, "Directory", 0, &type, command+1, &size) != ERROR_SUCCESS ||
  35. type != REG_SZ)
  36. /* Registry corrupted */
  37. return 0;
  38. strcat(command, "bin\\subwcrev.exe");
  39. if (_stat(command+1, &st) < 0)
  40. /* subwcrev.exe not part of the release */
  41. return 0;
  42. strcat(command, "\" ..\\.. ..\\..\\Modules\\getbuildinfo.c getbuildinfo2.c");
  43. puts(command); fflush(stdout);
  44. if (system(command) < 0)
  45. return 0;
  46. return 1;
  47. }
  48. int main(int argc, char*argv[])
  49. {
  50. char command[500] = "cl.exe -c -D_WIN32 -DUSE_DL_EXPORT -D_WINDOWS -DWIN32 -D_WINDLL ";
  51. int do_unlink, result;
  52. if (argc != 2) {
  53. fprintf(stderr, "make_buildinfo $(ConfigurationName)\n");
  54. return EXIT_FAILURE;
  55. }
  56. if (strcmp(argv[1], "Release") == 0) {
  57. strcat(command, "-MD ");
  58. }
  59. else if (strcmp(argv[1], "Debug") == 0) {
  60. strcat(command, "-D_DEBUG -MDd ");
  61. }
  62. else if (strcmp(argv[1], "ReleaseItanium") == 0) {
  63. strcat(command, "-MD /USECL:MS_ITANIUM ");
  64. }
  65. else if (strcmp(argv[1], "ReleaseAMD64") == 0) {
  66. strcat(command, "-MD ");
  67. strcat(command, "-MD /USECL:MS_OPTERON ");
  68. }
  69. else {
  70. fprintf(stderr, "unsupported configuration %s\n", argv[1]);
  71. return EXIT_FAILURE;
  72. }
  73. if ((do_unlink = make_buildinfo2()))
  74. strcat(command, "getbuildinfo2.c -DSUBWCREV ");
  75. else
  76. strcat(command, "..\\..\\Modules\\getbuildinfo.c");
  77. strcat(command, " -Fogetbuildinfo.o -I..\\..\\Include -I..\\..\\PC");
  78. puts(command); fflush(stdout);
  79. result = system(command);
  80. if (do_unlink)
  81. unlink("getbuildinfo2.c");
  82. if (result < 0)
  83. return EXIT_FAILURE;
  84. return 0;
  85. }