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