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