]> git.pond.sub.org Git - empserver/blob - Make.mk
Update copyright notice.
[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 # Delete target on error.  Every Makefile should have this.
43 .DELETE_ON_ERROR:
44
45 # Source files
46 -include sources.mk
47 dirs := $(sort $(dir $(src)))
48 csrc := $(filter %.c, $(src))
49 tsrc := $(filter %.t, $(src))
50 man1 := $(filter man/%.1, $(src))
51 man6 := $(filter man/%.6, $(src))
52
53 # Info topics and subjects
54 -include subjects.mk
55 topics := $(patsubst %.t,%,$(notdir $(tsrc)))
56 info := $(topics) $(subjects) all TOP
57
58 # Generated files
59 mk := sources.mk subjects.mk
60 ac := autom4te.cache config.h config.status config.log stamp-h  \
61 $(basename $(filter %.in, $(src)))
62 obj := $(csrc:.c=.o) $(filter %.o, $(ac:.c=.o))
63 # TODO AIX needs lwpInit.o lwpRestore.o lwpSave.o unless UCONTEXT
64 deps := $(obj:.o=.d)
65 libs := $(addprefix lib/, libcommon.a libgen.a libglobal.a)
66 util := $(addprefix src/util/, fairland files pconfig)
67 client := src/client/empire
68 server := src/server/emp_server
69 progs := $(util) $(client) $(server)
70 tsubj := $(addprefix info/, $(addsuffix .t, $(subjects)))
71 ttop := info/TOP.t
72 info.nr := $(addprefix info.nr/, $(info))
73 subjects.html := $(addprefix info.html/, $(addsuffix .html, $(subjects)))
74 topics.html := $(addprefix info.html/, $(addsuffix .html, $(topics)))
75 info.html := $(addprefix info.html/, $(addsuffix .html, $(info)))
76
77 ifeq ($(empthread),LWP)
78 empth_obj := src/lib/empthread/lwp.o
79 empth_lib := lib/liblwp.a
80 endif
81 ifeq ($(empthread),POSIX)
82 empth_obj := src/lib/empthread/pthread.o
83 empth_lib :=
84 endif
85 ifeq ($(empthread),Windows)
86 empth_obj := src/lib/empthread/ntthread.o
87 empth_lib :=
88 endif
89
90 # Abbreviations
91 scripts = $(srcdir)/src/scripts
92 depcomp = $(SHELL) $(srcdir)/depcomp
93 clean := $(obj) $(deps) $(libs) $(progs) $(empth_lib) $(tsubj)  \
94 $(info.nr) $(info.html)
95 distclean := $(ac) info/stamp $(ttop)
96 econfig := $(sysconfdir)/empire/econfig
97 edatadir := $(localstatedir)/empire
98 einfodir := $(datadir)/empire/info.nr
99 ehtmldir := $(datadir)/empire/info.html
100 # Recursively expanded so that $@ and $< work.
101 subst.in = sed \
102         -e 's?@configure_input\@?$(notdir $@).  Generated from $(notdir $<) by GNUmakefile.?g' \
103         -e 's?@econfig\@?$(econfig)?g' \
104         -e 's?@edatadir\@?$(edatadir)?g' \
105         -e 's?@einfodir\@?$(einfodir)?g' \
106         -e 's/@EMPIREHOST\@/$(EMPIREHOST)/g' \
107         -e 's/@EMPIREPORT\@/$(EMPIREPORT)/g'
108
109 # Compiler flags
110 CPPFLAGS += -I$(srcdir)/include -I.
111 ifeq ($(have_gcc),yes)
112 CFLAGS += -fno-common
113 CFLAGS += -Wall -W -Wno-unused -Wpointer-arith -Wstrict-prototypes      \
114 -Wmissing-prototypes -Wnested-externs -Wredundant-decls
115 endif
116 LDLIBS += -lm
117
118 ### Advertized goals
119
120 .PHONY: all
121 all: $(progs) info
122
123 .PHONY: info html
124 info: $(info.nr)
125 html: $(info.html)
126
127 .PHONY: clean
128 clean:
129         rm -f $(clean)
130
131 .PHONY: distclean
132 distclean: clean
133         rm -rf $(distclean)
134
135 .PHONY: install
136 install: all installdirs
137         $(INSTALL_PROGRAM) $(util) $(server) $(sbindir)
138         $(INSTALL_PROGRAM) $(client) $(bindir)
139         $(INSTALL_DATA) $(info.nr) $(einfodir)
140         $(INSTALL_DATA) $(addprefix $(srcdir)/, $(man1)) $(mandir)/man1
141         $(INSTALL_DATA) $(addprefix $(srcdir)/, $(man6)) $(mandir)/man6
142         if test -e $(econfig); then                                     \
143             if src/util/pconfig $(econfig) >$(econfig).new; then        \
144                 if cmp -s $(econfig) $(econfig).new; then               \
145                     rm $(econfig).new;                                  \
146                 else                                                    \
147                     echo "Check out $(econfig).new";                    \
148                 fi                                                      \
149             else                                                        \
150                 echo "Your $(econfig) doesn't work";                    \
151             fi                                                          \
152         else                                                            \
153             src/util/pconfig >$(econfig);                               \
154         fi
155
156 .PHONY: installdirs
157 installdirs:
158         mkdir -p $(bindir) $(sbindir) $(edatadir) $(einfodir) $(mandir)/man1 $(mandir)/man6 $(dir $(econfig))
159
160 .PHONY: install-html
161 install-html: html | $(ehtmldir)
162         $(INSTALL_DATA) $(info.html) $(ehtmldir)
163
164 .PHONY: uninstall
165 uninstall:
166         false # FIXME
167
168 .PHONY: dist
169 dist:
170         false # FIXME
171
172
173 ### Implicit rules
174
175 # Compile with dependencies as side effect, i.e. create %.d in
176 # addition to %.o.
177 ifeq ($(how_to_dep),fast)
178 %.o: %.c
179         $(COMPILE.c) -MT $@ -MMD -MP $(OUTPUT_OPTION) $<
180 endif
181 ifeq ($(how_to_dep),depcomp)
182 %.o: %.c
183         source='$<' object='$@' depfile='$(@:.o=.d)' $(CCDEPMODE) $(depcomp) \
184         $(COMPILE.c) $(OUTPUT_OPTION) $<
185 endif
186 # Cancel the rule to compile %.c straight to %, it interferes with
187 # automatic dependency generation
188 %: %.c
189
190 info.nr/%: info/%.t
191         $(NROFF) -I $(srcdir)/info $(filter %/CRT.MAC, $^) $< | $(AWK) -f $(filter %/Blank.awk, $^) >$@
192 # FIXME AT&T nroff doesn't grok -I
193
194 info.html/%.html: info/%.t
195         perl $(filter %.pl, $^) $< >$@
196
197
198 ### Explicit rules
199
200 $(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)
201         $(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -o $@
202
203 $(client): $(filter src/client/%, $(obj)) $(termlibs)
204         $(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -o $@
205
206 $(util): $(libs)
207
208 lib/libcommon.a: $(filter src/lib/common/%, $(obj))
209 lib/libgen.a: $(filter src/lib/gen/%, $(obj))
210 lib/libglobal.a: $(filter src/lib/global/%, $(obj))
211 lib/liblwp.a: $(filter src/lib/lwp/%, $(obj))
212
213 $(libs) $(empth_lib): | lib
214         $(AR) rc $@ $?
215         $(RANLIB) $@
216
217 # info.pl reads $(tsrc) and writes subjects.mk $(ttop) $(tsubj).  The
218 # naive rule
219 #     subjects.mk $(ttop) $(tsubj): $(tsrc)
220 #           COMMAND
221 # runs COMMAND once for each target.  That's because multiple targets
222 # in an explicit rule is just a shorthand for one rule per target,
223 # each with the same prerequisites and commands.  A pattern rule with
224 # multiple targets does what we want.  So we artificially turn the
225 # explicit rule into a pattern rule: we replace info with %, and
226 # insert a touch target info/stamp.
227 # FIXME if sources.mk is out-of-date, $(tsubj) is, and the bogus deps can prevent remaking of subjects.mk and thus sources.mk
228 $(patsubst info/%, \%/%, $(ttop) $(tsubj)): %/stamp
229         perl $(srcdir)/info/info.pl
230 info/stamp: $(tsrc) info/info.pl sources.mk
231         >$@
232 subjects.mk: $(ttop)
233         :
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/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) <$< >$@