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