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