1# $Id$
2# File: Makefile
3
4# This is not a very "nice" Makefile, but it usually works.
5
6#
7# Note that you may have to make modifications below according
8# to your machine, available libraries, compilation options,
9# and your "visual module" of choice.  This Makefile is intended
10# for use with Unix machines running X11, Curses, Ncurses, or Vt100,
11# or possibly for "Atari" or "Amiga" computers with "Curses" ports,
12# see below for more information.
13#
14# Note that "main-mac.c", the visual module for the Macintosh,
15# must be compiled in a special way, see elsewhere.
16#
17# Note that "main-win.c", the visual module for Windows,
18# must be compiled in a special way, see elsewhere.
19#
20# Note that "main-ibm.c", "main-emx.c", and "main-286.c",
21# the visual modules for various types of IBM-PC computers,
22# must be compiled with special Makefiles, see elsewhere.
23#
24# Note that "main-lsl.c", the visual module for ???,
25# must be compiled with "Makefile.lsl", see elsewhere.
26#
27# Note that "main-acn.c", the visual module for Risc Acorn,
28# must be compiled with "Makefile.acn", see elsewhere.
29#
30# Note that "Makefile.w31" and "Makefile.wat" are slight variations
31# on "Makefile.win" and "Makefile.ibm", respectively, which allow
32# the use of the "main-win.c" and "main-ibm.c" files, respectively,
33# with special compilers.
34#
35# If you are able to construct "main-xxx.c" and/or "Makefile.xxx"
36# files for a currently unsupported system, please send them to me
37# (benh@voicenet.com) for inclusion in future versions.
38#
39# This Makefile comes with "default" dependancies that may be obsolete.
40#
41# You may want to run "make depend" if you are planning on changing
42# anything.
43#
44
45
46#
47# The "source" and "object" files.
48#
49
50SERV_SRCS = \
51  common/z-util.c common/z-virt.c common/z-form.c common/z-rand.c \
52  common/net-win.c common/sockbuf.c common/common.c \
53  server/variable.c server/control.c server/hooks.c \
54  server/party.c server/tables.c server/util.c server/cave.c \
55  server/object1.c server/object2.c server/monster2.c \
56  server/xtra1.c server/xtra2.c server/spells1.c server/spells2.c \
57  server/melee1.c server/melee2.c server/save.c server/files.c \
58  server/cmd1.c server/cmd2.c server/cmd3.c server/cmd4.c server/cmd5.c \
59  server/cmd6.c server/store.c server/birth.c server/load2.c server/randart.c \
60  server/sched-win.c server/generate.c server/wild.c server/dungeon.c \
61  server/init1.c server/init2.c server/nserver.c server/printout.c \
62  server/main.c server/traps.c server/csfunc.c server/skills.c \
63  common/files.c common/w_z_pack.c server/world.c server/bldg.c \
64  server/runecraft.c server/auction.c server/quests.c common/SFMT.c \
65  server/go.c server/metaclient.c common/tables.c
66
67SERV_OBJS = \
68  common/z-util.o common/z-virt.o common/z-form.o common/z-rand.o \
69  common/net-win.o common/sockbuf.o common/common.o \
70  server/variable.o server/control.o server/hooks.o \
71  server/party.o server/tables.o server/util.o server/cave.o \
72  server/object1.o server/object2.o server/monster2.o \
73  server/xtra1.o server/xtra2.o server/spells1.o server/spells2.o \
74  server/melee1.o server/melee2.o server/save.o server/files.o \
75  server/cmd1.o server/cmd2.o server/cmd3.o server/cmd4.o server/cmd5.o \
76  server/cmd6.o server/store.o server/birth.o server/load2.o server/randart.o \
77  server/sched-win.o server/generate.o server/wild.o server/dungeon.o \
78  server/init1.o server/init2.o server/nserver.o server/printout.o \
79  server/main.o server/traps.o server/csfunc.o server/skills.o \
80  common/files.c common/w_z_pack.o server/world.o server/bldg.o \
81  server/runecraft.o server/auction.o server/quests.o common/SFMT.o \
82  server/go.o server/metaclient.o common/tables.o
83
84
85CLI_SRCS = \
86  common/z-util.c common/z-virt.c common/z-form.c common/z-rand.c \
87  common/net-win.c common/sockbuf.c common/net-ibm.c common/common.c \
88  client/z-term.c client/c-util.c client/c-cmd.c client/c-inven.c \
89  client/c-files.c client/c-tables.c client/c-store.c client/c-init.c \
90  client/variable.c client/readdib.c client/main-win.c client/nclient.c \
91  client/c-birth.c client/c-xtra1.c client/c-xtra2.c client/c-spell.c \
92  client/skills.c common/files.c common/SFMT.c client/snd-sdl.c \
93  common/tables.c
94# client/main-ibm.c client/main-cap.c client/main-gcu.c client/main-x11.c client/main-xaw.c
95# client/client.c
96
97CLI_OBJS = \
98  common/z-util.o common/z-virt.o common/z-form.o common/z-rand.o \
99  common/net-win.o common/sockbuf.o common/net-ibm.o common/common.o \
100  client/z-term.o client/c-util.o client/c-cmd.o client/c-inven.o \
101  client/c-files.o client/c-tables.o client/c-store.o client/c-init.o \
102  client/variable.o client/readdib.o client/main-win.o client/nclient.o \
103  client/c-birth.o client/c-xtra1.o client/c-xtra2.o client/c-spell.o \
104  client/skills.o common/files.o common/SFMT.o client/snd-sdl.o \
105  common/tables.o client/icon.o
106# client/main-ibm.o client/main-cap.o client/main-gcu.o client/main-x11.o client/main-xaw.o
107# client/client.o
108
109CONS_SRCS = \
110  common/z-util.c common/z-virt.c common/z-form.c common/net-unix.c \
111  common/sockbuf.c common/net-ibm.c common/common.c \
112  client/z-term.c \
113  client/main-ibm.c client/main-cap.c client/main-gcu.c \
114  client/main-x11.c client/main-xaw.c \
115  console/variable.c console/c-util.c console/console.c console/c-init.c
116
117CONS_OBJS = \
118  common/z-util.o common/z-virt.o common/z-form.o common/net-unix.o \
119  common/sockbuf.o common/net-ibm.o common/common.o \
120  client/z-term.o \
121  client/main-ibm.o client/main-cap.o client/main-gcu.o \
122  client/main-x11.o client/main-xaw.o \
123  console/variable.o console/c-util.o console/console.o console/c-init.o
124
125
126LUASRCS = \
127  server/script.c server/lua_bind.c \
128  server/w_util.c server/w_play.c server/w_spells.c
129
130# TODO: lua directory should be under common/ and not server/
131TOLUASRCS = \
132  server/lua/lapi.c server/lua/lcode.c server/lua/ldebug.c server/lua/ldo.c server/lua/lfunc.c server/lua/lgc.c \
133  server/lua/llex.c server/lua/lmem.c server/lua/lobject.c server/lua/lparser.c server/lua/lstate.c server/lua/lstring.c \
134  server/lua/ltable.c server/lua/ltests.c server/lua/ltm.c server/lua/lundump.c server/lua/lvm.c server/lua/lzio.c \
135  server/lua/lauxlib.c server/lua/lbaselib.c server/lua/ldblib.c server/lua/liolib.c server/lua/lstrlib.c \
136  server/lua/tolua_lb.c server/lua/tolua_rg.c server/lua/tolua_tt.c server/lua/tolua_tm.c server/lua/tolua_gp.c \
137  server/lua/tolua_eh.c server/lua/tolua_bd.c server/lua/lmathlib.c
138
139LUAOBJS = \
140  server/script.o server/lua_bind.o \
141  server/w_util.o server/w_play.o server/w_spells.o
142
143TOLUAOBJS = \
144  server/lua/lapi.o server/lua/lcode.o server/lua/ldebug.o server/lua/ldo.o server/lua/lfunc.o server/lua/lgc.o \
145  server/lua/llex.o server/lua/lmem.o server/lua/lobject.o server/lua/lparser.o server/lua/lstate.o server/lua/lstring.o \
146  server/lua/ltable.o server/lua/ltests.o server/lua/ltm.o server/lua/lundump.o server/lua/lvm.o server/lua/lzio.o \
147  server/lua/lauxlib.o server/lua/lbaselib.o server/lua/ldblib.o server/lua/liolib.o server/lua/lstrlib.o \
148  server/lua/tolua_lb.o server/lua/tolua_rg.o server/lua/tolua_tt.o server/lua/tolua_tm.o server/lua/tolua_gp.o \
149  server/lua/tolua_eh.o server/lua/tolua_bd.o server/lua/lmathlib.o
150
151CLI_LUASRCS = \
152  client/c-script.c client/lua_bind.c \
153  client/w_play.c client/w_util.c client/w_spells.c
154
155#  server/lua_bind.c \
156#  server/w_util.c server/w_play.c
157
158CLI_LUAOBJS = \
159  client/c-script.o client/lua_bind.o \
160  client/w_play.o client/w_util.o client/w_spells.o
161
162
163##
164## Following are some "system" definitions
165##
166## No changes are needed to compile a version that will run on both
167## X11 and Curses, in debugging mode, with maximal warnings, on many
168## normal Unix machines of the Sun OS variety (non-solaris).
169##
170## To use an "alternative" definition, simply "modify" (or "replace")
171## the definition below with one that you like.  For example, you can
172## change the compiler to "cc", or remove the "debugging" options, or
173## remove the X11 or Curses support, etc, as desired.
174##
175## See also "config.h" and "h-config.h" for important information.
176##
177## Some "examples" are given below, they can be used by simply
178## removing the FIRST column of "#" signs from the "block" of lines
179## you wish to use, and commenting out "standard" block below.
180##
181## This is not intended to be a "good" Makefile, just a "simple" one.
182##
183
184
185#
186# This is my compiler of choice, it seems to work most everywhere
187#
188CC = gcc
189
190# For allowing #if..#else..#endif constructs in LUA files - C. Blue
191# Note: The flags must contain
192# 1) the option that turns off elimination of comment lines (ie cpp
193#    must just copy comments 1:1). Usually this is '-C'.
194# 2) the option that turns off generation of a preprocessor header
195#    (lines starting on '# '). Usually this is '-P'.
196# Also, if your system doesnt have a dedicated cpp command, you might
197# need to use the gcc invocation below instead.
198#
199# cpp variant:
200CPP = cpp
201CPPFLAGS = -C -P
202# gcc variant:
203#CPP = gcc
204#CPPFLAGS = -x c -E -Wp,-C,-P
205
206
207#
208# Windres is needed for the application icon
209#
210WINDRES = windres
211
212
213#
214# Standard version (see main-x11.c and main-gcu.c)
215#
216# This version supports both "X11" and "curses" in a single executable.
217#
218# You may have to add various X11 include/library directories to the
219# "CFLAGS", if your machine places files in a weird location.
220#
221# You may be able to remove "-ltermcap" on some machines (ex: Solaris).
222#
223# You may have to replace "-lcurses" with "-lncurses" to use the
224# "new curses" library instead of the "old curses" library, and
225# you may have to add "-l/usr/include/ncurses" to the "CFLAGS".
226#
227# See "main-gcu.c" and "config.h" for some optional "curses" defines,
228# including "USE_GETCH" and "USE_CURS_SET".  Note that "config.h" will
229# attempt to "guess" at many of these flags based on your system.
230#
231#CFLAGS = -Wall -g -pipe -D"USE_X11" -D"USE_GCU"
232#LIBS = -L/usr/X11R6/lib -lX11 -lcurses
233
234##
235## Variation -- Cygwin
236##
237## With SDL
238CFLAGS = -g -Wall -D__USE_W32_SOCKETS -DWIN32 -DDUMB_WIN -DCYGWIN -DMEXP=19937 -DSOUND_SDL -DWINVER=0x0501 -Wno-unused-but-set-variable -DACC32
239LIBS = -lkernel32 -luser32 -lwsock32 -lgdi32 -lcomdlg32 -lwinmm -lSDL -lSDL_mixer
240##
241## Without SDL
242#CFLAGS = -Wall -O2 -D__USE_W32_SOCKETS -DWIN32 -DDUMB_WIN -DCYGWIN -DMEXP=19937
243#LIBS = -lkernel32 -luser32 -lwsock32 -lgdi32 -lcomdlg32 -lwinmm
244
245
246# Compile a client with 'test client' version/tag
247tomenet.test.exe: CFLAGS += -DTEST_CLIENT -O0
248
249# Normal release build
250tomenet.exe: CFLAGS += -O2
251
252
253# Lua
254SRCS += $(LUASRCS)
255SRCS += $(CLI_LUASRCS)
256SERV_OBJS += $(LUAOBJS)
257SERV_SRCS += $(TOLUASRCS)
258SERV_OBJS += $(TOLUAOBJS)
259CLI_OBJS += $(CLI_LUAOBJS)
260CLI_SRCS += $(TOLUASRCS)
261CLI_OBJS += $(TOLUAOBJS)
262CFLAGS += $(LUAFLAGS) -Iserver -Iserver/lua
263
264TOLUA = server/tolua.exe
265
266#
267# Hack -- "install" as the base target
268#
269# If you want to build a server, remove the two hashes from the lines
270# below.
271#
272
273install: date tomenet.exe tomenet.server.exe
274	cp tomenet.exe ..
275	cp tomenet.server.exe ..
276
277mini_install: install
278
279date:
280	touch common/common.c
281
282#
283# Build the TomeNET server
284#
285
286tomenet.server.exe: $(SERV_OBJS) $(TOLUA)
287	$(CC) $(CFLAGS) $(LDFLAGS) -o tomenet.server.exe $(SERV_OBJS) $(LIBS)
288
289
290#
291# Build the TomeNET client
292#
293
294tomenet.exe: $(CLI_OBJS) $(TOLUA)
295	$(CC) $(CFLAGS) $(LDFLAGS) -o tomenet.exe $(CLI_OBJS) $(LIBS)
296
297tomenet.test.exe: $(CLI_OBJS) $(TOLUA)
298	$(CC) $(CFLAGS) $(LDFLAGS) -o tomenet.exe $(CLI_OBJS) $(LIBS)
299
300
301#
302# Build the TomeNET remote console
303#
304
305tomenet.console.exe: $(CONS_OBJS)
306	$(CC) $(CFLAGS) $(LDFLAGS) -o tomenet.console.exe $(CONS_OBJS) $(LIBS)
307
308
309$(TOLUA): $(TOLUAOBJS) server/lua/tolua.c server/lua/tolualua.c
310	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(TOLUAOBJS) server/lua/tolua.c server/lua/tolualua.c $(LIBS)
311
312
313#
314# Build the custom LUA preprocessor
315#
316
317preproc/preproc: preproc/preproc.o
318	$(CC) $(CFLAGS) -o preproc/preproc preproc/preproc.o
319
320
321#
322# Rule for making a '.o'
323#
324.c.o:
325	$(CC) $(CFLAGS) -o $*.o -c $*.c
326
327
328#
329# Clean up old junk
330#
331
332clean:
333	cd server/lua; rm -f *.o
334	cd server; rm -f *.o w_play.c w_util.c w_spells.c *.pkg
335	cd client; rm -f *.o w_play.c w_util.c w_spells.c *.pkg
336	cd common; rm -f *.o w_z_pack.c
337	cd console; rm -f *.o
338	rm -f account/accedit.o preproc/preproc.o
339
340#
341# Lua library compilation rules
342#
343
344server/util.pkg: server/util.pre preproc/preproc
345	cd server; ../preproc/preproc util.pre util.pkg $(CPP) $(CPPFLAGS); cd ..
346
347server/player.pkg: server/player.pre preproc/preproc
348	cd server; ../preproc/preproc player.pre player.pkg $(CPP) $(CPPFLAGS); cd ..
349
350server/spells.pkg: server/spells.pre preproc/preproc
351	cd server; ../preproc/preproc spells.pre spells.pkg $(CPP) $(CPPFLAGS); cd ..
352
353client/util.pkg: client/util.pre preproc/preproc
354	cd client; ../preproc/preproc util.pre util.pkg $(CPP) $(CPPFLAGS); cd ..
355
356client/player.pkg: client/player.pre preproc/preproc
357	cd client; ../preproc/preproc player.pre player.pkg $(CPP) $(CPPFLAGS); cd ..
358
359client/spells.pkg: client/spells.pre preproc/preproc
360	cd client; ../preproc/preproc spells.pre spells.pkg $(CPP) $(CPPFLAGS); cd ..
361
362server/w_util.c: server/util.pkg $(TOLUA)
363	cd server; ./tolua.exe -n util -o w_util.c util.pkg; cd ..
364
365server/w_play.c: server/player.pkg $(TOLUA)
366	cd server; ./tolua.exe -n player -o w_play.c player.pkg; cd ..
367
368server/w_spells.c: server/spells.pkg $(TOLUA)
369	cd server; ./tolua.exe -n spells -o w_spells.c spells.pkg; cd ..
370
371client/w_play.c: client/player.pkg $(TOLUA)
372	cd client; pwd; ../server/tolua.exe -n player -o w_play.c player.pkg; cd ..
373
374client/w_util.c: client/util.pkg $(TOLUA)
375	cd client; ../server/tolua.exe -n util -o w_util.c util.pkg; cd ..
376
377client/w_spells.c: client/spells.pkg $(TOLUA)
378	cd client; ../server/tolua.exe -n spells -o w_spells.c spells.pkg; cd ..
379
380
381common/w_z_pack.c: common/z_pack.pkg $(TOLUA)
382	cd common; ../server/tolua.exe -n z_pack -o w_z_pack.c z_pack.pkg; cd ..
383
384#
385# Icon
386#
387client/icon.o: client/icon.rc client/tomenet4.ico
388	cd client; $(WINDRES) -o icon.o icon.rc; cd ..
389
390
391
392#
393# Generate dependancies automatically
394#
395
396depend:
397	makedepend -- $(CFLAGS) -D__MAKEDEPEND__ -- $(SERV_SRCS) $(CLI_SRCS)
398
399
400# DO NOT ADD ANYTHING BELOW THIS LINE.
401
402# DO NOT DELETE THIS LINE -- make depend depends on it.
403
404