From e75535497be3fcec83562c7d32e86efe95dbfd70 Mon Sep 17 00:00:00 2001 From: nhmall Date: Mon, 3 Jul 2023 11:44:50 -0400 Subject: [PATCH] add support for mips cross-compile to *.370 hints Also close #1041 --- sys/unix/hints/include/cross-post.370 | 49 +++++++++++++- sys/unix/hints/include/cross-pre.370 | 96 ++++++++++++++++++++++++++- 2 files changed, 140 insertions(+), 5 deletions(-) diff --git a/sys/unix/hints/include/cross-post.370 b/sys/unix/hints/include/cross-post.370 index b2f92f5c3..7be198461 100644 --- a/sys/unix/hints/include/cross-post.370 +++ b/sys/unix/hints/include/cross-post.370 @@ -103,6 +103,32 @@ $(TARGETPFX)winshim.o : ../win/shim/winshim.c $(HACK_H) $(TARGETPFX)libnhmain.o : ../sys/libnh/libnhmain.c $(HACK_H) endif # CROSS_TO_WASM # +ifdef CROSS_TO_MIPS +$(MIPS_TARGET): pregame $(TARGETPFX)date.o $(HOSTOBJ) $(HOBJ) $(LUACROSSLIB) $(MIPS_DATA_DIR) + -rm $@ + $(TARGET_CC) $(TARGET_LFLAGS) $(TARGET_CFLAGS) -o $@ \ + $(HOBJ) $(TARGETPFX)date.o $(TARGET_LIBS) + +$(MIPS_DATA_DIR): $(MIPS_DATA_DIR)/nhdat + touch $(MIPS_DATA_DIR)/perm + touch $(MIPS_DATA_DIR)/record + touch $(MIPS_DATA_DIR)/logfile + touch $(MIPS_DATA_DIR)/xlogfile + touch $(MIPS_DATA_DIR)/livelog + cp ../sys/unix/sysconf $(MIPS_DATA_DIR)/sysconf + +$(MIPS_DATA_DIR)/nhdat: + ( cd ..; $(MAKE) INSTDIR='$(MIPS_DATA_DIR)' $(MIPSDEP) dofiles-dlb ) + +# +$(TARGETPFX)unixmain.o : ../sys/unix/unixmain.c $(HACK_H) +$(TARGETPFX)unixres.o : ../sys/unix/unixres.c $(HACK_H) +$(TARGETPFX)unixunix.o : ../sys/unix/unixunix.c $(HACK_H) +$(TARGETPFX)ioctl.o : ../sys/share/ioctl.c $(HACK_H) +$(TARGETPFX)unixtty.o : ../sys/share/unixtty.c $(HACK_H) +endif # CROSS_TO_MIPS +# + ifdef CROSS_SHARED # shared file dependencies @@ -165,12 +191,31 @@ $(TARGETPFX)lvm.o : $(LUATOP)/src/lvm.c $(TARGETPFX)lzio.o : $(LUATOP)/src/lzio.c endif # BUILD_TARGET_LUA +ifdef BUILD_TARGET_NCURSES +.PHONY: build-ncurses +ifdef MAKEFILE_SRC +../lib/ncurses.tar.gz: + @echo "You will need to successfully execute 'make CROSS_TO_MIPS=1 fetch-ncurses' first" + @false +$(TARGETPFX)ncurses/lib/libncurses.a: ../lib/ncurses.tar.gz + (cd $(TARGETDIR) ; mkdir -p ncurses ; cd ncurses ; tar -xf ../../../lib/ncurses.tar.gz --strip-components=1 ; \ + ./configure --build i686-pc-linux-gnu --host mipsel-linux-gnu ; \ + make ; \ + cd ../../../src) +endif #MAKEFILE_SRC +ifdef MAKEFILE_TOP +.PHONY: fetch-ncurses +fetch-ncurses: + (cd lib ; curl https://invisible-island.net/datafiles/release/ncurses.tar.gz --output ncurses.tar.gz ; cd ..) +endif +endif #BUILD_TARGET_NCURSES + ifdef BUILD_PDCURSES ifdef WANT_WIN_CURSES $(TARGETPFX)pdclib.a : $(PDCLIBOBJS) $(PDCOBJS) if [ -f $@ ]; then rm $@; fi; $(TARGET_AR) rcs $@ $(PDCLIBOBJS) $(PDCOBJS) -endif +endif #WANT_WIN_CURSES # PDCurses src $(TARGETPFX)addch.o : $(PDCTOP)/pdcurses/addch.c $(TARGETPFX)addchstr.o : $(PDCTOP)/pdcurses/addchstr.c @@ -223,5 +268,3 @@ endif # BUILD_PDCURSES # # End of cross-compiling -POST section #===============-================================================= - - diff --git a/sys/unix/hints/include/cross-pre.370 b/sys/unix/hints/include/cross-pre.370 index d385e6cf6..a3b4d1d9a 100644 --- a/sys/unix/hints/include/cross-pre.370 +++ b/sys/unix/hints/include/cross-pre.370 @@ -26,6 +26,18 @@ override TARGETPFX = $(TARGETDIR)/ override TARGET_LIBS= endif +ifdef CROSS_TO_MIPS +CROSS=1 +BUILD_TARGET_LUA=1 +BUILD_TARGET_NCURSES=1 +HACKDIR=/ +PREFIX= +override TARGET = mips +override TARGETDIR=../targets/$(TARGET) +override TARGETPFX = $(TARGETDIR)/ +override TARGET_LIBS= +endif + ifdef CROSS override PREGAME= override BUILDMORE= @@ -126,10 +138,22 @@ PDCINCL= endif # WANT_WIN_CURSES endif # BUILD_PDCURSES +ifdef BUILD_TARGET_NCURSES +#================================================================= +# ncurses +# Source from https://invisible-island.net/datafiles/release/ncurses.tar.gz +# +#================================================================= +NCURSESLIBDIR ?= $(TARGETPFX)ncurses/lib +NCURSESLIB ?= $(NCURSESLIBDIR)/libncurses.a +#override TARGET_LIBS += $(NCURSESLIB) +override BUILDMORE += $(NCURSESLIB) +endif # BUILD_TARGET_NCURSES + 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: @@ -344,6 +368,74 @@ $(TARGETPFX)%.o : ../sys/libnh/%.c $(TARGETPFX)%.o : ../win/shim/%.c $(TARGET_CC) $(TARGET_CFLAGS) -c -o$@ $< endif # CROSS_TO_WASM + + +ifdef CROSS_TO_MIPS +#================================================================ +# MIPS cross-compile recipe +#================================================================ +# Uses an MIPS linux cross-compiler on linux or macos. +# +# 1. You can obtain the cross-compiler for ubuntu via: +# sudo apt -y install gcc-mipsel-linux-gnu g++-mipsel-linux-gnu +# For macOS, perhaps check for a mips cross-compiler on +# home-brew or macports. +# +# 2. Then +# make CROSS_TO_MIPS=1 WANT_WIN_TTY=1 WANT_WIN_CURSES=1 all +# +#================================================================= + +CFLAGS += -DCROSSCOMPILE + +# +# Override the build tools and some obj files to +# reflect the mips cross-compiler. +# +override TARGET_CC = mipsel-linux-gnu-gcc +override TARGET_CXX = CXX=mipsel-linux-gnu-g++ +override TARGET_AR = mipsel-linux-gnu-ar +#override TARGET_LINK = mipsel-linux-gnu-ld +MIPS_TARGET_CFLAGS = -c -O -I../include -I../sys/unix -I../win/share \ + $(LUAINCL) -DDLB \ + -DCROSSCOMPILE -DCROSSCOMPILE_TARGET \ + -DCROSS_TO_MIPS \ + -Wall -Wextra -Wno-missing-field-initializers -Wreturn-type -Wunused \ + -Wformat -Wswitch -Wshadow -Wwrite-strings \ + -Wimplicit -Wimplicit-function-declaration -Wimplicit-int \ + -Wmissing-parameter-type -Wold-style-definition -Wstrict-prototypes +MIPS_TARGET_CXXFLAGS = -c -O -I../include -I../sys/unix -I../win/share \ + $(LUAINCL) -DDLB \ + -DUSE_TILES -DCROSSCOMPILE -DCROSSCOMPILE_TARGET -DCROSS_TO_MIPS \ + -Wall -Wextra -Wno-missing-field-initializers -Wreturn-type -Wunused \ + -Wformat -Wswitch -Wshadow -Wwrite-strings -Wno-maybe-uninitialized +override TARGET_CFLAGS = $(MIPS_TARGET_CFLAGS) -Wmissing-declarations \ + -Wmissing-prototypes -pedantic -Wmissing-declarations \ + -Wformat-nonliteral +override TARGET_CXXFLAGS = $(MIPS_TARGET_CXXFLAGS) +ifdef CPLUSPLUS_NEEDED +override TARGET_LINK = mipsel-linux-gnu-gcc +else +override TARGET_LINK = mipsel-linux-gnu-g++ +endif +override TARGET_LFLAGS= +override SYSOBJ = $(TARGETPFX)ioctl.o $(TARGETPFX)unixmain.o $(TARGETPFX)unixtty.o \ + $(TARGETPFX)unixunix.o $(TARGETPFX)unixres.o +override WINLIB = $(NCURSESLIB) +override LUALIB= +override LUALIBS= +override TOPLUALIB= +#override GAMEBIN= +#override PACKAGE= +override PREGAME += mkdir -p $(TARGETDIR) ; +override CLEANMORE += rm -f -r $(TARGETDIR) ; +# Rule for file in sys/unix +#$(TARGETPFX)%.o : ../sys/unix/%.c +# $(TARGET_CC) $(TARGET_CFLAGS) -c -o$@ $< +# Rule for file in sys/share +#$(TARGETPFX)%.o : ../sys/share/%.c +# $(TARGET_CC) $(TARGET_CFLAGS) -c -o$@ $< +endif # CROSS_TO_MIPS #================================================================= ifdef WANT_WIN_CURSES