mood.c: Improve documentation of reload_current_mood().
[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 vardir := /var/paraslash
14 mandir := $(datarootdir)/man/man1
15 MKDIR_P := mkdir -p
16 prefixed_executables := $(addprefix para_, $(executables))
17
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 := 2022
24
25 ifeq ("$(origin O)", "command line")
26         build_dir := $(O)
27 else
28         build_dir := build
29 endif
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
35 lls_m4_dir := m4/lls
36 test_dir := t
37 yy_src_dir = yy
38 yy_build_dir = $(build_dir)/yy
39
40 # sort removes duplicate words, which is all we need here
41 all_objs := $(sort $(recv_objs) $(filter_objs) $(client_objs) $(gui_objs) \
42         $(audiod_objs) $(audioc_objs) $(mixer_objs) $(server_objs) \
43         $(write_objs) $(afh_objs) $(play_objs))
44 deps := $(addprefix $(dep_dir)/, $(all_objs:.o=.d))
45 deps += $(addprefix $(dep_dir)/, mp.bison.d mp.flex.d)
46
47 afh_objs += afh.lsg.o
48 audioc_objs += audioc.lsg.o
49 audiod_objs += $(addsuffix _cmd.lsg.o, recv filter audiod write) \
50         client.lsg.o audiod.lsg.o
51 client_objs += client.lsg.o
52 mixer_objs += mixer.lsg.o
53 filter_objs += filter_cmd.lsg.o filter.lsg.o
54 gui_objs += gui.lsg.o
55 play_objs += $(addsuffix _cmd.lsg.o, recv filter play write) play.lsg.o
56 recv_objs += recv_cmd.lsg.o recv.lsg.o
57 server_objs += server_cmd.lsg.o server.lsg.o
58 upgrade_db_objs += upgrade_db.lsg.o
59 write_objs += write_cmd.lsg.o write.lsg.o
60
61 cmd_suites := $(addsuffix _cmd, audiod server play recv filter write)
62 suites := $(addprefix $(lls_suite_dir)/, $(cmd_suites) $(executables))
63 m4_lls_deps := $(addsuffix .m4d, $(suites))
64 lsg_h := $(addsuffix .lsg.h, $(suites))
65
66 # flex/bison objects and headers are only needed if para_server is built
67 ifeq ("$(findstring server, $(executables))", "server")
68         server_objs += mp.flex.o mp.bison.o
69         yy_h := $(yy_build_dir)/mp.bison.h
70 endif
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 mixer_objs := $(addprefix $(object_dir)/, $(mixer_objs))
80 server_objs := $(addprefix $(object_dir)/, $(server_objs))
81 upgrade_db_objs := $(addprefix $(object_dir)/, $(upgrade_db_objs))
82 write_objs := $(addprefix $(object_dir)/, $(write_objs))
83 afh_objs := $(addprefix $(object_dir)/, $(afh_objs))
84 play_objs := $(addprefix $(object_dir)/, $(play_objs))
85
86 man_pages := $(patsubst %, $(man_dir)/%.1, $(prefixed_executables))
87
88 autocrap := config.h.in configure
89 tarball_pfx := $(PACKAGE_TARNAME)-$(GIT_VERSION)
90 tarball_delete := $(addprefix $(tarball_pfx)/, web .gitignore)
91 tarball := $(tarball_pfx).tar.xz
92
93 all: $(prefixed_executables) $(man_pages)
94 .PHONY: all mostlyclean clean distclean maintainer-clean install \
95         install-strip man dist tarball
96
97 man: $(man_pages)
98
99 include $(lls_m4_dir)/makefile
100 include $(test_dir)/makefile.test
101 include $(yy_src_dir)/makefile
102 ifeq ($(findstring clean, $(MAKECMDGOALS)),)
103 -include $(deps)
104 -include $(m4_lls_deps)
105 endif
106
107 $(object_dir) $(man_dir) $(dep_dir) $(m4depdir) $(lls_suite_dir) \
108         $(yy_build_dir):
109         @$(MKDIR_P) $@
110
111 CPPFLAGS += -DBINDIR='"$(bindir)"'
112 CPPFLAGS += -DCOPYRIGHT_YEAR='"$(COPYRIGHT_YEAR)"'
113 CPPFLAGS += -DBUILD_DATE='"$(build_date)"'
114 CPPFLAGS += -DLOGLEVELS='$(LOGLEVELS)'
115 CPPFLAGS += -DUNAME_RS='"$(uname_rs)"'
116 CPPFLAGS += -DCC_VERSION='"$(cc_version)"'
117 CPPFLAGS += -I$(lls_suite_dir)
118 CPPFLAGS += -I$(yy_build_dir)
119 CPPFLAGS += $(lopsub_cppflags)
120
121 STRICT_CFLAGS += -fno-strict-aliasing
122 STRICT_CFLAGS += -g
123 STRICT_CFLAGS += -Os
124 STRICT_CFLAGS += -Wundef -W -Wuninitialized
125 STRICT_CFLAGS += -Wchar-subscripts
126 STRICT_CFLAGS += -Werror-implicit-function-declaration
127 STRICT_CFLAGS += -Wmissing-noreturn
128 STRICT_CFLAGS += -Wbad-function-cast
129 STRICT_CFLAGS += -Wredundant-decls
130 STRICT_CFLAGS += -Wno-sign-compare -Wno-unknown-pragmas
131 STRICT_CFLAGS += -Wdeclaration-after-statement
132 STRICT_CFLAGS += -Wformat -Wformat-security -Wmissing-format-attribute
133
134 ifeq ($(ENABLE_UBSAN), yes)
135         STRICT_CFLAGS += -fsanitize=undefined
136         LDFLAGS += -lubsan
137 endif
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 STRICT_CFLAGS += $(call cc-option, -Wdiscarded-qualifiers)
156
157 # To put more focus on warnings, be less verbose as default
158 # Use 'make V=1' to see the full commands
159 ifeq ("$(origin V)", "command line")
160         SAY =
161 else
162         SAY = @echo '$(strip $(1))'
163 endif
164
165 audiod_commands := $(addprefix $(lls_suite_dir)/, \
166         $(addsuffix _cmd.lsg.man, audiod recv filter write))
167 filter_commands := $(lls_suite_dir)/filter_cmd.lsg.man
168 play_commands := $(lls_suite_dir)/play_cmd.lsg.man
169 recv_commands := $(lls_suite_dir)/recv_cmd.lsg.man
170 server_commands := $(lls_suite_dir)/server_cmd.lsg.man
171 write_commands := $(lls_suite_dir)/write_cmd.lsg.man
172
173 $(man_dir)/para_audiod.1: $(audiod_commands)
174 $(man_dir)/para_filter.1: $(filter_commands)
175 $(man_dir)/para_play.1: $(play_commands)
176 $(man_dir)/para_recv.1: $(recv_commands)
177 $(man_dir)/para_server.1: $(server_commands)
178 $(man_dir)/para_write.1: $(write_commands)
179
180 $(man_dir)/para_audiod.1: all_commands := $(audiod_commands)
181 $(man_dir)/para_filter.1: all_commands := $(filter_commands)
182 $(man_dir)/para_play.1: all_commands := $(play_commands)
183 $(man_dir)/para_recv.1: all_commands := $(recv_commands)
184 $(man_dir)/para_server.1: all_commands := $(server_commands)
185 $(man_dir)/para_write.1: all_commands := $(write_commands)
186
187 $(man_dir)/para_%.1: $(lls_suite_dir)/%.lsg.man \
188                 $(lls_m4_dir)/copyright.m4 | $(man_dir)
189         $(call SAY, LLSMAN $<)
190         cat $< $(all_commands) > $@
191         $(M4) -D COPYRIGHT_YEAR=$(COPYRIGHT_YEAR) $(lls_m4_dir)/copyright.m4 >> $@
192
193 $(object_dir)/%.o: %.c | $(object_dir)
194
195 $(object_dir)/opus%.o: CPPFLAGS += $(opus_cppflags)
196 $(object_dir)/gui.o $(object_dir)/gui%.o \
197 : CPPFLAGS += $(curses_cppflags)
198 $(object_dir)/spx%.o: CPPFLAGS += $(speex_cppflags)
199 $(object_dir)/flac%.o: CPPFLAGS += $(flac_cppflags)
200
201 $(object_dir)/mp3_afh.o: CPPFLAGS += $(id3tag_cppflags)
202 $(object_dir)/openssl.o: CPPFLAGS += $(openssl_cppflags)
203 $(object_dir)/gcrypt.o: CPPFLAGS += $(gcrypt_cppflags)
204 $(object_dir)/ao_write.o: CPPFLAGS += $(ao_cppflags)
205 $(object_dir)/alsa%.o: CPPFLAGS += $(alsa_cppflags)
206
207 $(object_dir)/interactive.o \
208 : CPPFLAGS += $(readline_cppflags)
209
210 $(object_dir)/resample_filter.o \
211 : CPPFLAGS += $(samplerate_cppflags)
212
213 $(object_dir)/oss_write.o \
214 : CPPFLAGS += $(oss_cppflags)
215
216 $(object_dir)/ao_write.o \
217 : CPPFLAGS += $(ao_cppflags) $(pthread_cppflags)
218
219 $(object_dir)/mp3dec_filter.o \
220 : CPPFLAGS += $(mad_cppflags)
221
222 $(object_dir)/aacdec_filter.o \
223 $(object_dir)/aac_afh.o \
224 : CPPFLAGS += $(faad_cppflags)
225
226 $(object_dir)/ogg_afh.o \
227 $(object_dir)/oggdec_filter.o \
228 : CPPFLAGS += $(vorbis_cppflags)
229
230 $(object_dir)/spx_common.o \
231 $(object_dir)/spxdec_filter.o \
232 $(object_dir)/spx_afh.o \
233 $(object_dir)/oggdec_filter.o \
234 $(object_dir)/ogg_afh.o \
235 $(object_dir)/ogg_afh_common.o \
236 $(object_dir)/opus%.o \
237 : CPPFLAGS += $(ogg_cppflags)
238
239 $(object_dir)/afs.o \
240 $(object_dir)/aft.o \
241 $(object_dir)/attribute.o \
242 $(object_dir)/blob.o  \
243 $(object_dir)/mood.o \
244 $(object_dir)/playlist.o \
245 $(object_dir)/score.o \
246 $(object_dir)/server.o \
247 $(object_dir)/vss.o \
248 $(object_dir)/command.o \
249 $(object_dir)/http_send.o \
250 $(object_dir)/dccp_send.o \
251 $(object_dir)/udp_send.o \
252 $(object_dir)/send_common.o \
253 $(object_dir)/mm.o \
254 : CPPFLAGS += $(osl_cppflags)
255
256 $(object_dir)/compress_filter.o: CFLAGS += -O3
257
258 define CC_CMD
259         $(call SAY, CC $<)
260         $(CC) -c -o $(object_dir)/$(*F).o -MMD -MF \
261                 $(dep_dir)/$(*F).d -MT $(object_dir)/$(*F).o \
262                 $(CPPFLAGS) $(STRICT_CFLAGS) $(CFLAGS) $<
263 endef
264 CC_PREREQUISITES := %.c | $(object_dir) $(dep_dir) $(lsg_h) $(yy_h)
265 # These two have the same prerequisites and the same recipe. There should be a
266 # better way to write this.
267 $(object_dir)/%.o: $(CC_PREREQUISITES)
268         $(CC_CMD)
269 $(dep_dir)/%.d: $(CC_PREREQUISITES)
270         $(CC_CMD)
271
272 para_recv para_afh para_play para_server: LDFLAGS += $(id3tag_ldflags)
273 para_write para_play para_audiod \
274 : LDFLAGS += $(ao_ldflags) $(pthread_ldflags)
275 para_client para_audioc para_play : LDFLAGS += $(readline_ldflags)
276 para_server para_upgrade_db: LDFLAGS += $(osl_ldflags)
277 para_gui: LDFLAGS += $(curses_ldflags)
278 para_server \
279 para_client \
280 para_audiod \
281 :LDFLAGS += \
282         $(crypto_ldflags)
283
284 para_audiod \
285 para_filter \
286 para_play \
287 : LDFLAGS += \
288         $(mad_ldflags) \
289         $(faad_ldflags) \
290         $(samplerate_ldflags) \
291         -lm
292
293 para_mixer: LDFLAGS += -lm
294
295 para_write \
296 para_play \
297 para_audiod \
298 para_mixer \
299 : LDFLAGS += \
300         $(oss_ldflags) \
301         $(alsa_ldflags)
302
303 para_afh \
304 para_audioc \
305 para_audiod \
306 para_client \
307 para_mixer \
308 para_filter \
309 para_gui \
310 para_play \
311 para_recv \
312 para_server \
313 para_upgrade_db \
314 para_write \
315 : LDFLAGS += $(lopsub_ldflags)
316
317 para_server \
318 para_filter \
319 para_audiod \
320 para_play \
321 para_afh \
322 para_recv \
323 : LDFLAGS += \
324         $(ogg_ldflags) \
325         $(vorbis_ldflags) \
326         $(speex_ldflags) \
327         $(opus_ldflags) \
328         $(faad_ldflags) \
329         $(flac_ldflags)
330
331 para_afh para_recv para_server para_play: LDFLAGS += $(iconv_ldflags)
332
333 $(foreach exe,$(executables),$(eval para_$(exe): $$($(exe)_objs)))
334 $(prefixed_executables):
335         $(call SAY, LD $@)
336         $(CC) $^ -o $@ $(LDFLAGS)
337
338 mostlyclean:
339         $(call SAY, MOSTLYCLEAN)
340         rm -f para_*
341         rm -rf $(object_dir)
342 clean: mostlyclean
343         $(call SAY, CLEAN)
344         rm -rf $(build_dir)
345 distclean: clean
346         $(call SAY, DISTCLEAN)
347         rm -f Makefile autoscan.log config.status config.log
348         rm -f config.h configure config.h.in
349 maintainer-clean: distclean
350         $(call SAY, MAINTAINER-CLEAN)
351         rm -f *.tar.bz2 *.tar.xz
352         rm -f GPATH GRTAGS GSYMS GTAGS
353
354 INSTALL ?= install
355 INSTALL_PROGRAM ?= $(INSTALL)
356 INSTALL_DATA ?= $(INSTALL) -m 644
357 ifneq ($(findstring strip, $(MAKECMDGOALS)),)
358         strip_option := -s
359 endif
360
361 install install-strip: all man
362         $(MKDIR_P) $(DESTDIR)$(bindir) $(DESTDIR)$(mandir)
363         $(INSTALL) $(strip_option) $(prefixed_executables) $(DESTDIR)$(bindir)
364         $(INSTALL_DATA) $(man_pages) $(DESTDIR)$(mandir)
365         $(MKDIR_P) $(DESTDIR)$(vardir) >/dev/null 2>&1 || true # not fatal, so don't complain
366
367 $(tarball) dist tarball:
368         $(call SAY, DIST)
369         rm -rf $(tarball) $(tarball_pfx)
370         git archive --format=tar --prefix=$(tarball_pfx)/ HEAD \
371            | tar --delete $(tarball_delete) > $(tarball_pfx).tar
372         $(MKDIR_P) $(tarball_pfx)
373         ./GIT-VERSION-GEN > $(tarball_pfx)/VERSION
374         cp $(autocrap) $(tarball_pfx)
375         tar rf $(tarball_pfx).tar $(tarball_pfx)/*
376         xz -9 $(tarball_pfx).tar
377         ls -l $(tarball)
378         ln -sf $(tarball) paraslash-git.tar.xz
379         rm -rf $(tarball_pfx)