1 /* $Id: buildno.c,v 1.1 2001/08/23 21:41:35 ekohl 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
;
93 s1
= s
= malloc(256 * 1024);
95 s
= s
+ sprintf (s
, "/* Do not edit - Machine generated */\n");
97 s
= s
+ sprintf (s
, "#ifndef _INC_REACTOS_BUILDNO\n" );
98 s
= s
+ sprintf (s
, "#define _INC_REACTOS_BUILDNO\n" );
100 s
= s
+ sprintf (s
, "#define KERNEL_VERSION_BUILD\t%d\n", build
);
101 s
= s
+ sprintf (s
, "#define KERNEL_VERSION_BUILD_STR\t\"%d\"\n", build
);
102 s
= s
+ sprintf (s
, "#define KERNEL_RELEASE_RC\t\"%d.%d.%d.%d\\0\"\n",
103 KERNEL_VERSION_MAJOR
, KERNEL_VERSION_MINOR
,
104 KERNEL_VERSION_PATCH_LEVEL
, build
);
105 s
= s
+ sprintf (s
, "#define KERNEL_RELEASE_STR\t\"%d.%d.%d.%d\"\n",
106 KERNEL_VERSION_MAJOR
,
107 KERNEL_VERSION_MINOR
,
108 KERNEL_VERSION_PATCH_LEVEL
,
110 s
= s
+ sprintf (s
, "#define KERNEL_VERSION_RC\t\"%d.%d.%d\\0\"\n",
111 KERNEL_VERSION_MAJOR
,
112 KERNEL_VERSION_MINOR
,
113 KERNEL_VERSION_PATCH_LEVEL
);
114 s
= s
+ sprintf (s
, "#define KERNEL_VERSION_STR\t\"%d.%d.%d\"\n",
115 KERNEL_VERSION_MAJOR
,
116 KERNEL_VERSION_MINOR
,
117 KERNEL_VERSION_PATCH_LEVEL
);
118 s
= s
+ sprintf (s
, "#endif\n/* EOF */\n");
120 h
= fopen (BUILDNO_INCLUDE_FILE
, "r");
123 fseek(h
, 0, SEEK_END
);
125 if (length
== strlen(s1
))
129 orig
= malloc(length
);
130 fseek(h
, 0, SEEK_SET
);
131 fread(orig
, 1, length
, h
);
132 if (memcmp(s1
, orig
, length
) == 0)
141 h
= fopen (BUILDNO_INCLUDE_FILE
, "w");
145 "%s: can not create file \"%s\"!\n",
147 BUILDNO_INCLUDE_FILE
);
150 fwrite(s1
, 1, strlen(s1
), h
);
159 "Usage: %s [-{p|q}]\n\n -p print version number and exit\n -q run in quiet mode\n",
167 main (int argc
, char * argv
[])
169 int print_only
= FALSE
;
178 struct tm t0_tm
= {0};
180 struct tm
* t1_tm
= NULL
;
189 if (argv
[1][0] == '-')
191 if (argv
[1][1] == 'q')
195 else if (argv
[1][1] == 'p')
213 * Set TZ information.
217 * We are building TODAY!
221 * "Parse" the release date.
223 day
= KERNEL_RELEASE_DATE
% 100;
224 month
= ( ( KERNEL_RELEASE_DATE
231 ( KERNEL_RELEASE_DATE
239 ReactOS Build Number Generator\n\n\
240 Last release: %4d-%02d-%02d\n",
247 tm_dump ("t0", & t0_tm
);
249 t0_tm
.tm_year
= (year
- 1900);
250 t0_tm
.tm_mon
= --month
; /* 0-11 */
258 tm_dump ("t0", & t0_tm
);
261 if (-1 == (t0
= mktime (& t0_tm
)))
265 "%s: can not convert release date!\n",
271 time (& t1
); /* current build time */
272 t1_tm
= gmtime (& t1
);
275 tm_dump ("t1", t1_tm
);
278 (t1_tm
->tm_year
< 70)
282 tm_dump ("t1", t1_tm
);
287 "Current date: %4d-%02d-%02d\n\n",
294 * Compute delta days.
296 build
= elapsed_days (t1
, t0
);
301 "Build number: %d (elapsed days since last release)\n",
305 "ROS Version : %d.%d.%d.%d\n",
306 KERNEL_VERSION_MAJOR
,
307 KERNEL_VERSION_MINOR
,
308 KERNEL_VERSION_PATCH_LEVEL
,
313 * (Over)write the include file, unless
314 * the user switched on -p.
316 if (FALSE
== print_only
)
322 printf ("%s: no code generated", argv
[0]);