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