1#	Makefile for NetHack's utility programs.
2# NetHack 3.7  Makefile.utl    $NHDT-Date: 1602258295 2020/10/09 15:44:55 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.53 $
3# Copyright (c) 2018 by Robert Patrick Rankin
4# NetHack may be freely redistributed.  See license for details.
5
6# Root of source tree:
7NHSROOT=..
8
9# newer makes predefine $(MAKE) to 'make' and do smarter processing of
10# recursive make calls if $(MAKE) is used
11# these makes allow $(MAKE) to be overridden by the environment if someone
12# wants to (or has to) use something other than the standard make, so we do
13# not want to unconditionally set $(MAKE) here
14#
15# unfortunately, some older makes do not predefine $(MAKE); if you have one of
16# these, uncomment the following line
17# (you will know that you have one if you get complaints about unable to
18# execute things like 'foo.o')
19# MAKE = make
20
21# if you are using gcc as your compiler,
22#	uncomment the CC definition below if it's not in your environment
23# CC = gcc
24#
25#	For Bull DPX/2 systems at B.O.S. 2.0 or higher use the following:
26#
27# CC = gcc -ansi -D_BULL_SOURCE -D_XOPEN_SOURCE -D_POSIX_SOURCE
28#
29#	If you are using GCC 2.2.2 or higher on a DPX/2, just use:
30#
31# CC = gcc -ansi
32#
33#	For HP/UX 10.20 with GCC:
34# CC = gcc -D_POSIX_SOURCE
35#
36# if your make doesn't define a default SHELL properly, you may need
37#    the line below (Atari users will need a bourne work-alike)
38# SHELL = /bin/sh
39# for Atari
40# SHELL=E:/GEMINI2/MUPFEL.TTP
41
42# flags may have to be changed as required
43# flags for 286 Xenix:
44# CFLAGS = -Ml2t16 -O -LARGE -I../include
45# LFLAGS = -Ml -F 4000 -SEG 512
46
47# flags for 286 Microport SysV-AT
48# CFLAGS = -DDUMB -Ml -I../include
49# LFLAGS = -Ml
50
51# flags for Atari GCC (3.2.1)
52# CFLAGS = -O -I../include
53# LFLAGS = -s
54# flags for Atari GCC (3.3)
55# CFLAGS = -mshort -O2 -I../include
56# LFLAGS = -mshort -s
57
58# flags for Apollos using their native cc
59# (as long as it claims to be __STDC__ but isn't)
60# CFLAGS = -DAPOLLO -O -I../include
61
62# flags for AIX 3.1 cc on IBM RS/6000 to define
63# a suitable subset of standard libraries
64# (note that there is more info regarding the "-qchars=signed"
65# switch in file Install.unx note 8)
66# CFLAGS = -D_NO_PROTO -D_XOPEN_SOURCE -O -I../include -qchars=signed
67# and for AIX 3.2:
68# CFLAGS = -D_NO_PROTO -D_XOPEN_SOURCE -D_ALL_SOURCE -O -I../include -qchars=signed
69
70# flags for A/UX 2.01 using native cc or c89
71# gcc predefines AUX so that's not needed there
72# CFLAGS = -ZS -D_POSIX_SOURCE -O -I../include -DAUX
73
74# flags for IRIX 4.0.x using native cc
75# SGI cc 3.10 will fail to compile makedefs with -O
76# CFLAGS = -I../include -D__STDC__ -woff 100,293
77
78# flags for Linux
79#   compile normally
80# CFLAGS = -O2 -fomit-frame-pointer -I../include
81# LFLAGS = -L/usr/X11R6/lib
82#   OR compile backwards compatible a.out format
83# CFLAGS = -O2 -b i486-linuxaout -fomit-frame-pointer -I../include
84# LFLAGS = -b i486-linuxaout -L/usr/X11R6/lib
85
86# flags for BeOS using the command line
87#   BeOS on a Mac/BeBox:
88#CC = mwcc
89#CFLAGS = -I../include
90#   BeOS on Intel:
91# the default values are fine
92
93# flags for debugging:
94# CFLAGS = -g -I../include
95
96CFLAGS += -I../include -I${LUA_INCDIR}
97ifeq ("$(GRAPHICS)","X11_GRAPHICS")
98CFLAGS += -DX11_GRAPHICS
99endif
100ifeq ("$(GRAPHICS)","QT_GRAPHICS")
101CFLAGS += -DQT_GRAPHICS
102endif
103ifeq ("$(GRAPHICS)","GNOME_GRAPHICS")
104CFLAGS += -DGNOME_GRAPHICS
105endif
106
107LFLAGS = -L${LUA_LIBDIR}
108
109# we specify C preprocessor flags via CFLAGS; files built with default rules
110# might include $(CPPFLAGS) which could get a value from user's environment;
111# we avoid that by forcing it empty rather than by overriding default rules
112CPPFLAGS =
113
114LIBS = -llua-${LUA_VER} -lm
115
116OBJDIR = ../src
117
118# if you change this to 1, feedback while building will omit -Dthis -Wthat
119# -Isomewhere so that each file being compiled is listed on one short line;
120# it requires support for '$<' in rules with more than one prerequisite
121# (rather than just in suffix default rule), such as is implemented by
122# gnu make and others which have picked up its extensions;
123# allowed values are 0, 1, and empty (which behaves like 0)
124QUIETCC=0
125
126# TODO? the link/load commands below are handled differently from the ones
127# in Makefile.src; these use '$(CC) $(LFLAGS)' and ought to be changed to use
128# $(LD) or $(LINK) as appropriate [quiet mode echoes a misleading $< value]
129
130# [LINK might be defined to use $(CXX); we don't want that here.]
131CLINK=$(CC)
132CXXLINK=$(CXX)
133
134# ----------------------------------------
135#
136# Nothing below this line should have to be changed.
137
138# Verbosity definitions, begin
139#   Set QUIETCC=1 above to output less feedback while building.
140#   CC and CXX obey verbosity, LD and LINK don't.
141#   AT is @ when not verbose, empty otherwise
142ACTUAL_CC := $(CC)
143ACTUAL_CXX := $(CXX)
144ACTUAL_LD := $(LD)
145ACTUAL_CLINK := $(CLINK)
146
147CC_V0 = $(ACTUAL_CC)
148CC_V = $(CC_V0)
149CC_V1 = @echo "[CC] $<"; $(ACTUAL_CC)
150CC = $(CC_V$(QUIETCC))
151
152CXX_V0 = $(ACTUAL_CXX)
153CXX_V = $(CXX_V0)
154CXX_V1 = @echo "[CXX] $<"; $(ACTUAL_CXX)
155CXX = $(CXX_V$(QUIETCC))
156
157# LD and LINK might be based on invoking CC and may not be able to substitute
158# for QUIETCC, so feedback from them is handled differently (via $AT)
159LD = $(ACTUAL_LD)
160CLINK = $(ACTUAL_CLINK)
161
162AT_V0 :=
163AT_V := $(AT_V0)
164AT_V1 := @
165AT = $(AT_V$(QUIETCC))
166# Verbosity, end
167
168# timestamps for primary header files, matching src/Makefile
169CONFIG_H = ../src/config.h-t
170HACK_H	 = ../src/hack.h-t
171
172# utility .c files
173MAKESRC = makedefs.c ../src/mdlib.c
174RECOVSRC = recover.c
175DLBSRC = dlb_main.c
176UTILSRCS = $(MAKESRC) panic.c $(RECOVSRC) $(DLBSRC)
177
178# files that define all monsters and objects
179CMONOBJ = ../src/monst.c ../src/objects.c
180OMONOBJ = $(OBJDIR)/monst.o $(OBJDIR)/objects.o
181# files that provide access to NetHack's names
182CNAMING = ../src/drawing.c $(CMONOBJ)
183ONAMING = $(OBJDIR)/drawing.o $(OMONOBJ)
184# dynamic memory allocation
185CALLOC = ../src/alloc.c panic.c
186OALLOC = $(OBJDIR)/alloc.o panic.o
187
188# object files for makedefs
189MAKEOBJS = makedefs.o $(OMONOBJ)
190
191# object files for recovery utility
192RECOVOBJS = recover.o
193
194# object files for the data librarian
195DLBOBJS = dlb_main.o $(OBJDIR)/dlb.o $(OALLOC)
196
197# Distinguish between the build tools for the native host
198# and the build tools for the target environment in commands.
199# This allows the same set of Makefiles to be used for native
200# builds and for cross-compiles by overriding these in hints
201# files or on the command line.
202
203TARGETPFX=
204TARGET_CC = $(CC)
205TARGET_CFLAGS = $(CFLAGS)
206TARGET_CLINK = $(CLINK)
207TARGET_LFLAGS = $(LFLAGS)
208TARGET_CXX = $(CXX)
209TARGET_CXXFLAGS = $(CXXFLAGS)
210
211#	dependencies for makedefs
212#
213makedefs:	$(MAKEOBJS) mdgrep.h
214	$(CLINK) $(LFLAGS) -o makedefs $(MAKEOBJS)
215
216makedefs.o: makedefs.c ../src/mdlib.c $(CONFIG_H) ../include/permonst.h \
217		../include/objclass.h ../include/monsym.h \
218		../include/artilist.h ../include/dungeon.h ../include/obj.h \
219		../include/monst.h ../include/you.h ../include/flag.h \
220		../include/dlb.h ../include/patchlevel.h
221	$(CC) $(CFLAGS) -c makedefs.c -o $@
222
223# Don't require perl to build; that is why mdgrep.h is spelled wrong below.
224mdgreph: mdgrep.pl
225	perl mdgrep.pl
226
227../include/onames.h: makedefs
228	./makedefs -o
229../include/pm.h: makedefs
230	./makedefs -p
231
232lintdefs:
233	@lint -axbh -I../include -DLINT $(MAKESRC) $(CMONOBJ) | sed '/_flsbuf/d'
234
235
236# we defer this makedefs call to the src Makefile, since it knows all about
237# the main src and include files date.h is a timestamp for
238../include/date.h::
239	@( cd ../src ; $(MAKE) ../include/date.h )
240
241# support code used by several of the utility programs (but not makedefs)
242panic.o:     panic.c $(CONFIG_H)
243	$(CC) $(CFLAGS) -c panic.c -o $@
244
245
246# with all of extern.h's functions to complain about, we drown in
247# 'defined but not used' without -u
248lintdgn:
249	@lint -axhu -I../include -DLINT $(UTILSRCS) $(CALLOC) \
250		| sed '/_flsbuf/d'
251
252
253#	dependencies for recover
254#
255recover: $(RECOVOBJS)
256	$(CLINK) $(LFLAGS) -o recover $(RECOVOBJS) $(LIBS)
257
258recover.o: recover.c $(CONFIG_H) ../include/date.h
259
260
261#	dependencies for dlb
262#
263dlb:	$(DLBOBJS)
264	$(CLINK) $(LFLAGS) -o dlb $(DLBOBJS) $(LIBS)
265
266dlb_main.o: dlb_main.c $(CONFIG_H) ../include/dlb.h ../include/date.h
267	$(CC) $(CFLAGS) -c dlb_main.c -o $@
268
269
270#	dependencies for tile utilities
271#
272TEXT_IO = tiletext.o tiletxt.o $(OALLOC) $(ONAMING)
273GIFREADERS = gifread.o
274PPMWRITERS = ppmwrite.o
275
276tileutils: tilemap gif2txt txt2ppm tile2x11
277
278gif2txt: $(GIFREADERS) $(TEXT_IO)
279	$(CLINK) $(LFLAGS) -o gif2txt $(GIFREADERS) $(TEXT_IO) $(LIBS)
280txt2ppm: $(PPMWRITERS) $(TEXT_IO)
281	$(CLINK) $(LFLAGS) -o txt2ppm $(PPMWRITERS) $(TEXT_IO) $(LIBS)
282
283tile2x11: tile2x11.o $(TEXT_IO)
284	$(CLINK) $(LFLAGS) -o tile2x11 tile2x11.o $(TEXT_IO) $(LIBS)
285
286tile2img.ttp: tile2img.o bitmfile.o $(TEXT_IO)
287	$(CLINK) $(LFLAGS) -o tile2img.ttp tile2img.o bitmfile.o \
288		$(TEXT_IO) $(LIBS)
289
290tile2bmp: tile2bmp.o $(TEXT_IO)
291	$(CLINK) $(LFLAGS) -o tile2bmp tile2bmp.o $(TEXT_IO)
292
293xpm2img.ttp: xpm2img.o bitmfile.o
294	$(CLINK) $(LFLAGS) -o xpm2img.ttp xpm2img.o bitmfile.o $(LIBS)
295
296tile2beos: tile2beos.o $(TEXT_IO)
297	$(CXXLINK) $(LFLAGS) -o tile2beos tile2beos.o $(TEXT_IO) -lbe
298
299#--compiling and linking in one step leaves extra debugging files (in their
300#  own subdirectories!) on OSX; compile and link separately to suppress
301#  that without mucking about with extra OS-specific CFLAGS and/or LFLAGS
302#tilemap: ../win/share/tilemap.c $(HACK_H)
303#	$(CC) $(CFLAGS) $(LFLAGS) -o tilemap ../win/share/tilemap.c $(LIBS)
304tilemap: tilemap.o
305	$(CLINK) $(LFLAGS) -o tilemap tilemap.o $(LIBS)
306../src/tile.c: tilemap
307	./tilemap
308
309../include/tile.h: ../win/share/tile.h
310	cp ../win/share/tile.h ../include/tile.h
311tiletext.o: ../win/share/tiletext.c $(CONFIG_H) ../include/tile.h
312	$(CC) $(CFLAGS) -c ../win/share/tiletext.c -o $@
313tiletxt.c: ./Makefile
314	@echo '/* alternate compilation for tilemap.c to create tiletxt.o' > tiletxt.c
315	@echo '   that does not rely on "cc -c -o tiletxt.o tilemap.c"'	 >> tiletxt.c
316	@echo '   since many pre-POSIX compilers did not support that */' >> tiletxt.c
317	echo '#define TILETEXT'			 >> tiletxt.c
318	echo '#include "../win/share/tilemap.c"' >> tiletxt.c
319	@echo '/*tiletxt.c*/'			 >> tiletxt.c
320tiletxt.o: tiletxt.c ../win/share/tilemap.c $(HACK_H)
321	$(CC) $(CFLAGS) -c tiletxt.c -o $@
322tilemap.o: ../win/share/tilemap.c $(HACK_H)
323	$(CC) $(CFLAGS) -c ../win/share/tilemap.c -o $@
324
325gifread.o: ../win/share/gifread.c $(CONFIG_H) ../include/tile.h
326	$(CC) $(CFLAGS) -c ../win/share/gifread.c -o $@
327ppmwrite.o: ../win/share/ppmwrite.c $(CONFIG_H) ../include/tile.h
328	$(CC) $(CFLAGS) -c ../win/share/ppmwrite.c -o $@
329
330tile2bmp.o: ../win/share/tile2bmp.c $(HACK_H) ../include/tile.h
331	$(CC) $(CFLAGS) -c ../win/share/tile2bmp.c -o $@
332
333tile2x11.o: ../win/X11/tile2x11.c $(HACK_H) ../include/tile.h \
334						../include/tile2x11.h
335	$(CC) $(CFLAGS) -c ../win/X11/tile2x11.c -o $@
336
337tile2img.o: ../win/gem/tile2img.c $(HACK_H) ../include/tile.h \
338						../include/bitmfile.h
339	$(CC) $(CFLAGS) -c ../win/gem/tile2img.c -o $@
340xpm2img.o: ../win/gem/xpm2img.c $(HACK_H) ../include/bitmfile.h
341	$(CC) $(CFLAGS) -c ../win/gem/xpm2img.c -o $@
342bitmfile.o: ../win/gem/bitmfile.c ../include/bitmfile.h
343	$(CC) $(CFLAGS) -c ../win/gem/bitmfile.c -o $@
344
345tile2beos.o: ../win/BeOS/tile2beos.cpp $(HACK_H) ../include/tile.h
346	$(CXX) $(CFLAGS) -c ../win/BeOS/tile2beos.cpp -o $@
347
348# note: tileedit.cpp was developed for Qt2 and will not compile using Qt5
349tileedit.o: ../win/Qt/tileedit.cpp
350	$(CXX) -I../include -I$(QTDIR)/include ../win/Qt/tileedit.cpp
351tileedit: tileedit.o $(TEXT_IO)
352	$(QTDIR)/bin/moc -o tileedit.moc tileedit.h
353	$(CXXLINK) -o tileedit -L$(QTDIR)/lib tileedit.o $(TEXT_IO) -lqt
354
355# using dependencies like
356#	../src/foo::
357#		@( cd ../src ; $(MAKE) foo )
358# would always force foo to be up-to-date according to the src Makefile
359# when it's needed here.  Unfortunately, some makes believe this syntax
360# means foo always changes, instead of foo should always be checked.
361# therefore, approximate via config.h dependencies, and hope that anybody
362# changing anything other than basic configuration also knows when not
363# to improvise things not in the instructions, like 'make makedefs' here
364# in util...
365
366# make sure host object files from src are available when needed
367$(OBJDIR)/alloc.o: ../src/alloc.c $(CONFIG_H)
368	$(CC) $(CFLAGS) -c ../src/alloc.c -o $@
369$(OBJDIR)/drawing.o: ../src/drawing.c $(CONFIG_H)
370	$(CC) $(CFLAGS) -c ../src/drawing.c -o $@
371$(OBJDIR)/decl.o: ../src/decl.c $(CONFIG_H)
372	$(CC) $(CFLAGS) -c ../src/decl.c -o $@
373$(OBJDIR)/monst.o: ../src/monst.c $(CONFIG_H)
374	$(CC) $(CFLAGS) -c ../src/monst.c -o $@
375$(OBJDIR)/objects.o: ../src/objects.c $(CONFIG_H)
376	$(CC) $(CFLAGS) -c ../src/objects.c -o $@
377$(OBJDIR)/dlb.o: ../src/dlb.c $(CONFIG_H) ../include/dlb.h
378	$(CC) $(CFLAGS) -c ../src/dlb.c -o $@
379
380# make sure hack.h dependencies get transitive information
381$(HACK_H): $(CONFIG_H)
382	@( cd ../src ; $(MAKE) $(HACK_H) )
383$(CONFIG_H): ../include/config.h
384	@( cd ../src ; $(MAKE) $(CONFIG_H) )
385
386SYSSHARE=../sys/share/
387
388tags: $(UTILSRCS)
389	@ctags -tw $(UTILSRCS)
390
391clean:
392	-rm -f *.o
393
394spotless: clean
395	-rm -f ../include/tile.h tiletxt.c
396	-rm -f makedefs recover dlb
397	-rm -f gif2txt txt2ppm tile2x11 tile2img.ttp xpm2img.ttp \
398		tilemap tileedit tile2bmp
399