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