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