1 /* $Id: buildno.c,v 1.5 2000/12/10 16:23:15 ea Exp $
3 * buildno - Generate the build number for ReactOS
5 * Copyright (c) 1999,2000 Emanuele Aliberti
9 * It assumes the last release date is defined in
10 * <reactos/version.h> as a macro named
14 * as a 32-bit unsigned long YYYYMMDD (UTC;
15 * MM=01-12; DD=01-31).
17 * The build number is the number of full days
18 * elapsed since the last release date (UTC).
20 * The build number is stored in the file
21 * <reactos/buildno.h> as a set of macros:
23 * KERNEL_VERSION_BUILD base 10 number
24 * KERNEL_VERSION_BUILD_STR C string
25 * KERNEL_VERSION_BUILD_RC RC string
30 * Fixed bugs: tm_year is (current_year - 1900),
31 * tm_month is 0-11 not 1-12 and code ignored TZ.
33 * Added -p option to make it simply print the
34 * version number, but skip buildno.h generation.
39 #include "../../include/reactos/version.h"
44 /* File to (over)write */
45 #define BUILDNO_INCLUDE_FILE "../../include/reactos/buildno.h"
47 static char * argv0
= "";
51 tm_dump (const char *tag
, struct tm
* t
)
53 printf ("%s->tm_sec = %d\n", tag
, t
->tm_sec
);
54 printf ("%s->tm_min = %d\n", tag
, t
->tm_min
);
55 printf ("%s->tm_hour = %d\n", tag
, t
->tm_hour
);
56 printf ("%s->tm_mday = %d\n", tag
, t
->tm_mday
);
57 printf ("%s->tm_mon = %d\n", tag
, t
->tm_mon
);
58 printf ("%s->tm_year = %d\n", tag
, t
->tm_year
);
59 printf ("%s->tm_wday = %d\n", tag
, t
->tm_wday
);
60 printf ("%s->tm_yday = %d\n", tag
, t
->tm_yday
);
61 printf ("%s->tm_isdst = %d\n\n", tag
, t
->tm_isdst
);
72 double seconds
= difftime (t_today
, t_release_day
);
73 double days
= seconds
/ (double) 86400.0;
77 sprintf (buf
, "%f", days
);
79 while ( *dot
&& *dot
!= '.') ++dot
;
90 h
= fopen ( BUILDNO_INCLUDE_FILE
, "w");
95 "%s: can not create file \"%s\"!\n",
103 "/* Do not edit - Machine generated */\n"
106 fprintf (h
, "#ifndef _INC_REACTOS_BUILDNO\n" );
107 fprintf (h
, "#define _INC_REACTOS_BUILDNO\n" );
111 "#define KERNEL_VERSION_BUILD\t%d\n",
116 "#define KERNEL_VERSION_BUILD_STR\t\"%d\"\n",
121 "#define KERNEL_RELEASE_RC\t\"%d.%d.%d.%d\\0\"\n",
122 KERNEL_VERSION_MAJOR
,
123 KERNEL_VERSION_MINOR
,
124 KERNEL_VERSION_PATCH_LEVEL
,
129 "#define KERNEL_RELEASE_STR\t\"%d.%d.%d.%d\"\n",
130 KERNEL_VERSION_MAJOR
,
131 KERNEL_VERSION_MINOR
,
132 KERNEL_VERSION_PATCH_LEVEL
,
137 "#define KERNEL_VERSION_RC\t\"%d.%d.%d\\0\"\n",
138 KERNEL_VERSION_MAJOR
,
139 KERNEL_VERSION_MINOR
,
140 KERNEL_VERSION_PATCH_LEVEL
144 "#define KERNEL_VERSION_STR\t\"%d.%d.%d\"\n",
145 KERNEL_VERSION_MAJOR
,
146 KERNEL_VERSION_MINOR
,
147 KERNEL_VERSION_PATCH_LEVEL
151 "#endif\n/* EOF */\n"
162 "Usage: %s [-{p|q}]\n\n -p print version number and exit\n -q run in quiet mode\n",
170 main (int argc
, char * argv
[])
172 int print_only
= FALSE
;
181 struct tm t0_tm
= {0};
183 struct tm
* t1_tm
= NULL
;
192 if (argv
[1][0] == '-')
194 if (argv
[1][1] == 'q')
198 else if (argv
[1][1] == 'p')
216 * Set TZ information.
220 * We are building TODAY!
224 * "Parse" the release date.
226 day
= KERNEL_RELEASE_DATE
% 100;
227 month
= ( ( KERNEL_RELEASE_DATE
234 ( KERNEL_RELEASE_DATE
242 ReactOS Build Number Generator\n\n\
243 Last release: %4d-%02d-%02d\n",
250 tm_dump ("t0", & t0_tm
);
252 t0_tm
.tm_year
= (year
- 1900);
253 t0_tm
.tm_mon
= --month
; /* 0-11 */
261 tm_dump ("t0", & t0_tm
);
264 if (-1 == (t0
= mktime (& t0_tm
)))
268 "%s: can not convert release date!\n",
274 time (& t1
); /* current build time */
275 t1_tm
= gmtime (& t1
);
278 tm_dump ("t1", t1_tm
);
281 (t1_tm
->tm_year
< 70)
285 tm_dump ("t1", t1_tm
);
290 "Current date: %4d-%02d-%02d\n\n",
297 * Compute delta days.
299 build
= elapsed_days (t1
, t0
);
304 "Build number: %d (elapsed days since last release)\n",
308 "ROS Version : %d.%d.%d.%d\n",
309 KERNEL_VERSION_MAJOR
,
310 KERNEL_VERSION_MINOR
,
311 KERNEL_VERSION_PATCH_LEVEL
,
316 * (Over)write the include file, unless
317 * the user switched on -p.
319 if (FALSE
== print_only
)
325 printf ("%s: no code generated", argv
[0]);