]> git.pond.sub.org Git - empserver/blob - Make.mk
(ac): Add file that should have been added in rev. 1.24.
[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 mk := sources.mk subjects.mk
85 ac := config.h config.log config.status stamp-h
86 ac += $(basename $(filter %.in, $(src)))
87 ac += $(srcdir)/autom4te.cache $(srcdir)/src/client/autom4te.cache
88 acdist := aclocal.m4 config.h.in configure stamp-h.in
89 acdistcli := $(addprefix src/client/, aclocal.m4 config.h.in configure)
90 obj := $(csrc:.c=.o) $(filter %.o, $(ac:.c=.o))
91 # TODO AIX needs lwpInit.o lwpRestore.o lwpSave.o unless UCONTEXT
92 deps := $(obj:.o=.d)
93 libs := $(addprefix lib/, libcommon.a libgen.a libglobal.a)
94 util := $(addprefix src/util/, $(addsuffix $(EXEEXT), fairland files pconfig))
95 client := src/client/empire$(EXEEXT)
96 server := src/server/emp_server$(EXEEXT)
97 tsubj := $(addprefix info/, $(addsuffix .t, $(subjects)))
98 ttop := info/TOP.t
99 info.nr := $(addprefix info.nr/, $(info))
100 info.html := $(addprefix info.html/, $(addsuffix .html, $(info)))
101
102 ifeq ($(empthread),LWP)
103 empth_obj := src/lib/empthread/lwp.o
104 empth_lib := lib/liblwp.a
105 endif
106 ifeq ($(empthread),POSIX)
107 empth_obj := src/lib/empthread/pthread.o
108 empth_lib :=
109 endif
110 ifeq ($(empthread),Windows)
111 empth_obj := src/lib/empthread/ntthread.o
112 empth_lib :=
113 endif
114
115 # Cleanliness
116 # Each generated file should be in one of the following sets.
117 # Removed by clean:
118 clean := $(obj) $(deps) $(libs) $(util) $(client) $(server) $(tsubj)    \
119 $(ttop) $(info.nr) $(info.html) $(empth_obj) $(empth_lib)
120 # Removed by distclean:
121 distclean := $(ac)
122 # Distributed by dist-source from $(srcdir)
123 src_distgen := $(acdist)
124 # Distributed by dist-source from .
125 bld_distgen := $(mk)
126 # Distributed by dist-client from $(srcdir)/src/client
127 cli_distgen := $(acdistcli)
128
129 # Compiler flags
130 CPPFLAGS += -I$(srcdir)/include -I.
131 ifeq ($(have_gcc),yes)
132 CFLAGS += -fno-builtin-carg     # conflicts with our carg()
133 CFLAGS += -fno-common
134 CFLAGS += -Wall -W -Wno-unused -Wpointer-arith -Wstrict-prototypes      \
135 -Wmissing-prototypes -Wnested-externs -Wredundant-decls
136 endif
137 LDLIBS += -lm
138
139 ### Advertized goals
140
141 .PHONY: all
142 all: $(util) $(client) $(server) info
143
144 .PHONY: info html
145 info: $(info.nr)
146 html: $(info.html)
147
148 .PHONY: clean
149 clean:
150         rm -f $(clean)
151
152 .PHONY: distclean
153 distclean: clean
154         rm -rf $(distclean)
155
156 .PHONY: install
157 install: all installdirs
158         $(INSTALL_PROGRAM) $(util) $(server) $(sbindir)
159         $(INSTALL_PROGRAM) $(client) $(bindir)
160         $(INSTALL_DATA) $(info.nr) $(einfodir)
161         $(INSTALL_DATA) $(addprefix $(srcdir)/, $(man1)) $(mandir)/man1
162         $(INSTALL_DATA) $(addprefix $(srcdir)/, $(man6)) $(mandir)/man6
163         if test -e $(econfig); then                                     \
164             if src/util/pconfig $(econfig) >$(econfig).new; then        \
165                 if cmp -s $(econfig) $(econfig).new; then               \
166                     rm $(econfig).new;                                  \
167                 else                                                    \
168                     echo "Check out $(econfig).new";                    \
169                 fi                                                      \
170             else                                                        \
171                 echo "Your $(econfig) doesn't work";                    \
172             fi                                                          \
173         else                                                            \
174             src/util/pconfig >$(econfig);                               \
175         fi
176
177 .PHONY: installdirs
178 installdirs:
179         mkdir -p $(bindir) $(sbindir) $(edatadir) $(einfodir) $(mandir)/man1 $(mandir)/man6 $(dir $(econfig))
180
181 .PHONY: install-html
182 install-html: html | $(ehtmldir)
183         $(INSTALL_DATA) $(info.html) $(ehtmldir)
184
185 .PHONY: uninstall
186 uninstall:
187         false # FIXME
188
189 .PHONY: dist
190 dist: dist-source dist-client dist-info
191
192
193 ### Implicit rules
194
195 # Compile with dependencies as side effect, i.e. create %.d in
196 # addition to %.o.
197 ifeq ($(how_to_dep),fast)
198 %.o: %.c
199         $(COMPILE.c) -MT $@ -MMD -MP $(OUTPUT_OPTION) $<
200 endif
201 ifeq ($(how_to_dep),depcomp)
202 %.o: %.c
203         source='$<' object='$@' depfile='$(@:.o=.d)' $(CCDEPMODE) $(depcomp) \
204         $(COMPILE.c) $(OUTPUT_OPTION) $<
205 endif
206 # Cancel the rule to compile %.c straight to %, it interferes with
207 # automatic dependency generation
208 %: %.c
209
210 # Work around MinGW Make's broken built-in link rule:
211 %$(EXEEXT): %.o
212         $(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -o $@
213
214
215 info.nr/%: info/%.t
216         $(NROFF) -I $(srcdir)/info $(filter %/CRT.MAC, $^) $< | $(AWK) -f $(filter %/Blank.awk, $^) >$@
217 # FIXME AT&T nroff doesn't grok -I
218
219 info.html/%.html: info/%.t
220         perl $(filter %.pl, $^) $< >$@
221
222
223 ### Explicit rules
224
225 # Compilation
226
227 $(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)
228         $(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -o $@
229
230 $(client): $(filter src/client/%, $(obj)) $(termlibs)
231         $(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -o $@
232
233 $(util): $(libs)
234
235 lib/libcommon.a: $(filter src/lib/common/%, $(obj))
236 lib/libgen.a: $(filter src/lib/gen/%, $(obj))
237 lib/libglobal.a: $(filter src/lib/global/%, $(obj))
238 lib/liblwp.a: $(filter src/lib/lwp/%, $(obj))
239
240 $(libs) $(empth_lib): | lib
241         $(AR) rc $@ $?
242         $(RANLIB) $@
243
244 # Info formatting
245
246 subjects.mk: $(tsrc) info/findsubj.pl sources.mk
247         perl $(srcdir)/info/findsubj.pl
248 # If sources.mk is out of date, $(tsrc) is.  If it contains files that
249 # went away, make can't remake subjects.mk.  Tell it to ignore such
250 # missing files:
251 $(tsrc):
252
253 $(tsubj): info/mksubj.pl
254         perl $(srcdir)/info/mksubj.pl $@ $(filter %.t, $^)
255
256 $(ttop): $(tsubj)
257         perl $(srcdir)/info/mktop.pl $@ $(filter %.t, $^)
258
259 info.nr/all: $(filter-out info.nr/all, $(info.nr))
260         (cd info.nr && ls -CF) >$@
261 # FIXME should use $^ and not ls
262
263 info.html/all.html: $(filter-out info.html/all.html, $(info.html)) info/ls2html.pl
264         (cd info.html && ls -CF *.html) | expand | perl $(filter %.pl, $^) >$@
265 # FIXME should use $^ and not ls
266
267 $(info.nr): info/CRT.MAC info/INFO.MAC info/Blank.awk | info.nr
268
269 $(subjects.html) info.html/TOP.html: info/subj2html.pl | info.html
270 $(topics.html): info/emp2html.pl | info.html
271
272 info.nr info.html lib:
273         mkdir -p $@
274
275 ifeq ($(cvs_controlled),yes)
276 # Find files and directories under CVS control
277 sources.mk: $(scripts)/cvsfiles.awk $(addprefix $(srcdir)/, $(addsuffix CVS/Entries, $(dirs)))
278         echo 'src := ' `cd $(srcdir) && $(AWK) -f src/scripts/cvsfiles.awk` >$@
279 endif
280
281
282 .PHONY: dist-source
283 dist-source: check-version $(src_distgen) $(bld_distgen)
284         $(tarball) $(TARNAME)-$(VERSION) $(bld_distgen) -C $(srcdir) $(src_distgen) $(src)
285
286 .PHONY: dist-client
287 dist-client: $(cli_distgen)
288         $(tarball) $(TARNAME)-client-$(VERSION)                         \
289         -C $(srcdir)/src/client                                         \
290                 $(notdir $(filter src/client/%, $(src)) $(cli_distgen)) \
291         -C $(srcdir)/include proto.h                                    \
292         -C $(srcdir)/man empire.6                                       \
293         -C $(srcdir) COPYING INSTALL install-sh
294
295 .PHONY: dist-info
296 dist-info: info html
297         $(tarball) $(TARNAME)-info-text-$(VERSION) -C info.nr $(info)
298         $(tarball) $(TARNAME)-info-html-$(VERSION) -C info.html $(addsuffix .html, $(info))
299
300 check-version:
301         if [ $(VERSION) != `sed -n '/EMP_VERS_/s/#define EMP_VERS_\([A-Z]*\)[ \t]*//p' <$(srcdir)/include/version.h | tr '\012' . | sed 's/\.$$//'` ]; \
302         then echo version.h does not match configure.ac >&2; false; \
303         fi
304
305 ifneq ($(deps),)
306 -include $(deps)
307 endif
308
309
310 # Automatic remake of configuration
311 # See (autoconf)Automatic Remaking.
312 # This requires sufficiently recent versions of autoconf and automake
313
314 $(srcdir)/configure: configure.ac aclocal.m4
315         cd $(srcdir) && autoconf
316
317 # autoheader might not change config.h.in, so touch a stamp file.
318 $(srcdir)/config.h.in: stamp-h.in
319 $(srcdir)/stamp-h.in: configure.ac aclocal.m4
320         cd $(srcdir) && autoheader
321         >$@
322
323 $(srcdir)/aclocal.m4: $(filter m4/%.m4, $(src))
324         cd $(srcdir) && aclocal -I m4
325
326 # config.status might not change config.h; use the stamp file.
327 config.h: stamp-h
328 stamp-h: config.h.in config.status
329         ./config.status config.h stamp-h
330
331 GNUmakefile: GNUmakefile.in config.status
332         ./config.status $@
333
334 config.status: configure
335         ./config.status --recheck
336
337 src/lib/global/path.c src/client/ipglob.c: %: %.in GNUmakefile
338         $(subst.in) <$< >$@
339
340
341 # Make files for standalone client distribution
342
343 $(srcdir)/src/client/configure: src/client/configure.ac src/client/aclocal.m4
344         cd $(dir $@) && autoconf
345
346 $(srcdir)/src/client/config.h.in: src/client/configure.ac src/client/aclocal.m4
347         cd $(dir $@) && autoheader
348         touch $@
349
350 $(srcdir)/src/client/aclocal.m4: m4/lib_socket_nsl.m4
351         cp -f $< $@