summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/makefile.unix
blob: aaff00d4298eff74989e73058e4430985fb36926 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
# -*- Makefile -*- for Dungeon Crawl (unix)

#
# Modified for Crawl Reference by $Author$ on $Date$
#

GAME = crawl

# this file contains a list of the libraries.
# it will make a variable called OBJECTS that contains all the libraries
include makefile.obj

OBJECTS += libunix.o

CXX = g++
DELETE = rm -f
COPY = cp
OS_TYPE = UNIX

# Change this to y (case-sensitive!) if you want to use Unicode glyphs
# in the map, and you have libncursesw available.
UNICODE_GLYPHS = n

# If you're using UNICODE_GLYPHS=y, and have a preferred Unicode
# (UTF-8) locale you want Crawl to use, you can set it here. The
# default is en_US.UTF-8. If you'd prefer that Crawl use the locale
# as set in your environment LC_* variables, use UNICODE_LOCALE = .
UNICODE_LOCALE =

# If you have lex and yacc, set DOYACC to y (lowercase y).
DOYACC := y

# Permissions to set on the game executable.
MCHMOD := 2755

# Permissions to set on the save directory.
MCHMOD_SAVEDIR := 775

# The user:group to install the game as.
INSTALL_UGRP ?= games:games
INSTALLDIR   ?= /usr/games/crawl

# If you're installing Crawl for multiple users, you *must* set this to a
# valid path before building Crawl. This is not necessary if you are building
# Crawl for a single user.

# SAVEDIR := /usr/games/crawl/saves/
# DATADIR := /usr/games/crawl/data/

LEX  := flex
YACC := bison -y

LUASRC := util/lua/src
LUALIB = lua
LUALIBA = l$(LUALIB).a

DBH_FILE  := /usr/include/db.h
NDBM_FILE := /usr/include/ndbm.h

HAVE_DBH  := $(shell [ -f $(DBH_FILE) ] && echo y)
HAVE_NDBM := $(shell [ -f $(NDBM_FILE) -a "`uname`" = "Darwin" ] && echo y)

ifeq ($(strip $(HAVE_DBH)),y)
ifneq ($(shell grep dbm_open $(DBH_FILE)),)
SELDBM := -DDB_DBH
LIBDBM := -ldb
endif
endif

ifeq ($(strip $(HAVE_NDBM)),y)
SELDBM ?= -DDB_NDBM
ifeq ($(SELDBM),-DDB_NDBM)
LIBDBM := -ldbm
endif
endif

SQLSRC   := util/sqlite
SQLLIB   := sqlite3
SQLLIBA  := lib$(SQLLIB).a
FSQLLIBA := $(SQLSRC)/$(SQLLIBA)

ifeq ($(strip $(LIBDBM)),)
LIBDBM         := -L$(SQLSRC) -lsqlite3
EXTRA_INCLUDES += -I$(SQLSRC)
EXTRA_DEPENDS  += $(FSQLLIBA)
endif

LIB = -l$(LIBCURS) -L$(LUASRC) -l$(LUALIB) $(LIBDBM)

INCLUDES := $(INCLUDES) -Iutil -I. -I$(LUASRC) $(EXTRA_INCLUDES)

CFWARN := -Wall -Wwrite-strings -Wshadow -pedantic

CFOTHERS := -fsigned-char -D$(OS_TYPE) $(EXTRA_FLAGS) -DCLUA_BINDINGS

ifneq ($(HURRY),y)
ifneq ($(DEBUG_CRAWL),y)
CFWARN += -Wuninitialized
CFOTHERS += -O2
endif
endif

ifneq ($(strip $(SAVEDIR)),)
CFOTHERS += '-DSAVE_DIR_PATH="$(strip $(SAVEDIR))"'
endif

ifneq ($(strip $(DATADIR)),)
CFOTHERS += '-DDATA_DIR_PATH="$(strip $(DATADIR))"'
endif

ifeq ($(strip $(UNICODE_GLYPHS)),y)
# Include path for (n)curses with Unicode support.
INCLUDES += -I/usr/include/ncursesw

# Your ncurses library may include Unicode support, and you may not have a
# separate libncursesw; in that case, change this line accordingly.
LIBCURS  = ncursesw
CFOTHERS += -DUNICODE_GLYPHS

ifneq ($(strip $(UNICODE_LOCALE)),)
ifneq ($(strip $(UNICODE_LOCALE)),.)
CFOTHERS += -DUNICODE_LOCALE=\"$(strip $(UNICODE_LOCALE))\"
else
CFOTHERS += -DUNICODE_LOCALE=\"\"
endif
endif

# The standard ncurses library also supports Unicode on Mac OS/Darwin.
ifeq ($(shell uname),Darwin)
LIBCURS = ncurses
endif

else
# Include path for curses or ncurses (non-Unicode).
INCLUDES += -I/usr/include/ncurses
LIBCURS  = ncurses
endif

CFOTHERS += $(SELDBM)

CFLAGS  := $(INCLUDES) $(CFWARN) $(CFOTHERS)
YCFLAGS := $(INCLUDES) $(CFOTHERS)

UTIL = util/

YTABC  := levcomp.tab.c
YTABH  := levcomp.tab.h

OBJECTS := $(UTIL)levcomp.tab.o $(UTIL)levcomp.lex.o $(OBJECTS)

ifeq ($(strip $(LEX)),)
DOYACC :=
endif

ifeq ($(strip $(YACC)),)
DOYACC :=
endif

GAME_DEPENDS := $(LUASRC)$(LUALIBA) $(EXTRA_DEPENDS) $(OBJECTS)
SRC_PKG_BASE := stone_soup
SRC_VERSION  := $(shell egrep 'VER_NUM  *".*"' version.h | \
			egrep -o '[0-9]\.[0-9](\.[0-9])?')
PKG_SRC_DIR  := $(SRC_PKG_BASE)-$(SRC_VERSION)-src
SRC_PKG_TAR  := $(PKG_SRC_DIR).tbz2
SRC_PKG_ZIP  := $(PKG_SRC_DIR).zip

PKG_TIDY_LIST := $(UTIL)*.o $(LEVCOMP) *.o \
		$(UTIL)*.tab.cc $(UTIL)*.tab.h $(UTIL)*.lex.cc *.ixx
PKG_EXCLUDES  := $(PWD)/misc/src-pkg-excludes.lst

##########################################################################

all: $(GAME)

##########################################################################
# Dependencies

DEPENDENCY_MKF := makefile.dep

depend: $(OBJECTS:.o=.cc)
	rm -f $(DEPENDENCY_MKF)
	@for i in $^; do \
	    echo "Updating dependencies for $$i"; \
	    $(CXX) -MM $(CFLAGS) $$i >>$(DEPENDENCY_MKF) 2>/dev/null; \
	done

-include $(DEPENDENCY_MKF)

##########################################################################
# The level compiler
#

ifeq ($(DOYACC),y)

prebuildyacc:	$(UTIL)levcomp.tab.cc $(UTIL)levcomp.tab.h $(UTIL)levcomp.lex.cc
		cp $^ prebuilt/

$(UTIL)levcomp.tab.cc: $(UTIL)levcomp.ypp
		cd $(UTIL) && $(YACC) -d -b levcomp levcomp.ypp \
			   && mv $(YTABC) levcomp.tab.cc || false

$(UTIL)levcomp.lex.cc: $(UTIL)levcomp.lpp
		cd $(UTIL) && $(LEX) -olevcomp.lex.cc levcomp.lpp

else

# Pull the level-compiler stuff up from prebuilt/

$(UTIL)levcomp.tab.cc: prebuilt/levcomp.tab.cc
		cp prebuilt/*.h $(UTIL)
		cp $< $@


$(UTIL)levcomp.lex.cc: prebuilt/levcomp.lex.cc
		cp $< $@

endif

##########################################################################


##########################################################################
# The actual build targets
#

install: $(GAME)
ifeq ($(DATADIR),)
	$(error DATADIR not set! Set DATADIR and run make clean install again)
endif
	[ -d $(INSTALLDIR) ] || mkdir -p $(INSTALLDIR)
	$(COPY) $(GAME) $(INSTALLDIR)
	chown $(INSTALL_UGRP) $(INSTALLDIR)/$(GAME)
	chmod ${MCHMOD} ${INSTALLDIR}/$(GAME)
	mkdir -p $(DATADIR)/dat
	mkdir -p $(DATADIR)/dat/lua
	mkdir -p $(DATADIR)/dat/clua
	mkdir -p $(DATADIR)/dat/descript
	mkdir -p $(DATADIR)/dat/database
	cp dat/*.des $(DATADIR)/dat
	cp dat/lua/*.lua $(DATADIR)/dat/lua
	cp dat/clua/*.lua $(DATADIR)/dat/clua
	cp dat/descript/*.txt $(DATADIR)/dat/descript
	cp dat/database/*.txt $(DATADIR)/dat/database
	mkdir -p $(DATADIR)/settings
	cp ../settings/* $(DATADIR)/settings/
	mkdir -p $(DATADIR)/docs
	cp ../docs/*.txt $(DATADIR)/docs
	chown -R $(INSTALL_UGRP) $(DATADIR)
ifneq ($(SAVEDIR),)
	mkdir -p $(SAVEDIR)
	chown $(INSTALL_UGRP) $(SAVEDIR)
	chmod $(MCHMOD_SAVEDIR) $(SAVEDIR)
endif

clean:
	$(DELETE) *.o
	$(DELETE) $(UTIL)*.o
	$(DELETE) $(LEVCOMP)
	$(DELETE) $(UTIL)*.tab.cc $(UTIL)*.tab.c $(UTIL)*.tab.h $(UTIL)*.lex.cc
	$(DELETE) *.ixx

clean-lua:
	cd $(LUASRC) && $(MAKE) clean

clean-sql:
	cd $(SQLSRC) && $(MAKE) clean

distclean: clean clean-lua clean-sql
	$(DELETE) bones.*
	$(DELETE) morgue.txt
	$(DELETE) scores
	$(DELETE) $(GAME)
	$(DELETE) *.sav
	$(DELETE) core
	$(DELETE) *.0*
	$(DELETE) *.lab
	$(DELETE) $(DEPENDENCY_MKF)

$(GAME): $(GAME_DEPENDS)
	${CXX} ${LDFLAGS} $(CFLAGS) $(OBJECTS) -o $(GAME) $(LIB)

.PHONY : debug

debug: $(GAME)

profile: $(GAME_DEPENDS)
	${CXX} -g -p ${LDFLAGS} $(CFLAGS) $(OBJECTS) -o $(GAME) $(LIB)

.cc.o:
	${CXX} ${CFLAGS} -c $<

# [ds] Note we don't use the standard CFLAGS here; that's intentional, most
# flex/bison combos I've tried don't produce code that passes the warnings
# test.
$(UTIL)%.o: $(UTIL)%.cc
	$(CXX) $(YCFLAGS) -o $@ -c $<

#############################################################################
# Build Lua

$(LUASRC)$(LUALIBA):
	echo Building Lua...
	cd $(LUASRC) && $(MAKE) crawl_unix

#############################################################################
# Build SQLite

$(FSQLLIBA):
	echo Building SQLite
	cd $(SQLSRC) && $(MAKE)

#############################################################################
# Packaging a source tarball for release
#

# To package, you *must* have lex and yacc to generate the intermediates.
ifeq ($(DOYACC),y)
package-source: distclean prebuildyacc pkgtidy depend removeold vlink \
				pkgtarbz2 pkgzip

pkgtidy:
	$(DELETE) $(PKG_TIDY_LIST)

removeold:
	if [ -f ../../$(SRC_PKG_TAR) ]; then $(DELETE) ../../$(SRC_PKG_TAR); fi
	if [ -f ../../$(SRC_PKG_ZIP) ]; then $(DELETE) ../../$(SRC_PKG_ZIP); fi

# [ds] Existing directory names could produce a bad package!
vlink:
	cd .. && WHERE=$$PWD && cd .. && \
		( [ -e $(PKG_SRC_DIR) ] || ln -sf $$WHERE $(PKG_SRC_DIR) )

pkgtarbz2:
	cd ../.. && tar -ch --bzip2 -f $(SRC_PKG_TAR) \
		-X $(PKG_EXCLUDES) $(PKG_SRC_DIR)

pkgzip:
	cd ../.. && zip -rq $(SRC_PKG_ZIP) $(PKG_SRC_DIR) \
		-x@$(PKG_EXCLUDES)

endif