]> git.pond.sub.org Git - empserver/blob - Make.mk
Units no longer die from lack of maintenance
[empserver] / Make.mk
1 #
2 #   Empire - A multi-player, client/server Internet based war game.
3 #   Copyright (C) 1986-2011, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 #                 Ken Stevens, Steve McClure, Markus Armbruster
5 #
6 #   Empire 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 3 of the License, or
9 #   (at your option) any later version.
10 #
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.
15 #
16 #   You should have received a copy of the GNU General Public License
17 #   along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 #
19 #   ---
20 #
21 #   See files README, COPYING and CREDITS in the root of the source
22 #   tree for related information and legal notices.  It is expected
23 #   that future projects/authors will amend these files as needed.
24 #
25 #   ---
26 #
27 #   Make.mk: The real Makefile, included by GNUmakefile
28 #
29 #   Known contributors to this file:
30 #      Markus Armbruster, 2005-2011
31 #
32
33 # This makefile was inspired by `Recursive Make Considered Harmful',
34 # Peter Miller, 1997.
35 # http://miller.emu.id.au/pmiller/books/rmch/
36
37 # Recursively expanded variables are occasionally useful, but can be
38 # slow and tricky.  Do not use them gratuitously.  If you don't
39 # understand this, always use `:=' rather than `='.
40
41 # Default goal
42 all:
43
44 # Delete target on error.  Every Makefile should have this.
45 .DELETE_ON_ERROR:
46
47 # Source files
48 ifeq ($(revctrl),git)
49 src := $(shell cd $(srcdir) && git ls-files)
50 else
51 include $(srcdir)/sources.mk
52 endif
53 dirs := $(sort $(dir $(src)))
54 csrc := $(filter %.c, $(src))
55 tsrc := $(filter %.t, $(src))
56 man6 := $(filter man/%.6, $(src))
57 builtins := $(filter src/lib/global/%.config, $(src))
58
59 # Info subjects (automatically generated)
60 -include subjects.mk
61
62 # Abbreviations
63 topics := $(patsubst %.t,%,$(notdir $(tsrc)))
64 info := $(topics) $(subjects) all TOP
65 subjects.html := $(addprefix info.html/, $(addsuffix .html, $(subjects)))
66 topics.html := $(addprefix info.html/, $(addsuffix .html, $(topics)))
67 scripts := $(srcdir)/src/scripts
68 depcomp := $(SHELL) $(srcdir)/depcomp
69 tarball := $(SHELL) -e $(scripts)/tarball
70 econfig := $(sysconfdir)/empire/econfig
71 schedule := $(sysconfdir)/empire/schedule
72 gamedir := $(localstatedir)/empire
73 builtindir := $(datadir)/empire/builtin
74 einfodir := $(datadir)/empire/info.nr
75 ehtmldir := $(datadir)/empire/info.html
76 client/w32 := arpa/inet.h netdb.h netinet/in.h sys/time.h sys/socket.h  \
77 sys/uio.h unistd.h w32io.c w32sockets.c w32types.h
78
79 # Abbreviate make output
80 # Run make with a V=1 parameter for full output.
81 ifneq ($(origin V),command line)
82 V:=
83 endif
84 # $(call quiet-command COMMAND,ABBREV) runs COMMAND, but prints only ABBREV.
85 # Recursively expanded so that variables in COMMAND and ABBREV work.
86 ifneq ($V$(findstring s,$(MAKEFLAGS)),)
87 quiet-command = $1
88 else
89 quiet-command = @echo $2 && $1
90 endif
91
92 # How to substitute Autoconf output variables
93 # Recursively expanded so that $@ and $< work.
94 subst.in = sed \
95         -e 's?@configure_input\@?$(notdir $@): Generated from $(notdir $<) by make.?g' \
96         -e 's?@builtindir\@?$(builtindir)?g'    \
97         -e 's?@econfig\@?$(econfig)?g'          \
98         -e 's?@einfodir\@?$(einfodir)?g'        \
99         -e 's?@gamedir\@?$(gamedir)?g'          \
100         -e 's/@EMPIREHOST\@/$(EMPIREHOST)/g'    \
101         -e 's/@EMPIREPORT\@/$(EMPIREPORT)/g'
102
103 # Generated files
104 # See `Cleanliness' below
105 mk := subjects.mk
106 ifeq ($(revctrl),git)
107 mk += $(srcdir)/sources.mk
108 endif
109 # Generated by Autoconf, not distributed:
110 ac := config.h config.log config.status info.html info.nr lib stamp-h
111 ac += $(basename $(filter %.in, $(src)))
112 ac += $(srcdir)/autom4te.cache $(srcdir)/src/client/autom4te.cache
113 # distributed by dist-source from $(srcdir):
114 acdist := aclocal.m4 config.h.in configure stamp-h.in
115 # distributed by dist-client from $(srcdir):
116 acdistcli := $(addprefix src/client/, aclocal.m4 config.h.in configure)
117 # Object files:
118 obj := $(csrc:.c=.o) $(filter %.o, $(ac:.c=.o))
119 # Dependencies:
120 deps := $(obj:.o=.d)
121 # Library archives:
122 libs := $(addprefix lib/, libcommon.a libgen.a libglobal.a)
123 # Programs:
124 util := $(addprefix src/util/, $(addsuffix $(EXEEXT), empdump empsched fairland files pconfig))
125 client := src/client/empire$(EXEEXT)
126 server := src/server/emp_server$(EXEEXT)
127 # Info subjects:
128 tsubj := $(addprefix info/, $(addsuffix .t, $(subjects)))
129 ttop := info/TOP.t
130 # Formatted info:
131 info.nr := $(addprefix info.nr/, $(info))
132 info.html := $(addprefix info.html/, $(addsuffix .html, $(info)))
133 info.all := $(info.nr) $(info.html) info.ps
134
135 # Conditionally generated files:
136 empth_obj := src/lib/empthread/io.o
137 empth_lib :=
138 ifeq ($(empthread),LWP)
139 empth_obj += src/lib/empthread/lwp.o src/lib/empthread/posix.o
140 empth_lib += lib/liblwp.a
141 endif
142 ifeq ($(empthread),POSIX)
143 empth_obj += src/lib/empthread/pthread.o src/lib/empthread/posix.o
144 endif
145 ifeq ($(empthread),Windows)
146 empth_obj += src/lib/empthread/ntthread.o
147 endif
148
149 ifeq ($(empthread),Windows)     # really: W32, regardless of thread package
150 libs += lib/libw32.a
151 $(client): lib/libw32.a
152 endif
153
154 # Cleanliness
155 # Each generated file should be in one of the following sets.
156 # Removed by clean:
157 clean := $(obj) $(deps) $(libs) $(util) $(client) $(server) $(tsubj)    \
158 $(ttop) $(info.all) $(empth_obj) $(empth_lib)
159 # Removed by distclean:
160 distclean := $(ac) $(mk)
161 # Distributed by dist-source from $(srcdir):
162 src_distgen := $(acdist)
163 # Distributed by dist-client from $(srcdir)/src/client; removed by distclean:
164 cli_distgen := $(acdistcli)
165
166 # Compiler flags
167 CPPFLAGS += -I$(srcdir)/include -I.
168 ifeq ($(empthread),Windows)     # really: W32, regardless of thread package
169 CPPFLAGS += -I$(srcdir)/src/lib/w32
170 endif
171 ifeq ($(have_gcc),yes)
172 CFLAGS += -fno-builtin-carg     # conflicts with our carg()
173 CFLAGS += -fno-common
174 CFLAGS += -Wall -W -Wno-unused-parameter -Wpointer-arith        \
175 -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs       \
176 -Wredundant-decls
177 endif
178 $(client): LDLIBS := $(LIBS_client)
179 $(server): LDLIBS := $(LIBS_server)
180
181 ### Advertized goals
182
183 .PHONY: all
184 all: $(util) $(client) $(server) info
185
186 .PHONY: info html
187 info: $(info.nr)
188 html: $(info.html)
189
190 .PHONY: clean
191 clean:
192         $(call quiet-command,rm -f $(clean),CLEAN)
193
194 .PHONY: distclean
195 distclean: clean
196         $(call quiet-command,rm -rf $(distclean) $(cli_distgen),DISTCLEAN)
197
198 .PHONY: install
199 install: all installdirs
200         $(INSTALL_PROGRAM) $(util) $(server) $(sbindir)
201         $(INSTALL_PROGRAM) $(client) $(bindir)
202         $(INSTALL) -m 444 $(addprefix $(srcdir)/, $(builtins)) $(builtindir)
203         $(INSTALL_DATA) $(info.nr) $(einfodir)
204         $(INSTALL_DATA) $(addprefix $(srcdir)/, $(man6)) $(mandir)/man6
205         sed -e '1,/^$$/d' -e 's/^/# /g' <$(srcdir)/doc/schedule >$(schedule).dist
206         echo >>$(schedule).dist
207         echo 'every 10 minutes' >>$(schedule).dist
208         [ -e $(schedule) ] || mv $(schedule).dist $(schedule)
209         if [ -e $(econfig) ]; then                                      \
210             echo "Attempting to update your econfig";                   \
211             if src/util/pconfig $(econfig) >$(econfig).dist; then       \
212                 if cmp -s $(econfig) $(econfig).dist; then              \
213                     echo "$(econfig) unchanged";                        \
214                     rm $(econfig).dist;                                 \
215                 fi;                                                     \
216             else                                                        \
217                 echo "Your $(econfig) doesn't work";                    \
218                 src/util/pconfig >$(econfig).dist;                      \
219             fi;                                                         \
220             if [ -e $(econfig).dist ]; then                             \
221                 echo "Check out $(econfig).dist";                       \
222             fi;                                                         \
223         else                                                            \
224             src/util/pconfig >$(econfig);                               \
225         fi
226
227 .PHONY: installdirs
228 installdirs:
229         mkdir -p $(sbindir) $(bindir) $(builtindir) $(einfodir) $(mandir)/man6 $(dir $(econfig)) $(gamedir)
230
231 .PHONY: install-html
232 install-html: html
233         mkdir -p $(ehtmldir)
234         $(INSTALL_DATA) $(info.html) $(ehtmldir)
235
236 .PHONY: uninstall
237 uninstall:
238         rm -f $(addprefix $(sbindir)/, $(notdir $(util) $(server)))
239         rm -f $(addprefix $(bindir)/, $(notdir $(client)))
240         rm -rf $(builtindir) $(einfodir)
241         rm -f $(addprefix $(mandir)/man6/, $(notdir $(man6)))
242         @echo "$(dir $(econfig)) and $(gamedir) not removed, you may wish to remove it manually."
243
244 .PHONY: dist
245 dist: dist-source dist-client dist-info
246
247
248 ### Implicit rules
249
250 # Compile with dependencies as side effect, i.e. create %.d in
251 # addition to %.o.
252 ifeq ($(how_to_dep),fast)
253 %.o: %.c
254         $(call quiet-command,$(COMPILE.c) -MT $@ -MMD -MP -MF $(@:.o=.d) \
255         $(OUTPUT_OPTION) $< || { rm -f $(@:.o=.d) $@; false; },CC $@)
256 # Why the rm?  If gcc's preprocessor chokes, it leaves an empty
257 # dependency file behind, and doesn't touch the object file.  If an
258 # old object file exists, and is newer than the .c file, make will
259 # then consider the object file up-to-date.
260 endif
261 ifeq ($(how_to_dep),depcomp)
262 %.o: %.c
263         $(call quiet-command,source='$<' object='$@' depfile='$(@:.o=.d)' \
264         $(CCDEPMODE) $(depcomp) $(COMPILE.c) $(OUTPUT_OPTION) $<,CC $@)
265 endif
266 # Cancel the rule to compile %.c straight to %, it interferes with
267 # automatic dependency generation
268 %: %.c
269
270 %$(EXEEXT): %.o
271         $(call quiet-command,$(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -o $@,LINK $@)
272
273
274 info.nr/%: info/%.t
275         $(call quiet-command,$(NROFF) $(filter %.MAC, $^) $< | $(AWK) -f $(filter %/Blank.awk, $^) >$@ && test -s $@,NROFF $@)
276 # Pipes in make are a pain.  The "test -s" catches obvious errors.
277
278 info.html/%.html: info/%.t
279         perl $(filter %.pl, $^) $< >$@
280
281
282 ### Explicit rules
283
284 # Compilation
285
286 $(server): $(filter src/server/% src/lib/commands/% src/lib/player/% src/lib/subs/% src/lib/update/%, $(obj)) $(empth_obj) $(empth_lib) $(libs)
287         $(call quiet-command,$(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -o $@,LINK $@)
288
289 $(client): $(filter src/client/%, $(obj)) src/lib/global/version.o
290         $(call quiet-command,$(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -o $@,LINK $@)
291
292 $(util): $(libs)
293
294 lib/libcommon.a: $(filter src/lib/common/%, $(obj))
295 lib/libgen.a: $(filter src/lib/gen/%, $(obj))
296 lib/libglobal.a: $(filter src/lib/global/%, $(obj))
297 lib/liblwp.a: $(filter src/lib/lwp/%, $(obj))
298 lib/libw32.a: $(filter src/lib/w32/%, $(obj))
299
300 $(libs) $(empth_lib):
301         $(call quiet-command,$(AR) rc $@ $?,AR $@)
302         $(RANLIB) $@
303
304 # Info formatting
305
306 # FIXME Remaking subjects doesn't work correctly when info sources get
307 # removed or subjects get dropped.
308
309 subjects.mk: info/findsubj.pl $(tsrc)
310         perl $(srcdir)/info/findsubj.pl $(filter %.t, $^)
311
312 $(tsubj): info/mksubj.pl
313         perl $(srcdir)/info/mksubj.pl $@ $(filter %.t, $^)
314
315 $(ttop): $(tsubj)
316         perl $(srcdir)/info/mktop.pl $@ $(filter %.t, $^)
317
318 info.nr/all: $(filter-out info.nr/all, $(info.nr))
319         >$@
320         (cd info.nr && LC_ALL=C ls -C $(info)) >>$@
321
322 info.html/all.html: info.nr/all info/ls2html.pl
323         expand $< | perl $(srcdir)/info/ls2html.pl >$@
324
325 $(info.nr): info/CRT.MAC info/INFO.MAC info/Blank.awk
326
327 $(subjects.html) info.html/TOP.html: info/subj2html.pl
328 $(topics.html): info/emp2html.pl
329
330 info.ps: info/TROFF.MAC info/INFO.MAC $(ttop) $(tsubj) $(tsrc)
331         groff $^ >$@
332
333 # Distributing
334
335 .PHONY: dist-source
336 dist-source: $(src_distgen)
337 ifeq ($(revctrl),git)
338         echo "src := $(src)" >$(srcdir)/sources.mk
339 endif
340         $(tarball) $(TARNAME)-$(VERSION) -C $(srcdir) $(src_distgen) $(src) sources.mk
341
342 .PHONY: dist-client
343 dist-client: $(cli_distgen)
344         $(tarball) $(TARNAME)-client-$(VERSION)                         \
345         -C $(srcdir)/src/client                                         \
346                 $(notdir $(filter src/client/%, $(src)) $(cli_distgen)) \
347         -C $(srcdir)/include proto.h version.h                          \
348         -C $(srcdir)/src/lib/global version.c                           \
349         -C $(srcdir)/src/lib $(addprefix w32/, $(client/w32))           \
350         -C $(srcdir)/man empire.6                                       \
351         -C $(srcdir) COPYING INSTALL install-sh
352
353 .PHONY: dist-info
354 dist-info: info html
355         $(tarball) $(TARNAME)-info-text-$(VERSION) -C info.nr $(info)
356         $(tarball) $(TARNAME)-info-html-$(VERSION) -C info.html $(addsuffix .html, $(info))
357
358 ifneq ($(deps),)
359 -include $(deps)
360 endif
361
362
363 # Automatic remake of configuration
364 # See (autoconf)Automatic Remaking.
365 # This requires sufficiently recent versions of autoconf and automake
366
367 $(srcdir)/configure: configure.ac aclocal.m4
368         cd $(srcdir) && autoconf
369
370 # autoheader might not change config.h.in, so touch a stamp file.
371 $(srcdir)/config.h.in: stamp-h.in
372 $(srcdir)/stamp-h.in: configure.ac aclocal.m4
373         cd $(srcdir) && autoheader
374         touch $@
375
376 $(srcdir)/aclocal.m4: $(filter m4/%.m4, $(src))
377         cd $(srcdir) && aclocal -I m4
378
379 # config.status might not change config.h; use the stamp file.
380 config.h: stamp-h
381 stamp-h: config.h.in config.status
382         ./config.status config.h stamp-h
383
384 GNUmakefile: GNUmakefile.in config.status
385         ./config.status $@
386
387 config.status: configure
388         ./config.status --recheck
389
390 src/lib/global/path.c src/client/ipglob.c: %: %.in GNUmakefile Make.mk
391         $(call quiet-command,$(subst.in) <$< >$@,GEN $@)
392
393
394 # Make files for standalone client distribution
395
396 $(srcdir)/src/client/configure: src/client/configure.ac src/client/aclocal.m4
397         cd $(dir $@) && autoconf
398
399 $(srcdir)/src/client/config.h.in: src/client/configure.ac src/client/aclocal.m4
400         cd $(dir $@) && autoheader
401         touch $@
402
403 $(srcdir)/src/client/aclocal.m4: m4/lib_socket_nsl.m4 m4/my_terminfo.m4 m4/my_windows_api.m4
404         cat $^ >$@