1#
2# NetHack 3.7  macosx10.14 $NHDT-Date: 1596498422 2020/08/03 23:47:02 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.64 $
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.14 or later.
9# 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
111POSTINSTALL+= bdftopcf win/X11/nh10.bdf > $(HACKDIR)/nh10.pcf; ( cd $(HACKDIR); mkfontdir -x .lev );
112# separate from CFLAGS so that we don't pass it to every file
113X11CFLAGS = -I/opt/X11/include
114CFLAGS += -DX11_GRAPHICS
115# avoid repeated complaints about _X_NONNULL(args...) in <X11/Xfuncproto.h>
116X11CFLAGS += -Wno-variadic-macros
117ifdef USE_XPM
118CFLAGS += -DUSE_XPM
119WINX11LIB += -lXpm
120VARDATND += rip.xpm
121endif
122WINSRC += $(WINX11SRC)
123WINOBJ += $(WINX11OBJ)
124WINLIB += $(WINX11LIB)
125LFLAGS=-L/opt/X11/lib
126endif	# WANT_WIN_X11
127
128ifdef WANT_WIN_QT
129CFLAGS += -DQT_GRAPHICS -DNOUSER_SOUNDS
130CFLAGS += -isysroot /Developer/SDKs/MacOSX10.4u.sdk -mmacosx-version-min=10.4
131LINK=g++
132WINSRC += $(WINQTSRC)
133WINLIB += $(WINQTLIB) $(LIBXPM)
134WINLIB += -framework Carbon -framework QuickTime -lz -framework OpenGL
135WINLIB += -framework AGL
136ifdef WANT_WIN_X11
137	# prevent duplicate tile.o in WINOBJ
138WINOBJ = $(sort $(WINQTOBJ) $(WINX11OBJ))
139ifdef WANT_WIN_TTY
140WINOBJ += $(WINTTYOBJ)
141endif	# WANT_WIN_TTY
142else	# !WANT_WIN_X11
143WINOBJ += $(WINQTOBJ)
144endif	# !WANT_WIN_X11
145
146# XXX if /Developer/qt exists and QTDIR not set, use that
147ifndef QTDIR
148$(error QTDIR not defined in the environment or Makefile)
149endif	# QTDIR
150# XXX make sure QTDIR points to something reasonable
151else	# !WANT_WIN_QT
152LINK=$(CC)
153endif	# !WANT_WIN_QT
154
155ifdef WANT_SHARE_INSTALL
156# if $GAMEUID is root, we install into roughly proper Mac locations, otherwise
157# we install into ~/nethackdir
158ifeq ($(GAMEUID),root)
159PREFIX:=/Library/NetHack
160SHELLDIR=/usr/local/bin
161HACKDIR=$(PREFIX)/nethackdir
162CHOWN=chown
163CHGRP=chgrp
164# We run sgid so the game has access to both HACKDIR and user preferences.
165GAMEPERM = 02755
166else	# ! root
167PREFIX:=/Users/$(GAMEUID)
168SHELLDIR=$(PREFIX)/bin
169HACKDIR=$(PREFIX)/Library/NetHack/nethackdir
170CHOWN=/usr/bin/true
171CHGRP=/usr/bin/true
172GAMEPERM = 0500
173endif	# ! root
174VARFILEPERM = 0664
175VARDIRPERM = 0775
176ROOTCHECK= [[ `id -u` == 0 ]] || ( echo "Must run install with sudo."; exit 1)
177# XXX it's nice we don't write over sysconf, but we've already erased it
178# make sure we have group GAMEUID and group GAMEGRP
179PREINSTALL= . sys/unix/hints/macosx.sh user2 $(GAMEUID); . sys/unix/hints/macosx.sh group2 $(GAMEGRP); mkdir $(SHELLDIR); chown $(GAMEUID) $(SHELLDIR)
180POSTINSTALL+= sys/unix/hints/macosx.sh editsysconf sys/unix/sysconf $(HACKDIR)/sysconf; $(CHOWN) $(GAMEUID) $(HACKDIR)/sysconf; $(CHGRP) $(GAMEGRP) $(HACKDIR)/sysconf; chmod $(VARFILEPERM) $(HACKDIR)/sysconf;
181CFLAGS+=-DSYSCF -DSYSCF_FILE=\"$(HACKDIR)/sysconf\" -DSECURE
182else ifdef WANT_SOURCE_INSTALL
183PREFIX=$(abspath $(NHSROOT))
184# suppress nethack.sh
185#SHELLDIR=
186HACKDIR=$(PREFIX)/playground
187CHOWN=/usr/bin/true
188CHGRP=/usr/bin/true
189GAMEPERM = 0700
190VARFILEPERM = 0600
191VARDIRPERM = 0700
192POSTINSTALL+= sys/unix/hints/macosx.sh editsysconf sys/unix/sysconf $(HACKDIR)/sysconf;
193# We can use "make all" to build the whole thing - but it misses some things:
194MOREALL=$(MAKE) install
195CFLAGS+=-DSYSCF -DSYSCF_FILE=\"$(HACKDIR)/sysconf\" -DSECURE
196else	# !WANT_SOURCE_INSTALL
197PREFIX:=$(wildcard ~)
198SHELLDIR=$(PREFIX)/bin
199HACKDIR=$(PREFIX)/nethackdir
200CHOWN=/usr/bin/true
201CHGRP=/usr/bin/true
202GAMEPERM = 0700
203VARFILEPERM = 0600
204VARDIRPERM = 0700
205ifdef WANT_WIN_X11
206# install nethack.rc as ~/.xnethackrc if no ~/.xnethackrc exists
207PREINSTALL= cp -n win/X11/nethack.rc ~/.xnethackrc || true
208endif	# WANT_WIN_X11
209POSTINSTALL+= sys/unix/hints/macosx.sh editsysconf sys/unix/sysconf $(HACKDIR)/sysconf; $(CHOWN) $(GAMEUID) $(HACKDIR)/sysconf; $(CHGRP) $(GAMEGRP) $(HACKDIR)/sysconf; chmod $(VARFILEPERM) $(HACKDIR)/sysconf;
210CFLAGS+=-DSYSCF -DSYSCF_FILE=\"$(HACKDIR)/sysconf\" -DSECURE
211endif	# !WANT_SOURCE_INSTALL
212
213INSTDIR=$(HACKDIR)
214VARDIR=$(HACKDIR)
215
216
217# ~/Library/Preferences/NetHack Defaults
218# OPTIONS=name:player,number_pad,menustyle:partial,!time,showexp
219# OPTIONS=hilite_pet,toptenwin,msghistory:200,windowtype:Qt
220#
221# Install.Qt mentions a patch for macos - it's not there (it seems to be in the Qt binary
222# package under the docs directory).
223
224#-POST
225ifdef MAKEFILE_TOP
226###
227### Packaging
228###
229# Notes:
230# 1) The Apple developer utilities must be installed in the default location.
231# 2) Do a normal build before trying to package the game.
232# 3) This matches the 3.4.3 Term package, but there are some things that
233#    should be changed.
234#
235# Packages that are being distributed must be signed by a Developer ID
236# Installer certificate.  Set DEVELOPER_CERT to the name of the certificate
237# if you wish for your package to be signed for distribution.
238#
239# If building a package for signing, you must use sudo approriately.
240# the binaries and package using sudo but you DO NOT use sudo to sign the
241# package.  If you use sudo to sign the package, it will fail.
242#
243#   sudo make all
244#   sudo make build_tty_pkg
245#   make sign_tty_pkg
246#
247
248
249ifdef WANT_WIN_TTY
250DEVUTIL=/Developer/Applications/Utilities
251SVS=$(shell $(NHSROOT)/util/makedefs --svs)
252SVSDOT=$(shell $(NHSROOT)/util/makedefs --svs .)
253
254PKGROOT_UG	= PKGROOT/$(PREFIX)
255PKGROOT_UGLN	= PKGROOT/$(HACKDIR)
256PKGROOT_BIN	= PKGROOT/$(SHELLDIR)
257
258#DEVELOPER_CERT = Developer ID Installer: Bart House
259DEVELOPER_CERT = NONE
260
261spotless::
262	rm -rf RESOURCES
263	rm -rf PKG
264	rm -rf PKGSCRIPTS
265	rm -rf PKGROOT
266	rm -f Info.plist
267	rm -f Distribution.xml
268	rm -f NetHack-*-mac-Term*
269
270build_tty_pkg:
271ifneq (,$(WANT_WIN_X11)$(WANT_WIN_QT))
272	-echo build_tty_pkg only works for a tty-only build
273	exit 1
274else
275	rm -rf NetHack-$(SVS)-mac-Term.pkg NetHack-$(SVS)-mac-Term.dmg
276	$(MAKE) build_package_root
277	rm -rf RESOURCES
278	mkdir RESOURCES
279	#enscript --language=rtf -o - < dat/license >RESOURCES/License.rtf
280	sys/unix/hints/macosx.sh descplist > RESOURCES/Description.plist
281	sys/unix/hints/macosx.sh infoplist > Info.plist
282
283	mkdir PKGROOT/Applications
284	#osacompile -o NetHackQt/NetHackQt.app/nethackdir/NetHackRecover.app \
285	#	 win/macosx/NetHackRecover.applescript
286	#cp win/macosx/recover.pl NetHackQt/NetHackQt.app/nethackdir
287	osacompile -o PKGROOT/Applications/NetHackRecover.app \
288		 win/macosx/NetHackRecover.applescript
289	cp win/macosx/recover.pl $(PKGROOT_UGLN)
290
291	osacompile -o PKGROOT/Applications/NetHackTerm.app \
292		 win/macosx/NetHackTerm.applescript
293
294	# XXX integrate into Makefile.doc
295	(cd doc; cat Guidebook.mn | ../util/makedefs --grep --input - --output - \
296	| tbl tmac.n - | groff | pstopdf -i -o Guidebook.pdf)
297	cp doc/Guidebook.pdf $(PKGROOT_UG)/doc/NetHackGuidebook.pdf
298
299	osacompile -o PKGROOT/Applications/NetHackGuidebook.app \
300		 win/macosx/NetHackGuidebook.applescript
301
302	mkdir -p PKG
303	pkgbuild --root PKGROOT --identifier org.nethack.term --scripts PKGSCRIPTS PKG/NH-Term.pkg
304	productbuild --synthesize --product Info.plist --package PKG/NH-Term.pkg Distribution.xml
305	productbuild --distribution Distribution.xml --resources RESOURCES --package-path PKG NetHack-$(SVS)-mac-Term-unsigned.pkg
306ifeq ($(DEVELOPER_CERT),NONE)
307	cp NetHack-$(SVS)-mac-Term-unsigned.pkg NetHack-$(SVS)-mac-Term.pkg
308	hdiutil create -verbose -srcfolder NetHack-$(SVS)-mac-Term-unsigned.pkg NetHack-$(SVS)-mac-Term-unsigned.dmg
309	@echo -------------------------------------------
310	@echo PACKAGE IS NOT SIGNED FOR DISTRIBUTION!!!!!
311	@echo ===========================================
312else
313	@echo "run 'make sign_tty_pkg' to complete package"
314endif
315
316sign_tty_pkg:
317	productsign --timestamp=none --sign "$(DEVELOPER_CERT)" NetHack-$(SVS)-mac-Term-unsigned.pkg NetHack-$(SVS)-mac-Term.pkg || (echo "Package signing failed"; exit 1)
318	spctl -a -v --type install NetHack-$(SVS)-mac-Term.pkg || (echo "Package not signed properly"; exit 1)
319	hdiutil create -verbose -srcfolder NetHack-$(SVS)-mac-Term.pkg NetHack-$(SVS)-mac-Term.dmg
320
321build_package_root:
322	cd src/..       # make sure we are at TOP
323	rm -rf PKGROOT
324	mkdir -p $(PKGROOT_UG)/lib $(PKGROOT_BIN) $(PKGROOT_UG)/man/man6 $(PKGROOT_UG)/doc $(PKGROOT_UGLN)
325	install -p src/nethack $(PKGROOT_BIN)
326	# XXX should this be called nethackrecover?
327	install -p util/recover $(PKGROOT_BIN)
328	install -p doc/nethack.6 $(PKGROOT_UG)/man/man6
329	install -p doc/recover.6 $(PKGROOT_UG)/man/man6
330	install -p doc/Guidebook $(PKGROOT_UG)/doc
331	install -p dat/nhdat $(PKGROOT_UGLN)
332	sys/unix/hints/macosx.sh editsysconf sys/unix/sysconf $(PKGROOT_UGLN)/sysconf
333	cd dat; install -p $(DATNODLB) ../$(PKGROOT_UGLN)
334# XXX these files should be somewhere else for good Mac form
335	touch $(PKGROOT_UGLN)/perm $(PKGROOT_UGLN)/record $(PKGROOT_UGLN)/logfile $(PKGROOT_UGLN)/xlogfile
336	mkdir $(PKGROOT_UGLN)/save
337# XXX what about a news file?
338
339	mkdir -p PKGSCRIPTS
340	echo '#!/bin/sh'                              >  PKGSCRIPTS/postinstall
341	echo dseditgroup -o create -r '"Games Group"' -s 3600 $(GAMEGRP) >> PKGSCRIPTS/postinstall
342	echo $(CHOWN) $(GAMEUID) $(HACKDIR)        >> PKGSCRIPTS/postinstall
343	echo $(CHOWN) $(GAMEUID) $(HACKDIR)/*        >> PKGSCRIPTS/postinstall
344	echo $(CHGRP) $(GAMEGRP) $(HACKDIR)        >> PKGSCRIPTS/postinstall
345	echo $(CHGRP) $(GAMEGRP) $(HACKDIR)/*        >> PKGSCRIPTS/postinstall
346	echo $(CHOWN) $(GAMEUID) $(SHELLDIR)/nethack  >> PKGSCRIPTS/postinstall
347	echo $(CHGRP) $(GAMEGRP) $(SHELLDIR)/nethack  >> PKGSCRIPTS/postinstall
348	echo $(CHOWN) $(GAMEUID) $(SHELLDIR)/recover  >> PKGSCRIPTS/postinstall
349	echo $(CHGRP) $(GAMEGRP) $(SHELLDIR)/recover  >> PKGSCRIPTS/postinstall
350	echo chmod $(VARDIRPERM)  $(HACKDIR)          >> PKGSCRIPTS/postinstall
351	echo chmod $(VARDIRPERM)  $(HACKDIR)/save     >> PKGSCRIPTS/postinstall
352	echo chmod $(FILEPERM)    $(HACKDIR)/license  >> PKGSCRIPTS/postinstall
353	echo chmod $(FILEPERM)    $(HACKDIR)/nhdat    >> PKGSCRIPTS/postinstall
354	echo chmod $(FILEPERM)    $(HACKDIR)/symbols  >> PKGSCRIPTS/postinstall
355	echo chmod $(VARFILEPERM) $(HACKDIR)/perm     >> PKGSCRIPTS/postinstall
356	echo chmod $(VARFILEPERM) $(HACKDIR)/record   >> PKGSCRIPTS/postinstall
357	echo chmod $(VARFILEPERM) $(HACKDIR)/logfile  >> PKGSCRIPTS/postinstall
358	echo chmod $(VARFILEPERM) $(HACKDIR)/xlogfile >> PKGSCRIPTS/postinstall
359	echo chmod $(VARFILEPERM) $(HACKDIR)/sysconf  >> PKGSCRIPTS/postinstall
360	echo chmod $(GAMEPERM)   $(SHELLDIR)/nethack  >> PKGSCRIPTS/postinstall
361	echo chmod $(EXEPERM)    $(SHELLDIR)/recover  >> PKGSCRIPTS/postinstall
362	chmod 0775 PKGSCRIPTS/postinstall
363
364endif	# end of build_tty_pkg
365endif	# WANT_WIN_TTY for packaging
366
367ifdef WANT_WIN_QT
368# XXX untested and incomplete (see below)
369build_qt_pkg:
370ifneq (,$(WANT_WIN_X11)$(WANT_WIN_TTY))
371	-echo build_qt_pkg only works for a qt-only build
372	exit 1
373else
374	$(MAKE) build_package_root
375	rm -rf NetHackQt
376	mkdir -p NetHackQt/NetHackQt.app/nethackdir/save
377	mkdir NetHackQt/Documentation
378	cp doc/Guidebook.txt doc/nethack.txt doc/recover.txt NetHackQt/Documentation
379
380	osacompile -o NetHackQt/NetHackQt.app/nethackdir/NetHackRecover.app \
381		 win/macosx/NetHackRecover.applescript
382	cp win/macosx/recover.pl NetHackQt/NetHackQt.app/nethackdir
383
384	mkdir -p NetHackQt/NetHackQt.app/Contents/Frameworks
385	cp $(QTDIR)/libqt-mt.3.dylib NetHackQt/NetHackQt.app/Contents/Frameworks
386
387	mkdir NetHackQt/NetHackQt.app/Contents/MacOS
388	mv PKGROOT/nethack NetHackQt/NetHackQt.app/Contents/MacOS
389
390	mv PKGROOT/lib/nethackdir NetHackQt/NetHackQt.app/nethackdir
391
392# XXX still missing:
393#NetHackQt/NetHackQt.app
394# /Contents
395#	Info.plist
396#	Resources/nethack.icns
397#NetHackQt/Documentation
398#NetHackQtRecover.txt
399#NetHack Defaults.txt
400#changes.patch XXX is this still needed?  why isn't it part of the tree?
401#  doesn't go here
402	hdiutil create -verbose -srcfolder NetHackQt NetHack-$(SVS)-macosx-qt.dmg
403endif	# end of build_qt_pkg
404endif	# WANT_WIN_QT for packaging
405endif	# MAKEFILE_TOP
406