1#
2# NetHack 3.6  macosx10.11 $NHDT-Date: 1566346603 2019/08/21 00:16:43 $  $NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.53 $
3# Copyright (c) Kenneth Lorber, Kensington, Maryland, 2015.
4# NetHack may be freely redistributed.  See license for details.
5#
6#-PRE
7# Mac OS X (Darwin) hints file
8# This is for Mac OS X 10.10 through 10.13, and has been tested on 10.11
9# (El Capitan) and 10.13. If this doesn't work for some other
10# version of Mac OS X, make a new file for that OS, don't change this one.
11# And let us know about it.
12# Useful info: http://www.opensource.apple.com/darwinsource/index.html
13
14# You'll need to obtain and install XQuartz if you want X11 support.
15# (Attempting to run X11.app will describe where to get it.)
16
17# This hints file can build several different types of installations.
18# Edit the next section to match the type of build you need.
19
20# 1. Which window system(s) should be included in this binary?
21WANT_WIN_TTY=1
22#WANT_WIN_X11=1
23#WANT_WIN_QT=1
24#WANT_WIN_CURSES=1
25
26# 1a. What is the default window system?
27WANT_DEFAULT=tty
28#WANT_DEFAULT=x11
29#WANT_DEFAULT=qt
30#WANT_DEFAULT=curses
31
32# 1b. If you set WANT_WIN_QT, you need to
33#  A) set QTDIR either here or in the environment to point to the Qt2 or Qt3
34#     library installation root.  (Qt4 will not work; Qt3 does not presently
35#     compile under Leopard (MacOSX 10.5) out-of-the-box.)
36#  B) set XPMLIB to point to the Xpm library
37ifdef WANT_WIN_QT
38QTDIR=/Developer/Qt
39LIBXPM= -L/opt/X11/lib -lXpm
40endif	# WANT_WIN_QT
41
42# 2. Is this a build for a binary that will be shared among different users
43#    or will it be private to you?
44#    If it is shared:
45#	- it will be owned by the user and group listed
46#	- if the user does not exist, you MUST create it before installing
47#	  NetHack
48#	- if the group does not exist, it will be created.
49#	  NB: if the group already exists and is being used for something
50#	   besides games, you probably want to specify a new group instead
51#	  NB: the group will be created locally; if your computer is centrally
52#	   administered this may not be what you (or your admin) want.
53#	   Consider a non-shared install (WANT_SHARE_INSTALL=0) instead.
54#	- 'make install' must be run as "sudo make install"
55#WANT_SHARE_INSTALL=1
56GAMEUID  = $(USER)
57GAMEGRP  = games
58# build to run in the source tree - primarily for development.  Build with "make all"
59#WANT_SOURCE_INSTALL=1
60
61CC=gcc
62
63# At the moment this is just for debugging, but in the future it could be
64# useful for other things.  Requires SYSCF and an ANSI compiler.
65#WANT_WIN_CHAIN=1
66
67#
68# You shouldn't need to change anything below here.
69#
70
71#CFLAGS+=-W -Wimplicit -Wreturn-type -Wunused -Wformat -Wswitch -Wshadow -Wcast-qual -Wwrite-strings -DGCC_WARN
72CFLAGS+=-Wall -Wextra -Wno-missing-field-initializers -Wimplicit -Wreturn-type -Wunused -Wformat -Wswitch -Wshadow -Wwrite-strings -DGCC_WARN -ansi -pedantic -Wno-long-long
73# As of LLVM build 2336.1.00, this gives dozens of spurious messages, so
74# leave it out by default.
75#CFLAGS+=-Wunreachable-code
76
77# XXX -g vs -O should go here, -I../include goes in the makefile
78CFLAGS+=-g -I../include
79# older binaries use NOCLIPPING, but that disables SIGWINCH
80#CFLAGS+=-DNOCLIPPING
81CFLAGS+= -DNOMAIL -DNOTPARMDECL -DHACKDIR=\"$(HACKDIR)\"
82CFLAGS+= -DDEFAULT_WINDOW_SYS=\"$(WANT_DEFAULT)\" -DDLB
83
84CFLAGS+= -DGREPPATH=\"/usr/bin/grep\"
85
86ifdef WANT_WIN_CHAIN
87CFLAGS+= -DWINCHAIN
88HINTSRC=$(CHAINSRC)
89HINTOBJ=$(CHAINOBJ)
90endif
91
92ifdef WANT_WIN_TTY
93WINSRC = $(WINTTYSRC)
94WINOBJ = $(WINTTYOBJ)
95WINLIB = $(WINTTYLIB)
96WINTTYLIB=-lncurses
97else	# !WANT_WIN_TTY
98CFLAGS += -DNOTTYGRAPHICS
99endif	# !WANT_WIN_TTY
100
101ifdef WANT_WIN_CURSES
102CFLAGS += -DCURSES_GRAPHICS
103WINSRC += $(WINCURSESSRC)
104WINOBJ += $(WINCURSESOBJ)
105WINLIB += -lncurses
106endif
107
108ifdef WANT_WIN_X11
109WINX11LIB = -lXaw -lXmu -lXext -lXt -lX11
110VARDATND = x11tiles NetHack.ad pet_mark.xbm pilemark.xbm
111# -x: if built without dlb, some versions of mkfontdir think *.lev are fonts
112POSTINSTALL+= bdftopcf win/X11/nh10.bdf > $(HACKDIR)/nh10.pcf; ( cd $(HACKDIR); mkfontdir -x .lev );
113# separate from CFLAGS so that we don't pass it to every file
114X11CFLAGS = -I/opt/X11/include
115CFLAGS += -DX11_GRAPHICS
116# avoid repeated complaints about _X_NONNULL(args...) in <X11/Xfuncproto.h>
117X11CFLAGS += -Wno-variadic-macros
118ifdef USE_XPM
119CFLAGS += -DUSE_XPM
120WINX11LIB += -lXpm
121VARDATND += rip.xpm
122endif
123WINSRC += $(WINX11SRC)
124WINOBJ += $(WINX11OBJ)
125WINLIB += $(WINX11LIB)
126LFLAGS=-L/opt/X11/lib
127endif	# WANT_WIN_X11
128
129ifdef WANT_WIN_QT
130CFLAGS += -DQT_GRAPHICS -DNOUSER_SOUNDS
131CFLAGS += -isysroot /Developer/SDKs/MacOSX10.4u.sdk -mmacosx-version-min=10.4
132LINK=g++
133WINSRC += $(WINQTSRC)
134WINLIB += $(WINQTLIB) $(LIBXPM)
135WINLIB += -framework Carbon -framework QuickTime -lz -framework OpenGL
136WINLIB += -framework AGL
137ifdef WANT_WIN_X11
138	# prevent duplicate tile.o in WINOBJ
139WINOBJ = $(sort $(WINQTOBJ) $(WINX11OBJ))
140ifdef WANT_WIN_TTY
141WINOBJ += $(WINTTYOBJ)
142endif	# WANT_WIN_TTY
143else	# !WANT_WIN_X11
144WINOBJ += $(WINQTOBJ)
145endif	# !WANT_WIN_X11
146
147# XXX if /Developer/qt exists and QTDIR not set, use that
148ifndef QTDIR
149$(error QTDIR not defined in the environment or Makefile)
150endif	# QTDIR
151# XXX make sure QTDIR points to something reasonable
152else	# !WANT_WIN_QT
153LINK=$(CC)
154endif	# !WANT_WIN_QT
155
156ifdef WANT_SHARE_INSTALL
157# if $GAMEUID is root, we install into roughly proper Mac locations, otherwise
158# we install into ~/nethackdir
159ifeq ($(GAMEUID),root)
160PREFIX:=/Library/NetHack
161SHELLDIR=/usr/local/bin
162HACKDIR=$(PREFIX)/nethackdir
163CHOWN=chown
164CHGRP=chgrp
165# We run sgid so the game has access to both HACKDIR and user preferences.
166GAMEPERM = 02755
167else	# ! root
168PREFIX:=/Users/$(GAMEUID)
169SHELLDIR=$(PREFIX)/bin
170HACKDIR=$(PREFIX)/Library/NetHack/nethackdir
171CHOWN=/usr/bin/true
172CHGRP=/usr/bin/true
173GAMEPERM = 0500
174endif	# ! root
175VARFILEPERM = 0664
176VARDIRPERM = 0775
177ROOTCHECK= [[ `id -u` == 0 ]] || ( echo "Must run install with sudo."; exit 1)
178# XXX it's nice we don't write over sysconf, but we've already erased it
179# make sure we have group GAMEUID and group GAMEGRP
180PREINSTALL= . sys/unix/hints/macosx.sh user2 $(GAMEUID); . sys/unix/hints/macosx.sh group2 $(GAMEGRP); mkdir $(SHELLDIR); chown $(GAMEUID) $(SHELLDIR)
181POSTINSTALL+= sys/unix/hints/macosx.sh editsysconf sys/unix/sysconf $(HACKDIR)/sysconf; $(CHOWN) $(GAMEUID) $(HACKDIR)/sysconf; $(CHGRP) $(GAMEGRP) $(HACKDIR)/sysconf; chmod $(VARFILEPERM) $(HACKDIR)/sysconf;
182CFLAGS+=-DSYSCF -DSYSCF_FILE=\"$(HACKDIR)/sysconf\" -DSECURE
183else ifdef WANT_SOURCE_INSTALL
184PREFIX=$(abspath $(NHSROOT))
185# suppress nethack.sh
186#SHELLDIR=
187HACKDIR=$(PREFIX)/playground
188CHOWN=/usr/bin/true
189CHGRP=/usr/bin/true
190GAMEPERM = 0700
191VARFILEPERM = 0600
192VARDIRPERM = 0700
193POSTINSTALL+= sys/unix/hints/macosx.sh editsysconf sys/unix/sysconf $(HACKDIR)/sysconf;
194# We can use "make all" to build the whole thing - but it misses some things:
195MOREALL=$(MAKE) install
196CFLAGS+=-DSYSCF -DSYSCF_FILE=\"$(HACKDIR)/sysconf\" -DSECURE
197else	# !WANT_SOURCE_INSTALL
198PREFIX:=$(wildcard ~)
199SHELLDIR=$(PREFIX)/bin
200HACKDIR=$(PREFIX)/nethackdir
201CHOWN=/usr/bin/true
202CHGRP=/usr/bin/true
203GAMEPERM = 0700
204VARFILEPERM = 0600
205VARDIRPERM = 0700
206ifdef WANT_WIN_X11
207# install nethack.rc as ~/.nethackrc if no ~/.nethackrc exists
208PREINSTALL= cp -n win/X11/nethack.rc ~/.nethackrc || true
209endif	# WANT_WIN_X11
210POSTINSTALL+= sys/unix/hints/macosx.sh editsysconf sys/unix/sysconf $(HACKDIR)/sysconf; $(CHOWN) $(GAMEUID) $(HACKDIR)/sysconf; $(CHGRP) $(GAMEGRP) $(HACKDIR)/sysconf; chmod $(VARFILEPERM) $(HACKDIR)/sysconf;
211CFLAGS+=-DSYSCF -DSYSCF_FILE=\"$(HACKDIR)/sysconf\" -DSECURE
212endif	# !WANT_SOURCE_INSTALL
213
214INSTDIR=$(HACKDIR)
215VARDIR=$(HACKDIR)
216
217
218# ~/Library/Preferences/NetHack Defaults
219# OPTIONS=name:player,number_pad,menustyle:partial,!time,showexp
220# OPTIONS=hilite_pet,toptenwin,msghistory:200,windowtype:Qt
221#
222# Install.Qt mentions a patch for macos - it's not there (it seems to be in the Qt binary
223# package under the docs directory).
224
225#-POST
226ifdef MAKEFILE_TOP
227###
228### Packaging
229###
230# Notes:
231# 1) The Apple developer utilities must be installed in the default location.
232# 2) Do a normal build before trying to package the game.
233# 3) This matches the 3.4.3 Term package, but there are some things that should
234#    be changed.
235
236ifdef WANT_WIN_TTY
237DEVUTIL=/Developer/Applications/Utilities
238SVS=$(shell $(NHSROOT)/util/makedefs --svs)
239SVSDOT=$(shell $(NHSROOT)/util/makedefs --svs .)
240
241PKGROOT_UG	= PKGROOT/$(PREFIX)
242PKGROOT_UGLN	= PKGROOT/$(HACKDIR)
243PKGROOT_BIN	= PKGROOT/$(SHELLDIR)
244build_tty_pkg:
245ifneq (,$(WANT_WIN_X11)$(WANT_WIN_QT))
246	-echo build_tty_pkg only works for a tty-only build
247	exit 1
248else
249	rm -rf NetHack-$(SVS)-mac-Term.pkg NetHack-$(SVS)-mac-Term.dmg
250	$(MAKE) build_package_root
251	rm -rf RESOURCES
252	mkdir RESOURCES
253	#enscript --language=rtf -o - < dat/license >RESOURCES/License.rtf
254	sys/unix/hints/macosx.sh descplist > RESOURCES/Description.plist
255	sys/unix/hints/macosx.sh infoplist > Info.plist
256
257	mkdir PKGROOT/Applications
258	#osacompile -o NetHackQt/NetHackQt.app/nethackdir/NetHackRecover.app \
259	#	 win/macosx/NetHackRecover.applescript
260	#cp win/macosx/recover.pl NetHackQt/NetHackQt.app/nethackdir
261	osacompile -o PKGROOT/Applications/NetHackRecover.app \
262		 win/macosx/NetHackRecover.applescript
263	cp win/macosx/recover.pl $(PKGROOT_UGLN)
264
265	osacompile -o PKGROOT/Applications/NetHackTerm.app \
266		 win/macosx/NetHackTerm.applescript
267
268	# XXX integrate into Makefile.doc
269	(cd doc; cat Guidebook.mn | ../util/makedefs --grep --input - --output - \
270	| tbl tmac.n - | groff | pstopdf -i -o Guidebook.pdf)
271	cp doc/Guidebook.pdf $(PKGROOT_UG)/doc/NetHackGuidebook.pdf
272
273	osacompile -o PKGROOT/Applications/NetHackGuidebook.app \
274		 win/macosx/NetHackGuidebook.applescript
275
276	mkdir -p PKG
277	pkgbuild --root PKGROOT --identifier org.nethack.term --scripts PKGSCRIPTS PKG/NH-Term.pkg
278	productbuild --synthesize --product Info.plist --package PKG/NH-Term.pkg Distribution.xml
279	productbuild --distribution Distribution.xml --resources RESOURCES --package-path PKG NetHack-$(SVS)-mac-Term.pkg
280	hdiutil create -verbose -srcfolder NetHack-$(SVS)-mac-Term.pkg NetHack-$(SVS)-mac-Term.dmg
281
282build_package_root:
283	cd src/..       # make sure we are at TOP
284	rm -rf PKGROOT
285	mkdir -p $(PKGROOT_UG)/lib $(PKGROOT_BIN) $(PKGROOT_UG)/man/man6 $(PKGROOT_UG)/doc $(PKGROOT_UGLN)
286	install -p src/nethack $(PKGROOT_BIN)
287	# XXX should this be called nethackrecover?
288	install -p util/recover $(PKGROOT_BIN)
289	install -p doc/nethack.6 $(PKGROOT_UG)/man/man6
290	install -p doc/recover.6 $(PKGROOT_UG)/man/man6
291	install -p doc/Guidebook $(PKGROOT_UG)/doc
292	install -p dat/nhdat $(PKGROOT_UGLN)
293	sys/unix/hints/macosx.sh editsysconf sys/unix/sysconf $(PKGROOT_UGLN)/sysconf
294	cd dat; install -p $(DATNODLB) ../$(PKGROOT_UGLN)
295# XXX these files should be somewhere else for good Mac form
296	touch $(PKGROOT_UGLN)/perm $(PKGROOT_UGLN)/record $(PKGROOT_UGLN)/logfile $(PKGROOT_UGLN)/xlogfile
297	mkdir $(PKGROOT_UGLN)/save
298# XXX what about a news file?
299
300	mkdir -p PKGSCRIPTS
301	echo '#!/bin/sh'                              >  PKGSCRIPTS/postinstall
302	echo dseditgroup -o create -r '"Games Group"' -s 3600 $(GAMEGRP) >> PKGSCRIPTS/postinstall
303	echo $(CHOWN) -R $(GAMEUID) $(HACKDIR)        >> PKGSCRIPTS/postinstall
304	echo $(CHGRP) -R $(GAMEGRP) $(HACKDIR)        >> PKGSCRIPTS/postinstall
305	echo $(CHOWN) $(GAMEUID) $(SHELLDIR)/nethack  >> PKGSCRIPTS/postinstall
306	echo $(CHGRP) $(GAMEGRP) $(SHELLDIR)/nethack  >> PKGSCRIPTS/postinstall
307	echo $(CHOWN) $(GAMEUID) $(SHELLDIR)/recover  >> PKGSCRIPTS/postinstall
308	echo $(CHGRP) $(GAMEGRP) $(SHELLDIR)/recover  >> PKGSCRIPTS/postinstall
309	echo chmod $(VARDIRPERM)  $(HACKDIR)          >> PKGSCRIPTS/postinstall
310	echo chmod $(VARDIRPERM)  $(HACKDIR)/save     >> PKGSCRIPTS/postinstall
311	echo chmod $(FILEPERM)    $(HACKDIR)/license  >> PKGSCRIPTS/postinstall
312	echo chmod $(FILEPERM)    $(HACKDIR)/nhdat    >> PKGSCRIPTS/postinstall
313	echo chmod $(FILEPERM)    $(HACKDIR)/symbols  >> PKGSCRIPTS/postinstall
314	echo chmod $(VARFILEPERM) $(HACKDIR)/perm     >> PKGSCRIPTS/postinstall
315	echo chmod $(VARFILEPERM) $(HACKDIR)/record   >> PKGSCRIPTS/postinstall
316	echo chmod $(VARFILEPERM) $(HACKDIR)/logfile  >> PKGSCRIPTS/postinstall
317	echo chmod $(VARFILEPERM) $(HACKDIR)/xlogfile >> PKGSCRIPTS/postinstall
318	echo chmod $(VARFILEPERM) $(HACKDIR)/sysconf  >> PKGSCRIPTS/postinstall
319	echo chmod $(GAMEPERM)   $(SHELLDIR)/nethack  >> PKGSCRIPTS/postinstall
320	echo chmod $(EXEPERM)    $(SHELLDIR)/recover  >> PKGSCRIPTS/postinstall
321	chmod 0775 PKGSCRIPTS/postinstall
322
323endif	# end of build_tty_pkg
324endif	# WANT_WIN_TTY for packaging
325
326ifdef WANT_WIN_QT
327# XXX untested and incomplete (see below)
328build_qt_pkg:
329ifneq (,$(WANT_WIN_X11)$(WANT_WIN_TTY))
330	-echo build_qt_pkg only works for a qt-only build
331	exit 1
332else
333	$(MAKE) build_package_root
334	rm -rf NetHackQt
335	mkdir -p NetHackQt/NetHackQt.app/nethackdir/save
336	mkdir NetHackQt/Documentation
337	cp doc/Guidebook.txt doc/nethack.txt doc/recover.txt NetHackQt/Documentation
338
339	osacompile -o NetHackQt/NetHackQt.app/nethackdir/NetHackRecover.app \
340		 win/macosx/NetHackRecover.applescript
341	cp win/macosx/recover.pl NetHackQt/NetHackQt.app/nethackdir
342
343	mkdir -p NetHackQt/NetHackQt.app/Contents/Frameworks
344	cp $(QTDIR)/libqt-mt.3.dylib NetHackQt/NetHackQt.app/Contents/Frameworks
345
346	mkdir NetHackQt/NetHackQt.app/Contents/MacOS
347	mv PKGROOT/nethack NetHackQt/NetHackQt.app/Contents/MacOS
348
349	mv PKGROOT/lib/nethackdir NetHackQt/NetHackQt.app/nethackdir
350
351# XXX still missing:
352#NetHackQt/NetHackQt.app
353# /Contents
354#	Info.plist
355#	Resources/nethack.icns
356#NetHackQt/Documentation
357#NetHackQtRecover.txt
358#NetHack Defaults.txt
359#changes.patch XXX is this still needed?  why isn't it part of the tree?
360#  doesn't go here
361	hdiutil create -verbose -srcfolder NetHackQt NetHack-$(SVS)-macosx-qt.dmg
362endif	# end of build_qt_pkg
363endif	# WANT_WIN_QT for packaging
364endif	# MAKEFILE_TOP
365