]> git.pond.sub.org Git - empserver/blob - Make.mk
Fix the previous revision.
[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
51 # Info topics and subjects
52 -include subjects.mk
53 topics := $(patsubst %.t,%,$(notdir $(tsrc)))
54 info := $(topics) $(subjects) all
55
56 # Generated files
57 mk := sources.mk subjects.mk
58 ac := autom4te.cache config.h config.status config.log stamp-h  \
59 $(basename $(filter %.in, $(src)))
60 obj := $(csrc:.c=.o) $(filter %.o, $(ac:.c=.o))
61 # TODO AIX needs lwpInit.o lwpRestore.o lwpSave.o unless UCONTEXT
62 deps := $(obj:.o=.d)
63 libs := $(addprefix lib/, libcommon.a libgen.a libglobal.a)
64 util := $(addprefix src/util/, fairland files pconfig)
65 progs := $(util) src/client/empire src/server/emp_server
66 tsubj := $(addprefix info/, $(addsuffix .t, $(subjects)))
67 ttop := info/TOP.t
68 info.nr := $(addprefix info.nr/, $(info))
69 subjects.html := $(addprefix info.html/, $(addsuffix .html, $(subjects)))
70 topics.html := $(addprefix info.html/, $(addsuffix .html, $(topics)))
71 info.html := $(addprefix info.html/, $(addsuffix .html, $(info)))
72
73 ifeq ($(empthread),POSIX)
74 empth_obj := src/lib/empthread/pthread.o
75 empth_lib :=
76 else
77 empth_obj := src/lib/empthread/lwp.o
78 empth_lib := lib/liblwp.a
79 endif
80
81 # Abbreviations
82 scripts = $(srcdir)/src/scripts
83 clean := $(obj) $(deps) $(libs) $(progs) $(empth_lib) $(tsubj)  \
84 $(info.nr) $(info.html)
85 distclean := $(ac) info/stamp $(ttop)
86
87 # Compiler flags
88 CPPFLAGS += -I$(srcdir)/include -Iinclude
89 ifeq ($(have_gcc),yes)
90 CFLAGS += -fno-common
91 CFLAGS += -Wall -W -Wno-unused -Wpointer-arith -Wstrict-prototypes      \
92 -Wmissing-prototypes -Wnested-externs -Wredundant-decls
93 endif
94 LDLIBS += -lm
95
96 ### Advertized goals
97
98 .PHONY: all
99 all: $(progs) info
100
101 .PHONY: info html
102 info: $(info.nr)
103 html: $(info.html)
104
105 .PHONY: clean
106 clean:
107         rm -f $(clean)
108
109 .PHONY: distclean
110 distclean: clean
111         rm -rf $(distclean)
112
113 .PHONY: install install-html
114 install: all
115         false # FIXME
116 install-html: html
117         false # FIXME
118
119 .PHONY: uninstall
120 uninstall:
121         false # FIXME
122
123 .PHONY: dist
124 dist:
125         false # FIXME
126
127
128 ### Implicit rules
129
130 # Compile with dependencies as side effect, i.e. create %.d in
131 # addition to %.o.
132 ifeq ($(how_to_dep),fast)
133 %.o: %.c
134         $(COMPILE.c) -MT $@ -MMD -MP $(OUTPUT_OPTION) $<
135 endif
136 ifeq ($(how_to_dep),depcomp)
137 %.o: %.c
138         source='$<' object='$@' depfile='$(@:.o=.d)' $(CCDEPMODE) $(depcomp) \
139         $(COMPILE.c) $(OUTPUT_OPTION) $<
140 endif
141 # Cancel the rule to compile %.c straight to %, it interferes with
142 # automatic dependency generation
143 %: %.c
144
145 info.nr/%: info/%.t
146         $(NROFF) -I $(srcdir)/info $(filter %/CRT.MAC, $^) $< | $(AWK) -f $(filter %/Blank.awk, $^) >$@
147 # FIXME AT&T nroff doesn't grok -I
148
149 info.html/%.html: info/%.t
150         perl $(filter %.pl, $^) $< >$@
151
152
153 ### Explicit rules
154
155 src/server/emp_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)
156         $(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -o $@
157
158 src/client/empire: $(filter src/client/%, $(obj)) $(termlibs)
159         $(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -o $@
160
161 $(util): $(libs)
162
163 lib/libcommon.a: $(filter src/lib/common/%, $(obj))
164 lib/libgen.a: $(filter src/lib/gen/%, $(obj))
165 lib/libglobal.a: $(filter src/lib/global/%, $(obj))
166 lib/liblwp.a: $(filter src/lib/lwp/%, $(obj))
167
168 $(libs) $(empth_lib): | lib
169         $(AR) rc $@ $?
170         $(RANLIB) $@
171
172 # info.pl reads $(tsrc) and writes subjects.mk $(ttop) $(tsubj).  The
173 # naive rule
174 #     subjects.mk $(ttop) $(tsubj): $(tsrc)
175 #           COMMAND
176 # runs COMMAND once for each target.  That's because multiple targets
177 # in an explicit rule is just a shorthand for one rule per target,
178 # each with the same prerequisites and commands.  A pattern rule with
179 # multiple targets does what we want.  So we artificially turn the
180 # explicit rule into a pattern rule: we replace info with %, and
181 # insert a touch target info/stamp.
182 $(patsubst info/%, \%/%, $(ttop) $(tsubj)): %/stamp
183         perl $(srcdir)/info/info.pl
184 info/stamp: $(tsrc) info/info.pl sources.mk
185         >$@
186 subjects.mk: $(ttop)
187         :
188
189 info.nr/all: $(filter-out info.nr/all, $(info.nr))
190         (cd info.nr && ls -CF) >$@
191 # FIXME should use $^ and not ls
192
193 info.html/all.html: $(filter-out info.html/all.html, $(info.html)) info/ls2html.pl
194         (cd info.html && ls -CF *.html) | expand | perl $(filter %.pl, $^) >$@
195 # FIXME should use $^ and not ls
196
197 $(info.nr): info/CRT.MAC info/INFO.MAC info/Blank.awk | info.nr
198
199 $(subjects.html): info/subj2html.pl | info.html
200 $(topics.html): info/emp2html.pl | info.html
201
202 info.nr info.html lib:
203         mkdir -p $@
204
205 ifeq ($(cvs_controlled),yes)
206 # Find files and directories under CVS control
207 sources.mk: $(scripts)/cvsfiles.awk $(addprefix $(srcdir)/, $(addsuffix CVS/Entries, $(dirs)))
208         echo 'src := ' `cd $(srcdir) && $(AWK) -f src/scripts/cvsfiles.awk` >$@
209 endif
210
211 ifneq ($(deps),)
212 -include $(deps)
213 endif
214
215 # Automatic remake of configuration
216 # See (autoconf)Automatic Remaking.
217 # This requires sufficiently recent versions of autoconf and automake
218
219 $(srcdir)/configure: configure.ac aclocal.m4
220         cd $(srcdir) && autoconf
221
222 # autoheader might not change config.h.in, so touch a stamp file.
223 $(srcdir)/config.h.in: stamp-h.in
224 $(srcdir)/stamp-h.in: configure.ac aclocal.m4
225         cd $(srcdir) && autoheader
226         >$@
227
228 $(srcdir)/aclocal.m4: $(filter m4/%.m4, $(src))
229         cd $(srcdir) && aclocal -I m4
230
231 # config.status might not change config.h; use the stamp file.
232 config.h: stamp-h
233 stamp-h: config.h.in config.status
234         ./config.status config.h stamp-h
235
236 GNUmakefile: GNUmakefile.in config.status
237         ./config.status $@
238
239 config.status: configure
240         ./config.status --recheck
241
242 src/lib/global/path.c src/client/ipglob.c: %: %.in GNUmakefile
243         $(subst.in) <$< >$@