build: Rename DEBUG_CPPFLAGS to STRICT_CFLAGS.
[paraslash.git] / Makefile.real
1 VARDIR := /var/paraslash
2 MANDIR := $(datarootdir)/man/man1
3 STRIP := $(CROSS_COMPILE)strip
4 HOSTCC ?= cc
5 MKDIR_P := mkdir -p
6 prefixed_executables := $(addprefix para_, $(executables))
7
8 build_date := $(shell date)
9 uname_s := $(shell uname -s 2>/dev/null || echo "UNKNOWN_OS")
10 uname_rs := $(shell uname -rs)
11 cc_version := $(shell $(CC) --version | head -n 1)
12 GIT_VERSION := $(shell ./GIT-VERSION-GEN git-version.h)
13
14 ifeq ("$(origin O)", "command line")
15 build_dir := $(O)
16 else
17 build_dir := build
18 endif
19 ggo_dir := $(build_dir)/ggo
20 object_dir := $(build_dir)/objects
21 dep_dir := $(build_dir)/deps
22 man_dir := $(build_dir)/man/man1
23 cmdline_dir := $(build_dir)/cmdline
24 m4depdir := $(build_dir)/m4deps
25 help2man_dir := $(build_dir)/help2man
26 hostbin_dir := $(build_dir)/host/bin
27 m4_ggo_dir := m4/gengetopt
28 test_dir := t
29
30 # sort removes duplicate words, which is all we need here
31 all_objs := $(sort $(recv_objs) $(filter_objs) $(client_objs) $(gui_objs) \
32 $(audiod_objs) $(audioc_objs) $(fade_objs) $(server_objs) \
33 $(write_objs) $(afh_objs) $(play_objs))
34 deps := $(addprefix $(dep_dir)/, $(all_objs:.o=.d))
35 m4_deps := $(addprefix $(m4depdir)/, $(addsuffix .m4d, $(executables)))
36
37 # now prefix all objects with object dir
38 recv_objs := $(addprefix $(object_dir)/, $(recv_objs))
39 filter_objs := $(addprefix $(object_dir)/, $(filter_objs))
40 client_objs := $(addprefix $(object_dir)/, $(client_objs))
41 gui_objs := $(addprefix $(object_dir)/, $(gui_objs))
42 audiod_objs := $(addprefix $(object_dir)/, $(audiod_objs))
43 audioc_objs := $(addprefix $(object_dir)/, $(audioc_objs))
44 fade_objs := $(addprefix $(object_dir)/, $(fade_objs))
45 server_objs := $(addprefix $(object_dir)/, $(server_objs))
46 write_objs := $(addprefix $(object_dir)/, $(write_objs))
47 afh_objs := $(addprefix $(object_dir)/, $(afh_objs))
48 play_objs := $(addprefix $(object_dir)/, $(play_objs))
49
50 man_pages := $(patsubst %, $(man_dir)/%.1, $(prefixed_executables))
51
52 autocrap := config.h.in configure
53 tarball_pfx := $(PACKAGE_TARNAME)-$(PACKAGE_VERSION)
54 tarball_delete := $(addprefix $(tarball_pfx)/, web .gitignore)
55 tarball := $(tarball_pfx).tar.bz2
56
57 .PHONY: dep all clean clean2 distclean maintainer-clean install man tarball
58 all: dep $(prefixed_executables) $(man_pages)
59 dep: $(deps)
60 man: $(man_pages)
61 tarball: $(tarball)
62
63 include $(m4_ggo_dir)/makefile
64 include $(test_dir)/makefile.test
65 ifeq ($(findstring clean, $(MAKECMDGOALS)),)
66 -include $(deps)
67 -include $(m4_deps)
68 endif
69
70 $(object_dir) $(man_dir) $(ggo_dir) $(cmdline_dir) $(dep_dir) $(m4depdir) \
71 $(help2man_dir) $(hostbin_dir):
72 $(Q) $(MKDIR_P) $@
73
74 # When in doubt, use brute force (Ken Thompson)
75 TOUPPER = \
76 $(subst a,A,$(subst b,B,$(subst c,C,$(subst d,D,$(subst e,E,\
77 $(subst f,F,$(subst g,G,$(subst h,H,$(subst i,I,$(subst j,J,\
78 $(subst k,K,$(subst l,L,$(subst m,M,$(subst n,N,$(subst o,O,\
79 $(subst p,P,$(subst q,Q,$(subst r,R,$(subst s,S,$(subst t,T,\
80 $(subst u,U,$(subst v,V,$(subst w,W,$(subst x,X,$(subst y,Y,\
81 $(subst z,Z,$1))))))))))))))))))))))))))
82
83 STRICT_CFLAGS += -g -Wunused -Wundef -W
84 STRICT_CFLAGS += -Wredundant-decls
85 STRICT_CFLAGS += -Wall -Wno-sign-compare -Wno-unknown-pragmas
86 STRICT_CFLAGS += -Wformat-security
87 STRICT_CFLAGS += -Wmissing-format-attribute
88
89 ifeq ($(uname_s),Linux)
90 CPPFLAGS += -fdata-sections -ffunction-sections
91 LDFLAGS += -Wl,--gc-sections
92 CPPFLAGS += -Wstrict-prototypes
93 CPPFLAGS += -Wshadow
94 # causes warnings on *BSD for the feature test macros
95 CPPFLAGS += -Wunused-macros
96 endif
97 CPPFLAGS += -Os
98 CPPFLAGS += -Wuninitialized
99 CPPFLAGS += -Wchar-subscripts
100 CPPFLAGS += -DBINDIR='"$(BINDIR)"'
101 CPPFLAGS += -DBUILD_DATE='"$(build_date)"'
102 CPPFLAGS += -DUNAME_RS='"$(uname_rs)"'
103 CPPFLAGS += -DCC_VERSION='"$(cc_version)"'
104 CPPFLAGS += -Werror-implicit-function-declaration
105 CPPFLAGS += -Wmissing-noreturn
106 CPPFLAGS += -Wbad-function-cast
107 CPPFLAGS += -fno-strict-aliasing
108 CPPFLAGS += -DMAIN_INPUT_FILE_IS_$(*F)
109 CPPFLAGS += $(arch_cppflags)
110 CPPFLAGS += -I/usr/local/include
111 CPPFLAGS += -I$(cmdline_dir)
112
113 LDFLAGS += $(clock_gettime_ldflags)
114
115 # To put more focus on warnings, be less verbose as default
116 # Use 'make V=1' to see the full commands
117 ifeq ("$(origin V)", "command line")
118 Q :=
119 else
120 Q := @
121 endif
122
123 %_command_list.h: %.cmd %.c
124 @[ -z "$(Q)" ] || echo 'GEN $@'
125 $(Q) ./command_util.bash h < $< >$@
126 %_command_list.man: %.cmd %.c
127 @[ -z "$(Q)" ] || echo 'GEN $@'
128 $(Q) ./command_util.bash man < $< > $@
129 %_completion.h: %.cmd %.c
130 @[ -z "$(Q)" ] || echo 'GEN $@'
131 $(Q) ./command_util.bash compl $(strip $(call TOUPPER,$(*F)))_COMPLETERS \
132 $(strip $(call TOUPPER,$(*F)))_COMMANDS < $< > $@
133
134 server_command_list.h server_command_list.man server_completion.h: command.c
135 afs_command_list.h afs_command_list.man afs_completion.h: afs.c aft.c attribute.c
136 audiod_command_list.h audiod_command_list.man audiod_completion.h: audiod_command.c
137
138 server_command_lists := server_command_list.man afs_command_list.man
139 audiod_command_lists := audiod_command_list.man
140 play_command_lists := play_command_list.man
141
142 $(man_dir)/para_server.1: $(server_command_lists)
143 $(man_dir)/para_audiod.1: $(audiod_command_lists)
144 $(man_dir)/para_play.1: $(play_command_lists)
145
146 $(man_dir)/para_server.1: man_util_command_lists := $(server_command_lists)
147 $(man_dir)/para_audiod.1: man_util_command_lists := $(audiod_command_lists)
148 $(man_dir)/para_play.1: man_util_command_lists := $(play_command_lists)
149
150 $(man_dir)/para_%.1: $(ggo_dir)/%.ggo man_util.bash | $(man_dir) $(help2man_dir)
151 @[ -z "$(Q)" ] || echo 'MAN $<'
152 $(Q) \
153 COMMAND_LISTS="$(man_util_command_lists)" \
154 FILTERS="$(filters)" \
155 GENGETOPT=$(GENGETOPT) \
156 GGO_DIR=$(ggo_dir) \
157 HELP2MAN=$(HELP2MAN) \
158 HELP2MAN_DIR=$(help2man_dir) \
159 RECEIVERS="$(receivers)" \
160 VERSION="$(GIT_VERSION)" \
161 WRITERS="$(writers)" \
162 ./man_util.bash $@
163
164 $(hostbin_dir)/error2: error2.c | $(hostbin_dir)
165 @[ -z "$(Q)" ] || echo 'HCC $<'
166 $(Q) $(HOSTCC) -o $@ $<
167 error2.h: $(hostbin_dir)/error2 Makefile
168 @[ -z "$(Q)" ] || echo 'ER2 $<'
169 @echo "$(object_executable_matrix)" | $< > $@
170
171 $(object_dir)/%.o: %.c | $(object_dir)
172 $(object_dir)/opus%.o $(dep_dir)/opus%.d: CPPFLAGS += $(opus_cppflags)
173 $(object_dir)/gui%.o $(dep_dir)/gui%.d: CPPFLAGS += $(curses_cppflags)
174 $(object_dir)/spx%.o $(dep_dir)/spx%.d: CPPFLAGS += $(speex_cppflags)
175 $(object_dir)/%.cmdline.o: CPPFLAGS += -Wno-unused-function
176
177 $(object_dir)/mp3_afh.o $(dep_dir)/mp3_afh.d: CPPFLAGS += $(id3tag_cppflags)
178 $(object_dir)/crypt.o $(dep_dir)/crypt.d: CPPFLAGS += $(openssl_cppflags)
179 $(object_dir)/gcrypt.o $(dep_dir)/gcrypt.d: CPPFLAGS += $(gcrypt_cppflags)
180
181 $(object_dir)/mp3dec_filter.o $(dep_dir)/mp3dec_filter.d \
182 : CPPFLAGS += $(mad_cppflags)
183
184 $(object_dir)/compress_filter.o: CPPFLAGS += -O3
185 $(object_dir)/ao_write.o $(dep_dir)/ao_write.d: CPPFLAGS += $(ao_cppflags)
186
187 $(object_dir)/aacdec_filter.o $(dep_dir)/aacdec_filter.d \
188 $(object_dir)/aac_common.o $(dep_dir)/aac_common.d \
189 $(object_dir)/aac_afh.o $(dep_dir)/aac_afh.d \
190 : CPPFLAGS += $(faad_cppflags)
191
192 $(object_dir)/ogg_afh.o $(dep_dir)/ogg_afh.d \
193 $(object_dir)/oggdec_filter.o $(dep_dir)/oggdec_filter.d \
194 : CPPFLAGS += $(vorbis_cppflags)
195
196 $(object_dir)/spx_common.o $(dep_dir)/spx_common.d \
197 $(object_dir)/spxdec_filter.o $(dep_dir)/spxdec_filter.d \
198 $(object_dir)/spx_afh.o $(dep_dir)/spx_afh.d \
199 $(object_dir)/oggdec_filter.o $(dep_dir)/oggdec_filter.d \
200 $(object_dir)/ogg_afh.o $(dep_dir)/ogg_afh.d \
201 $(object_dir)/ogg_afh_common.o $(dep_dir)/ogg_afh_common.d \
202 $(object_dir)/opus%.o $(dep_dir)/opus%.d \
203 : CPPFLAGS += $(ogg_cppflags)
204
205 $(object_dir)/afs.o $(dep_dir)/afs.d \
206 $(object_dir)/aft.o $(dep_dir)/aft.d \
207 $(object_dir)/attribute.o $(dep_dir)/attribute.d \
208 $(object_dir)/blob.o $(dep_dir)/blob.d \
209 $(object_dir)/mood.o $(dep_dir)/mood.d \
210 $(object_dir)/playlist.o $(dep_dir)/playlist.d \
211 $(object_dir)/score.o $(dep_dir)/score.d \
212 $(object_dir)/server.o $(dep_dir)/server.d \
213 $(object_dir)/vss.o $(dep_dir)/vss.d \
214 $(object_dir)/command.o $(dep_dir)/command.d \
215 $(object_dir)/http_send.o $(dep_dir)/http_send.d \
216 $(object_dir)/dccp_send.o $(dep_dir)/dccp_send.d \
217 $(object_dir)/udp_send.o $(dep_dir)/udp_send.d \
218 $(object_dir)/send_common.o $(dep_dir)/send_common.d \
219 $(object_dir)/mm.o $(dep_dir)/mm.d \
220 : CPPFLAGS += $(osl_cppflags)
221
222 $(object_dir)/%.o: %.c | $(object_dir)
223 @[ -z "$(Q)" ] || echo 'CC $<'
224 $(Q) $(CC) -c -o $@ $(CPPFLAGS) $(STRICT_CFLAGS) $<
225
226 $(object_dir)/%.cmdline.o: $(cmdline_dir)/%.cmdline.c $(cmdline_dir)/%.cmdline.h | $(object_dir)
227 @[ -z "$(Q)" ] || echo 'CC $<'
228 $(Q) $(CC) -c -o $@ $(CPPFLAGS) $<
229
230 $(dep_dir)/%.cmdline.d: $(cmdline_dir)/%.cmdline.c error2.h | $(dep_dir)
231 @[ -z "$(Q)" ] || echo 'DEP $<'
232 $(Q) ./depend.sh $(dep_dir) $(object_dir) $(cmdline_dir) \
233 $(CPPFLAGS) $< > $@
234
235 $(dep_dir)/%.d: %.c error2.h | $(dep_dir)
236 @[ -z "$(Q)" ] || echo 'DEP $<'
237 $(Q) ./depend.sh $(dep_dir) $(object_dir) $(cmdline_dir) \
238 $(CPPFLAGS) $< > $@
239
240 para_recv para_afh para_play para_server: LDFLAGS += $(id3tag_ldflags)
241 para_write para_play para_audiod: LDFLAGS += $(ao_ldflags) $(core_audio_ldflags)
242 para_client para_audioc para_play : LDFLAGS += $(readline_ldflags)
243 para_server: LDFLAGS += $(osl_ldflags)
244 para_gui: LDFLAGS += $(curses_ldflags)
245 para_server \
246 para_client \
247 para_audiod \
248 :LDFLAGS += \
249 $(openssl_ldflags) \
250 $(gcrypt_ldflags)
251
252 para_audiod \
253 para_filter \
254 para_play \
255 : LDFLAGS += \
256 $(mad_ldflags) \
257 $(samplerate_ldflags) \
258 -lm
259
260 para_write \
261 para_play \
262 para_audiod \
263 para_fade \
264 : LDFLAGS += \
265 $(oss_ldflags) \
266 $(alsa_ldflags)
267
268 para_server \
269 para_filter \
270 para_audiod \
271 para_play \
272 para_afh \
273 para_recv \
274 : LDFLAGS += \
275 $(ogg_ldflags) \
276 $(vorbis_ldflags) \
277 $(speex_ldflags) \
278 $(opus_ldflags) \
279 $(faad_ldflags) \
280 $(flac_ldflags)
281
282 para_server \
283 para_client \
284 para_audioc \
285 para_audiod \
286 para_recv \
287 : LDFLAGS += \
288 $(socket_ldflags) $(nsl_ldflags)
289
290 $(foreach exe,$(executables),$(eval para_$(exe): $$($(exe)_objs)))
291 $(prefixed_executables):
292 @[ -z "$(Q)" ] || echo 'LD $@'
293 $(Q) $(CC) $^ -o $@ $(LDFLAGS)
294
295 clean:
296 @[ -z "$(Q)" ] || echo 'CLEAN'
297 $(Q) rm -f $(prefixed_executables)
298 $(Q) rm -rf $(object_dir)
299
300 clean2: clean
301 @[ -z "$(Q)" ] || echo 'CLEAN2'
302 $(Q) rm -f *_command_list.* *_completion.h
303 $(Q) rm -rf $(build_dir)
304 distclean: clean2 test-clean
305 @[ -z "$(Q)" ] || echo 'DISTCLEAN'
306 $(Q) rm -f Makefile autoscan.log config.status config.log error2.h
307 $(Q) rm -rf autom4te.cache
308 $(Q) rm -f GPATH GRTAGS GSYMS GTAGS
309
310 maintainer-clean: distclean
311 rm -f *.tar.bz2 config.h configure config.h.in
312 rm -rf web_sync
313
314 install: all man
315 $(MKDIR_P) $(BINDIR) $(MANDIR)
316 $(INSTALL) -s --strip-program $(STRIP) -m 755 \
317 $(prefixed_executables) $(BINDIR)
318 $(INSTALL) -m 644 $(man_pages) $(MANDIR)
319 $(MKDIR_P) $(VARDIR) >/dev/null 2>&1 || true # not fatal, so don't complain
320
321 $(tarball):
322 $(Q) rm -rf $(tarball) $(tarball_pfx)
323 $(Q) git archive --format=tar --prefix=$(tarball_pfx)/ HEAD \
324 | tar --delete $(tarball_delete) > $(tarball_pfx).tar
325 $(Q) $(MKDIR_P) $(tarball_pfx)
326 $(Q) ./GIT-VERSION-GEN > $(tarball_pfx)/VERSION
327 $(Q) cp $(autocrap) $(tarball_pfx)
328 $(Q) tar rf $(tarball_pfx).tar $(tarball_pfx)/*
329 $(Q) bzip2 -9 $(tarball_pfx).tar
330 $(Q) ls -l $(tarball)
331 $(Q) rm -rf $(tarball_pfx)