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