incremental improvements to cross-compiling support in NetHack 3.7
Some support of new code #defines to faciliate cross-compiling:
OPTIONS_AT_RUNTIME If this is defined, code to support obtaining
the compile time options and features is
included. If you define this, you'll also have
to compile sys/mdlib.c and link the resulting
object file into your game binary/executable.
CROSSCOMPILE Flags that this is a cross-compiled NetHack build,
where there are two stages:
1. makedefs and some other utilities are compiled
on the host platform and executed there to generate
some output files and header files needed by the
game.
2. the NetHack game files are compiled by a
cross-compiler to generate binary/executables for
a different platform than the one the build is
being run on. The executables produced for the
target platform may not be able to execute on the
build platform, except perhaps via a software
emulator.
The 2-stage process (1. host, 2.target) can be done
on the same platform to test the cross-compile
process. In that case, the host and target platforms
would be the same.
CROSSCOMPILE_HOST Separates/identifies code paths that should only be
be included in the compile on the host side, for
utilities that will be run on the host as part of
stage 1 to produce output files needed to build the
game. Examples are the code for makedefs, tile
conversion utilities, uudecode, dlb, etc.
CROSSCOMPILE_TARGET Separates/identifies code paths that should be
included on the build for the target platform
during stage 2, the cross-compiler stage. That
includes most of the pieces of the game itself
but the code is only flagged as such if it must
not execute on the host.
If you don't define any of those, things should build as before.
One follow-on change that is likely required is setting the new dependency
makedefs has on src/mdlib.c in Makefiles etc.
More information about the changes:
makedefs
- splinter off some of makedefs functionality into a separate file
called src/mdlib.c.
- src/mdlib.c, while included during the compile of makedefs.c
for producing the makedefs utility, can also be compiled
as a stand-alone object file for inclusion in the link step
of your NetHack game build. The src/mdlib.c code can then
deliver the same functionality that it provided to makedefs
right to your NetHack game code at run-time.
For example, do_runtime_info() will provide the caller with
the features and options that were built into the game.
Previously, that information was produced at build time on the
host and stored in a dat file. Under a cross-compile situation,
those values are highly suspect and might not even reflect the
correct options and setting for the cross-compiled target
platform's binary/executable. The compile of those values and
the functionality to obtain them needs to move to the target
cross-compiler stage of the build (stage 2).
- date information on the target-side binary is produced from
the cross-compiler preprocessor pre-defined macros __DATE__
and __TIME__, as they reflect the actual compile time of the
cross-compiled target and not host-side execution of a utility
to produce them. The cross-compiler itself, through those
pre-defined preprocessor macros, provides them to the target
platform binary/executable. They reflect the actual build
time of the target binary/executable (not values produced
at the time the makefiles utility was built and the
appropriate option selected to store them in a text file.)
- most Makefiles should not require adding the new file
src/mdlib.c because util/makedefs.c has a preprocessor
include "../src/mdlib.c" to draw in its contents. As previously
stated though, the Makefile dependency may be required:
makedefs.o: ../util/makedefs.c ../src/mdlib.c
^^^^^^^^^^^^^^^
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
/*-Copyright (c) Robert Patrick Rankin, 2017. */
|
||||
/* NetHack may be freely redistributed. See license for details. */
|
||||
|
||||
#ifdef MAKEDEFS_C
|
||||
#if defined(MAKEDEFS_C) || defined (MDLIB_C)
|
||||
/* in makedefs.c, all we care about is the list of names */
|
||||
|
||||
#define A(nam, typ, s1, s2, mt, atk, dfn, cry, inv, al, cl, rac, cost, clr) nam
|
||||
@@ -32,7 +32,7 @@ static const char *artifact_names[] = {
|
||||
/* clang-format on */
|
||||
|
||||
static NEARDATA struct artifact artilist[] = {
|
||||
#endif /* MAKEDEFS_C */
|
||||
#endif /* MAKEDEFS_C || MDLIB_C */
|
||||
|
||||
/* Artifact cost rationale:
|
||||
* 1. The more useful the artifact, the better its cost.
|
||||
@@ -256,7 +256,7 @@ A("The Palantir of Westernesse", CRYSTAL_BALL,
|
||||
|
||||
#undef A
|
||||
|
||||
#ifndef MAKEDEFS_C
|
||||
#if !defined(MAKEDEFS_C) && !defined(MDLIB_C)
|
||||
#undef NO_ATTK
|
||||
#undef NO_DFNS
|
||||
#undef DFNS
|
||||
|
||||
@@ -16,7 +16,7 @@ E char *FDECL(fmt_ptr, (const genericptr));
|
||||
|
||||
/* This next pre-processor directive covers almost the entire file,
|
||||
* interrupted only occasionally to pick up specific functions as needed. */
|
||||
#if !defined(MAKEDEFS_C) && !defined(LEV_LEX_C)
|
||||
#if !defined(MAKEDEFS_C) && !defined(MDLIB_C) && !defined(LEV_LEX_C)
|
||||
|
||||
/* ### allmain.c ### */
|
||||
|
||||
@@ -583,10 +583,10 @@ E boolean FDECL(hurtle_jump, (genericptr_t, int, int));
|
||||
E boolean FDECL(hurtle_step, (genericptr_t, int, int));
|
||||
|
||||
/* ### drawing.c ### */
|
||||
#endif /* !MAKEDEFS_C && !LEV_LEX_C */
|
||||
#endif /* !MAKEDEFS_C && !MDLIB_C && !LEV_LEX_C */
|
||||
E int FDECL(def_char_to_objclass, (CHAR_P));
|
||||
E int FDECL(def_char_to_monclass, (CHAR_P));
|
||||
#if !defined(MAKEDEFS_C) && !defined(LEV_LEX_C)
|
||||
#if !defined(MAKEDEFS_C) && !defined(MDLIB_C) && !defined(LEV_LEX_C)
|
||||
E void FDECL(switch_symbols, (int));
|
||||
E void FDECL(assign_graphics, (int));
|
||||
E void NDECL(init_symbols);
|
||||
@@ -713,9 +713,9 @@ E int NDECL(done2);
|
||||
E void FDECL(done_intr, (int));
|
||||
#endif
|
||||
E void FDECL(done_in_by, (struct monst *, int));
|
||||
#endif /* !MAKEDEFS_C && !LEV_LEX_C */
|
||||
#endif /* !MAKEDEFS_C && MDLIB_C && !LEV_LEX_C */
|
||||
E void VDECL(panic, (const char *, ...)) PRINTF_F(1, 2) NORETURN;
|
||||
#if !defined(MAKEDEFS_C) && !defined(LEV_LEX_C)
|
||||
#if !defined(MAKEDEFS_C) && !defined(MDLIB_C) && !defined(LEV_LEX_C)
|
||||
E void FDECL(done, (int));
|
||||
E void FDECL(container_contents, (struct obj *, BOOLEAN_P,
|
||||
BOOLEAN_P, BOOLEAN_P));
|
||||
@@ -1663,10 +1663,14 @@ E char *NDECL(lan_username);
|
||||
#endif
|
||||
|
||||
/* ### nhlsel.c ### */
|
||||
#if !defined(CROSSCOMPILE) || defined(CROSSCOMPILE_TARGET)
|
||||
E struct selectionvar *FDECL(l_selection_check, (lua_State *, int));
|
||||
E int FDECL(l_selection_register, (lua_State *));
|
||||
#endif
|
||||
|
||||
/* ### nhlua.c ### */
|
||||
|
||||
#if !defined(CROSSCOMPILE) || defined(CROSSCOMPILE_TARGET)
|
||||
E lua_State * NDECL(nhl_init);
|
||||
E boolean FDECL(nhl_loadlua, (lua_State *, const char *));
|
||||
E boolean FDECL(load_lua, (const char *));
|
||||
@@ -1685,14 +1689,21 @@ E int FDECL(get_table_boolean_opt, (lua_State *, const char *, int));
|
||||
E int FDECL(get_table_option, (lua_State *, const char *, const char *, const char *const *));
|
||||
E int FDECL(str_lines_max_width, (const char *));
|
||||
E char *FDECL(stripdigits, (char *));
|
||||
#endif /* !CROSSCOMPILE || CROSSCOMPILE_TARGET */
|
||||
|
||||
/* ### nhregex.c ### */
|
||||
|
||||
E struct nhregex *NDECL(regex_init);
|
||||
E boolean FDECL(regex_compile, (const char *, struct nhregex *));
|
||||
E const char *FDECL(regex_error_desc, (struct nhregex *));
|
||||
E boolean FDECL(regex_match, (const char *, struct nhregex *));
|
||||
E void FDECL(regex_free, (struct nhregex *));
|
||||
|
||||
/* ### mdlib.c ### */
|
||||
|
||||
E void NDECL(runtime_info_init);
|
||||
E const char *FDECL(do_runtime_info, (int *));
|
||||
|
||||
/* ### nttty.c ### */
|
||||
|
||||
#ifdef WIN32
|
||||
@@ -2405,7 +2416,7 @@ E void NDECL(sysopt_release);
|
||||
E void FDECL(sysopt_seduce_set, (int));
|
||||
|
||||
/* ### sp_lev.c ### */
|
||||
|
||||
#if !defined(CROSSCOMPILE) || defined(CROSSCOMPILE_TARGET)
|
||||
E boolean FDECL(check_room, (xchar *, xchar *, xchar *, xchar *, BOOLEAN_P));
|
||||
E boolean FDECL(create_room, (XCHAR_P, XCHAR_P, XCHAR_P, XCHAR_P, XCHAR_P,
|
||||
XCHAR_P, XCHAR_P, XCHAR_P));
|
||||
@@ -2434,6 +2445,7 @@ E void FDECL(set_floodfillchk_match_under, (XCHAR_P));
|
||||
E void FDECL(selection_do_ellipse, (struct selectionvar *, int, int, int, int, int));
|
||||
E void NDECL(update_croom);
|
||||
E void FDECL(l_register_des, (lua_State *));
|
||||
#endif /* !CROSSCOMPILE || CROSSCOMPILE_TARGET */
|
||||
|
||||
/* ### spell.c ### */
|
||||
|
||||
@@ -3069,7 +3081,7 @@ E int FDECL(destroy_mitem, (struct monst *, int, int));
|
||||
E int FDECL(resist, (struct monst *, CHAR_P, int, int));
|
||||
E void NDECL(makewish);
|
||||
|
||||
#endif /* !MAKEDEFS_C && !LEV_LEX_C */
|
||||
#endif /* !MAKEDEFS_C && !MDLIB_C && !LEV_LEX_C */
|
||||
|
||||
#undef E
|
||||
|
||||
|
||||
@@ -124,6 +124,41 @@ typedef uchar nhsym;
|
||||
#define LARGEST_INT 32767
|
||||
|
||||
#include "coord.h"
|
||||
|
||||
#if defined(CROSSCOMPILE)
|
||||
struct cross_target_s {
|
||||
const char *build_date;
|
||||
const char *copyright_banner_c;
|
||||
const char *git_sha;
|
||||
const char *git_branch;
|
||||
const char *version_string;
|
||||
const char *version_id;
|
||||
unsigned long version_number;
|
||||
unsigned long version_features;
|
||||
unsigned long ignored_features;
|
||||
unsigned long version_sanity1;
|
||||
unsigned long version_sanity2;
|
||||
unsigned long version_sanity3;
|
||||
unsigned long build_time;
|
||||
};
|
||||
extern struct cross_target_s cross_target;
|
||||
#if defined(CROSSCOMPILE_TARGET) && !defined(MAKEDEFS_C)
|
||||
#define BUILD_DATE cross_target.build_date /* "Wed Apr 1 00:00:01 2020" */
|
||||
#define COPYRIGHT_BANNER_C cross_target.copyright_banner_c
|
||||
#define NETHACK_GIT_SHA cross_target.git_sha
|
||||
#define NETHACK_GIT_BRANCH cross_target.git_branch
|
||||
#define VERSION_ID cross_target.version_id
|
||||
#define IGNORED_FEATURES cross_target.ignored_features
|
||||
#define VERSION_FEATURES cross_target.version_features
|
||||
#define VERSION_NUMBER cross_target.version_number
|
||||
#define VERSION_SANITY1 cross_target.version_sanity1
|
||||
#define VERSION_SANITY2 cross_target.version_sanity2
|
||||
#define VERSION_SANITY3 cross_target.version_sanity3
|
||||
#define VERSION_STRING cross_target.version_string
|
||||
#define BUILD_TIME cross_target.build_time /* (1574157640UL) */
|
||||
#endif /* CROSSCOMPILE_TARGET && !MAKEDEFS_C */
|
||||
#endif /* CROSSCOMPILE */
|
||||
|
||||
/*
|
||||
* Automatic inclusions for the subsidiary files.
|
||||
* Please don't change the order. It does matter.
|
||||
|
||||
@@ -15,7 +15,7 @@ struct qtmsg {
|
||||
long offset, size, summary_size;
|
||||
};
|
||||
|
||||
#ifdef MAKEDEFS_C /***** MAKEDEFS *****/
|
||||
#if defined(MAKEDEFS_C) || defined(MDLIB_C) /***** MAKEDEFS *****/
|
||||
|
||||
#define N_MSG 100 /* arbitrary */
|
||||
|
||||
@@ -47,7 +47,7 @@ struct qthdr {
|
||||
"Too many messages in class (line %d)\nAdjust N_MSG in qtext.h and " \
|
||||
"recompile.\n"
|
||||
|
||||
#else /***** !MAKEDEFS *****/
|
||||
#else /***** !MAKEDEFS && !MDLIB_C *****/
|
||||
|
||||
struct qtlists {
|
||||
struct qtmsg *common,
|
||||
@@ -113,6 +113,6 @@ struct qtlists {
|
||||
#define QTN_DEMONIC 20
|
||||
|
||||
#define QT_BANISHED 60
|
||||
#endif /***** !MAKEDEFS *****/
|
||||
#endif /***** !MAKEDEFS && !MDLIB_C *****/
|
||||
|
||||
#endif /* QTEXT_H */
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* NetHack 3.7 sfproto.h Tue Jun 25 09:57:33 2019 */
|
||||
/* Copyright (c) NetHack Development Team 2018. */
|
||||
/* NetHack 3.7 sfproto.h */
|
||||
/* Copyright (c) NetHack Development Team 2019. */
|
||||
/* NetHack may be freely redistributed. See license for details. */
|
||||
|
||||
/* THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE! */
|
||||
|
||||
@@ -527,7 +527,7 @@ E char *FDECL(tgetstr, (const char *, char **));
|
||||
E char *FDECL(tgoto, (const char *, int, int));
|
||||
#endif
|
||||
|
||||
#if defined(ALLOC_C) || defined(MAKEDEFS_C)
|
||||
#if defined(ALLOC_C) || defined(MAKEDEFS_C) || defined(MDLIB_C)
|
||||
E genericptr_t FDECL(malloc, (size_t));
|
||||
E genericptr_t FDECL(realloc, (genericptr_t, size_t));
|
||||
#endif
|
||||
@@ -569,6 +569,7 @@ E int FDECL(atoi, (const char *));
|
||||
#endif /* !__cplusplus && !__GO32__ */
|
||||
#endif /* WIN32 */
|
||||
|
||||
#if !defined(CROSSCOMPILE) || defined(CROSSCOMPILE_TARGET)
|
||||
#include "lua.h"
|
||||
#include "lualib.h"
|
||||
#include "lauxlib.h"
|
||||
@@ -578,5 +579,5 @@ E int FDECL(atoi, (const char *));
|
||||
#else
|
||||
#define LUA_INTCAST(i) (i)
|
||||
#endif
|
||||
|
||||
#endif /* !CROSSCOMPILE || CROSSCOMPILE_TARGET */
|
||||
#endif /* SYSTEM_H */
|
||||
|
||||
Reference in New Issue
Block a user