From 14b532bf10813265dda2bcc2b4639b04ad943f15 Mon Sep 17 00:00:00 2001 From: nhmall Date: Mon, 28 Sep 2020 16:28:15 -0400 Subject: [PATCH] add cross-compile recipe for msdos - If you want to obtain the djgpp cross-compiler and tools/libs for MSDOS, which is available for linux and macOS, you can use the following script to obtain it: sh sys/msdos/fetch-cross-compiler.sh That script won't install anything, it is just file fetches. It will store the cross-compiler in subfolders of lib and the hints files are configured to find it appropriately there. Note: Both the fetch and the msdos cross-compile package target require unzip and zip to be available on your host build system. Cross-compiler bits: https://github.com/andrewwutw/build-djgpp and the pre-built binary for your platform from: https://github.com/andrewwutw/build-djgpp/releases/download/v3.0/ and a DOS-extender (for including in msdos packaging) from http://sandmann.dotster.com/cwsdpmi/csdpmi7b.zip and pdcurses from: https://github.com/wmcbrine/PDCurses.git The MSDOS cross-compile can then be carried out by specifying CROSS_TO_MSDOS=1 on the make command line. For example: make CROSS_TO_MSDOS=1 all make CROSS_TO_MSDOS=1 package You can explicitly include tty and curses support if desired, otherwise you'll end up with a tty-only cross-compile build: make WANT_WIN_TTY=1 WANT_WIN_CURSES=1 CROSS_TO_MSDOS=1 all Also note that building the msdos targets using the make command above, does not preclude you from building local linux or macOS targets as well. Just drop the CROSS_TO_MSDOS=1 from the make command line. The cross-compiler hints additions are enclosed inside ifdef sections and won't interfere with the non-cross-compile build in that case. --- sys/msdos/fetch-cross-compiler.sh | 97 ++++++++++++++++++++++++++ sys/unix/hints/include/cross-post.2020 | 46 ++++++++++++ sys/unix/hints/include/cross-pre.2020 | 80 +++++++++++++++++++++ 3 files changed, 223 insertions(+) create mode 100644 sys/msdos/fetch-cross-compiler.sh diff --git a/sys/msdos/fetch-cross-compiler.sh b/sys/msdos/fetch-cross-compiler.sh new file mode 100644 index 000000000..12d861fd3 --- /dev/null +++ b/sys/msdos/fetch-cross-compiler.sh @@ -0,0 +1,97 @@ +#!/bin/sh +#set -x + +if [ -z "$TRAVIS_BUILD_DIR" ]; then + export DJGPP_TOP=$(pwd)/lib/djgpp +else + export DJGPP_TOP="$TRAVIS_BUILD_DIR/lib/djgpp" +fi + +if [ -z "$GCCVER" ]; then + export GCCVER=gcc1010 +fi + +if [ -z "$LUA_VERSION" ]; then + export LUA_VERSION=5.4.0 +fi + +if [ ! -d "$(pwd)/lib" ]; then + echo "Set up for Unix build and 'make fetch-lua' first." + exit 1 +fi + +#DJGPP_URL="https://github.com/andrewwutw/build-djgpp/releases/download/v2.9/" +DJGPP_URL="https://github.com/andrewwutw/build-djgpp/releases/download/v3.0/" +if [ "$(uname)" = "Darwin" ]; then + #Mac + DJGPP_FILE="djgpp-osx-$GCCVER.tar.bz2" + if [ -z "HINTS" ]; then + export HINTS=macOS.2020 + fi +elif [ "$(expr substr $(uname -s) 1 5)" = "Linux" ]; then + #Linux + DJGPP_FILE="djgpp-linux64-$GCCVER.tar.bz2" + if [ -z "$HINTS" ]; then + export HINTS=linux.2020 + fi +elif [ "$(expr substr $(uname -s) 1 10)" = "MINGW32_NT" ]; then + #mingw + DJGPP_FILE="djgpp-mingw-$GCCVER-standalone.zip" +else + echo "No DJGPP release for you, sorry." + exit 1 +fi + +DJGPP_URL="$DJGPP_URL$DJGPP_FILE" + +# export + +if [ ! -d lib ]; then +mkdir -p lib +fi + +cd lib +if [ ! -f "$DJGPP_FILE" ]; then + if [ "$(uname)" = "Darwin" ]; then + #Mac + curl -L $DJGPP_URL -o $DJGPP_FILE + else + wget --no-hsts "$DJGPP_URL" + fi +fi + +if [ ! -d djgpp/i586-pc-msdosdjgpp ]; then + tar xjf "$DJGPP_FILE" + rm -f $DJGPP_FILE +fi + +# DOS-extender for use with djgpp +if [ ! -d djgpp/cwsdpmi ]; then + if [ "$(uname)" = "Darwin" ]; then + #Mac + curl http://sandmann.dotster.com/cwsdpmi/csdpmi7b.zip -o csdpmi7b.zip + else + wget --no-hsts http://sandmann.dotster.com/cwsdpmi/csdpmi7b.zip + fi + cd djgpp + mkdir -p cwsdpmi + cd cwsdpmi + unzip ../../csdpmi7b.zip + cd ../../ + rm csdpmi7b.zip +fi + +# PDCurses +if [ ! -d "pdcurses" ]; then + echo "Getting ../pdcurses from https://github.com/wmcbrine/PDCurses.git" ; \ + git clone --depth 1 https://github.com/wmcbrine/PDCurses.git pdcurses +fi + +cd ../ + +# Don't fail the build if lua fetch failed because we cannot do anything about it +# but don't bother proceeding forward either +if [ ! -d "lib/lua-$LUA_VERSION/src" ]; then + exit 0 +fi + diff --git a/sys/unix/hints/include/cross-post.2020 b/sys/unix/hints/include/cross-post.2020 index 14b54fc7b..844fa3e2b 100644 --- a/sys/unix/hints/include/cross-post.2020 +++ b/sys/unix/hints/include/cross-post.2020 @@ -3,6 +3,52 @@ # # Cross-compiling -POST section +ifdef CROSS_TO_MSDOS +# +$(TARGETDIR)/msdos.o : ../sys/msdos/msdos.c $(HACK_H) +$(TARGETDIR)/pckeys.o : ../sys/msdos/pckeys.c $(HACK_H) +$(TARGETDIR)/pctiles.o : ../sys/msdos/pctiles.c ../sys/msdos/portio.h $(HACK_H) +$(TARGETDIR)/video.o : ../sys/msdos/video.c ../sys/msdos/portio.h $(HACK_H) +$(TARGETDIR)/vidtxt.o : ../sys/msdos/vidtxt.c ../sys/msdos/portio.h \ + ../win/share/tile.h ../include/tileset.h $(HACK_H) +$(TARGETDIR)/vidvga.o : ../sys/msdos/vidvga.c ../sys/msdos/portio.h \ + ../win/share/tile.h ../include/tileset.h $(HACK_H) +$(TARGETDIR)/vidvesa.o : ../sys/msdos/vidvesa.c ../sys/msdos/portio.h \ + ../win/share/tile.h ../include/tileset.h $(HACK_H) +$(TARGETDIR)/vidstub.o : ../sys/msdos/vidvesa.c ../sys/msdos/portio.h \ + $(HACK_H) +$(TARGETDIR)/tile.o : tile.c +# +#.PHONY: dospkg +dospkg: $(GAMEBIN) $(TARGETDIR)/recover.exe ../dat/nhtiles.bmp + $(TARGET_STUBEDIT) $(GAMEBIN) minstack=2048K + mkdir -p $(TARGETDIR)/pkg + cp $(GAMEBIN) $(TARGETDIR)/pkg/NETHACK.EXE + cp ../dat/nhdat $(TARGETDIR)/pkg/NHDAT + cp ../dat/license $(TARGETDIR)/pkg/LICENSE + cp ../dat/nhtiles.bmp $(TARGETDIR)/pkg/NHTILES.BMP + cp ../dat/symbols $(TARGETDIR)/pkg/SYMBOLS + cp ../sys/share/NetHack.cnf $(TARGETDIR)/pkg/NETHACK.CNF + cp ../sys/msdos/sysconf $(TARGETDIR)/pkg/SYSCONF + cp ../doc/nethack.txt $(TARGETDIR)/pkg/NETHACK.TXT + cp ../lib/djgpp/cwsdpmi/bin/CWSDPMI.EXE $(TARGETDIR)/pkg/CWSDPMI.EXE + -touch $(TARGETDIR)/pkg/RECORD + zip -9 $(TARGETDIR)/NH370DOS.ZIP $(TARGETDIR)/pkg/* + @echo msdos package zip file $(TARGETDIR)/NH370DOS.ZIP +endif # CROSS_TO_MSDOS + +# +# shared file dependencies +# +$(TARGETDIR)/pcmain.o : ../sys/share/pcmain.c $(HACK_H) +$(TARGETDIR)/pcsys.o : ../sys/share/pcsys.c $(HACK_H) +$(TARGETDIR)/pctty.o : ../sys/share/pctty.c $(HACK_H) +$(TARGETDIR)/pcunix.o : ../sys/share/pcunix.c $(HACK_H) +$(TARGETDIR)/tileset.o : ../win/share/tileset.c +$(TARGETDIR)/bmptiles.o : ../win/share/bmptiles.c +$(TARGETDIR)/giftiles.o : ../win/share/giftiles.c +$(TARGETDIR)/recover.exe : $(TARGETDIR)/recover.o + # # Lua lib $(LUACROSSLIB): $(LUALIBOBJS) diff --git a/sys/unix/hints/include/cross-pre.2020 b/sys/unix/hints/include/cross-pre.2020 index 4fd3b09df..b3da7e30b 100644 --- a/sys/unix/hints/include/cross-pre.2020 +++ b/sys/unix/hints/include/cross-pre.2020 @@ -3,6 +3,15 @@ # # Cross-compiling -PRE section # + +ifdef CROSS_TO_MSDOS +BUILD_LUA=1 +BUILD_PDCURSES=1 +override TARGET = msdos +override TARGETDIR = ../targets/$(TARGET) +override TARGET_LIBS= +endif + ifdef BUILD_LUA #===============-================================================= # LUA library @@ -74,6 +83,9 @@ PDCOBJS = $(TARGETDIR)/pdcclip.o $(TARGETDIR)/pdcdisp.o \ $(TARGETDIR)/pdcscrn.o $(TARGETDIR)/pdcsetsc.o \ $(TARGETDIR)/pdcutil.o override TARGET_LIBS += $(PDCLIB) +ifdef CROSS_TO_MSDOS +PDCINCL += -I$(PDCTOP)/dos +endif BUILDMORE += $(PDCLIB) # Rules for PDCurses files $(TARGETDIR)/%.o : $(PDCTOP)/pdcurses/%.c @@ -87,6 +99,74 @@ PDCINCL= endif # WANT_WIN_CURSES endif # BUILD_PDCURSES +ifdef CROSS_TO_MSDOS +#===============-================================================= +# MSDOS cross-compile recipe +#===============-================================================= +# Uses an MSDOS djgpp cross-compiler on linux or macos. +# +# 1. You can obtain the cross-compiler for your system via: +# sys/msdos/fetch-cross.sh +# 2. Then +# make CROSS_TO_MSDOS=1 WANT_WIN_TTY=1 WANT_WIN_CURSES=1 all +# +# Source from http://www.lua.org/ftp/lua-5.4.0.tar.gz +#================================================================= + +CFLAGS += -DCROSSCOMPILE -DCROSSCOMPILE_HOST + +# +# Override the build tools and some obj files to +# reflect the msdos djgpp cross-compiler. +# +TOOLTOP1 = ../lib/djgpp/bin +TOOLTOP2 = ../lib/djgpp/i586-pc-msdosdjgpp/bin +override TARGET_CC = $(TOOLTOP1)/i586-pc-msdosdjgpp-gcc +override TARGET_CXX = $(TOOLTOP2)/g++ +override TARGET_AR = $(TOOLTOP1)/i586-pc-msdosdjgpp-gcc-ar +override TARGET_STUBEDIT = ../lib/djgpp/i586-pc-msdosdjgpp/bin/stubedit +override TARGET_CFLAGS = -c -O -I../include -I../sys/msdos -I../win/share \ + $(LUAINCL) -DDLB $(PDCURSESDEF) \ + -DUSE_TILES -DCROSSCOMPILE -DCROSSCOMPILE_TARGET +override TARGET_CXXFLAGS = $(TARGET_CFLAGS) +override TARGET_LINK = $(TOOLTOP1)/i586-pc-msdosdjgpp-gcc +override TARGET_LFLAGS= +override TARGET_LIBS += -lpc +override SYSSRC = ../sys/share/pcmain.c ../sys/msdos/msdos.c \ + ../sys/share/pcsys.c ../sys/share/pctty.c \ + ../sys/share/pcunix.c ../sys/msdos/video.c \ + ../sys/msdos/vidtxt.c ../sys/msdos/pckeys.c \ + ../sys/msdos/vidvga.c ../sys/msdos/vidvesa.c \ + ../win/share/bmptiles.c ../win/share/giftiles.c \ + ../win/share/tileset.c +override SYSOBJ= $(TARGETDIR)/pcmain.o $(TARGETDIR)/msdos.o \ + $(TARGETDIR)/pcsys.o $(TARGETDIR)/pctty.o \ + $(TARGETDIR)/pcunix.o $(TARGETDIR)/video.o \ + $(TARGETDIR)/vidtxt.o $(TARGETDIR)/pckeys.o \ + $(TARGETDIR)/vidvga.o $(TARGETDIR)/vidvesa.o \ + $(TARGETDIR)/bmptiles.o $(TARGETDIR)/giftiles.o \ + $(TARGETDIR)/tileset.o $(TARGETDIR)/tile.o +override WINLIB= +override LUALIB= +override GAMEBIN = $(TARGETDIR)/nethack.exe +override PACKAGE= dospkg +VARDATND += nhtiles.bmp +PREGAME = mkdir -p $(TARGETDIR) +CLEANMORE += rm -r $(TARGETDIR) +BUILDMORE += $(TARGETDIR)/recover.exe +# +ifdef WANT_WIN_CURSES +# rules for pdcurses dos-specific files +$(TARGETDIR)/%.o : $(PDCTOP)/dos/%.c + $(TARGET_CC) $(PDCINCL) $(TARGET_CFLAGS) -o$@ $< +endif # WANT_WIN_CURSES +# +# Rule for files in sys/msdos +$(TARGETDIR)/%.o : ../sys/msdos/%.c + $(TARGET_CC) $(TARGET_CFLAGS) -o$@ $< +endif # CROSS_TO_MSDOS +#================================================================= + ifdef WANT_WIN_CURSES # rules for pdcurses dos-specific files $(TARGETDIR)/%.o : $(PDCTOP)/sdl1/%.c -- 2.50.1