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