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