From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) by mx.groups.io with SMTP id smtpd.web11.394.1595608682908691608 for ; Fri, 24 Jul 2020 09:38:03 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@akeo-ie.20150623.gappssmtp.com header.s=20150623 header.b=dCw8PktG; spf=none, err=permanent DNS error (domain: akeo.ie, ip: 209.85.128.41, mailfrom: pete@akeo.ie) Received: by mail-wm1-f41.google.com with SMTP id k20so1155031wmi.5 for ; Fri, 24 Jul 2020 09:38:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=akeo-ie.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=hqToHTcylkFEr2PKSW1Wz4dPoXQ6HPiSOWS8NNC++YM=; b=dCw8PktG8xYW5S1h5kfzbU16R61l4dGgq6tfj5kwIKjNBKDrrjkAgZu50BpadvtBQo KfTc559yM2r/cW+L0ZcP0CwfOeZt+Ba9NGNIfcspdTWtJ5+MG4iV1YBrqvG5/4BwyZ75 Boj7QP7dD6zj07DUrsKdByMt0ctiXohInKUh6D+mkceRtTeGj8UuV5bhsYRoz8G6umYU eqGNY9GnCPbONTGeI6oGV3feKBqI8WPwm/p5ceVKy6DJyD+OKkHGfC8LqbGqPJ99ed2G 21nUjyg6oYZ/5XNmnQByRG26mzWTUSxyGq+vUnpo0OzfatefvM8nvUabcWLvWXZf57QK l29g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=hqToHTcylkFEr2PKSW1Wz4dPoXQ6HPiSOWS8NNC++YM=; b=DcNHml3ThrYi6FmauEfOsvWi6CHmgmYYQZlJDYFPTdzgWFN+QtEsd/DNIlmzCwGHwc vw5+FwAcizE+8nkZtBxm8InN5oCYEVi5JVrjphMfNm7QaI8Y8E1lzLkM/zZq4RKjZtPr a1O85GhkcpdphdPICnzlEcigE17Z1wRmmmdAG3UDugKTSIU2zJ5iQ9Tw0zPc1/HOH90W 44udS6/Dzul+oAOVccAy75418bz9k0i5XfxDuYctgQ5StnJXVguyLXg4shCiigIwmAB7 U0IBkgc+79NTJilQBNtEyNaUaBAXJz6pW2ceLbPaLd408O4ZdvqiLwFd128CYTAi30xD zjvg== X-Gm-Message-State: AOAM531+KgVX5ZsbVQpuOK2FRj5pu+gN3WfWKVJbIB2Imvsw3vUY4Rw7 RyS3LssxHH55c1QrLK/psj4hQ1h5apCqyQ== X-Google-Smtp-Source: ABdhPJygQHVic/ORUm0BgvwZpoP3yB2pu9I7MXIKuVtseCm7Mci0RDfmZc4PwJtby+WSZv5kxjTttQ== X-Received: by 2002:a1c:1d2:: with SMTP id 201mr8898738wmb.132.1595608677035; Fri, 24 Jul 2020 09:37:57 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([84.203.55.132]) by smtp.gmail.com with ESMTPSA id 62sm2064882wrq.31.2020.07.24.09.37.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 24 Jul 2020 09:37:55 -0700 (PDT) From: "Pete Batard" To: devel@edk2.groups.io Cc: ard.biesheuvel@arm.com, leif@nuviainc.com Subject: [PATCH 1/1] EmbeddedPkg/TimeBaseLib: Add macros to get build year/month/day Date: Fri, 24 Jul 2020 17:37:42 +0100 Message-Id: <20200724163742.5828-1-pete@akeo.ie> X-Mailer: git-send-email 2.21.0.windows.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit These can be used, for instance, to automate the population of an SMBIOS Type 0 BIOS Release Date when building a UEFI firmware (which is how we plan to use these macros for the Raspberry Pi platform). These macros should work for any compiler that follows ISO/IEC 9899, but we add a check for the compiler we have tested to be on the safe side. Note that we decided against adding a #error or #warn for compilers that haven't been validated, as we don't want to introduce breakage for people who may already be using the header with something else than gcc, MSVC or Clang. Instead, we expect those to send a patch that adds their compiler to the list, once they have tested the macros there. Signed-off-by: Pete Batard --- EmbeddedPkg/Include/Library/TimeBaseLib.h | 32 ++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/EmbeddedPkg/Include/Library/TimeBaseLib.h b/EmbeddedPkg/Include/Library/TimeBaseLib.h index 4103c89b3891..ee2f191d985b 100644 --- a/EmbeddedPkg/Include/Library/TimeBaseLib.h +++ b/EmbeddedPkg/Include/Library/TimeBaseLib.h @@ -12,6 +12,38 @@ #include +// +// Convenience macros to obtain a build date +// +// These macros should work for any compiler that follows ISO/IEC 9899, +// in which case __DATE__ is defined as a "Mmm dd yyyy" 11 chars string, +// but add an explicit filter for compilers that have been validated. +// +#if (defined(__GNUC__) || defined(_MSC_VER) || defined(__clang__)) +#define TIME_BUILD_YEAR (__DATE__[7] == '?' ? 1900 \ + : (((__DATE__[7] - '0') * 1000 ) \ + + (__DATE__[8] - '0') * 100 \ + + (__DATE__[9] - '0') * 10 \ + + __DATE__[10] - '0')) +#define TIME_BUILD_MONTH ( __DATE__ [2] == '?' ? 1 \ + : __DATE__ [2] == 'n' ? ( \ + __DATE__ [1] == 'a' ? 1 : 6) \ + : __DATE__ [2] == 'b' ? 2 \ + : __DATE__ [2] == 'r' ? ( \ + __DATE__ [0] == 'M' ? 3 : 4) \ + : __DATE__ [2] == 'y' ? 5 \ + : __DATE__ [2] == 'l' ? 7 \ + : __DATE__ [2] == 'g' ? 8 \ + : __DATE__ [2] == 'p' ? 9 \ + : __DATE__ [2] == 't' ? 10 \ + : __DATE__ [2] == 'v' ? 11 \ + : 12) +#define TIME_BUILD_DAY ( __DATE__[4] == '?' ? 1 \ + : ((__DATE__[4] == ' ' ? 0 : \ + ((__DATE__[4] - '0') * 10)) \ + + __DATE__[5] - '0')) +#endif + // Define EPOCH (1970-JANUARY-01) in the Julian Date representation #define EPOCH_JULIAN_DATE 2440588 -- 2.21.0.windows.1