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.
6 ifeq ("$(origin CC)", "default")
12 LOGLEVELS := LL_DEBUG,LL_INFO,LL_NOTICE,LL_WARNING,LL_ERROR,LL_CRIT,LL_EMERG
13 SEVERITIES := \"debug\",\"info\",\"notice\",\"warning\",\"error\",\"crit\",\"emerg\"
14 vardir := /var/paraslash
15 mandir := $(datarootdir)/man/man1
18 build_date := $(shell date)
19 uname_s := $(shell uname -s 2>/dev/null || echo "UNKNOWN_OS")
20 uname_rs := $(shell uname -rs)
21 cc_version := $(shell $(CC) --version | head -n 1)
22 GIT_VERSION := $(shell ./GIT-VERSION-GEN git-version.h)
23 COPYRIGHT_YEAR := 2024
25 ifeq ("$(origin O)", "command line")
30 object_dir := $(build_dir)/objects
31 dep_dir := $(build_dir)/deps
32 man_dir := $(build_dir)/man/man1
33 m4depdir := $(build_dir)/m4deps
34 lls_suite_dir := $(build_dir)/lls
38 yy_build_dir := $(build_dir)/yy
40 executables := recv filter audioc write afh play
42 ifeq ($(HAVE_OSL),yes)
43 executables += server upgrade_db
44 server_objs := $(addsuffix .o, \
45 server afh_common mp3_afh vss command net string \
46 signal time daemon http_send close_on_fork \
47 crypt_common base64 ipc dccp_send fd user_list \
48 chunk_queue afs aft mood mp score attribute blob \
49 playlist sched acl send_common udp_send color fec \
50 wma_afh wma_common sideband version lsu \
52 ifeq ($(CRYPTOLIB),openssl)
53 server_objs += openssl.o
55 server_objs += gcrypt.o
57 ifeq ($(NEED_OGG_OBJECTS),yes)
58 server_objs += ogg_afh_common.o
60 ifeq ($(NEED_VORBIS_OBJECTS),yes)
61 server_objs += ogg_afh.o
63 ifeq ($(NEED_SPEEX_OBJECTS),yes)
64 server_objs += spx_afh.o spx_common.o
66 ifeq ($(NEED_OPUS_OBJECTS),yes)
67 server_objs += opus_afh.o opus_common.o
69 ifeq ($(NEED_FLAC_OBJECTS),yes)
70 server_objs += flac_afh.o
72 ifeq ($(HAVE_FAAD),yes)
73 server_objs += aac_afh.o mp4.o
75 upgrade_db_objs := $(addsuffix .o, crypt_common exec fd string \
76 upgrade_db version base64)
80 executables += client audiod
81 client_objs := $(addsuffix .o, \
82 client net string fd lsu sched stdin stdout time sideband client_common \
83 buffer_tree crypt_common base64 version $(CRYPTOLIB) \
85 ifeq ($(HAVE_READLINE),yes)
86 client_objs += interactive.o
88 audiod_objs := $(addsuffix .o, \
89 audiod signal string daemon stat net crypt_common base64 sideband \
90 time grab_client filter_common wav_filter compress_filter amp_filter \
91 http_recv dccp_recv recv_common fd sched write_common file_write \
92 audiod_command fecdec_filter client_common udp_recv color fec \
93 prebuffer_filter version bitstream imdct wma_common wmadec_filter \
94 buffer_tree sync_filter lsu $(CRYPTOLIB) \
96 audiod_audio_formats := "wma"
97 ifeq ($(NEED_VORBIS_OBJECTS),yes)
98 audiod_objs += oggdec_filter.o
99 audiod_audio_formats += ,"ogg"
101 ifeq ($(NEED_SPEEX_OBJECTS),yes)
102 audiod_objs += spxdec_filter.o spx_common.o
103 audiod_audio_formats += ,"spx"
105 ifeq ($(NEED_OPUS_OBJECTS),yes)
106 audiod_objs += opusdec_filter.o opus_common.o
107 audiod_audio_formats += ,"opus"
109 ifeq ($(NEED_FLAC_OBJECTS),yes)
110 audiod_objs += flacdec_filter.o
111 audiod_audio_formats += ,"flac"
113 ifeq ($(HAVE_FAAD),yes)
114 audiod_objs += aacdec_filter.o
115 audiod_audio_formats += ,"aac"
117 ifeq ($(HAVE_MAD),yes)
118 audiod_objs += mp3dec_filter.o
119 audiod_audio_formats += ,"mp3"
121 ifeq ($(HAVE_OSS),yes)
122 audiod_objs += oss_write.o
124 ifeq ($(HAVE_ALSA),yes)
125 audiod_objs += alsa_write.o
127 ifeq ($(NEED_AO_OBJECTS),yes)
128 audiod_objs += ao_write.o
130 ifeq ($(HAVE_SAMPLERATE),yes)
131 audiod_objs += resample_filter.o check_wav.o
134 ifneq ($(HAVE_OSS)-$(HAVE_ALSA),no-no)
136 mixer_objs := $(addsuffix .o, mixer exec string fd time lsu version)
137 ifeq ($(HAVE_OSS),yes)
138 mixer_objs += oss_mix.o
140 ifeq ($(HAVE_ALSA),yes)
141 mixer_objs += alsa_mix.o
144 ifeq ($(HAVE_CURSES),yes)
146 gui_objs := $(addsuffix .o, exec signal string stat ringbuffer fd \
147 gui gui_theme lsu time sched version)
149 filter_objs := $(addsuffix .o, \
150 filter_common wav_filter compress_filter filter string stdin stdout \
151 sched fd amp_filter fecdec_filter fec lsu version prebuffer_filter \
152 time bitstream imdct wma_common wmadec_filter buffer_tree net \
155 ifeq ($(NEED_VORBIS_OBJECTS),yes)
156 filter_objs += oggdec_filter.o
158 ifeq ($(NEED_SPEEX_OBJECTS),yes)
159 filter_objs += spxdec_filter.o spx_common.o
161 ifeq ($(NEED_OPUS_OBJECTS),yes)
162 filter_objs += opusdec_filter.o opus_common.o
164 ifeq ($(NEED_FLAC_OBJECTS),yes)
165 filter_objs += flacdec_filter.o
167 ifeq ($(HAVE_FAAD),yes)
168 filter_objs += aacdec_filter.o
170 ifeq ($(HAVE_MAD),yes)
171 filter_objs += mp3dec_filter.o
173 ifeq ($(HAVE_SAMPLERATE),yes)
174 filter_objs += resample_filter.o check_wav.o
177 recv_objs := $(addsuffix .o, \
178 http_recv recv_common recv time string net dccp_recv fd sched stdout \
179 udp_recv buffer_tree afh_recv afh_common wma_afh wma_common mp3_afh \
182 ifeq ($(NEED_OGG_OBJECTS),yes)
183 recv_objs += ogg_afh_common.o
185 ifeq ($(NEED_VORBIS_OBJECTS),yes)
186 recv_objs += ogg_afh.o
188 ifeq ($(NEED_SPEEX_OBJECTS),yes)
189 recv_objs += spx_afh.o spx_common.o
191 ifeq ($(NEED_OPUS_OBJECTS),yes)
192 recv_objs += opus_afh.o opus_common.o
194 ifeq ($(NEED_FLAC_OBJECTS),yes)
195 recv_objs += flac_afh.o
197 ifeq ($(HAVE_FAAD),yes)
198 recv_objs += aac_afh.o mp4.o
201 audio_format_handlers := mp3 wma
202 afh_objs := $(addsuffix .o, afh string fd mp3_afh afh_common time wma_afh \
204 ifeq ($(NEED_OGG_OBJECTS),yes)
205 afh_objs += ogg_afh_common.o
207 ifeq ($(NEED_VORBIS_OBJECTS),yes)
208 afh_objs += ogg_afh.o
209 audio_format_handlers += ogg
211 ifeq ($(NEED_SPEEX_OBJECTS),yes)
212 afh_objs += spx_common.o
213 audio_format_handlers += spx
215 ifeq ($(NEED_OPUS_OBJECTS),yes)
216 afh_objs += opus_afh.o opus_common.o
217 audio_format_handlers += opus
219 ifeq ($(NEED_FLAC_OBJECTS),yes)
220 afh_objs += flac_afh.o
221 audio_format_handlers += flac
223 ifeq ($(HAVE_FAAD),yes)
224 afh_objs += aac_afh.o mp4.o
225 audio_format_handlers += aac
228 play_objs := $(addsuffix .o, \
229 play fd sched buffer_tree time string net afh_recv afh_common \
230 wma_afh wma_common mp3_afh recv_common udp_recv http_recv dccp_recv \
231 filter_common fec bitstream imdct wav_filter compress_filter \
232 amp_filter prebuffer_filter fecdec_filter wmadec_filter write_common \
233 file_write version sync_filter lsu \
235 ifeq ($(NEED_OGG_OBJECTS),yes)
236 play_objs += ogg_afh_common.o
238 ifeq ($(NEED_VORBIS_OBJECTS),yes)
239 play_objs += oggdec_filter.o ogg_afh.o
241 ifeq ($(NEED_SPEEX_OBJECTS),yes)
242 play_objs += spxdec_filter.o spx_afh.o spx_common.o
244 ifeq ($(NEED_OPUS_OBJECTS),yes)
245 play_objs += opusdec_filter.o opus_afh.o opus_common.o
247 ifeq ($(NEED_FLAC_OBJECTS),yes)
248 play_objs += flacdec_filter.o flac_afh.o
250 ifeq ($(HAVE_FAAD),yes)
251 play_objs += aac_afh.o aacdec_filter.o mp4.o
253 ifeq ($(HAVE_MAD),yes)
254 play_objs += mp3dec_filter.o
256 ifeq ($(HAVE_OSS),yes)
257 play_objs += oss_write.o
259 ifeq ($(HAVE_ALSA),yes)
260 play_objs += alsa_write.o
262 ifeq ($(NEED_AO_OBJECTS),yes)
263 play_objs += ao_write.o
265 ifeq ($(HAVE_READLINE),yes)
266 play_objs += interactive.o
268 ifeq ($(HAVE_SAMPLERATE),yes)
269 play_objs += resample_filter.o check_wav.o
272 write_objs := $(addsuffix .o, write write_common file_write time fd \
273 string sched stdin buffer_tree check_wav version)
274 ifeq ($(NEED_AO_OBJECTS),yes)
275 write_objs += ao_write.o
277 ifeq ($(HAVE_OSS),yes)
278 write_objs += oss_write.o
280 ifeq ($(HAVE_ALSA),yes)
281 write_objs += alsa_write.o
284 audioc_objs := $(addsuffix .o, audioc string lsu net fd time version)
285 ifeq ($(HAVE_READLINE),yes)
286 audioc_objs += buffer_tree.o interactive.o sched.o
289 # sort removes duplicate words, which is all we need here
290 dep_objs := $(sort $(recv_objs) $(filter_objs) $(client_objs) $(gui_objs) \
291 $(audiod_objs) $(audioc_objs) $(mixer_objs) $(server_objs) \
292 $(write_objs) $(afh_objs) $(play_objs) mp.bison mp.flex)
293 deps := $(addprefix $(dep_dir)/, $(dep_objs:.o=.d))
295 afh_objs += afh.lsg.o
296 audioc_objs += audioc.lsg.o
297 audiod_objs += $(addsuffix _cmd.lsg.o, recv filter audiod write) \
298 client.lsg.o audiod.lsg.o
299 client_objs += client.lsg.o
300 mixer_objs += mixer.lsg.o
301 filter_objs += filter_cmd.lsg.o filter.lsg.o
302 gui_objs += gui.lsg.o
303 play_objs += $(addsuffix _cmd.lsg.o, recv filter play write) play.lsg.o
304 recv_objs += recv_cmd.lsg.o recv.lsg.o
305 server_objs += server_cmd.lsg.o server.lsg.o
306 upgrade_db_objs += upgrade_db.lsg.o
307 write_objs += write_cmd.lsg.o write.lsg.o
309 cmd_suites := $(addsuffix _cmd, audiod server play recv filter write)
310 suites := $(addprefix $(lls_suite_dir)/, $(cmd_suites) $(executables))
311 m4_lls_deps := $(addsuffix .m4d, $(suites))
312 lsg_h := $(addsuffix .lsg.h, $(suites))
314 # flex/bison objects and headers are only needed if para_server is built
315 ifeq ("$(findstring server, $(executables))", "server")
316 server_objs += mp.flex.o mp.bison.o
317 yy_h := $(yy_build_dir)/mp.bison.h
320 # now prefix all objects with object dir
321 recv_objs := $(addprefix $(object_dir)/, $(recv_objs))
322 filter_objs := $(addprefix $(object_dir)/, $(filter_objs))
323 client_objs := $(addprefix $(object_dir)/, $(client_objs))
324 gui_objs := $(addprefix $(object_dir)/, $(gui_objs))
325 audiod_objs := $(addprefix $(object_dir)/, $(audiod_objs))
326 audioc_objs := $(addprefix $(object_dir)/, $(audioc_objs))
327 mixer_objs := $(addprefix $(object_dir)/, $(mixer_objs))
328 server_objs := $(addprefix $(object_dir)/, $(server_objs))
329 upgrade_db_objs := $(addprefix $(object_dir)/, $(upgrade_db_objs))
330 write_objs := $(addprefix $(object_dir)/, $(write_objs))
331 afh_objs := $(addprefix $(object_dir)/, $(afh_objs))
332 play_objs := $(addprefix $(object_dir)/, $(play_objs))
334 prefixed_executables := $(addprefix para_, $(executables))
335 man_pages := $(patsubst %, $(man_dir)/%.1, $(prefixed_executables))
337 autocrap := config.h.in configure
338 tarball_pfx := $(PACKAGE_TARNAME)-$(GIT_VERSION)
339 tarball_delete := $(addprefix $(tarball_pfx)/, web .gitignore)
340 tarball := $(tarball_pfx).tar.xz
342 all: $(prefixed_executables) $(man_pages)
343 .PHONY: all mostlyclean clean distclean maintainer-clean install \
344 install-strip man dist tarball
348 include $(lls_m4_dir)/makefile
349 include $(test_dir)/makefile.test
350 include $(yy_src_dir)/makefile
351 ifeq ($(findstring clean, $(MAKECMDGOALS)),)
353 -include $(m4_lls_deps)
356 $(object_dir) $(man_dir) $(dep_dir) $(m4depdir) $(lls_suite_dir) \
360 CPPFLAGS += -DBINDIR='"$(bindir)"'
361 CPPFLAGS += -DCOPYRIGHT_YEAR='"$(COPYRIGHT_YEAR)"'
362 CPPFLAGS += -DBUILD_DATE='"$(build_date)"'
363 CPPFLAGS += -DLOGLEVELS='$(LOGLEVELS)'
364 CPPFLAGS += -DSEVERITIES=$(SEVERITIES)
365 CPPFLAGS += -DUNAME_RS='"$(uname_rs)"'
366 CPPFLAGS += -DCC_VERSION='"$(cc_version)"'
367 CPPFLAGS += -I$(lls_suite_dir)
368 CPPFLAGS += -I$(yy_build_dir)
369 CPPFLAGS += $(lopsub_cppflags)
370 CPPFLAGS += -Wunused-macros
372 STRICT_CFLAGS += -fno-strict-aliasing
373 STRICT_CFLAGS += -ftrapv
376 STRICT_CFLAGS += -Wundef -W -Wuninitialized
377 STRICT_CFLAGS += -Wchar-subscripts
378 STRICT_CFLAGS += -Werror-implicit-function-declaration
379 STRICT_CFLAGS += -Wmissing-noreturn
380 STRICT_CFLAGS += -Wbad-function-cast
381 STRICT_CFLAGS += -Wredundant-decls
382 STRICT_CFLAGS += -Wno-sign-compare -Wno-unknown-pragmas
383 STRICT_CFLAGS += -Wdeclaration-after-statement
384 STRICT_CFLAGS += -Wformat -Wformat-security -Wmissing-format-attribute
385 STRICT_CFLAGS += -fdata-sections -ffunction-sections
386 STRICT_CFLAGS += -Wstrict-prototypes
387 STRICT_CFLAGS += -Wshadow
389 LDFLAGS += -Wl,--gc-sections
391 ifeq ($(ENABLE_UBSAN), yes)
392 STRICT_CFLAGS += -fsanitize=undefined
396 ifeq ($(uname_s),Linux)
397 # these cause warnings on *BSD
398 STRICT_CFLAGS += -Wunused -Wall
401 cc-option = $(shell \
402 $(CC) $(1) -Werror -c -x c /dev/null -o /dev/null > /dev/null 2>&1 \
406 STRICT_CFLAGS += $(call cc-option, -Wformat-signedness)
407 STRICT_CFLAGS += $(call cc-option, -Wdiscarded-qualifiers)
408 STRICT_CFLAGS += $(call cc-option, -Wsuggest-attribute=malloc)
410 # To put more focus on warnings, be less verbose as default
411 # Use 'make V=1' to see the full commands
412 ifeq ("$(origin V)", "command line")
415 SAY = @echo '$(strip $(1))'
418 audiod_commands := $(addprefix $(lls_suite_dir)/, \
419 $(addsuffix _cmd.lsg.man, audiod recv filter write))
420 filter_commands := $(lls_suite_dir)/filter_cmd.lsg.man
421 play_commands := $(lls_suite_dir)/play_cmd.lsg.man
422 recv_commands := $(lls_suite_dir)/recv_cmd.lsg.man
423 server_commands := $(lls_suite_dir)/server_cmd.lsg.man
424 write_commands := $(lls_suite_dir)/write_cmd.lsg.man
426 $(man_dir)/para_audiod.1: $(audiod_commands)
427 $(man_dir)/para_filter.1: $(filter_commands)
428 $(man_dir)/para_play.1: $(play_commands)
429 $(man_dir)/para_recv.1: $(recv_commands)
430 $(man_dir)/para_server.1: $(server_commands)
431 $(man_dir)/para_write.1: $(write_commands)
433 $(man_dir)/para_audiod.1: all_commands := $(audiod_commands)
434 $(man_dir)/para_filter.1: all_commands := $(filter_commands)
435 $(man_dir)/para_play.1: all_commands := $(play_commands)
436 $(man_dir)/para_recv.1: all_commands := $(recv_commands)
437 $(man_dir)/para_server.1: all_commands := $(server_commands)
438 $(man_dir)/para_write.1: all_commands := $(write_commands)
440 $(man_dir)/para_%.1: $(lls_suite_dir)/%.lsg.man \
441 $(lls_m4_dir)/copyright.m4 | $(man_dir)
442 $(call SAY, LLSMAN $<)
443 cat $< $(all_commands) > $@
444 $(M4) -D COPYRIGHT_YEAR=$(COPYRIGHT_YEAR) $(lls_m4_dir)/copyright.m4 >> $@
446 $(object_dir)/%.o: %.c | $(object_dir)
448 OD = $(addsuffix .d, $(addprefix $(dep_dir)/, $(1))) \
449 $(addsuffix .o, $(addprefix $(object_dir)/, $(1)))
451 $(call OD, audiod): \
452 CPPFLAGS += -DAUDIOD_AUDIO_FORMAT_ARRAY='$(audiod_audio_formats)'
453 $(call OD, afh command): \
454 CPPFLAGS += -DAUDIO_FORMAT_HANDLERS='"$(audio_format_handlers)"'
455 $(call OD, opus%): CPPFLAGS += $(opus_cppflags)
456 $(call OD, gui gui%): CPPFLAGS += $(curses_cppflags)
457 $(call OD, spx%): CPPFLAGS += $(speex_cppflags)
458 $(call OD, flac%): CPPFLAGS += $(flac_cppflags)
459 $(call OD, mp3_afh): CPPFLAGS += $(id3tag_cppflags)
460 $(call OD, openssl): CPPFLAGS += $(openssl_cppflags)
461 $(call OD, gcrypt): CPPFLAGS += $(gcrypt_cppflags)
462 $(call OD, ao_write): CPPFLAGS += $(ao_cppflags)
463 $(call OD, alsa%): CPPFLAGS += $(alsa_cppflags)
464 $(call OD, interactive): CPPFLAGS += $(readline_cppflags)
465 $(call OD, resample_filter): CPPFLAGS += $(samplerate_cppflags)
466 $(call OD, oss_write): CPPFLAGS += $(oss_cppflags)
467 $(call OD, ao_write): CPPFLAGS += $(ao_cppflags) $(pthread_cppflags)
468 $(call OD, mp3dec_filter): CPPFLAGS += $(mad_cppflags)
469 $(call OD, aacdec_filter aac_afh): CPPFLAGS += $(faad_cppflags)
470 $(call OD, ogg_afh oggdec_filter): CPPFLAGS += $(vorbis_cppflags)
471 $(call OD, spx_common spxdec_filter spx_afh oggdec_filter ogg_afh \
472 ogg_afh_common opus%): CPPFLAGS += $(ogg_cppflags)
473 $(call OD, afs aft attribute blob mood playlist score server vss command \
474 http_send dccp_send udp_send send_common mm.o): \
475 CPPFLAGS += $(osl_cppflags)
477 $(call OD, compress_filter): CFLAGS += -O3
478 $(call OD, openssl): CFLAGS += -Wno-deprecated-declarations
480 $(object_dir)/%.o: %.c | $(object_dir) $(dep_dir) $(lsg_h) $(yy_h)
483 $(CC) -c -o $(object_dir)/$(*F).o -MMD -MF \
484 $(dep_dir)/$(*F).d -MT $(object_dir)/$(*F).o \
485 $(CPPFLAGS) $(STRICT_CFLAGS) $(CFLAGS) $<
487 CC_PREREQUISITES := %.c | $(object_dir) $(dep_dir) $(lsg_h) $(yy_h)
488 # These two have the same prerequisites and the same recipe. There should be a
489 # better way to write this.
490 $(object_dir)/%.o: $(CC_PREREQUISITES)
492 $(dep_dir)/%.d: $(CC_PREREQUISITES)
495 para_recv para_afh para_play para_server: LDFLAGS += $(id3tag_ldflags)
496 para_write para_play para_audiod \
497 : LDFLAGS += $(ao_ldflags) $(pthread_ldflags)
498 para_client para_audioc para_play : LDFLAGS += $(readline_ldflags)
499 para_server para_upgrade_db: LDFLAGS += $(osl_ldflags)
500 para_gui: LDFLAGS += $(curses_ldflags)
513 $(samplerate_ldflags) \
516 para_mixer: LDFLAGS += -lm
538 : LDFLAGS += $(lopsub_ldflags)
554 para_afh para_recv para_server para_play: LDFLAGS += $(iconv_ldflags)
556 $(foreach exe,$(executables),$(eval para_$(exe): $$($(exe)_objs)))
557 $(prefixed_executables):
559 $(CC) $^ -o $@ $(LDFLAGS)
562 $(call SAY, MOSTLYCLEAN)
569 $(call SAY, DISTCLEAN)
570 rm -f Makefile autoscan.log config.status config.log
571 rm -f config.h configure config.h.in
572 maintainer-clean: distclean test-clean
573 $(call SAY, MAINTAINER-CLEAN)
574 rm -f *.tar.bz2 *.tar.xz
575 rm -f GPATH GRTAGS GSYMS GTAGS
578 INSTALL_PROGRAM ?= $(INSTALL)
579 INSTALL_DATA ?= $(INSTALL) -m 644
580 ifneq ($(findstring strip, $(MAKECMDGOALS)),)
584 install install-strip: all man
585 $(MKDIR_P) $(DESTDIR)$(bindir) $(DESTDIR)$(mandir)
586 $(INSTALL) $(strip_option) $(prefixed_executables) $(DESTDIR)$(bindir)
587 $(INSTALL_DATA) $(man_pages) $(DESTDIR)$(mandir)
588 $(MKDIR_P) $(DESTDIR)$(vardir) >/dev/null 2>&1 || true # not fatal, so don't complain
590 $(tarball) dist tarball:
592 rm -rf $(tarball) $(tarball_pfx)
593 git archive --format=tar --prefix=$(tarball_pfx)/ HEAD \
594 | tar --delete $(tarball_delete) > $(tarball_pfx).tar
595 $(MKDIR_P) $(tarball_pfx)
596 ./GIT-VERSION-GEN > $(tarball_pfx)/VERSION
597 cp $(autocrap) $(tarball_pfx)
598 tar rf $(tarball_pfx).tar $(tarball_pfx)/*
599 xz -9 $(tarball_pfx).tar
601 ln -sf $(tarball) paraslash-git.tar.xz
602 rm -rf $(tarball_pfx)