2 # Empire - A multi-player, client/server Internet based war game.
3 # Copyright (C) 1986-2006, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 # Ken Stevens, Steve McClure
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 # See files README, COPYING and CREDITS in the root of the source
23 # tree for related information and legal notices. It is expected
24 # that future projects/authors will amend these files as needed.
30 # Known contributors to this file:
31 # Markus Armbruster, 2005
34 # This makefile was inspired by `Recursive Make Considered Harmful',
36 # http://www.pcug.org.au/~millerp/rmch/recu-make-cons-harm.html
38 # Recursively expanded variables are occasionally useful, but can be
39 # slow and tricky. Do not use them gratuitously. If you don't
40 # understand this, always use `:=' rather than `='.
45 # Delete target on error. Every Makefile should have this.
50 dirs := $(sort $(dir $(src)))
51 csrc := $(filter %.c, $(src))
52 tsrc := $(filter %.t, $(src))
53 man1 := $(filter man/%.1, $(src))
54 man6 := $(filter man/%.6, $(src))
56 # Info topics and subjects
60 topics := $(patsubst %.t,%,$(notdir $(tsrc)))
61 info := $(topics) $(subjects) all TOP
62 subjects.html := $(addprefix info.html/, $(addsuffix .html, $(subjects)))
63 topics.html := $(addprefix info.html/, $(addsuffix .html, $(topics)))
64 scripts = $(srcdir)/src/scripts
65 depcomp = $(SHELL) $(srcdir)/depcomp
66 tarball = $(SHELL) $(scripts)/tarball
67 econfig := $(sysconfdir)/empire/econfig
68 edatadir := $(localstatedir)/empire
69 einfodir := $(datadir)/empire/info.nr
70 ehtmldir := $(datadir)/empire/info.html
72 # How to substitute Autoconf output variables
73 # Recursively expanded so that $@ and $< work.
75 -e 's?@configure_input\@?$(notdir $@). Generated from $(notdir $<) by GNUmakefile.?g' \
76 -e 's?@econfig\@?$(econfig)?g' \
77 -e 's?@edatadir\@?$(edatadir)?g' \
78 -e 's?@einfodir\@?$(einfodir)?g' \
79 -e 's/@EMPIREHOST\@/$(EMPIREHOST)/g' \
80 -e 's/@EMPIREPORT\@/$(EMPIREPORT)/g'
83 # See `Cleanliness' below
84 # sources.mk subjects.mk
85 # Generated by Autoconf, not distributed:
86 ac := config.h config.log config.status stamp-h
87 ac += $(basename $(filter %.in, $(src)))
88 ac += $(srcdir)/autom4te.cache $(srcdir)/src/client/autom4te.cache
89 # distributed by dist-source from $(srcdir):
90 acdist := aclocal.m4 config.h.in configure stamp-h.in
91 # distributed by dist-client from $(srcdir):
92 acdistcli := $(addprefix src/client/, aclocal.m4 config.h.in configure)
94 obj := $(csrc:.c=.o) $(filter %.o, $(ac:.c=.o))
95 # TODO AIX needs lwpInit.o lwpRestore.o lwpSave.o unless UCONTEXT
99 libs := $(addprefix lib/, libcommon.a libgen.a libglobal.a)
101 util := $(addprefix src/util/, $(addsuffix $(EXEEXT), fairland files pconfig))
102 client := src/client/empire$(EXEEXT)
103 server := src/server/emp_server$(EXEEXT)
105 tsubj := $(addprefix info/, $(addsuffix .t, $(subjects)))
108 info.nr := $(addprefix info.nr/, $(info))
109 info.html := $(addprefix info.html/, $(addsuffix .html, $(info)))
111 # Conditionally generated files:
112 ifeq ($(empthread),LWP)
113 empth_obj := src/lib/empthread/lwp.o
114 empth_lib := lib/liblwp.a
116 ifeq ($(empthread),POSIX)
117 empth_obj := src/lib/empthread/pthread.o
120 ifeq ($(empthread),Windows)
121 empth_obj := src/lib/empthread/ntthread.o
126 # Each generated file should be in one of the following sets.
128 clean := $(obj) $(deps) $(libs) $(util) $(client) $(server) $(tsubj) \
129 $(ttop) $(info.nr) $(info.html) $(empth_obj) $(empth_lib)
130 # Removed by distclean:
131 distclean := $(ac) subjects.mk
132 # Distributed by dist-source from $(srcdir)
133 src_distgen := $(acdist)
134 # Distributed by dist-source from .
135 bld_distgen := sources.mk
136 # Distributed by dist-client from $(srcdir)/src/client
137 cli_distgen := $(acdistcli)
140 CPPFLAGS += -I$(srcdir)/include -I.
141 ifeq ($(have_gcc),yes)
142 CFLAGS += -fno-builtin-carg # conflicts with our carg()
143 CFLAGS += -fno-common
144 CFLAGS += -Wall -W -Wno-unused -Wpointer-arith -Wstrict-prototypes \
145 -Wmissing-prototypes -Wnested-externs -Wredundant-decls
152 all: $(util) $(client) $(server) info
167 install: all installdirs
168 $(INSTALL_PROGRAM) $(util) $(server) $(sbindir)
169 $(INSTALL_PROGRAM) $(client) $(bindir)
170 $(INSTALL_DATA) $(info.nr) $(einfodir)
171 $(INSTALL_DATA) $(addprefix $(srcdir)/, $(man1)) $(mandir)/man1
172 $(INSTALL_DATA) $(addprefix $(srcdir)/, $(man6)) $(mandir)/man6
173 if test -e $(econfig); then \
174 if src/util/pconfig $(econfig) >$(econfig).new; then \
175 if cmp -s $(econfig) $(econfig).new; then \
178 echo "Check out $(econfig).new"; \
181 echo "Your $(econfig) doesn't work"; \
184 src/util/pconfig >$(econfig); \
189 mkdir -p $(bindir) $(sbindir) $(edatadir) $(einfodir) $(mandir)/man1 $(mandir)/man6 $(dir $(econfig))
192 install-html: html | $(ehtmldir)
193 $(INSTALL_DATA) $(info.html) $(ehtmldir)
200 dist: dist-source dist-client dist-info
205 # Compile with dependencies as side effect, i.e. create %.d in
207 ifeq ($(how_to_dep),fast)
209 $(COMPILE.c) -MT $@ -MMD -MP $(OUTPUT_OPTION) $<
211 ifeq ($(how_to_dep),depcomp)
213 source='$<' object='$@' depfile='$(@:.o=.d)' $(CCDEPMODE) $(depcomp) \
214 $(COMPILE.c) $(OUTPUT_OPTION) $<
216 # Cancel the rule to compile %.c straight to %, it interferes with
217 # automatic dependency generation
220 # Work around MinGW Make's broken built-in link rule:
222 $(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -o $@
226 $(NROFF) -I $(srcdir)/info $(filter %/CRT.MAC, $^) $< | $(AWK) -f $(filter %/Blank.awk, $^) >$@
227 # FIXME AT&T nroff doesn't grok -I
229 info.html/%.html: info/%.t
230 perl $(filter %.pl, $^) $< >$@
237 $(server): $(filter src/server/% src/lib/as/% src/lib/commands/% src/lib/player/% src/lib/subs/% src/lib/update/%, $(obj)) $(empth_obj) $(libs) $(empth_lib)
238 $(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -o $@
240 $(client): $(filter src/client/%, $(obj)) $(termlibs)
241 $(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -o $@
245 lib/libcommon.a: $(filter src/lib/common/%, $(obj))
246 lib/libgen.a: $(filter src/lib/gen/%, $(obj))
247 lib/libglobal.a: $(filter src/lib/global/%, $(obj))
248 lib/liblwp.a: $(filter src/lib/lwp/%, $(obj))
250 $(libs) $(empth_lib): | lib
256 subjects.mk: $(tsrc) info/findsubj.pl sources.mk
257 perl $(srcdir)/info/findsubj.pl
258 # If sources.mk is out of date, $(tsrc) is. If it contains files that
259 # went away, make can't remake subjects.mk. Tell it to ignore such
263 $(tsubj): info/mksubj.pl
264 perl $(srcdir)/info/mksubj.pl $@ $(filter %.t, $^)
267 perl $(srcdir)/info/mktop.pl $@ $(filter %.t, $^)
269 info.nr/all: $(filter-out info.nr/all, $(info.nr))
270 (cd info.nr && ls -CF $(info)) >$@
271 # FIXME shouldn't use ls
273 info.html/all.html: $(filter-out info.html/all.html, $(info.html)) info/ls2html.pl
274 (cd info.html && ls -CF $(notdir $(info.html))) | expand | perl $(filter %.pl, $^) >$@
275 # FIXME shouldn't use ls
277 $(info.nr): info/CRT.MAC info/INFO.MAC info/Blank.awk | info.nr
279 $(subjects.html) info.html/TOP.html: info/subj2html.pl | info.html
280 $(topics.html): info/emp2html.pl | info.html
282 info.nr info.html lib:
285 ifeq ($(cvs_controlled),yes)
286 # Find files and directories under CVS control
287 sources.mk: $(scripts)/cvsfiles.awk $(addprefix $(srcdir)/, $(addsuffix CVS/Entries, $(dirs)))
288 echo 'src := ' `cd $(srcdir) && $(AWK) -f src/scripts/cvsfiles.awk` >$@
290 sources.mk: $(srcdir)/sources.mk
296 dist-source: $(src_distgen) $(bld_distgen)
297 $(tarball) $(TARNAME)-$(VERSION) $(bld_distgen) -C $(srcdir) $(src_distgen) $(src)
300 dist-client: $(cli_distgen)
301 $(tarball) $(TARNAME)-client-$(VERSION) \
302 -C $(srcdir)/src/client \
303 $(notdir $(filter src/client/%, $(src)) $(cli_distgen)) \
304 -C $(srcdir)/include proto.h \
305 -C $(srcdir)/man empire.6 \
306 -C $(srcdir) COPYING INSTALL install-sh
310 $(tarball) $(TARNAME)-info-text-$(VERSION) -C info.nr $(info)
311 $(tarball) $(TARNAME)-info-html-$(VERSION) -C info.html $(addsuffix .html, $(info))
318 # Automatic remake of configuration
319 # See (autoconf)Automatic Remaking.
320 # This requires sufficiently recent versions of autoconf and automake
322 $(srcdir)/configure: configure.ac aclocal.m4
323 cd $(srcdir) && autoconf
325 # autoheader might not change config.h.in, so touch a stamp file.
326 $(srcdir)/config.h.in: stamp-h.in
327 $(srcdir)/stamp-h.in: configure.ac aclocal.m4
328 cd $(srcdir) && autoheader
331 $(srcdir)/aclocal.m4: $(filter m4/%.m4, $(src))
332 cd $(srcdir) && aclocal -I m4
334 # config.status might not change config.h; use the stamp file.
336 stamp-h: config.h.in config.status
337 ./config.status config.h stamp-h
339 GNUmakefile: GNUmakefile.in config.status
342 config.status: configure
343 ./config.status --recheck
345 src/lib/global/path.c src/client/ipglob.c: %: %.in GNUmakefile
349 # Make files for standalone client distribution
351 $(srcdir)/src/client/configure: src/client/configure.ac src/client/aclocal.m4
352 cd $(dir $@) && autoconf
354 $(srcdir)/src/client/config.h.in: src/client/configure.ac src/client/aclocal.m4
355 cd $(dir $@) && autoheader
358 $(srcdir)/src/client/aclocal.m4: m4/lib_socket_nsl.m4