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