]> git.tuebingen.mpg.de Git - paraslash.git/blob - Makefile.real
build: Construct audiod and client object list in Makefile.
[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 .ONESHELL:
10 .SHELLFLAGS := -ec
11
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
16 MKDIR_P := mkdir -p
17 prefixed_executables := $(addprefix para_, $(executables))
18
19 build_date := $(shell date)
20 uname_s := $(shell uname -s 2>/dev/null || echo "UNKNOWN_OS")
21 uname_rs := $(shell uname -rs)
22 cc_version := $(shell $(CC) --version | head -n 1)
23 GIT_VERSION := $(shell ./GIT-VERSION-GEN git-version.h)
24 COPYRIGHT_YEAR := 2024
25
26 ifeq ("$(origin O)", "command line")
27         build_dir := $(O)
28 else
29         build_dir := build
30 endif
31 object_dir := $(build_dir)/objects
32 dep_dir := $(build_dir)/deps
33 man_dir := $(build_dir)/man/man1
34 m4depdir := $(build_dir)/m4deps
35 lls_suite_dir := $(build_dir)/lls
36 lls_m4_dir := m4/lls
37 test_dir := t
38 yy_src_dir := yy
39 yy_build_dir := $(build_dir)/yy
40
41 ifneq ($(CRYPTOLIB),)
42         ifeq ($(HAVE_OSL),yes)
43                 server_objs := $(addsuffix .o, \
44                         server afh_common mp3_afh vss command net string \
45                         signal time daemon http_send close_on_fork \
46                         crypt_common base64 ipc dccp_send fd user_list \
47                         chunk_queue afs aft mood mp score attribute blob \
48                         playlist sched acl send_common udp_send color fec \
49                         wma_afh wma_common sideband version lsu \
50                 )
51                 ifeq ($(CRYPTOLIB),openssl)
52                         server_objs += openssl.o
53                 else
54                         server_objs += gcrypt.o
55                 endif
56                 ifeq ($(NEED_OGG_OBJECTS),yes)
57                         server_objs += ogg_afh_common.o
58                 endif
59                 ifeq ($(NEED_VORBIS_OBJECTS),yes)
60                         server_objs += ogg_afh.o
61                 endif
62                 ifeq ($(NEED_SPEEX_OBJECTS),yes)
63                         server_objs += spx_afh.o spx_common.o
64                 endif
65                 ifeq ($(NEED_OPUS_OBJECTS),yes)
66                         server_objs += opus_afh.o opus_common.o
67                 endif
68                 ifeq ($(NEED_FLAC_OBJECTS),yes)
69                         server_objs += flac_afh.o
70                 endif
71                 ifeq ($(HAVE_FAAD),yes)
72                         server_objs += aac_afh.o mp4.o
73                 endif
74                 upgrade_db_objs := $(addsuffix .o, crypt_common exec fd string \
75                         upgrade_db version base64)
76         endif
77 endif
78 ifneq ($(CRYPTOLIB),)
79         client_objs := $(addsuffix .o, \
80                 client net string fd lsu sched stdin stdout time sideband client_common \
81                 buffer_tree crypt_common base64 version $(CRYPTOLIB) \
82         )
83         ifeq ($(HAVE_READLINE),yes)
84                 client_objs += interactive.o
85         endif
86         audiod_objs := $(addsuffix .o, \
87                 audiod signal string daemon stat net crypt_common base64 sideband \
88                 time grab_client filter_common wav_filter compress_filter amp_filter \
89                 http_recv dccp_recv recv_common fd sched write_common file_write \
90                 audiod_command fecdec_filter client_common udp_recv color fec \
91                 prebuffer_filter version bitstream imdct wma_common wmadec_filter \
92                 buffer_tree sync_filter lsu $(CRYPTOLIB) \
93         )
94         audiod_audio_formats := "wma"
95         ifeq ($(NEED_VORBIS_OBJECTS),yes)
96                 audiod_objs += oggdec_filter.o
97                 audiod_audio_formats += ,"ogg"
98         endif
99         ifeq ($(NEED_SPEEX_OBJECTS),yes)
100                 audiod_objs += spxdec_filter.o spx_common.o
101                 audiod_audio_formats += ,"spx"
102         endif
103         ifeq ($(NEED_OPUS_OBJECTS),yes)
104                 audiod_objs += opusdec_filter.o opus_common.o
105                 audiod_audio_formats += ,"opus"
106         endif
107         ifeq ($(NEED_FLAC_OBJECTS),yes)
108                 audiod_objs += flacdec_filter.o
109                 audiod_audio_formats += ,"flac"
110         endif
111         ifeq ($(HAVE_FAAD),yes)
112                 audiod_objs += aacdec_filter.o
113                 audiod_audio_formats += ,"aac"
114         endif
115         ifeq ($(HAVE_MAD),yes)
116                 audiod_objs += mp3dec_filter.o
117                 audiod_audio_formats += ,"mp3"
118         endif
119         ifeq ($(HAVE_OSS),yes)
120                 audiod_objs += oss_write.o
121         endif
122         ifeq ($(HAVE_ALSA),yes)
123                 audiod_objs += alsa_write.o
124         endif
125         ifeq ($(NEED_AO_OBJECTS),yes)
126                 audiod_objs += ao_write.o
127         endif
128         ifeq ($(HAVE_SAMPLERATE),yes)
129                 audiod_objs += resample_filter.o check_wav.o
130         endif
131 endif
132
133 # sort removes duplicate words, which is all we need here
134 all_objs := $(sort $(recv_objs) $(filter_objs) $(client_objs) $(gui_objs) \
135         $(audiod_objs) $(audioc_objs) $(mixer_objs) $(server_objs) \
136         $(write_objs) $(afh_objs) $(play_objs))
137 deps := $(addprefix $(dep_dir)/, $(all_objs:.o=.d))
138 deps += $(addprefix $(dep_dir)/, mp.bison.d mp.flex.d)
139
140 afh_objs += afh.lsg.o
141 audioc_objs += audioc.lsg.o
142 audiod_objs += $(addsuffix _cmd.lsg.o, recv filter audiod write) \
143         client.lsg.o audiod.lsg.o
144 client_objs += client.lsg.o
145 mixer_objs += mixer.lsg.o
146 filter_objs += filter_cmd.lsg.o filter.lsg.o
147 gui_objs += gui.lsg.o
148 play_objs += $(addsuffix _cmd.lsg.o, recv filter play write) play.lsg.o
149 recv_objs += recv_cmd.lsg.o recv.lsg.o
150 server_objs += server_cmd.lsg.o server.lsg.o
151 upgrade_db_objs += upgrade_db.lsg.o
152 write_objs += write_cmd.lsg.o write.lsg.o
153
154 cmd_suites := $(addsuffix _cmd, audiod server play recv filter write)
155 suites := $(addprefix $(lls_suite_dir)/, $(cmd_suites) $(executables))
156 m4_lls_deps := $(addsuffix .m4d, $(suites))
157 lsg_h := $(addsuffix .lsg.h, $(suites))
158
159 # flex/bison objects and headers are only needed if para_server is built
160 ifeq ("$(findstring server, $(executables))", "server")
161         server_objs += mp.flex.o mp.bison.o
162         yy_h := $(yy_build_dir)/mp.bison.h
163 endif
164
165 # now prefix all objects with object dir
166 recv_objs := $(addprefix $(object_dir)/, $(recv_objs))
167 filter_objs := $(addprefix $(object_dir)/, $(filter_objs))
168 client_objs := $(addprefix $(object_dir)/, $(client_objs))
169 gui_objs := $(addprefix $(object_dir)/, $(gui_objs))
170 audiod_objs := $(addprefix $(object_dir)/, $(audiod_objs))
171 audioc_objs := $(addprefix $(object_dir)/, $(audioc_objs))
172 mixer_objs := $(addprefix $(object_dir)/, $(mixer_objs))
173 server_objs := $(addprefix $(object_dir)/, $(server_objs))
174 upgrade_db_objs := $(addprefix $(object_dir)/, $(upgrade_db_objs))
175 write_objs := $(addprefix $(object_dir)/, $(write_objs))
176 afh_objs := $(addprefix $(object_dir)/, $(afh_objs))
177 play_objs := $(addprefix $(object_dir)/, $(play_objs))
178
179 man_pages := $(patsubst %, $(man_dir)/%.1, $(prefixed_executables))
180
181 autocrap := config.h.in configure
182 tarball_pfx := $(PACKAGE_TARNAME)-$(GIT_VERSION)
183 tarball_delete := $(addprefix $(tarball_pfx)/, web .gitignore)
184 tarball := $(tarball_pfx).tar.xz
185
186 all: $(prefixed_executables) $(man_pages)
187 .PHONY: all mostlyclean clean distclean maintainer-clean install \
188         install-strip man dist tarball
189
190 man: $(man_pages)
191
192 include $(lls_m4_dir)/makefile
193 include $(test_dir)/makefile.test
194 include $(yy_src_dir)/makefile
195 ifeq ($(findstring clean, $(MAKECMDGOALS)),)
196 -include $(deps)
197 -include $(m4_lls_deps)
198 endif
199
200 $(object_dir) $(man_dir) $(dep_dir) $(m4depdir) $(lls_suite_dir) \
201         $(yy_build_dir):
202         @$(MKDIR_P) $@
203
204 CPPFLAGS += -DBINDIR='"$(bindir)"'
205 CPPFLAGS += -DCOPYRIGHT_YEAR='"$(COPYRIGHT_YEAR)"'
206 CPPFLAGS += -DBUILD_DATE='"$(build_date)"'
207 CPPFLAGS += -DLOGLEVELS='$(LOGLEVELS)'
208 CPPFLAGS += -DSEVERITIES=$(SEVERITIES)
209 CPPFLAGS += -DUNAME_RS='"$(uname_rs)"'
210 CPPFLAGS += -DCC_VERSION='"$(cc_version)"'
211 CPPFLAGS += -I$(lls_suite_dir)
212 CPPFLAGS += -I$(yy_build_dir)
213 CPPFLAGS += $(lopsub_cppflags)
214 CPPFLAGS += -Wunused-macros
215
216 STRICT_CFLAGS += -fno-strict-aliasing
217 STRICT_CFLAGS += -ftrapv
218 STRICT_CFLAGS += -g
219 STRICT_CFLAGS += -Os
220 STRICT_CFLAGS += -Wundef -W -Wuninitialized
221 STRICT_CFLAGS += -Wchar-subscripts
222 STRICT_CFLAGS += -Werror-implicit-function-declaration
223 STRICT_CFLAGS += -Wmissing-noreturn
224 STRICT_CFLAGS += -Wbad-function-cast
225 STRICT_CFLAGS += -Wredundant-decls
226 STRICT_CFLAGS += -Wno-sign-compare -Wno-unknown-pragmas
227 STRICT_CFLAGS += -Wdeclaration-after-statement
228 STRICT_CFLAGS += -Wformat -Wformat-security -Wmissing-format-attribute
229 STRICT_CFLAGS += -fdata-sections -ffunction-sections
230 STRICT_CFLAGS += -Wstrict-prototypes
231 STRICT_CFLAGS += -Wshadow
232
233 LDFLAGS += -Wl,--gc-sections
234
235 ifeq ($(ENABLE_UBSAN), yes)
236         STRICT_CFLAGS += -fsanitize=undefined
237         LDFLAGS += -lubsan
238 endif
239
240 ifeq ($(uname_s),Linux)
241         # these cause warnings on *BSD
242         STRICT_CFLAGS += -Wunused -Wall
243 endif
244
245 cc-option = $(shell \
246         $(CC) $(1) -Werror -c -x c /dev/null -o /dev/null > /dev/null 2>&1 \
247         && echo "$(1)" \
248 )
249
250 STRICT_CFLAGS += $(call cc-option, -Wformat-signedness)
251 STRICT_CFLAGS += $(call cc-option, -Wdiscarded-qualifiers)
252 STRICT_CFLAGS += $(call cc-option, -Wsuggest-attribute=malloc)
253
254 # To put more focus on warnings, be less verbose as default
255 # Use 'make V=1' to see the full commands
256 ifeq ("$(origin V)", "command line")
257         SAY =
258 else
259         SAY = @echo '$(strip $(1))'
260 endif
261
262 audiod_commands := $(addprefix $(lls_suite_dir)/, \
263         $(addsuffix _cmd.lsg.man, audiod recv filter write))
264 filter_commands := $(lls_suite_dir)/filter_cmd.lsg.man
265 play_commands := $(lls_suite_dir)/play_cmd.lsg.man
266 recv_commands := $(lls_suite_dir)/recv_cmd.lsg.man
267 server_commands := $(lls_suite_dir)/server_cmd.lsg.man
268 write_commands := $(lls_suite_dir)/write_cmd.lsg.man
269
270 $(man_dir)/para_audiod.1: $(audiod_commands)
271 $(man_dir)/para_filter.1: $(filter_commands)
272 $(man_dir)/para_play.1: $(play_commands)
273 $(man_dir)/para_recv.1: $(recv_commands)
274 $(man_dir)/para_server.1: $(server_commands)
275 $(man_dir)/para_write.1: $(write_commands)
276
277 $(man_dir)/para_audiod.1: all_commands := $(audiod_commands)
278 $(man_dir)/para_filter.1: all_commands := $(filter_commands)
279 $(man_dir)/para_play.1: all_commands := $(play_commands)
280 $(man_dir)/para_recv.1: all_commands := $(recv_commands)
281 $(man_dir)/para_server.1: all_commands := $(server_commands)
282 $(man_dir)/para_write.1: all_commands := $(write_commands)
283
284 $(man_dir)/para_%.1: $(lls_suite_dir)/%.lsg.man \
285                 $(lls_m4_dir)/copyright.m4 | $(man_dir)
286         $(call SAY, LLSMAN $<)
287         cat $< $(all_commands) > $@
288         $(M4) -D COPYRIGHT_YEAR=$(COPYRIGHT_YEAR) $(lls_m4_dir)/copyright.m4 >> $@
289
290 $(object_dir)/%.o: %.c | $(object_dir)
291
292 OD = $(addsuffix .d, $(addprefix $(dep_dir)/, $(1))) \
293         $(addsuffix .o, $(addprefix $(object_dir)/, $(1)))
294
295 $(call OD, audiod): \
296         CPPFLAGS += -DAUDIOD_AUDIO_FORMAT_ARRAY='$(audiod_audio_formats)'
297 $(call OD, opus%): CPPFLAGS += $(opus_cppflags)
298 $(call OD, gui gui%): CPPFLAGS += $(curses_cppflags)
299 $(call OD, spx%): CPPFLAGS += $(speex_cppflags)
300 $(call OD, flac%): CPPFLAGS += $(flac_cppflags)
301 $(call OD, mp3_afh): CPPFLAGS += $(id3tag_cppflags)
302 $(call OD, openssl): CPPFLAGS += $(openssl_cppflags)
303 $(call OD, gcrypt): CPPFLAGS += $(gcrypt_cppflags)
304 $(call OD, ao_write): CPPFLAGS += $(ao_cppflags)
305 $(call OD, alsa%): CPPFLAGS += $(alsa_cppflags)
306 $(call OD, interactive): CPPFLAGS += $(readline_cppflags)
307 $(call OD, resample_filter): CPPFLAGS += $(samplerate_cppflags)
308 $(call OD, oss_write): CPPFLAGS += $(oss_cppflags)
309 $(call OD, ao_write): CPPFLAGS += $(ao_cppflags) $(pthread_cppflags)
310 $(call OD, mp3dec_filter): CPPFLAGS += $(mad_cppflags)
311 $(call OD, aacdec_filter aac_afh): CPPFLAGS += $(faad_cppflags)
312 $(call OD, ogg_afh oggdec_filter): CPPFLAGS += $(vorbis_cppflags)
313 $(call OD, spx_common spxdec_filter spx_afh oggdec_filter ogg_afh \
314         ogg_afh_common opus%): CPPFLAGS += $(ogg_cppflags)
315 $(call OD, afs aft attribute blob mood playlist score server vss command \
316         http_send dccp_send udp_send send_common mm.o): \
317         CPPFLAGS += $(osl_cppflags)
318
319 $(call OD, compress_filter): CFLAGS += -O3
320 $(call OD, openssl): CFLAGS += -Wno-deprecated-declarations
321
322 $(object_dir)/%.o: %.c | $(object_dir) $(dep_dir) $(lsg_h) $(yy_h)
323 define CC_CMD
324         $(call SAY, CC $<)
325         $(CC) -c -o $(object_dir)/$(*F).o -MMD -MF \
326                 $(dep_dir)/$(*F).d -MT $(object_dir)/$(*F).o \
327                 $(CPPFLAGS) $(STRICT_CFLAGS) $(CFLAGS) $<
328 endef
329 CC_PREREQUISITES := %.c | $(object_dir) $(dep_dir) $(lsg_h) $(yy_h)
330 # These two have the same prerequisites and the same recipe. There should be a
331 # better way to write this.
332 $(object_dir)/%.o: $(CC_PREREQUISITES)
333         $(CC_CMD)
334 $(dep_dir)/%.d: $(CC_PREREQUISITES)
335         $(CC_CMD)
336
337 para_recv para_afh para_play para_server: LDFLAGS += $(id3tag_ldflags)
338 para_write para_play para_audiod \
339 : LDFLAGS += $(ao_ldflags) $(pthread_ldflags)
340 para_client para_audioc para_play : LDFLAGS += $(readline_ldflags)
341 para_server para_upgrade_db: LDFLAGS += $(osl_ldflags)
342 para_gui: LDFLAGS += $(curses_ldflags)
343 para_server \
344 para_client \
345 para_audiod \
346 :LDFLAGS += \
347         $(crypto_ldflags)
348
349 para_audiod \
350 para_filter \
351 para_play \
352 : LDFLAGS += \
353         $(mad_ldflags) \
354         $(faad_ldflags) \
355         $(samplerate_ldflags) \
356         -lm
357
358 para_mixer: LDFLAGS += -lm
359
360 para_write \
361 para_play \
362 para_audiod \
363 para_mixer \
364 : LDFLAGS += \
365         $(oss_ldflags) \
366         $(alsa_ldflags)
367
368 para_afh \
369 para_audioc \
370 para_audiod \
371 para_client \
372 para_mixer \
373 para_filter \
374 para_gui \
375 para_play \
376 para_recv \
377 para_server \
378 para_upgrade_db \
379 para_write \
380 : LDFLAGS += $(lopsub_ldflags)
381
382 para_server \
383 para_filter \
384 para_audiod \
385 para_play \
386 para_afh \
387 para_recv \
388 : LDFLAGS += \
389         $(ogg_ldflags) \
390         $(vorbis_ldflags) \
391         $(speex_ldflags) \
392         $(opus_ldflags) \
393         $(faad_ldflags) \
394         $(flac_ldflags)
395
396 para_afh para_recv para_server para_play: LDFLAGS += $(iconv_ldflags)
397
398 $(foreach exe,$(executables),$(eval para_$(exe): $$($(exe)_objs)))
399 $(prefixed_executables):
400         $(call SAY, LD $@)
401         $(CC) $^ -o $@ $(LDFLAGS)
402
403 mostlyclean:
404         $(call SAY, MOSTLYCLEAN)
405         rm -f para_*
406         rm -rf $(object_dir)
407 clean: mostlyclean
408         $(call SAY, CLEAN)
409         rm -rf $(build_dir)
410 distclean: clean
411         $(call SAY, DISTCLEAN)
412         rm -f Makefile autoscan.log config.status config.log
413         rm -f config.h configure config.h.in
414 maintainer-clean: distclean test-clean
415         $(call SAY, MAINTAINER-CLEAN)
416         rm -f *.tar.bz2 *.tar.xz
417         rm -f GPATH GRTAGS GSYMS GTAGS
418
419 INSTALL ?= install
420 INSTALL_PROGRAM ?= $(INSTALL)
421 INSTALL_DATA ?= $(INSTALL) -m 644
422 ifneq ($(findstring strip, $(MAKECMDGOALS)),)
423         strip_option := -s
424 endif
425
426 install install-strip: all man
427         $(MKDIR_P) $(DESTDIR)$(bindir) $(DESTDIR)$(mandir)
428         $(INSTALL) $(strip_option) $(prefixed_executables) $(DESTDIR)$(bindir)
429         $(INSTALL_DATA) $(man_pages) $(DESTDIR)$(mandir)
430         $(MKDIR_P) $(DESTDIR)$(vardir) >/dev/null 2>&1 || true # not fatal, so don't complain
431
432 $(tarball) dist tarball:
433         $(call SAY, DIST)
434         rm -rf $(tarball) $(tarball_pfx)
435         git archive --format=tar --prefix=$(tarball_pfx)/ HEAD \
436            | tar --delete $(tarball_delete) > $(tarball_pfx).tar
437         $(MKDIR_P) $(tarball_pfx)
438         ./GIT-VERSION-GEN > $(tarball_pfx)/VERSION
439         cp $(autocrap) $(tarball_pfx)
440         tar rf $(tarball_pfx).tar $(tarball_pfx)/*
441         xz -9 $(tarball_pfx).tar
442         ls -l $(tarball)
443         ln -sf $(tarball) paraslash-git.tar.xz
444         rm -rf $(tarball_pfx)