mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 18:22:07 +00:00
Support SOURCE_DATE_EPOCH for reproducible builds
See https://reproducible-builds.org/docs/source-date-epoch/ Fixes #286
This commit is contained in:
@@ -12,6 +12,7 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
#include "asm/section.h"
|
#include "asm/section.h"
|
||||||
|
|
||||||
@@ -140,7 +141,7 @@ struct Symbol *sym_AddMacro(char const *symName, int32_t defLineNo, char *body,
|
|||||||
struct Symbol *sym_Ref(char const *symName);
|
struct Symbol *sym_Ref(char const *symName);
|
||||||
struct Symbol *sym_AddString(char const *symName, char const *value);
|
struct Symbol *sym_AddString(char const *symName, char const *value);
|
||||||
void sym_Purge(char const *symName);
|
void sym_Purge(char const *symName);
|
||||||
void sym_Init(void);
|
void sym_Init(time_t now);
|
||||||
|
|
||||||
/* Functions to save and restore the current symbol scope. */
|
/* Functions to save and restore the current symbol scope. */
|
||||||
char const *sym_GetCurrentSymbolScope(void);
|
char const *sym_GetCurrentSymbolScope(void);
|
||||||
|
|||||||
@@ -218,7 +218,7 @@ static char *make_escape(const char *str)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Short options */
|
/* Short options */
|
||||||
static char const *optstring = "b:D:Eg:hi:LM:o:p:r:VvW:w";
|
static const char *optstring = "b:D:Eg:hi:LM:o:p:r:VvW:w";
|
||||||
|
|
||||||
/* Variables for the long-only options */
|
/* Variables for the long-only options */
|
||||||
static int depType; /* Variants of `-M` */
|
static int depType; /* Variants of `-M` */
|
||||||
@@ -283,6 +283,16 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
char *tzMainfile;
|
char *tzMainfile;
|
||||||
|
|
||||||
|
time_t now = time(NULL);
|
||||||
|
char *sourceDateEpoch = getenv("SOURCE_DATE_EPOCH");
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Support SOURCE_DATE_EPOCH for reproducible builds
|
||||||
|
* https://reproducible-builds.org/docs/source-date-epoch/
|
||||||
|
*/
|
||||||
|
if (sourceDateEpoch)
|
||||||
|
now = (time_t)strtoul(sourceDateEpoch, NULL, 0);
|
||||||
|
|
||||||
dependfile = NULL;
|
dependfile = NULL;
|
||||||
|
|
||||||
/* Initial number of allocated elements in array */
|
/* Initial number of allocated elements in array */
|
||||||
@@ -481,7 +491,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
nTotalLines = 0;
|
nTotalLines = 0;
|
||||||
nIFDepth = 0;
|
nIFDepth = 0;
|
||||||
sym_Init();
|
sym_Init(now);
|
||||||
sym_SetExportAll(exportall);
|
sym_SetExportAll(exportall);
|
||||||
|
|
||||||
opt_ParseDefines();
|
opt_ParseDefines();
|
||||||
|
|||||||
@@ -1092,6 +1092,12 @@ The following symbols are defined by the assembler:
|
|||||||
.It Ic EQU Ta Dv __RGBDS_MINOR__ Ta Minor version number of RGBDS
|
.It Ic EQU Ta Dv __RGBDS_MINOR__ Ta Minor version number of RGBDS
|
||||||
.It Ic EQU Ta Dv __RGBDS_PATCH__ Ta Patch version number of RGBDS
|
.It Ic EQU Ta Dv __RGBDS_PATCH__ Ta Patch version number of RGBDS
|
||||||
.El
|
.El
|
||||||
|
.Pp
|
||||||
|
The current time values will be taken from the
|
||||||
|
.Dv SOURCE_DATE_EPOCH
|
||||||
|
environment variable if that is defined as a UNIX timestamp.
|
||||||
|
Refer to the spec at
|
||||||
|
.Lk https://reproducible-builds.org/docs/source-date-epoch/ .
|
||||||
.Sh DEFINING DATA
|
.Sh DEFINING DATA
|
||||||
.Ss Declaring variables in a RAM section
|
.Ss Declaring variables in a RAM section
|
||||||
.Ic DS
|
.Ic DS
|
||||||
|
|||||||
@@ -655,7 +655,7 @@ static inline struct Symbol *createBuiltinSymbol(char const *name)
|
|||||||
/*
|
/*
|
||||||
* Initialize the symboltable
|
* Initialize the symboltable
|
||||||
*/
|
*/
|
||||||
void sym_Init(void)
|
void sym_Init(time_t now)
|
||||||
{
|
{
|
||||||
PCSymbol = createBuiltinSymbol("@");
|
PCSymbol = createBuiltinSymbol("@");
|
||||||
struct Symbol *_NARGSymbol = createBuiltinSymbol("_NARG");
|
struct Symbol *_NARGSymbol = createBuiltinSymbol("_NARG");
|
||||||
@@ -677,8 +677,6 @@ void sym_Init(void)
|
|||||||
sym_AddEqu("__RGBDS_MINOR__", PACKAGE_VERSION_MINOR)->isBuiltin = true;
|
sym_AddEqu("__RGBDS_MINOR__", PACKAGE_VERSION_MINOR)->isBuiltin = true;
|
||||||
sym_AddEqu("__RGBDS_PATCH__", PACKAGE_VERSION_PATCH)->isBuiltin = true;
|
sym_AddEqu("__RGBDS_PATCH__", PACKAGE_VERSION_PATCH)->isBuiltin = true;
|
||||||
|
|
||||||
time_t now = time(NULL);
|
|
||||||
|
|
||||||
if (now == (time_t)-1) {
|
if (now == (time_t)-1) {
|
||||||
warn("Couldn't determine current time");
|
warn("Couldn't determine current time");
|
||||||
/* Fall back by pretending we are at the Epoch */
|
/* Fall back by pretending we are at the Epoch */
|
||||||
|
|||||||
Reference in New Issue
Block a user