]> git.proxmox.com Git - mirror_edk2.git/blobdiff - EmbeddedPkg/Include/Library/TimeBaseLib.h
EmbeddedPkg/TimeBaseLib: Add macros to get build year/month/day
[mirror_edk2.git] / EmbeddedPkg / Include / Library / TimeBaseLib.h
index dd0b99f2b612c601b96673408ce2e126d1fcf8bd..ee2f191d985b0deaa71e8927e6e97e792d4e08b4 100644 (file)
@@ -1,15 +1,9 @@
 /** @file\r
 *\r
 *  Copyright (c) 2016, Hisilicon Limited. All rights reserved.\r
-*  Copyright (c) 2016, Linaro Limited. All rights reserved.\r
+*  Copyright (c) 2016-2019, Linaro Limited. All rights reserved.\r
 *\r
-*  This program and the accompanying materials\r
-*  are licensed and made available under the terms and conditions of the BSD License\r
-*  which accompanies this distribution.  The full text of the license may be found at\r
-*  http://opensource.org/licenses/bsd-license.php\r
-*\r
-*  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-*  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+*  SPDX-License-Identifier: BSD-2-Clause-Patent\r
 *\r
 **/\r
 \r
 \r
 #include <Uefi/UefiBaseType.h>\r
 \r
+//\r
+// Convenience macros to obtain a build date\r
+//\r
+// These macros should work for any compiler that follows ISO/IEC 9899,\r
+// in which case __DATE__ is defined as a "Mmm dd yyyy" 11 chars string,\r
+// but add an explicit filter for compilers that have been validated.\r
+//\r
+#if (defined(__GNUC__) || defined(_MSC_VER) || defined(__clang__))\r
+#define TIME_BUILD_YEAR  (__DATE__[7] == '?' ? 1900 \\r
+          : (((__DATE__[7] - '0') * 1000 )          \\r
+          + (__DATE__[8] - '0') * 100               \\r
+          + (__DATE__[9] - '0') * 10                \\r
+          + __DATE__[10] - '0'))\r
+#define TIME_BUILD_MONTH ( __DATE__ [2] == '?' ? 1  \\r
+          : __DATE__ [2] == 'n' ? (                 \\r
+            __DATE__ [1] == 'a' ? 1 : 6)            \\r
+          : __DATE__ [2] == 'b' ? 2                 \\r
+          : __DATE__ [2] == 'r' ? (                 \\r
+            __DATE__ [0] == 'M' ? 3 : 4)            \\r
+          : __DATE__ [2] == 'y' ? 5                 \\r
+          : __DATE__ [2] == 'l' ? 7                 \\r
+          : __DATE__ [2] == 'g' ? 8                 \\r
+          : __DATE__ [2] == 'p' ? 9                 \\r
+          : __DATE__ [2] == 't' ? 10                \\r
+          : __DATE__ [2] == 'v' ? 11                \\r
+          : 12)\r
+#define TIME_BUILD_DAY ( __DATE__[4] == '?' ? 1     \\r
+          : ((__DATE__[4] == ' ' ? 0 :              \\r
+            ((__DATE__[4] - '0') * 10))             \\r
+          + __DATE__[5] - '0'))\r
+#endif\r
+\r
 // Define EPOCH (1970-JANUARY-01) in the Julian Date representation\r
 #define EPOCH_JULIAN_DATE                               2440588\r
 \r
@@ -59,7 +85,7 @@ EpochToEfiTime (
 /**\r
   Converts EFI_TIME to Epoch seconds (elapsed since 1970 JANUARY 01, 00:00:00 UTC)\r
  **/\r
-UINTN\r
+UINT32\r
 EFIAPI\r
 EfiTimeToEpoch (\r
   IN  EFI_TIME  *Time\r