35 int main(int argc, char **argv) |
36 int main(int argc, char **argv) |
36 { |
37 { |
37 char vertag[128], lastlog[128], lasthash[128], *hash = NULL; |
38 char vertag[128], lastlog[128], lasthash[128], *hash = NULL; |
38 FILE *stream = NULL; |
39 FILE *stream = NULL; |
39 int gotrev = 0, needupdate = 1; |
40 int gotrev = 0, needupdate = 1; |
|
41 |
|
42 // [SP] Stuff for build time. |
|
43 time_t now; |
|
44 char currentTime[128]; |
|
45 char* cp; |
40 |
46 |
41 vertag[0] = '\0'; |
47 vertag[0] = '\0'; |
42 lastlog[0] = '\0'; |
48 lastlog[0] = '\0'; |
43 |
49 |
44 if (argc != 2) |
50 if (argc != 2) |
94 return 0; |
100 return 0; |
95 } |
101 } |
96 // Read the revision that's in this file already. If it's the same as |
102 // Read the revision that's in this file already. If it's the same as |
97 // what we've got, then we don't need to modify it and can avoid rebuilding |
103 // what we've got, then we don't need to modify it and can avoid rebuilding |
98 // dependant files. |
104 // dependant files. |
|
105 // [SP] I'm including build date in the file now so it must always be rebuilt. |
|
106 // In LDForge, this is ony used by the very-quick-to-build version.cc anyway. |
|
107 #if 0 |
99 if (fgets(lasthash, sizeof lasthash, stream) == lasthash) |
108 if (fgets(lasthash, sizeof lasthash, stream) == lasthash) |
100 { |
109 { |
101 stripnl(lasthash); |
110 stripnl(lasthash); |
102 if (strcmp(hash, lasthash + 3) == 0) |
111 if (strcmp(hash, lasthash + 3) == 0) |
103 { |
112 { |
104 needupdate = 0; |
113 needupdate = 0; |
105 } |
114 } |
106 } |
115 } |
|
116 #endif |
107 fclose (stream); |
117 fclose (stream); |
|
118 } |
|
119 |
|
120 // [SP] Current time. |
|
121 now = time (NULL); |
|
122 strftime (currentTime, sizeof currentTime, "%F %T %z", localtime (&now)); |
|
123 |
|
124 // [SP] For some dumb reason asctime includes a newline character. Get rid of it. |
|
125 for (cp = ¤tTime[0]; *cp != '\0'; ++cp) |
|
126 { |
|
127 if (*cp == '\n') |
|
128 { |
|
129 *cp = '\0'; |
|
130 break; |
|
131 } |
108 } |
132 } |
109 |
133 |
110 if (needupdate) |
134 if (needupdate) |
111 { |
135 { |
112 stream = fopen (argv[1], "w"); |
136 stream = fopen (argv[1], "w"); |
120 "// This file was automatically generated by the\n" |
144 "// This file was automatically generated by the\n" |
121 "// updaterevision tool. Do not edit by hand.\n" |
145 "// updaterevision tool. Do not edit by hand.\n" |
122 "\n" |
146 "\n" |
123 "#define GIT_DESCRIPTION \"%s\"\n" |
147 "#define GIT_DESCRIPTION \"%s\"\n" |
124 "#define GIT_HASH \"%s\"\n" |
148 "#define GIT_HASH \"%s\"\n" |
125 "#define GIT_TIME \"%s\"\n", |
149 "#define GIT_TIME \"%s\"\n" |
126 hash, vertag, hash, lastlog); |
150 "#define BUILD_TIME \"%s\"\n", |
|
151 hash, vertag, hash, lastlog, currentTime); |
127 fclose(stream); |
152 fclose(stream); |
128 fprintf(stderr, "%s updated to commit %s.\n", argv[1], vertag); |
153 fprintf(stderr, "%s updated to commit %s (build time: %s).\n", argv[1], vertag, currentTime); |
129 } |
154 } |
130 else |
155 else |
131 { |
156 { |
132 fprintf (stderr, "%s is up to date at commit %s.\n", argv[1], vertag); |
157 fprintf (stderr, "%s is up to date at commit %s.\n", argv[1], vertag); |
133 } |
158 } |