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