From 85b23ae08ffc8c1fbe001d9690ffdcee1eb58a39 Mon Sep 17 00:00:00 2001
From: Sascha Wildner <saw@online.de>
Date: Wed, 7 Feb 2018 10:17:40 +0100
Subject: [PATCH] phanta setup

---
 games/phantasia/Makefile       | 36 ++++++++++++------------------------
 games/phantasia/Makefile.inc   |  1 +
 games/phantasia/include.h      | 11 +++++++++++
 games/phantasia/setup.c        | 12 +++++++++++-
 games/phantasia/setup/Makefile | 14 ++++++++++++++
 5 files changed, 49 insertions(+), 25 deletions(-)
 create mode 100644 games/phantasia/Makefile.inc
 create mode 100644 games/phantasia/setup/Makefile

diff --git a/games/phantasia/Makefile b/games/phantasia/Makefile
index 1f23ed373e..0365f229dd 100644
--- a/games/phantasia/Makefile
+++ b/games/phantasia/Makefile
@@ -9,38 +9,26 @@ LDADD=	-lm
 VARGAMES=
 GAMESCURSES=
 
-NXLDLIBS=	-lm
-
 DATAFILES=	characs gold lastdead mess monsters motd scoreboard void
-CLEANFILES=	${DATAFILES} cross-phantglobs.no map setup.nx setup.no \
-		stamp.setuprun
-
-all: stamp.setuprun
-
-build-tools: setup.nx
-
-cross-phantglobs.no: phantglobs.c
-	${NXCC} ${NXCFLAGS} -c ${.ALLSRC} -o ${.TARGET}
+CLEANFILES=	${DATAFILES} map
 
-stamp.setuprun: monsters.asc setup.nx
-	./setup.nx -m ${.CURDIR}/monsters.asc
-	touch ${.TARGET}
+FILES=		${DATAFILES}
+FILESMODE=		660
+FILESMODE_monsters=	640
+FILESGRP=	${BINGRP}
+FILESDIR=	/var/games/phantasia
+SUBDIR=	setup
 
-setup.nx: cross-phantglobs.no setup.no ${LIBM}
-	${NXCC} ${NXCFLAGS} ${NXLDFLAGS} ${.ALLSRC} ${NXLDLIBS} -o ${.TARGET}
+${DATAFILES:Nmonsters}: monsters
 
-beforeinstall:
-.for file in ${DATAFILES}
-.if !exists(${DESTDIR}/var/games/phantasia/${file})
-	${INSTALL} -o ${BINOWN} -g ${BINGRP} -m 660 \
-	    ${file} ${DESTDIR}/var/games/phantasia
-.endif
-.endfor
+monsters: setup monsters.asc
+	${.OBJDIR}/setup/setup.nx -m ${.ALLSRC}
 
 # Make Phantasia map.  Change the map commands reflect your installation.
 # PLOTDEVICE is used for plotting the map.  Change as appropriate.
+# requires dports graphics/plotutils
 map: map.c
-	${CC} -static -O ${.CURDIR}/map.c -lplot -o ${.TARGET}
+	${CC} -static -O ${.CURDIR}/map.c -L/usr/local/lib -lplot -o ${.TARGET}
 	./map | plot > /dev/tty
 
 .include <bsd.prog.mk>
diff --git a/games/phantasia/Makefile.inc b/games/phantasia/Makefile.inc
new file mode 100644
index 0000000000..01b5f23410
--- /dev/null
+++ b/games/phantasia/Makefile.inc
@@ -0,0 +1 @@
+.include "../Makefile.inc"
diff --git a/games/phantasia/include.h b/games/phantasia/include.h
index 4876e86448..b59d4bdfde 100644
--- a/games/phantasia/include.h
+++ b/games/phantasia/include.h
@@ -3,7 +3,9 @@
  */
 
 #include <ctype.h>
+#ifndef COMPILING_SETUP
 #include <curses.h>
+#endif
 #include <math.h>
 #include <setjmp.h>
 #include <signal.h>
@@ -14,6 +16,15 @@
 #include <string.h>
 #include <unistd.h>
 
+#ifdef COMPILING_SETUP
+/* XXX this used to be provided by curses.h */
+#include <stdio.h>	/* for FILE */
+#include <stdbool.h>	/* for bool */
+#ifndef TRUE
+#define	TRUE	1
+#endif
+#endif
+
 #include "macros.h"
 #include "phantdefs.h"
 #include "phantstruct.h"
diff --git a/games/phantasia/setup.c b/games/phantasia/setup.c
index de4cf71bc1..41e3a5d7a1 100644
--- a/games/phantasia/setup.c
+++ b/games/phantasia/setup.c
@@ -3,11 +3,21 @@
  *
  * $FreeBSD: src/games/phantasia/setup.c,v 1.11 1999/11/16 02:57:34 billf Exp $
  */
-#include "include.h"
+/*#include "include.h"*/
+#include <sys/param.h>
 #include <sys/types.h>
 #include <sys/stat.h>
+#include <fcntl.h>
+#include <math.h>
+#include <setjmp.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
 #include <unistd.h>
 
+#include "include.h"
+
 void Error(const char *, const char *) __dead2;
 
 static const char *const files[] = {		/* all files to create */
diff --git a/games/phantasia/setup/Makefile b/games/phantasia/setup/Makefile
new file mode 100644
index 0000000000..d12889ddb6
--- /dev/null
+++ b/games/phantasia/setup/Makefile
@@ -0,0 +1,14 @@
+.PATH: ${.CURDIR}/..
+
+PROG=	setup
+SRCS=	phantglobs.c setup.c
+
+# for floor()
+LDADD+=	-lm
+
+CFLAGS+=-DCOMPILING_SETUP -I${.CURDIR}/..
+
+# this setup is used in place, it is not installed anywhere
+install:
+
+.include <bsd.hostprog.mk>
-- 
2.15.1

