PHiLIP
build_defs.h
1 /*
2  * build_defs.h
3  *
4  * Created on: May 17, 2018
5  * Author: steveha from stackoverflow.com
6  * URL: https://stackoverflow.com/questions/11697820/how-to-use-date-and-time-predefined-macros-in-as-two-integers-then-stri
7  */
8 
9 #ifndef BUILD_DEFS_H_
10 #define BUILD_DEFS_H_
11 
12 // Example of __DATE__ string: "Jul 27 2012"
13 // Example of __TIME__ string: "21:06:19"
14 
15 #define COMPUTE_BUILD_YEAR \
16  ( \
17  (__DATE__[ 9] - '0') * 10 + \
18  (__DATE__[10] - '0') \
19  )
20 
21 #define COMPUTE_BUILD_DAY \
22  ( \
23  ((__DATE__[4] >= '0') ? (__DATE__[4] - '0') * 10 : 0) + \
24  (__DATE__[5] - '0') \
25  )
26 
27 #define BUILD_MONTH_IS_JAN (__DATE__[0] == 'J' && __DATE__[1] == 'a' && __DATE__[2] == 'n')
28 #define BUILD_MONTH_IS_FEB (__DATE__[0] == 'F')
29 #define BUILD_MONTH_IS_MAR (__DATE__[0] == 'M' && __DATE__[1] == 'a' && __DATE__[2] == 'r')
30 #define BUILD_MONTH_IS_APR (__DATE__[0] == 'A' && __DATE__[1] == 'p')
31 #define BUILD_MONTH_IS_MAY (__DATE__[0] == 'M' && __DATE__[1] == 'a' && __DATE__[2] == 'y')
32 #define BUILD_MONTH_IS_JUN (__DATE__[0] == 'J' && __DATE__[1] == 'u' && __DATE__[2] == 'n')
33 #define BUILD_MONTH_IS_JUL (__DATE__[0] == 'J' && __DATE__[1] == 'u' && __DATE__[2] == 'l')
34 #define BUILD_MONTH_IS_AUG (__DATE__[0] == 'A' && __DATE__[1] == 'u')
35 #define BUILD_MONTH_IS_SEP (__DATE__[0] == 'S')
36 #define BUILD_MONTH_IS_OCT (__DATE__[0] == 'O')
37 #define BUILD_MONTH_IS_NOV (__DATE__[0] == 'N')
38 #define BUILD_MONTH_IS_DEC (__DATE__[0] == 'D')
39 
40 #define COMPUTE_BUILD_MONTH \
41  ( \
42  (BUILD_MONTH_IS_JAN) ? 1 : \
43  (BUILD_MONTH_IS_FEB) ? 2 : \
44  (BUILD_MONTH_IS_MAR) ? 3 : \
45  (BUILD_MONTH_IS_APR) ? 4 : \
46  (BUILD_MONTH_IS_MAY) ? 5 : \
47  (BUILD_MONTH_IS_JUN) ? 6 : \
48  (BUILD_MONTH_IS_JUL) ? 7 : \
49  (BUILD_MONTH_IS_AUG) ? 8 : \
50  (BUILD_MONTH_IS_SEP) ? 9 : \
51  (BUILD_MONTH_IS_OCT) ? 10 : \
52  (BUILD_MONTH_IS_NOV) ? 11 : \
53  (BUILD_MONTH_IS_DEC) ? 12 : \
54  /* error default */ 99 \
55  )
56 
57 #define COMPUTE_BUILD_HOUR ((__TIME__[0] - '0') * 10 + __TIME__[1] - '0')
58 #define COMPUTE_BUILD_MIN ((__TIME__[3] - '0') * 10 + __TIME__[4] - '0')
59 #define COMPUTE_BUILD_SEC ((__TIME__[6] - '0') * 10 + __TIME__[7] - '0')
60 
61 #define BUILD_DATE_IS_BAD (__DATE__[0] == '?')
62 
63 #define BUILD_YEAR ((BUILD_DATE_IS_BAD) ? 99 : COMPUTE_BUILD_YEAR)
64 #define BUILD_MONTH ((BUILD_DATE_IS_BAD) ? 99 : COMPUTE_BUILD_MONTH)
65 #define BUILD_DAY ((BUILD_DATE_IS_BAD) ? 99 : COMPUTE_BUILD_DAY)
66 
67 #define BUILD_TIME_IS_BAD (__TIME__[0] == '?')
68 
69 #define BUILD_HOUR ((BUILD_TIME_IS_BAD) ? 99 : COMPUTE_BUILD_HOUR)
70 #define BUILD_MIN ((BUILD_TIME_IS_BAD) ? 99 : COMPUTE_BUILD_MIN)
71 #define BUILD_SEC ((BUILD_TIME_IS_BAD) ? 99 : COMPUTE_BUILD_SEC)
72 
73 #endif /* BUILD_DEFS_H_ */