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