compile NetHack-3.7 without makedefs-generated .h files
This evolves and hopefully eases the game-build requirements by
removing game-compile dependencies on any header files generated
by the makedefs utility, including:
date.h dependency and its inclusion is removed and comparable functionality
is produced at runtime via new file src/date.c.
pm.h dependency and its inclusion is removed and comparable functionality is
produced by moving the monster definitions from monst.c into new header
file called monsters.h and altering them slightly. The former pm.h header
file #define PM_ values are now replaced with appropriate emitted enum
entries during the compiler preprocessing.
onames.h dependency and its inclusion is removed and comparable functionality
is produced by moving the object definitions from objects.c into new header
file called objects.h and altering them slightly. The former onames.h header
file #define values are now replaced with appropriate emitted enum entries
during the compiler preprocessing.
artilist.h has been slightly altered, and the former onames.h artifact-related
header file #define ART_ values are now replaced with appropriate emitted enum
entries during the compiler preprocessing.
makedefs can still produce date.h (makedefs -v), pm.h (makedefs -p), and
onames.h (makedefs -o) for reference purposes. They won't be used during
the compiler.
The other uses for makedefs remain. They are used to prepare external
file content that the game utilizes, not prerequisite code for the
compile:
makedefs -d (database)
makedefs -r (rumors)
makedefs -h (oracles)
makedefs -s (epitaphs, engravings, bogusmons)
date.c
Pull the code for date/time stamping from mdlib.c into date.c.
Set date.o to be dependent on source files, header files, and .o files
so that date.o is rebuilt from date.c when any of those changes, thus
ensuring an accurate date/time stamp. It also includes git sha
functionality formerly done by makedefs writing #define directives
into include/date.h. For unix it passes the git info on
the compile line for date.c (via sys/unix/hints/linux.2020, macOS.2020)
nethack --dumpenums (optional, but on by default)
Allow developer to obtain some internal enum values from NetHack
without having to resort to an external utility such as
makedefs.
Uncomment #define NODUMPENUMS in config.h to disable this.
The updates to sys/windows/Makefile.gcc have not been tested yet.
This commit is contained in:
2
src/.gitignore
vendored
2
src/.gitignore
vendored
@@ -12,4 +12,4 @@ graphicschk
|
||||
nhdat
|
||||
o
|
||||
nhdat*
|
||||
|
||||
date.nmk
|
||||
|
||||
@@ -28,6 +28,7 @@ early_init(void)
|
||||
objects_globals_init();
|
||||
monst_globals_init();
|
||||
sys_early_init();
|
||||
runtime_info_init();
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -803,6 +804,9 @@ static const struct early_opt earlyopts[] = {
|
||||
{ARG_DEBUG, "debug", 5, TRUE},
|
||||
{ARG_VERSION, "version", 4, TRUE},
|
||||
{ARG_SHOWPATHS, "showpaths", 9, FALSE},
|
||||
#ifndef NODUMPENUMS
|
||||
{ARG_DUMPENUMS, "dumpenums", 9, FALSE},
|
||||
#endif
|
||||
#ifdef WIN32
|
||||
{ARG_WINDOWS, "windows", 4, TRUE},
|
||||
#endif
|
||||
@@ -881,6 +885,12 @@ argcheck(int argc, char *argv[], enum earlyarg e_arg)
|
||||
case ARG_SHOWPATHS: {
|
||||
return 2;
|
||||
}
|
||||
#ifndef NODUMPENUMS
|
||||
case ARG_DUMPENUMS: {
|
||||
dump_enums();
|
||||
return 2;
|
||||
}
|
||||
#endif
|
||||
#ifdef WIN32
|
||||
case ARG_WINDOWS: {
|
||||
if (extended_opt) {
|
||||
@@ -953,4 +963,59 @@ debug_fields(const char *opts)
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
#ifndef NODUMPENUMS
|
||||
void
|
||||
dump_enums(void)
|
||||
{
|
||||
int i, j;
|
||||
enum enum_dumps {
|
||||
monsters_enum,
|
||||
objects_enum,
|
||||
objects_misc_enum,
|
||||
NUM_ENUM_DUMPS
|
||||
};
|
||||
static const char *titles[NUM_ENUM_DUMPS] =
|
||||
{ "monnums", "objects_nums" , "misc_object_nums" };
|
||||
struct enum_dump {
|
||||
int val;
|
||||
const char *nm;
|
||||
};
|
||||
|
||||
#define DUMP_ENUMS
|
||||
struct enum_dump monsdump[] = {
|
||||
#include "monsters.h"
|
||||
{ NUMMONS, "NUMMONS" },
|
||||
};
|
||||
struct enum_dump objdump[] = {
|
||||
#include "objects.h"
|
||||
{ NUM_OBJECTS, "NUM_OBJECTS" },
|
||||
};
|
||||
#undef DUMP_ENUMS
|
||||
|
||||
struct enum_dump omdump[] = {
|
||||
{ LAST_GEM, "LAST_GEM" },
|
||||
{ NUM_GLASS_GEMS, "NUM_GLASS_GEMS" },
|
||||
{ MAXSPELL, "MAXSPELL" },
|
||||
};
|
||||
struct enum_dump *ed[NUM_ENUM_DUMPS] = { monsdump, objdump, omdump };
|
||||
static const char *pfx[NUM_ENUM_DUMPS] = { "PM_", "", "" };
|
||||
int szd[NUM_ENUM_DUMPS] = { SIZE(monsdump), SIZE(objdump), SIZE(omdump) };
|
||||
|
||||
for (i = 0; i < NUM_ENUM_DUMPS; ++ i) {
|
||||
raw_printf("enum %s = {", titles[i]);
|
||||
for (j = 0; j < szd[i]; ++j) {
|
||||
raw_printf(" %s%s = %i%s",
|
||||
(j == szd[i] - 1) ? "" : pfx[i],
|
||||
ed[i]->nm,
|
||||
ed[i]->val,
|
||||
(j == szd[i] - 1) ? "" : ",");
|
||||
ed[i]++;
|
||||
}
|
||||
raw_print("};");
|
||||
raw_print("");
|
||||
}
|
||||
raw_print("");
|
||||
}
|
||||
#endif /* NODUMPENUMS */
|
||||
/*allmain.c*/
|
||||
|
||||
144
src/date.c
Normal file
144
src/date.c
Normal file
@@ -0,0 +1,144 @@
|
||||
/* NetHack 3.7 date.c $NHDT-Date: 1608933420 2020/12/25 21:57:00 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.17 $ */
|
||||
/* Copyright (c) Michael Allison, 2021. */
|
||||
/* NetHack may be freely redistributed. See license for details. */
|
||||
|
||||
#include "config.h"
|
||||
|
||||
/* these are in extern.h but we don't include hack.h */
|
||||
void populate_nomakedefs(struct version_info *);
|
||||
void free_nomakedefs(void);
|
||||
|
||||
#define Snprintf(str, size, ...) \
|
||||
nh_snprintf(__func__, __LINE__, str, size, __VA_ARGS__)
|
||||
extern void nh_snprintf(const char *func, int line, char *str, size_t size,
|
||||
const char *fmt, ...);
|
||||
extern char *mdlib_version_string(char *, const char *);
|
||||
extern char *version_id_string(char *, int, const char *);
|
||||
extern char *bannerc_string(char *, int, const char *);
|
||||
extern int case_insensitive_comp(const char *, const char *);
|
||||
|
||||
struct nomakedefs_s nomakedefs = {
|
||||
/* https://groups.google.com/forum/#!original/
|
||||
comp.sources.games/91SfKYg_xzI/dGnR3JnspFkJ */
|
||||
"Tue, 28-Jul-87 13:18:57 EDT",
|
||||
"Version 1.0, built Jul 28 13:18:57 1987.",
|
||||
(const char *) 0, /* git_sha */
|
||||
(const char *) 0, /* git_branch */
|
||||
"1.0.0-0",
|
||||
"NetHack Version 1.0.0-0 - last build Tue Jul 28 13:18:57 1987.",
|
||||
0x01010000UL,
|
||||
0x00000000UL,
|
||||
0x00000000UL,
|
||||
0x00000000UL,
|
||||
0x00000000UL,
|
||||
0x00000000UL,
|
||||
554476737UL,
|
||||
};
|
||||
|
||||
#if defined(__DATE__) && defined(__TIME__)
|
||||
|
||||
#define extract_field(t,s,n,z) \
|
||||
do { \
|
||||
for (i = 0; i < n; ++i) \
|
||||
t[i] = s[i + z]; \
|
||||
t[i] = '\0'; \
|
||||
} while (0)
|
||||
|
||||
void
|
||||
populate_nomakedefs(struct version_info *version)
|
||||
{
|
||||
int i;
|
||||
char tmpbuf1[BUFSZ], tmpbuf2[BUFSZ], *strp;
|
||||
const char *mth[] = {
|
||||
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
|
||||
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
|
||||
struct tm t = {0};
|
||||
time_t timeresult;
|
||||
/*
|
||||
* In a cross-compiled environment, you can't execute
|
||||
* the target binaries during the build, so we can't
|
||||
* use makedefs to write the values of the build
|
||||
* date and time to a file for retrieval. Not for
|
||||
* information meaningful to the target execution
|
||||
* environment.
|
||||
*
|
||||
* How can we capture the build date/time of the target
|
||||
* binaries in such a situation? We need to rely on the
|
||||
* cross-compiler itself to do it for us during the
|
||||
* cross-compile.
|
||||
*
|
||||
* To that end, we are going to make use of the
|
||||
* following pre-defined preprocessor macros for this:
|
||||
* gcc, msvc, clang __DATE__ "Feb 12 1996"
|
||||
* gcc, msvc, clang __TIME__ "23:59:01"
|
||||
*
|
||||
*/
|
||||
/* if (sizeof __DATE__ + sizeof __TIME__ + sizeof "123" <
|
||||
sizeof tmpbuf1) */
|
||||
Snprintf(tmpbuf1, sizeof tmpbuf1, "%s %s", __DATE__, __TIME__);
|
||||
/* "Feb 12 1996 23:59:01"
|
||||
01234567890123456789 */
|
||||
if ((int) strlen(tmpbuf1) == 20) {
|
||||
extract_field(tmpbuf2, tmpbuf1, 4, 7); /* year */
|
||||
t.tm_year = atoi(tmpbuf2) - 1900;
|
||||
extract_field(tmpbuf2, tmpbuf1, 3, 0); /* mon */
|
||||
for (i = 0; i < SIZE(mth); ++i)
|
||||
if (!case_insensitive_comp(tmpbuf2, mth[i])) {
|
||||
t.tm_mon = i;
|
||||
break;
|
||||
}
|
||||
extract_field(tmpbuf2, tmpbuf1, 2, 4); /* mday */
|
||||
strp = tmpbuf2;
|
||||
if (*strp == ' ')
|
||||
strp++;
|
||||
t.tm_mday = atoi(strp);
|
||||
extract_field(tmpbuf2, tmpbuf1, 2, 12); /* hour */
|
||||
t.tm_hour = atoi(tmpbuf2);
|
||||
extract_field(tmpbuf2, tmpbuf1, 2, 15); /* min */
|
||||
t.tm_min = atoi(tmpbuf2);
|
||||
extract_field(tmpbuf2, tmpbuf1, 2, 18); /* sec */
|
||||
t.tm_sec = atoi(tmpbuf2);
|
||||
timeresult = mktime(&t);
|
||||
nomakedefs.build_time = (unsigned long) timeresult;
|
||||
nomakedefs.build_date = strdup(tmpbuf1);
|
||||
}
|
||||
|
||||
nomakedefs.version_number = version->incarnation;
|
||||
nomakedefs.version_features = version->feature_set;
|
||||
#ifdef MD_IGNORED_FEATURES
|
||||
nomakedefs.ignored_features = MD_IGNORED_FEATURES;
|
||||
#endif
|
||||
nomakedefs.version_sanity1 = version->entity_count;
|
||||
nomakedefs.version_sanity2 = version->struct_sizes1;
|
||||
nomakedefs.version_sanity3 = version->struct_sizes2;
|
||||
nomakedefs.version_string = strdup(mdlib_version_string(tmpbuf2, "."));
|
||||
nomakedefs.version_id = strdup(version_id_string(tmpbuf2, sizeof tmpbuf2,
|
||||
nomakedefs.build_date));
|
||||
nomakedefs.copyright_banner_c = strdup(bannerc_string(
|
||||
tmpbuf2, sizeof tmpbuf2,
|
||||
nomakedefs.build_date));
|
||||
#ifdef NETHACK_GIT_SHA
|
||||
nomakedefs.git_sha = strdup(NETHACK_GIT_SHA);
|
||||
#endif
|
||||
#ifdef NETHACK_GIT_BRANCH
|
||||
nomakedefs.git_branch = strdup(NETHACK_GIT_BRANCH);
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
free_nomakedefs(void)
|
||||
{
|
||||
if (nomakedefs.build_date)
|
||||
free((genericptr_t) nomakedefs.build_date);
|
||||
if (nomakedefs.version_string)
|
||||
free((genericptr_t) nomakedefs.version_string);
|
||||
if (nomakedefs.version_id)
|
||||
free((genericptr_t) nomakedefs.version_id);
|
||||
if (nomakedefs.copyright_banner_c)
|
||||
free((genericptr_t) nomakedefs.copyright_banner_c);
|
||||
}
|
||||
|
||||
#endif /* __DATE__ && __TIME__ */
|
||||
|
||||
|
||||
/*date.c*/
|
||||
@@ -1763,6 +1763,7 @@ nh_terminate(int status)
|
||||
dlb_cleanup();
|
||||
l_nhcore_done();
|
||||
}
|
||||
free_nomakedefs();
|
||||
|
||||
#ifdef VMS
|
||||
/*
|
||||
|
||||
211
src/mdlib.c
211
src/mdlib.c
@@ -48,17 +48,17 @@
|
||||
#endif /* !MAKEDEFS_C */
|
||||
|
||||
/* shorten up some lines */
|
||||
#if defined(CROSSCOMPILE_TARGET) || defined(OPTIONS_AT_RUNTIME)
|
||||
#define FOR_RUNTIME
|
||||
#endif
|
||||
|
||||
#if defined(MAKEDEFS_C) || defined(FOR_RUNTIME)
|
||||
#include <stdarg.h>
|
||||
/* REPRODUCIBLE_BUILD will change this to TRUE */
|
||||
static boolean date_via_env = FALSE;
|
||||
|
||||
static char *version_string(char *, const char *);
|
||||
static char *version_id_string(char *, const char *);
|
||||
static char *bannerc_string(char *, const char *);
|
||||
char *mdlib_version_string(char *, const char *);
|
||||
char *version_id_string(char *, int, const char *);
|
||||
char *bannerc_string(char *, int, const char *);
|
||||
int case_insensitive_comp(const char *, const char *);
|
||||
|
||||
static void make_version(void);
|
||||
static char *eos(char *);
|
||||
@@ -71,20 +71,17 @@ static char *mdlib_strsubst(char *, const char *, const char *);
|
||||
static int mkstemp(char *);
|
||||
#endif
|
||||
#endif
|
||||
#endif /* MAKEDEFS_C || FOR_RUNTIME */
|
||||
|
||||
#if defined(MAKEDEFS_C) || defined(FOR_RUNTIME) || defined(WIN32) \
|
||||
|| (defined(CROSSCOMPILE_TARGET) && defined(__DATE__) && defined(__TIME__))
|
||||
static int case_insensitive_comp(const char *, const char *);
|
||||
#endif
|
||||
#endif /* MAKEDEFS_C || FOR_RUNTIME */
|
||||
|
||||
#if !defined(MAKEDEFS_C) && defined(WIN32)
|
||||
extern int GUILaunched;
|
||||
#endif
|
||||
|
||||
/* these two are in extern.h but we don't include hack.h */
|
||||
/* these are in extern.h but we don't include hack.h */
|
||||
void runtime_info_init(void);
|
||||
const char *do_runtime_info(int *);
|
||||
void populate_nomakedefs(struct version_info *);
|
||||
|
||||
void build_options(void);
|
||||
static int count_and_validate_winopts(void);
|
||||
@@ -92,10 +89,6 @@ static void opt_out_words(char *, int *);
|
||||
static void build_savebones_compat_string(void);
|
||||
static int idxopttext, done_runtime_opt_init_once = 0;
|
||||
#define MAXOPT 40
|
||||
#if !defined(MAKEDEFS_C) && defined(CROSSCOMPILE_TARGET) \
|
||||
&& defined(__DATE__) && defined(__TIME__)
|
||||
static char rttimebuf[MAXOPT];
|
||||
#endif
|
||||
static char *opttext[120] = { 0 };
|
||||
char optbuf[BUFSZ];
|
||||
static struct version_info version;
|
||||
@@ -257,8 +250,8 @@ make_version(void)
|
||||
|
||||
#if defined(MAKEDEFS_C) || defined(FOR_RUNTIME)
|
||||
|
||||
static char *
|
||||
version_string(char *outbuf, const char *delim)
|
||||
char *
|
||||
mdlib_version_string(char *outbuf, const char *delim)
|
||||
{
|
||||
Sprintf(outbuf, "%d%s%d%s%d", VERSION_MAJOR, delim, VERSION_MINOR, delim,
|
||||
PATCHLEVEL);
|
||||
@@ -268,8 +261,40 @@ version_string(char *outbuf, const char *delim)
|
||||
return outbuf;
|
||||
}
|
||||
|
||||
static char *
|
||||
version_id_string(char *outbuf, const char *build_date)
|
||||
#define Snprintf(str, size, ...) \
|
||||
nh_snprintf(__func__, __LINE__, str, size, __VA_ARGS__)
|
||||
extern void nh_snprintf(const char *func, int line, char *str, size_t size,
|
||||
const char *fmt, ...);
|
||||
|
||||
#ifdef MAKEDEFS_C
|
||||
DISABLE_WARNING_FORMAT_NONLITERAL
|
||||
|
||||
void
|
||||
nh_snprintf(const char *func UNUSED, int line UNUSED, char *str, size_t size,
|
||||
const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
int n;
|
||||
|
||||
va_start(ap, fmt);
|
||||
#ifdef NO_VSNPRINTF
|
||||
n = vsprintf(str, fmt, ap);
|
||||
#else
|
||||
n = vsnprintf(str, size, fmt, ap);
|
||||
#endif
|
||||
va_end(ap);
|
||||
|
||||
if (n < 0 || (size_t)n >= size) { /* is there a problem? */
|
||||
str[size-1] = 0; /* make sure it is nul terminated */
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
RESTORE_WARNING_FORMAT_NONLITERAL
|
||||
#endif /* MAKEDEFS_C */
|
||||
|
||||
char *
|
||||
version_id_string(char *outbuf, int bufsz, const char *build_date)
|
||||
{
|
||||
char subbuf[64], versbuf[64];
|
||||
char statusbuf[64];
|
||||
@@ -293,16 +318,16 @@ version_id_string(char *outbuf, const char *build_date)
|
||||
Strcpy(&subbuf[1], PORT_SUB_ID);
|
||||
#endif
|
||||
|
||||
Sprintf(outbuf, "%s NetHack%s Version %s%s - last %s %s.", PORT_ID,
|
||||
subbuf, version_string(versbuf, "."), statusbuf,
|
||||
Snprintf(outbuf, bufsz, "%s NetHack%s Version %s%s - last %s %s.", PORT_ID,
|
||||
subbuf, mdlib_version_string(versbuf, "."), statusbuf,
|
||||
date_via_env ? "revision" : "build", build_date);
|
||||
return outbuf;
|
||||
}
|
||||
|
||||
/* still within #if MAKDEFS_C || FOR_RUNTIME */
|
||||
|
||||
static char *
|
||||
bannerc_string(char *outbuf, const char *build_date)
|
||||
char *
|
||||
bannerc_string(char *outbuf, int bufsz, const char *build_date)
|
||||
{
|
||||
char subbuf[64], versbuf[64];
|
||||
|
||||
@@ -319,14 +344,9 @@ bannerc_string(char *outbuf, const char *build_date)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
Sprintf(outbuf, " Version %s %s%s, %s %s.",
|
||||
version_string(versbuf, "."), PORT_ID, subbuf,
|
||||
date_via_env ? "revised" : "built", &build_date[4]);
|
||||
#if 0
|
||||
Sprintf(outbuf, "%s NetHack%s %s Copyright 1985-%s (built %s)",
|
||||
PORT_ID, subbuf, version_string(versbuf,"."), RELEASE_YEAR,
|
||||
&build_date[4]);
|
||||
#endif
|
||||
Snprintf(outbuf, bufsz, " Version %s %s%s, %s %s.",
|
||||
mdlib_version_string(versbuf, "."), PORT_ID, subbuf,
|
||||
date_via_env ? "revised" : "built", build_date);
|
||||
return outbuf;
|
||||
}
|
||||
|
||||
@@ -348,27 +368,6 @@ mkstemp(char *template)
|
||||
#endif /* HAS_NO_MKSTEMP */
|
||||
#endif /* MAKEDEFS_C || FOR_RUNTIME */
|
||||
|
||||
#if defined(MAKEDEFS_C) || defined(FOR_RUNTIME) || defined(WIN32) \
|
||||
|| (defined(CROSSCOMPILE_TARGET) && defined(__DATE__) && defined(__TIME__))
|
||||
static int
|
||||
case_insensitive_comp(const char *s1, const char *s2)
|
||||
{
|
||||
uchar u1, u2;
|
||||
|
||||
for (;; s1++, s2++) {
|
||||
u1 = (uchar) *s1;
|
||||
if (isupper(u1))
|
||||
u1 = tolower(u1);
|
||||
u2 = (uchar) *s2;
|
||||
if (isupper(u2))
|
||||
u2 = tolower(u2);
|
||||
if (u1 == '\0' || u1 != u2)
|
||||
break;
|
||||
}
|
||||
return u1 - u2;
|
||||
}
|
||||
#endif
|
||||
|
||||
static char *
|
||||
eos(char *str)
|
||||
{
|
||||
@@ -791,103 +790,33 @@ build_options(void)
|
||||
return;
|
||||
}
|
||||
|
||||
#if defined(__DATE__) && defined(__TIME__)
|
||||
#define extract_field(t,s,n,z) \
|
||||
do { \
|
||||
for (i = 0; i < n; ++i) \
|
||||
t[i] = s[i + z]; \
|
||||
t[i] = '\0'; \
|
||||
} while (0)
|
||||
#endif
|
||||
int
|
||||
case_insensitive_comp(const char *s1, const char *s2)
|
||||
{
|
||||
uchar u1, u2;
|
||||
|
||||
for (;; s1++, s2++) {
|
||||
u1 = (uchar) *s1;
|
||||
if (isupper(u1))
|
||||
u1 = tolower(u1);
|
||||
u2 = (uchar) *s2;
|
||||
if (isupper(u2))
|
||||
u2 = tolower(u2);
|
||||
if (u1 == '\0' || u1 != u2)
|
||||
break;
|
||||
}
|
||||
return u1 - u2;
|
||||
}
|
||||
|
||||
void
|
||||
runtime_info_init(void)
|
||||
{
|
||||
#if !defined(MAKEDEFS_C) && defined(CROSSCOMPILE_TARGET) \
|
||||
&& defined(__DATE__) && defined(__TIME__)
|
||||
int i;
|
||||
char tmpbuf[BUFSZ], *strp;
|
||||
const char *mth[] = {
|
||||
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
|
||||
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
|
||||
struct tm t = {0};
|
||||
time_t timeresult;
|
||||
#endif
|
||||
|
||||
if (!done_runtime_opt_init_once) {
|
||||
done_runtime_opt_init_once = 1;
|
||||
build_savebones_compat_string();
|
||||
/* construct the current version number */
|
||||
make_version();
|
||||
#if !defined(MAKEDEFS_C) && defined(CROSSCOMPILE_TARGET)
|
||||
#if defined(__DATE__) && defined(__TIME__)
|
||||
/*
|
||||
* In a cross-compiled environment, you can't execute
|
||||
* the target binaries during the build, so we can't
|
||||
* use makedefs to write the values of the build
|
||||
* date and time to a file for retrieval. Not for
|
||||
* information meaningful to the target execution
|
||||
* environment.
|
||||
*
|
||||
* How can we capture the build date/time of the target
|
||||
* binaries in such a situation? We need to rely on the
|
||||
* cross-compiler itself to do it for us during the
|
||||
* cross-compile.
|
||||
*
|
||||
* To that end, we are going to make use of the
|
||||
* following pre-defined preprocessor macros for this:
|
||||
* gcc, msvc, clang __DATE__ "Feb 12 1996"
|
||||
* gcc, msvc, clang __TIME__ "23:59:01"
|
||||
*
|
||||
*/
|
||||
if (sizeof __DATE__ + sizeof __TIME__ + sizeof "123" <
|
||||
sizeof rttimebuf)
|
||||
Sprintf(rttimebuf, "%s %s", __DATE__, __TIME__);
|
||||
/* "Feb 12 1996 23:59:01"
|
||||
01234567890123456789 */
|
||||
if ((int) strlen(rttimebuf) == 20) {
|
||||
extract_field(tmpbuf, rttimebuf, 4, 7); /* year */
|
||||
t.tm_year = atoi(tmpbuf) - 1900;
|
||||
extract_field(tmpbuf, rttimebuf, 3, 0); /* mon */
|
||||
for (i = 0; i < SIZE(mth); ++i)
|
||||
if (!case_insensitive_comp(tmpbuf, mth[i])) {
|
||||
t.tm_mon = i;
|
||||
break;
|
||||
}
|
||||
extract_field(tmpbuf, rttimebuf, 2, 4); /* mday */
|
||||
strp = tmpbuf;
|
||||
if (*strp == ' ')
|
||||
strp++;
|
||||
t.tm_mday = atoi(strp);
|
||||
extract_field(tmpbuf, rttimebuf, 2, 12); /* hour */
|
||||
t.tm_hour = atoi(tmpbuf);
|
||||
extract_field(tmpbuf, rttimebuf, 2, 15); /* min */
|
||||
t.tm_min = atoi(tmpbuf);
|
||||
extract_field(tmpbuf, rttimebuf, 2, 18); /* sec */
|
||||
t.tm_sec = atoi(tmpbuf);
|
||||
timeresult = mktime(&t);
|
||||
BUILD_TIME = (unsigned long) timeresult;
|
||||
BUILD_DATE = rttimebuf;
|
||||
}
|
||||
#endif /* __DATE__ && __TIME__ */
|
||||
VERSION_NUMBER = version.incarnation;
|
||||
VERSION_FEATURES = version.feature_set;
|
||||
#ifdef MD_IGNORED_FEATURES
|
||||
IGNORED_FEATURES = MD_IGNORED_FEATURES;
|
||||
#endif
|
||||
VERSION_SANITY1 = version.entity_count;
|
||||
VERSION_SANITY2 = version.struct_sizes1;
|
||||
VERSION_SANITY3 = version.struct_sizes2;
|
||||
VERSION_STRING = strdup(version_string(tmpbuf, "."));
|
||||
VERSION_ID = strdup(version_id_string(tmpbuf, BUILD_DATE));
|
||||
COPYRIGHT_BANNER_C = strdup(bannerc_string(tmpbuf, BUILD_DATE));
|
||||
#ifdef NETHACK_HOST_GIT_SHA
|
||||
NETHACK_GIT_SHA = strdup(NETHACK_HOST_GIT_SHA);
|
||||
#endif
|
||||
#ifdef NETHACK_HOST_GIT_BRANCH
|
||||
NETHACK_GIT_BRANCH = strdup(NETHACK_HOST_GIT_BRANCH);
|
||||
#endif
|
||||
#endif /* !MAKEDEFS_C && CROSSCOMPILE_TARGET */
|
||||
populate_nomakedefs(&version); /* date.c */
|
||||
idxopttext = 0;
|
||||
build_options();
|
||||
}
|
||||
@@ -904,7 +833,7 @@ do_runtime_info(int *rtcontext)
|
||||
if (*rtcontext >= 0 && *rtcontext < (MAXOPT - 1)) {
|
||||
retval = opttext[*rtcontext];
|
||||
*rtcontext += 1;
|
||||
}
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
3310
src/monst.c
3310
src/monst.c
File diff suppressed because it is too large
Load Diff
1182
src/objects.c
1182
src/objects.c
File diff suppressed because it is too large
Load Diff
@@ -197,7 +197,7 @@ static const char *const shkhealthfoods[] = {
|
||||
* The iprobs array in each entry defines the probabilities for various kinds
|
||||
* of objects to be present in the given shop type. You can associate with
|
||||
* each percentage either a generic object type (represented by one of the
|
||||
* *_CLASS macros) or a specific object (represented by an onames.h define).
|
||||
* *_CLASS enum value) or a specific object enum value.
|
||||
* In the latter case, prepend it with a unary minus so the code can know
|
||||
* (by testing the sign) whether to use mkobj() or mksobj().
|
||||
*/
|
||||
|
||||
127
src/version.c
127
src/version.c
@@ -5,50 +5,9 @@
|
||||
|
||||
#include "hack.h"
|
||||
#include "dlb.h"
|
||||
#include "date.h"
|
||||
|
||||
#if defined(CROSSCOMPILE)
|
||||
struct cross_target_s cross_target = {
|
||||
/* https://groups.google.com/forum/#!original/
|
||||
comp.sources.games/91SfKYg_xzI/dGnR3JnspFkJ */
|
||||
"Tue, 28-Jul-87 13:18:57 EDT",
|
||||
"Version 1.0, built Jul 28 13:18:57 1987.",
|
||||
"0000000000000000000000000000000000000000",
|
||||
"master",
|
||||
"1.0.0-0",
|
||||
"NetHack Version 1.0.0-0 - last build Tue Jul 28 13:18:57 1987.",
|
||||
0x01010000UL,
|
||||
0x00000000UL,
|
||||
0x00000000UL,
|
||||
0x00000000UL,
|
||||
0x00000000UL,
|
||||
0x00000000UL,
|
||||
554476737UL,
|
||||
};
|
||||
#endif /* CROSSCOMPILE */
|
||||
|
||||
#if defined(NETHACK_GIT_SHA)
|
||||
const char *NetHack_git_sha
|
||||
#if !defined(CROSSCOMPILE) || !defined(CROSSCOMPILE_TARGET)
|
||||
= NETHACK_GIT_SHA
|
||||
#else
|
||||
#ifdef NETHACK_HOST_GIT_SHA
|
||||
= NETHACK_HOST_GIT_SHA
|
||||
#endif
|
||||
#endif
|
||||
;
|
||||
#endif
|
||||
|
||||
#if defined(NETHACK_GIT_BRANCH)
|
||||
const char *NetHack_git_branch
|
||||
#if !defined(CROSSCOMPILE) || !defined(CROSSCOMPILE_TARGET)
|
||||
= NETHACK_GIT_BRANCH
|
||||
#else
|
||||
#ifdef NETHACK_HOST_GIT_BRANCH
|
||||
= NETHACK_HOST_GIT_BRANCH
|
||||
#endif
|
||||
#endif
|
||||
;
|
||||
#ifndef OPTIONS_AT_RUNTIME
|
||||
#define OPTIONS_AT_RUNTIME
|
||||
#endif
|
||||
|
||||
static void insert_rtoption(char *);
|
||||
@@ -57,17 +16,16 @@ static void insert_rtoption(char *);
|
||||
char *
|
||||
version_string(char *buf)
|
||||
{
|
||||
return strcpy(buf, VERSION_STRING);
|
||||
return strcpy(buf, nomakedefs.version_string);
|
||||
}
|
||||
|
||||
/* fill and return the given buffer with the long nethack version string */
|
||||
char *
|
||||
getversionstring(char *buf)
|
||||
{
|
||||
Strcpy(buf, VERSION_ID);
|
||||
Strcpy(buf, nomakedefs.version_id);
|
||||
|
||||
#if defined(RUNTIME_PORT_ID) \
|
||||
|| defined(NETHACK_GIT_SHA) || defined(NETHACK_GIT_BRANCH)
|
||||
#if defined(RUNTIME_PORT_ID)
|
||||
{
|
||||
int c = 0;
|
||||
#if defined(RUNTIME_PORT_ID)
|
||||
@@ -82,28 +40,28 @@ getversionstring(char *buf)
|
||||
#if defined(RUNTIME_PORT_ID)
|
||||
tmp = get_port_id(tmpbuf);
|
||||
if (tmp)
|
||||
Sprintf(eos(buf), "%s%s", c++ ? "," : "", tmp);
|
||||
Snprintf(eos(buf), (sizeof buf - strlen(buf)) - 1,
|
||||
"%s%s", c++ ? "," : "", tmp);
|
||||
#endif
|
||||
#if defined(NETHACK_GIT_SHA)
|
||||
if (NetHack_git_sha)
|
||||
Sprintf(eos(buf), "%s%s", c++ ? "," : "", NetHack_git_sha);
|
||||
#endif
|
||||
#if defined(NETHACK_GIT_BRANCH)
|
||||
if (nomakedefs.git_sha)
|
||||
Snprintf(eos(buf), (sizeof buf - strlen(buf)) - 1,
|
||||
"%s%s", c++ ? "," : "", nomakedefs.git_sha);
|
||||
#if (NH_DEVEL_STATUS != NH_STATUS_RELEASED)
|
||||
if (NetHack_git_branch)
|
||||
Sprintf(eos(buf), "%sbranch:%s",
|
||||
c++ ? "," : "", NetHack_git_branch);
|
||||
#endif
|
||||
if (nomakedefs.git_branch)
|
||||
Snprintf(eos(buf), (sizeof buf - strlen(buf)) - 1,
|
||||
"%sbranch:%s",
|
||||
c++ ? "," : "", nomakedefs.git_branch);
|
||||
#endif
|
||||
if (c)
|
||||
Strcat(buf, ")");
|
||||
Snprintf(eos(buf), (sizeof buf - strlen(buf)) - 1,
|
||||
"%s", ")");
|
||||
else /* if nothing has been added, strip " (" back off */
|
||||
*p = '\0';
|
||||
if (dotoff)
|
||||
Strcat(buf, ".");
|
||||
Snprintf(eos(buf), (sizeof buf - strlen(buf)) - 1,
|
||||
"%s", ".");
|
||||
}
|
||||
#endif /* RUNTIME_PORT_ID || NETHACK_GIT_SHA || NETHACK_GIT_BRANCH */
|
||||
|
||||
#endif /* RUNTIME_PORT_ID */
|
||||
return buf;
|
||||
}
|
||||
|
||||
@@ -148,7 +106,7 @@ doextversion(void)
|
||||
(const char *) 0
|
||||
};
|
||||
#endif /*0*/
|
||||
#if defined(OPTIONS_AT_RUNTIME) || defined(CROSSCOMPILE_TARGET)
|
||||
#if defined(OPTIONS_AT_RUNTIME)
|
||||
use_dlb = FALSE;
|
||||
#else
|
||||
done_rt = TRUE;
|
||||
@@ -267,7 +225,7 @@ early_version_info(boolean pastebuf)
|
||||
raw_printf("%s", buf);
|
||||
|
||||
if (pastebuf) {
|
||||
#if defined(RUNTIME_PASTEBUF_SUPPORT) && !defined(LIBNH)
|
||||
#if defined(RUNTIME_PASTEBUF_SUPPORT) && !defined(LIBNH)
|
||||
/*
|
||||
* Call a platform/port-specific routine to insert the
|
||||
* version information into a paste buffer. Useful for
|
||||
@@ -327,7 +285,7 @@ comp_times(long filetime)
|
||||
{
|
||||
/* BUILD_TIME is constant but might have L suffix rather than UL;
|
||||
'filetime' is historically signed but ought to have been unsigned */
|
||||
return (boolean) ((unsigned long) filetime < (unsigned long) BUILD_TIME);
|
||||
return (boolean) ((unsigned long) filetime < (unsigned long) nomakedefs.build_time);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -338,9 +296,9 @@ check_version(struct version_info *version_data, const char *filename,
|
||||
if (
|
||||
#ifdef VERSION_COMPATIBILITY
|
||||
version_data->incarnation < VERSION_COMPATIBILITY
|
||||
|| version_data->incarnation > VERSION_NUMBER
|
||||
|| version_data->incarnation > nomakedefs.version_number
|
||||
#else
|
||||
version_data->incarnation != VERSION_NUMBER
|
||||
version_data->incarnation != nomakedefs.version_number
|
||||
#endif
|
||||
) {
|
||||
if (complain)
|
||||
@@ -348,17 +306,17 @@ check_version(struct version_info *version_data, const char *filename,
|
||||
return FALSE;
|
||||
} else if (
|
||||
#ifndef IGNORED_FEATURES
|
||||
version_data->feature_set != VERSION_FEATURES
|
||||
version_data->feature_set != nomakedefs.version_features
|
||||
#else
|
||||
(version_data->feature_set & ~IGNORED_FEATURES)
|
||||
!= (VERSION_FEATURES & ~IGNORED_FEATURES)
|
||||
(version_data->feature_set & ~nomakedefs.ignored_features)
|
||||
!= (VERSION_FEATURES & ~nomakedefs.ignored_features)
|
||||
#endif
|
||||
|| ((utdflags & UTD_SKIP_SANITY1) == 0
|
||||
&& version_data->entity_count != VERSION_SANITY1)
|
||||
&& version_data->entity_count != nomakedefs.version_sanity1)
|
||||
|| ((utdflags & UTD_CHECKSIZES) &&
|
||||
(version_data->struct_sizes1 != VERSION_SANITY2))
|
||||
(version_data->struct_sizes1 != nomakedefs.version_sanity2))
|
||||
|| ((utdflags & UTD_CHECKSIZES) &&
|
||||
(version_data->struct_sizes2 != VERSION_SANITY3))) {
|
||||
(version_data->struct_sizes2 != nomakedefs.version_sanity3))) {
|
||||
if (complain)
|
||||
pline("Configuration incompatibility for file \"%s\".", filename);
|
||||
return FALSE;
|
||||
@@ -421,23 +379,16 @@ store_formatindicator(NHFILE *nhfp)
|
||||
void
|
||||
store_version(NHFILE *nhfp)
|
||||
{
|
||||
#if !defined(CROSSCOMPILE) || !defined(CROSSCOMPILE_TARGET)
|
||||
static const struct version_info version_data = {
|
||||
VERSION_NUMBER, VERSION_FEATURES,
|
||||
VERSION_SANITY1, VERSION_SANITY2, VERSION_SANITY3
|
||||
#else
|
||||
struct version_info version_data = {
|
||||
0UL,0UL,0UL,0UL,0Ul
|
||||
#endif
|
||||
};
|
||||
|
||||
#if defined(CROSSCOMPILE) && defined(CROSSCOMPILE_TARGET)
|
||||
version_data.incarnation = VERSION_NUMBER; /* actual version number */
|
||||
version_data.feature_set = VERSION_FEATURES; /* bitmask of config settings */
|
||||
version_data.entity_count = VERSION_SANITY1; /* # of monsters and objects */
|
||||
version_data.struct_sizes1 = VERSION_SANITY2; /* size of key structs */
|
||||
version_data.struct_sizes2 = VERSION_SANITY3; /* size of more key structs */
|
||||
#endif
|
||||
version_data.incarnation = nomakedefs.version_number; /* actual version number */
|
||||
version_data.feature_set = nomakedefs.version_features; /* bitmask of config settings */
|
||||
version_data.entity_count = nomakedefs.version_sanity1; /* # of monsters and objects */
|
||||
version_data.struct_sizes1 = nomakedefs.version_sanity2; /* size of key structs */
|
||||
version_data.struct_sizes2 = nomakedefs.version_sanity3; /* size of more key structs */
|
||||
|
||||
if (nhfp->structlevel) {
|
||||
bufoff(nhfp->fd);
|
||||
/* bwrite() before bufon() uses plain write() */
|
||||
@@ -504,10 +455,10 @@ copyright_banner_line(int indx)
|
||||
if (indx == 2)
|
||||
return COPYRIGHT_BANNER_B;
|
||||
#endif
|
||||
#ifdef COPYRIGHT_BANNER_C
|
||||
|
||||
if (indx == 3)
|
||||
return COPYRIGHT_BANNER_C;
|
||||
#endif
|
||||
return nomakedefs.copyright_banner_c;
|
||||
|
||||
#ifdef COPYRIGHT_BANNER_D
|
||||
if (indx == 4)
|
||||
return COPYRIGHT_BANNER_D;
|
||||
|
||||
Reference in New Issue
Block a user