]> git.pond.sub.org Git - empserver/blob - Make.mk
Cosmetics.
[empserver] / Make.mk
1
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
5
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.
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, write to the Free Software
18 #   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
20 #   ---
21
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.
25
26 #   ---
27
28 #   Make.mk: 
29 #  
30 #   Known contributors to this file:
31 #      Markus Armbruster, 2005
32
33
34 # This makefile was inspired by `Recursive Make Considered Harmful',
35 # Peter Miller, 1997.
36 # http://www.pcug.org.au/~millerp/rmch/recu-make-cons-harm.html
37
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 `='.
41
42 # Default goal
43 all:
44
45 # Delete target on error.  Every Makefile should have this.
46 .DELETE_ON_ERROR:
47
48 # Source files
49 -include sources.mk
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))
55
56 # Info topics and subjects
57 -include subjects.mk
58
59 # Abbreviations
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
71
72 # How to substitute Autoconf output variables
73 # Recursively expanded so that $@ and $< work.
74 subst.in = sed \
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'
81
82 # Generated files
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)
93 # Object files:
94 obj := $(csrc:.c=.o) $(filter %.o, $(ac:.c=.o))
95 # TODO AIX needs lwpInit.o lwpRestore.o lwpSave.o unless UCONTEXT
96 # Dependencies:
97 deps := $(obj:.o=.d)
98 # Library archives:
99 libs := $(addprefix lib/, libcommon.a libgen.a libglobal.a)
100 # Programs:
101 util := $(addprefix src/util/, $(addsuffix $(EXEEXT), fairland files pconfig))
102 client := src/client/empire$(EXEEXT)
103 server := src/server/emp_server$(EXEEXT)
104 # Info subjects:
105 tsubj := $(addprefix info/, $(addsuffix .t, $(subjects)))
106 ttop := info/TOP.t
107 # Formatted info:
108 info.nr := $(addprefix info.nr/, $(info))
109 info.html := $(addprefix info.html/, $(addsuffix .html, $(info)))
110
111 # Conditionally generated files:
112 ifeq ($(empthread),LWP)
113 empth_obj := src/lib/empthread/lwp.o
114 empth_lib := lib/liblwp.a
115 endif
116 ifeq ($(empthread),POSIX)
117 empth_obj := src/lib/empthread/pthread.o
118 empth_lib :=
119 endif
120 ifeq ($(empthread),Windows)
121 empth_obj := src/lib/empthread/ntthread.o
122 empth_lib :=
123 endif
124
125 # Cleanliness
126 # Each generated file should be in one of the following sets.
127 # Removed by clean:
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)
138
139 # Compiler flags
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
146 endif
147 LDLIBS += -lm
148
149 ### Advertized goals
150
151 .PHONY: all
152 all: $(util) $(client) $(server) info
153
154 .PHONY: info html
155 info: $(info.nr)
156 html: $(info.html)
157
158 .PHONY: clean
159 clean:
160         rm -f $(clean)
161
162 .PHONY: distclean
163 distclean: clean
164         rm -rf $(distclean)
165
166 .PHONY: install
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               \
176                     rm $(econfig).new;                                  \
177                 else                                                    \
178                     echo "Check out $(econfig).new";                    \
179                 fi                                                      \
180             else                                                        \
181                 echo "Your $(econfig) doesn't work";                    \
182             fi                                                          \
183         else                                                            \
184             src/util/pconfig >$(econfig);                               \
185         fi
186
187 .PHONY: installdirs
188 installdirs:
189         mkdir -p $(bindir) $(sbindir) $(edatadir) $(einfodir) $(mandir)/man1 $(mandir)/man6 $(dir $(econfig))
190
191 .PHONY: install-html
192 install-html: html | $(ehtmldir)
193         $(INSTALL_DATA) $(info.html) $(ehtmldir)
194
195 .PHONY: uninstall
196 uninstall:
197         false # FIXME
198
199 .PHONY: dist
200 dist: dist-source dist-client dist-info
201
202
203 ### Implicit rules
204
205 # Compile with dependencies as side effect, i.e. create %.d in
206 # addition to %.o.
207 ifeq ($(how_to_dep),fast)
208 %.o: %.c
209         $(COMPILE.c) -MT $@ -MMD -MP $(OUTPUT_OPTION) $<
210 endif
211 ifeq ($(how_to_dep),depcomp)
212 %.o: %.c
213         source='$<' object='$@' depfile='$(@:.o=.d)' $(CCDEPMODE) $(depcomp) \
214         $(COMPILE.c) $(OUTPUT_OPTION) $<
215 endif
216 # Cancel the rule to compile %.c straight to %, it interferes with
217 # automatic dependency generation
218 %: %.c
219
220 # Work around MinGW Make's broken built-in link rule:
221 %$(EXEEXT): %.o
222         $(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -o $@
223
224
225 info.nr/%: info/%.t
226         $(NROFF) -I $(srcdir)/info $(filter %/CRT.MAC, $^) $< | $(AWK) -f $(filter %/Blank.awk, $^) >$@
227 # FIXME AT&T nroff doesn't grok -I
228
229 info.html/%.html: info/%.t
230         perl $(filter %.pl, $^) $< >$@
231
232
233 ### Explicit rules
234
235 # Compilation
236
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 $@
239
240 $(client): $(filter src/client/%, $(obj)) $(termlibs)
241         $(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -o $@
242
243 $(util): $(libs)
244
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))
249
250 $(libs) $(empth_lib): | lib
251         $(AR) rc $@ $?
252         $(RANLIB) $@
253
254 # Info formatting
255
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
260 # missing files:
261 $(tsrc):
262
263 $(tsubj): info/mksubj.pl
264         perl $(srcdir)/info/mksubj.pl $@ $(filter %.t, $^)
265
266 $(ttop): $(tsubj)
267         perl $(srcdir)/info/mktop.pl $@ $(filter %.t, $^)
268
269 info.nr/all: $(filter-out info.nr/all, $(info.nr))
270         (cd info.nr && ls -CF $(info)) >$@
271 # FIXME shouldn't use ls
272
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
276
277 $(info.nr): info/CRT.MAC info/INFO.MAC info/Blank.awk | info.nr
278
279 $(subjects.html) info.html/TOP.html: info/subj2html.pl | info.html
280 $(topics.html): info/emp2html.pl | info.html
281
282 info.nr info.html lib:
283         mkdir -p $@
284
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` >$@
289 else
290 sources.mk: $(srcdir)/sources.mk
291         cp -f $^ $@
292 endif
293
294
295 .PHONY: dist-source
296 dist-source: check-version $(src_distgen) $(bld_distgen)
297         $(tarball) $(TARNAME)-$(VERSION) $(bld_distgen) -C $(srcdir) $(src_distgen) $(src)
298
299 .PHONY: dist-client
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
307
308 .PHONY: dist-info
309 dist-info: info html
310         $(tarball) $(TARNAME)-info-text-$(VERSION) -C info.nr $(info)
311         $(tarball) $(TARNAME)-info-html-$(VERSION) -C info.html $(addsuffix .html, $(info))
312
313 check-version:
314         if [ $(VERSION) != `sed -n '/EMP_VERS_/s/#define EMP_VERS_\([A-Z]*\)[ \t]*//p' <$(srcdir)/include/version.h | tr '\012' . | sed 's/\.$$//'` ]; \
315         then echo version.h does not match configure.ac >&2; false; \
316         fi
317
318 ifneq ($(deps),)
319 -include $(deps)
320 endif
321
322
323 # Automatic remake of configuration
324 # See (autoconf)Automatic Remaking.
325 # This requires sufficiently recent versions of autoconf and automake
326
327 $(srcdir)/configure: configure.ac aclocal.m4
328         cd $(srcdir) && autoconf
329
330 # autoheader might not change config.h.in, so touch a stamp file.
331 $(srcdir)/config.h.in: stamp-h.in
332 $(srcdir)/stamp-h.in: configure.ac aclocal.m4
333         cd $(srcdir) && autoheader
334         >$@
335
336 $(srcdir)/aclocal.m4: $(filter m4/%.m4, $(src))
337         cd $(srcdir) && aclocal -I m4
338
339 # config.status might not change config.h; use the stamp file.
340 config.h: stamp-h
341 stamp-h: config.h.in config.status
342         ./config.status config.h stamp-h
343
344 GNUmakefile: GNUmakefile.in config.status
345         ./config.status $@
346
347 config.status: configure
348         ./config.status --recheck
349
350 src/lib/global/path.c src/client/ipglob.c: %: %.in GNUmakefile
351         $(subst.in) <$< >$@
352
353
354 # Make files for standalone client distribution
355
356 $(srcdir)/src/client/configure: src/client/configure.ac src/client/aclocal.m4
357         cd $(dir $@) && autoconf
358
359 $(srcdir)/src/client/config.h.in: src/client/configure.ac src/client/aclocal.m4
360         cd $(dir $@) && autoheader
361         touch $@
362
363 $(srcdir)/src/client/aclocal.m4: m4/lib_socket_nsl.m4
364         cp -f $< $@