blob: 22b9882477af39ed420f072b26f127d4dd8fd476 [file] [log] [blame]
Tim Peters84457af2006-03-09 01:59:27 +00001#include <windows.h>
2#include <sys/types.h>
3#include <sys/stat.h>
4#include <stdio.h>
5
Christian Heimes5b5e81c2007-12-31 16:14:33 +00006#define CMD_SIZE 500
7
Tim Peters84457af2006-03-09 01:59:27 +00008/* This file creates the getbuildinfo.o object, by first
9 invoking subwcrev.exe (if found), and then invoking cl.exe.
10 As a side effect, it might generate PCBuild\getbuildinfo2.c
11 also. If this isn't a subversion checkout, or subwcrev isn't
12 found, it compiles ..\\Modules\\getbuildinfo.c instead.
13
14 Currently, subwcrev.exe is found from the registry entries
15 of TortoiseSVN.
16
17 No attempt is made to place getbuildinfo.o into the proper
18 binary directory. This isn't necessary, as this tool is
19 invoked as a pre-link step for pythoncore, so that overwrites
20 any previous getbuildinfo.o.
21
22*/
23
24int make_buildinfo2()
25{
26 struct _stat st;
27 HKEY hTortoise;
Christian Heimes5b5e81c2007-12-31 16:14:33 +000028 char command[CMD_SIZE+1];
Tim Peters84457af2006-03-09 01:59:27 +000029 DWORD type, size;
30 if (_stat(".svn", &st) < 0)
31 return 0;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000032 /* Allow suppression of subwcrev.exe invocation if a no_subwcrev file is present. */
33 if (_stat("no_subwcrev", &st) == 0)
34 return 0;
Tim Peters84457af2006-03-09 01:59:27 +000035 if (RegOpenKey(HKEY_LOCAL_MACHINE, "Software\\TortoiseSVN", &hTortoise) != ERROR_SUCCESS &&
36 RegOpenKey(HKEY_CURRENT_USER, "Software\\TortoiseSVN", &hTortoise) != ERROR_SUCCESS)
37 /* Tortoise not installed */
38 return 0;
39 command[0] = '"'; /* quote the path to the executable */
40 size = sizeof(command) - 1;
41 if (RegQueryValueEx(hTortoise, "Directory", 0, &type, command+1, &size) != ERROR_SUCCESS ||
42 type != REG_SZ)
43 /* Registry corrupted */
44 return 0;
Christian Heimes5b5e81c2007-12-31 16:14:33 +000045 strcat_s(command, CMD_SIZE, "bin\\subwcrev.exe");
Tim Peters84457af2006-03-09 01:59:27 +000046 if (_stat(command+1, &st) < 0)
47 /* subwcrev.exe not part of the release */
48 return 0;
Christian Heimes5b5e81c2007-12-31 16:14:33 +000049 strcat_s(command, CMD_SIZE, "\" .. ..\\Modules\\getbuildinfo.c getbuildinfo2.c");
Tim Peters84457af2006-03-09 01:59:27 +000050 puts(command); fflush(stdout);
51 if (system(command) < 0)
52 return 0;
53 return 1;
54}
55
56int main(int argc, char*argv[])
57{
58 char command[500] = "cl.exe -c -D_WIN32 -DUSE_DL_EXPORT -D_WINDOWS -DWIN32 -D_WINDLL ";
59 int do_unlink, result;
60 if (argc != 2) {
61 fprintf(stderr, "make_buildinfo $(ConfigurationName)\n");
62 return EXIT_FAILURE;
63 }
64 if (strcmp(argv[1], "Release") == 0) {
Christian Heimes5b5e81c2007-12-31 16:14:33 +000065 strcat_s(command, CMD_SIZE, "-MD ");
Tim Peters84457af2006-03-09 01:59:27 +000066 }
67 else if (strcmp(argv[1], "Debug") == 0) {
Christian Heimes5b5e81c2007-12-31 16:14:33 +000068 strcat_s(command, CMD_SIZE, "-D_DEBUG -MDd ");
Tim Peters84457af2006-03-09 01:59:27 +000069 }
70 else if (strcmp(argv[1], "ReleaseItanium") == 0) {
Christian Heimes5b5e81c2007-12-31 16:14:33 +000071 strcat_s(command, CMD_SIZE, "-MD /USECL:MS_ITANIUM ");
Tim Peters84457af2006-03-09 01:59:27 +000072 }
73 else if (strcmp(argv[1], "ReleaseAMD64") == 0) {
Christian Heimes5b5e81c2007-12-31 16:14:33 +000074 strcat_s(command, CMD_SIZE, "-MD ");
75 strcat_s(command, CMD_SIZE, "-MD /USECL:MS_OPTERON ");
Tim Peters84457af2006-03-09 01:59:27 +000076 }
77 else {
78 fprintf(stderr, "unsupported configuration %s\n", argv[1]);
79 return EXIT_FAILURE;
80 }
81
82 if ((do_unlink = make_buildinfo2()))
Christian Heimes5b5e81c2007-12-31 16:14:33 +000083 strcat_s(command, CMD_SIZE, "getbuildinfo2.c -DSUBWCREV ");
Tim Peters84457af2006-03-09 01:59:27 +000084 else
Christian Heimes5b5e81c2007-12-31 16:14:33 +000085 strcat_s(command, CMD_SIZE, "..\\Modules\\getbuildinfo.c");
86 strcat_s(command, CMD_SIZE, " -Fogetbuildinfo.o -I..\\Include -I..\\PC");
Tim Peters84457af2006-03-09 01:59:27 +000087 puts(command); fflush(stdout);
88 result = system(command);
89 if (do_unlink)
Christian Heimes5b5e81c2007-12-31 16:14:33 +000090 _unlink("getbuildinfo2.c");
Tim Peters84457af2006-03-09 01:59:27 +000091 if (result < 0)
92 return EXIT_FAILURE;
93 return 0;
Martin v. Löwis3150a272006-01-18 19:18:51 +000094}