Copy lib/lua-$(VERSION)/src/liblua.h to lib/lua/ rather than lib/.
Instead of copying any of the header files or telling the compiler
where to find the lua ones, generate include/nhlua.h on the fly and
restrict the knowledge of where they are to it (paths are relative
to include/).
|/* nhlua.h - generated by top Makefile */
|#include "../lib/lua-5.3.5/src/lua.h"
|LUA_API int (lua_error) (lua_State *L) NORETURN;
|#include "../lib/lua-5.3.5/src/lualib.h"
|#include "../lib/lua-5.3.5/src/lauxlib.h"
|/*nhlua.h*/
This might need to be redone (or augmented by having CFLAGS add back
'-I path-to-lua') if some compiler can't find '#include "luaconf.h"'
issued by lua.h.
undefined reference to g.variables if certain parts of
drawing.c are included in host-side utilities, so
surround the offending code in
-> #if !defined(CROSSCOMPILE) || defined(CROSSCOMPILE_TARGET)
Reduce the implied reliance of a specific version of lua.
Instead of copying liblua.a to src/, copy it to lib/. Instead of
telling the compiler to look for headers in lib/lua-5.3.5/src/ as
well as in include/, copy the relevant ones to lib/ and tell the
compiler to look for them there. 'make spotless' in src/ will
remove both the object library and the header files from lib/ but
there really should be a new Makefile.lib to take care of that
directory.
Update Makefile.src to be able to build lua in case someone starts
with 'make all' there instead of in the top Makefile. It doesn't
duplicate the option to fetch the lua source package though.
NHinternal/../genFiles.c has been updated to mention lib/liblua.a
and lib/lua*.h as 'generated at compile time' in Files and to skip
lib/lua-* entirely if it comes across that (so not operating on a
completely clean tree). But it won't be accurate unless/until
other ports stage their lua files there instead of in src/ and
lib/lua-$(VERSION)/src/.
I haven't tried 'make depend' to see what it makes of the numerous
changes....
Unix Makefile.utl wasn't aware of the dependency of makedefs.o on
src/mdlib.c so didn't rebuild makedefs when it should have.
Eliminate several warnings:
mdlib.c - #if inside the arguments to macro Sprintf();
nhlua.c - nhl_error() ends with a call to lua_error() which doesn't
return, but neither of them were declared that way;
nhlsel.c - because of the previous, the 'else error' case of
l_selection_ellipse() led to complaints about uninitialized
variables;
sp_lev.c - missing 'const'.
I did minimal testing which went ok, but revisiting a couple of levels
gave me un-freed memory allocated by restore.c line 1337. (I haven't
looked at that at all.)
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
^^^^^^^^^^^^^^^