Convert receivers to lopsub.
[paraslash.git] / Makefile.real
1 # Implicit rules are implemented in make as suffix rules. The following rule
2 # empties the suffix list to disable the predefined implicit rules. This
3 # increases performance and avoids hard-to-debug behaviour.
4 .SUFFIXES:
5 MAKEFLAGS += -Rr
6 ifeq ("$(origin CC)", "default")
7 CC := cc
8 endif
9
10 LOGLEVELS := LL_DEBUG,LL_INFO,LL_NOTICE,LL_WARNING,LL_ERROR,LL_CRIT,LL_EMERG
11 vardir := /var/paraslash
12 mandir := $(datarootdir)/man/man1
13 STRIP := $(CROSS_COMPILE)strip
14 MKDIR_P := mkdir -p
15 prefixed_executables := $(addprefix para_, $(executables))
16
17 build_date := $(shell date)
18 uname_s := $(shell uname -s 2>/dev/null || echo "UNKNOWN_OS")
19 uname_rs := $(shell uname -rs)
20 cc_version := $(shell $(CC) --version | head -n 1)
21 GIT_VERSION := $(shell ./GIT-VERSION-GEN git-version.h)
22 COPYRIGHT_YEAR := 2017
23
24 ifeq ("$(origin O)", "command line")
25 build_dir := $(O)
26 else
27 build_dir := build
28 endif
29 ggo_dir := $(build_dir)/ggo
30 object_dir := $(build_dir)/objects
31 dep_dir := $(build_dir)/deps
32 man_dir := $(build_dir)/man/man1
33 cmdline_dir := $(build_dir)/cmdline
34 m4depdir := $(build_dir)/m4deps
35 help2man_dir := $(build_dir)/help2man
36 lls_suite_dir := $(build_dir)/lls
37 lls_m4_dir := m4/lls
38 m4_ggo_dir := m4/gengetopt
39 test_dir := t
40
41 # sort removes duplicate words, which is all we need here
42 all_objs := $(sort $(recv_objs) $(filter_objs) $(client_objs) $(gui_objs) \
43 $(audiod_objs) $(audioc_objs) $(fade_objs) $(server_objs) \
44 $(write_objs) $(afh_objs) $(play_objs))
45 deps := $(addprefix $(dep_dir)/, $(filter-out %.cmdline.d, $(all_objs:.o=.d)))
46 converted_executables := audioc
47 unconverted_executables := $(filter-out $(converted_executables), $(executables))
48
49 audioc_objs += audioc.lsg.o
50 audiod_objs += audiod_cmd.lsg.o recv_cmd.lsg.o
51 server_objs += server_cmd.lsg.o
52 play_objs += play_cmd.lsg.o recv_cmd.lsg.o
53 recv_objs += recv_cmd.lsg.o
54
55 m4_deps := $(addprefix $(m4depdir)/, $(addsuffix .m4d, $(unconverted_executables)))
56 m4_lls_deps := audiod_cmd server_cmd play_cmd recv_cmd $(converted_executables)
57 m4_lls_deps := $(addprefix $(lls_suite_dir)/, $(addsuffix .m4d, $(m4_lls_deps)))
58
59 # now prefix all objects with object dir
60 recv_objs := $(addprefix $(object_dir)/, $(recv_objs))
61 filter_objs := $(addprefix $(object_dir)/, $(filter_objs))
62 client_objs := $(addprefix $(object_dir)/, $(client_objs))
63 gui_objs := $(addprefix $(object_dir)/, $(gui_objs))
64 audiod_objs := $(addprefix $(object_dir)/, $(audiod_objs))
65 audioc_objs := $(addprefix $(object_dir)/, $(audioc_objs))
66 fade_objs := $(addprefix $(object_dir)/, $(fade_objs))
67 server_objs := $(addprefix $(object_dir)/, $(server_objs))
68 write_objs := $(addprefix $(object_dir)/, $(write_objs))
69 afh_objs := $(addprefix $(object_dir)/, $(afh_objs))
70 play_objs := $(addprefix $(object_dir)/, $(play_objs))
71
72 man_pages := $(patsubst %, $(man_dir)/%.1, $(prefixed_executables))
73
74 autocrap := config.h.in configure
75 tarball_pfx := $(PACKAGE_TARNAME)-$(GIT_VERSION)
76 tarball_delete := $(addprefix $(tarball_pfx)/, web .gitignore)
77 tarball := $(tarball_pfx).tar.bz2
78
79 .PHONY: all clean clean2 distclean maintainer-clean install man tarball
80 all: $(prefixed_executables) $(man_pages)
81 man: $(man_pages)
82 tarball: $(tarball)
83
84 include $(lls_m4_dir)/makefile
85 include $(m4_ggo_dir)/makefile
86 include $(test_dir)/makefile.test
87 ifeq ($(findstring clean, $(MAKECMDGOALS)),)
88 -include $(deps)
89 -include $(m4_deps)
90 -include $(m4_lls_deps)
91 endif
92
93 $(object_dir) $(man_dir) $(ggo_dir) $(cmdline_dir) $(dep_dir) $(m4depdir) \
94 $(help2man_dir) $(lls_suite_dir):
95 $(Q) $(MKDIR_P) $@
96
97 CPPFLAGS += -DBINDIR='"$(bindir)"'
98 CPPFLAGS += -DCOPYRIGHT_YEAR='"$(COPYRIGHT_YEAR)"'
99 CPPFLAGS += -DBUILD_DATE='"$(build_date)"'
100 CPPFLAGS += -DLOGLEVELS='$(LOGLEVELS)'
101 CPPFLAGS += -DUNAME_RS='"$(uname_rs)"'
102 CPPFLAGS += -DCC_VERSION='"$(cc_version)"'
103 CPPFLAGS += -I/usr/local/include
104 CPPFLAGS += -I$(cmdline_dir)
105 CPPFLAGS += -I$(lls_suite_dir)
106 CPPFLAGS += $(lopsub_cppflags)
107
108 CFLAGS += -Os
109 CFLAGS += -Wuninitialized
110 CFLAGS += -Wchar-subscripts
111 CFLAGS += -Werror-implicit-function-declaration
112 CFLAGS += -Wmissing-noreturn
113 CFLAGS += -Wbad-function-cast
114 CFLAGS += -fno-strict-aliasing
115
116 STRICT_CFLAGS = $(CFLAGS)
117 STRICT_CFLAGS += -g -Wundef -W
118 STRICT_CFLAGS += -Wredundant-decls
119 STRICT_CFLAGS += -Wno-sign-compare -Wno-unknown-pragmas
120 STRICT_CFLAGS += -Wformat -Wformat-security
121 STRICT_CFLAGS += -Wmissing-format-attribute
122 STRICT_CFLAGS += -Wdeclaration-after-statement
123
124 LDFLAGS += $(clock_gettime_ldflags)
125
126 ifeq ($(uname_s),Linux)
127 # these cause warnings on *BSD
128 CPPFLAGS += -Wunused-macros
129 STRICT_CFLAGS += -fdata-sections -ffunction-sections
130 STRICT_CFLAGS += -Wstrict-prototypes
131 STRICT_CFLAGS += -Wshadow
132 STRICT_CFLAGS += -Wunused -Wall
133 LDFLAGS += -Wl,--gc-sections
134 endif
135
136 cc-option = $(shell \
137 $(CC) $(1) -Werror -c -x c /dev/null -o /dev/null > /dev/null 2>&1 \
138 && echo "$(1)" \
139 )
140
141 STRICT_CFLAGS += $(call cc-option, -Wformat-signedness)
142
143 # To put more focus on warnings, be less verbose as default
144 # Use 'make V=1' to see the full commands
145 ifeq ("$(origin V)", "command line")
146 Q :=
147 else
148 Q := @
149 endif
150
151 server_command_lists := $(lls_suite_dir)/server_cmd.lsg.man
152 audiod_command_lists := \
153 $(lls_suite_dir)/audiod_cmd.lsg.man \
154 $(lls_suite_dir)/recv_cmd.lsg.man
155 play_command_lists := $(lls_suite_dir)/play_cmd.lsg.man
156 recv_command_lists := $(lls_suite_dir)/recv_cmd.lsg.man
157
158 $(man_dir)/para_server.1: $(server_command_lists)
159 $(man_dir)/para_audiod.1: $(audiod_command_lists)
160 $(man_dir)/para_play.1: $(play_command_lists)
161 $(man_dir)/para_recv.1: $(recv_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 $(man_dir)/para_recv.1: man_util_command_lists := $(recv_command_lists)
167
168 $(man_dir)/para_%.1: $(lls_suite_dir)/%.lsg.man $(man_util_command_lists) \
169 $(lls_m4_dir)/copyright.m4 | $(man_dir)
170 @[ -z "$(Q)" ] || echo 'LLSMAN $<'
171 $(Q) cat $< $(man_util_command_lists) > $@
172 $(Q) $(M4) -D COPYRIGHT_YEAR=$(COPYRIGHT_YEAR) $(lls_m4_dir)/copyright.m4 >> $@
173
174 $(man_dir)/para_%.1: $(man_util_command_lists) \
175 $(ggo_dir)/%.ggo man_util.bash \
176 | $(man_dir) $(help2man_dir)
177 @[ -z "$(Q)" ] || echo 'MAN $<'
178 $(Q) \
179 COMMAND_LISTS="$(man_util_command_lists)" \
180 FILTERS="$(filters)" \
181 GENGETOPT=$(GENGETOPT) \
182 GGO_DIR=$(ggo_dir) \
183 HELP2MAN=$(HELP2MAN) \
184 HELP2MAN_DIR=$(help2man_dir) \
185 RECEIVERS="$(receivers)" \
186 VERSION="$(GIT_VERSION)" \
187 WRITERS="$(writers)" \
188 ./man_util.bash $@
189
190 $(object_dir)/%.o: %.c | $(object_dir)
191
192 $(object_dir)/opus%.o $(dep_dir)/opus%.d: CPPFLAGS += $(opus_cppflags)
193 $(object_dir)/gui.o $(object_dir)/gui%.o $(dep_dir)/gui%.d \
194 : CPPFLAGS += $(curses_cppflags)
195 $(object_dir)/spx%.o $(dep_dir)/spx%.d: CPPFLAGS += $(speex_cppflags)
196 $(object_dir)/flac%.o $(dep_dir)/flac%.d: CPPFLAGS += $(flac_cppflags)
197
198 $(object_dir)/mp3_afh.o $(dep_dir)/mp3_afh.d: CPPFLAGS += $(id3tag_cppflags)
199 $(object_dir)/crypt.o $(dep_dir)/crypt.d: CPPFLAGS += $(openssl_cppflags)
200 $(object_dir)/gcrypt.o $(dep_dir)/gcrypt.d: CPPFLAGS += $(gcrypt_cppflags)
201 $(object_dir)/ao_write.o $(dep_dir)/ao_write.d: CPPFLAGS += $(ao_cppflags)
202 $(object_dir)/aac_afh.o $(dep_dir)/aac_afh.d: CPPFLAGS += $(mp4v2_cppflags)
203 $(object_dir)/alsa%.o $(dep_dir)/alsa%.d: CPPFLAGS += $(alsa_cppflags)
204
205 $(object_dir)/interactive.o $(dep_dir)/interactive.d \
206 : CPPFLAGS += $(readline_cppflags)
207
208 $(object_dir)/resample_filter.o $(dep_dir)/resample_filter.d \
209 : CPPFLAGS += $(samplerate_cppflags)
210
211 $(object_dir)/oss_write.o $(dep_dir)/oss_write.d \
212 : CPPFLAGS += $(oss_cppflags)
213
214 $(object_dir)/ao_write.o $(dep_dir)/ao_write.d \
215 : CPPFLAGS += $(ao_cppflags) $(pthread_cppflags)
216
217 $(object_dir)/mp3dec_filter.o $(dep_dir)/mp3dec_filter.d \
218 : CPPFLAGS += $(mad_cppflags)
219
220 $(object_dir)/aacdec_filter.o $(dep_dir)/aacdec_filter.d \
221 $(object_dir)/aac_common.o $(dep_dir)/aac_common.d \
222 $(object_dir)/aac_afh.o $(dep_dir)/aac_afh.d \
223 : CPPFLAGS += $(faad_cppflags)
224
225 $(object_dir)/ogg_afh.o $(dep_dir)/ogg_afh.d \
226 $(object_dir)/oggdec_filter.o $(dep_dir)/oggdec_filter.d \
227 : CPPFLAGS += $(vorbis_cppflags)
228
229 $(object_dir)/spx_common.o $(dep_dir)/spx_common.d \
230 $(object_dir)/spxdec_filter.o $(dep_dir)/spxdec_filter.d \
231 $(object_dir)/spx_afh.o $(dep_dir)/spx_afh.d \
232 $(object_dir)/oggdec_filter.o $(dep_dir)/oggdec_filter.d \
233 $(object_dir)/ogg_afh.o $(dep_dir)/ogg_afh.d \
234 $(object_dir)/ogg_afh_common.o $(dep_dir)/ogg_afh_common.d \
235 $(object_dir)/opus%.o $(dep_dir)/opus%.d \
236 : CPPFLAGS += $(ogg_cppflags)
237
238 $(object_dir)/afs.o $(dep_dir)/afs.d \
239 $(object_dir)/aft.o $(dep_dir)/aft.d \
240 $(object_dir)/attribute.o $(dep_dir)/attribute.d \
241 $(object_dir)/blob.o $(dep_dir)/blob.d \
242 $(object_dir)/mood.o $(dep_dir)/mood.d \
243 $(object_dir)/playlist.o $(dep_dir)/playlist.d \
244 $(object_dir)/score.o $(dep_dir)/score.d \
245 $(object_dir)/server.o $(dep_dir)/server.d \
246 $(object_dir)/vss.o $(dep_dir)/vss.d \
247 $(object_dir)/command.o $(dep_dir)/command.d \
248 $(object_dir)/http_send.o $(dep_dir)/http_send.d \
249 $(object_dir)/dccp_send.o $(dep_dir)/dccp_send.d \
250 $(object_dir)/udp_send.o $(dep_dir)/udp_send.d \
251 $(object_dir)/send_common.o $(dep_dir)/send_common.d \
252 $(object_dir)/mm.o $(dep_dir)/mm.d \
253 : CPPFLAGS += $(osl_cppflags)
254
255 $(object_dir)/%.cmdline.o: CFLAGS += -Wno-unused-function
256 $(object_dir)/compress_filter.o: CFLAGS += -O3
257
258 $(object_dir)/%.o: %.c | $(object_dir)
259 @[ -z "$(Q)" ] || echo 'CC $<'
260 $(Q) $(CC) -c -o $@ $(CPPFLAGS) $(STRICT_CFLAGS) $<
261
262 $(object_dir)/%.cmdline.o: $(cmdline_dir)/%.cmdline.c $(cmdline_dir)/%.cmdline.h | $(object_dir)
263 @[ -z "$(Q)" ] || echo 'CC $<'
264 $(Q) $(CC) -c -o $@ $(CPPFLAGS) $(CFLAGS) $<
265
266 # The compiler outputs dependencies either as foo.h or as some_directory/foo.h,
267 # depending on whether the latter file exists. Since make needs the directory
268 # part we prefix the dependency as appropriate.
269 $(dep_dir)/%.d: %.c | $(dep_dir)
270 @[ -z "$(Q)" ] || echo 'DEP $<'
271 $(Q) $(CC) $(CPPFLAGS) -MM -MG -MP -MT $@ -MT $(object_dir)/$(*F).o $< \
272 | sed -e "s@ \([a-zA-Z0-9_]\{1,\}\.cmdline.h\)@ $(cmdline_dir)/\1@g" \
273 -e "s@ \([a-zA-Z0-9_]\{1,\}.lsg.h\)@ $(lls_suite_dir)/\1@g" > $@
274
275 para_recv para_afh para_play para_server: LDFLAGS += $(id3tag_ldflags)
276 para_write para_play para_audiod \
277 : LDFLAGS += $(ao_ldflags) $(pthread_ldflags) $(core_audio_ldflags)
278 para_client para_audioc para_play : LDFLAGS += $(readline_ldflags)
279 para_server: LDFLAGS += $(osl_ldflags)
280 para_gui: LDFLAGS += $(curses_ldflags)
281 para_server \
282 para_client \
283 para_audiod \
284 :LDFLAGS += \
285 $(crypto_ldflags)
286
287 para_audiod \
288 para_filter \
289 para_play \
290 : LDFLAGS += \
291 $(mad_ldflags) \
292 $(faad_ldflags) \
293 $(samplerate_ldflags) \
294 -lm
295
296 para_write \
297 para_play \
298 para_audiod \
299 para_fade \
300 : LDFLAGS += \
301 $(oss_ldflags) \
302 $(alsa_ldflags)
303
304 para_audioc \
305 para_audiod \
306 para_play \
307 para_recv \
308 para_server \
309 : LDFLAGS += $(lopsub_ldflags)
310
311 para_server \
312 para_filter \
313 para_audiod \
314 para_play \
315 para_afh \
316 para_recv \
317 : LDFLAGS += \
318 $(ogg_ldflags) \
319 $(vorbis_ldflags) \
320 $(speex_ldflags) \
321 $(opus_ldflags) \
322 $(faad_ldflags) \
323 $(flac_ldflags)
324
325 para_server \
326 para_play \
327 para_afh \
328 para_recv \
329 : LDFLAGS += \
330 $(mp4v2_ldflags)
331
332 para_afh para_recv para_server para_play: LDFLAGS += $(iconv_ldflags)
333
334 $(foreach exe,$(executables),$(eval para_$(exe): $$($(exe)_objs)))
335 $(prefixed_executables):
336 @[ -z "$(Q)" ] || echo 'LD $@'
337 $(Q) $(CC) $^ -o $@ $(LDFLAGS)
338
339 clean:
340 @[ -z "$(Q)" ] || echo 'CLEAN'
341 $(Q) rm -f para_*
342 $(Q) rm -rf $(object_dir)
343
344 clean2: clean
345 @[ -z "$(Q)" ] || echo 'CLEAN2'
346 $(Q) rm -rf $(build_dir)
347 distclean: clean2 test-clean
348 @[ -z "$(Q)" ] || echo 'DISTCLEAN'
349 $(Q) rm -f Makefile autoscan.log config.status config.log
350 $(Q) rm -f GPATH GRTAGS GSYMS GTAGS
351
352 maintainer-clean: distclean
353 @[ -z "$(Q)" ] || echo 'MAINTAINER-CLEAN'
354 $(Q) rm -f *.tar.bz2 config.h configure config.h.in
355
356 install: all man
357 $(MKDIR_P) $(bindir) $(mandir)
358 $(INSTALL) -s --strip-program $(STRIP) -m 755 \
359 $(prefixed_executables) $(bindir)
360 $(INSTALL) -m 644 $(man_pages) $(mandir)
361 $(MKDIR_P) $(vardir) >/dev/null 2>&1 || true # not fatal, so don't complain
362
363 $(tarball):
364 $(Q) rm -rf $(tarball) $(tarball_pfx)
365 $(Q) git archive --format=tar --prefix=$(tarball_pfx)/ HEAD \
366 | tar --delete $(tarball_delete) > $(tarball_pfx).tar
367 $(Q) $(MKDIR_P) $(tarball_pfx)
368 $(Q) ./GIT-VERSION-GEN > $(tarball_pfx)/VERSION
369 $(Q) cp $(autocrap) $(tarball_pfx)
370 $(Q) tar rf $(tarball_pfx).tar $(tarball_pfx)/*
371 $(Q) bzip2 -9 $(tarball_pfx).tar
372 $(Q) ls -l $(tarball)
373 $(Q) ln -sf $(tarball) paraslash-git.tar.bz2
374 $(Q) rm -rf $(tarball_pfx)