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:
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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user