cb3bcaa3f16463e0b0f4a9167d225f669483683f
[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 $@ $(CPPFLAGS) $(STRICT_CFLAGS) $<
252
253 # The compiler outputs dependencies either as foo.h or as some_directory/foo.h,
254 # depending on whether the latter file exists. Since make needs the directory
255 # part we prefix the dependency as appropriate.
256 $(dep_dir)/%.d: %.c | $(dep_dir)
257         @[ -z "$(Q)" ] || echo 'DEP $<'
258         $(Q) $(CC) $(CPPFLAGS) -MM -MG -MT $@ -MT $(object_dir)/$(*F).o $< \
259                 | sed -e "s@ \([a-zA-Z0-9_]\{1,\}.lsg.h\)@ $(lls_suite_dir)/\1@g" > $@
260
261 para_recv para_afh para_play para_server: LDFLAGS += $(id3tag_ldflags)
262 para_write para_play para_audiod \
263 : LDFLAGS += $(ao_ldflags) $(pthread_ldflags) $(core_audio_ldflags)
264 para_client para_audioc para_play : LDFLAGS += $(readline_ldflags)
265 para_server: LDFLAGS += $(osl_ldflags)
266 para_gui: LDFLAGS += $(curses_ldflags)
267 para_server \
268 para_client \
269 para_audiod \
270 :LDFLAGS += \
271         $(crypto_ldflags)
272
273 para_audiod \
274 para_filter \
275 para_play \
276 : LDFLAGS += \
277         $(mad_ldflags) \
278         $(faad_ldflags) \
279         $(samplerate_ldflags) \
280         -lm
281
282 para_write \
283 para_play \
284 para_audiod \
285 para_fade \
286 : LDFLAGS += \
287         $(oss_ldflags) \
288         $(alsa_ldflags)
289
290 para_afh \
291 para_audioc \
292 para_audiod \
293 para_client \
294 para_fade \
295 para_filter \
296 para_gui \
297 para_play \
298 para_recv \
299 para_server \
300 para_write \
301 : LDFLAGS += $(lopsub_ldflags)
302
303 para_server \
304 para_filter \
305 para_audiod \
306 para_play \
307 para_afh \
308 para_recv \
309 : LDFLAGS += \
310         $(ogg_ldflags) \
311         $(vorbis_ldflags) \
312         $(speex_ldflags) \
313         $(opus_ldflags) \
314         $(faad_ldflags) \
315         $(flac_ldflags)
316
317 para_server \
318 para_play \
319 para_afh \
320 para_recv \
321 : LDFLAGS += \
322         $(mp4v2_ldflags)
323
324 para_afh para_recv para_server para_play: LDFLAGS += $(iconv_ldflags)
325
326 $(foreach exe,$(executables),$(eval para_$(exe): $$($(exe)_objs)))
327 $(prefixed_executables):
328         @[ -z "$(Q)" ] || echo 'LD $@'
329         $(Q) $(CC) $^ -o $@ $(LDFLAGS)
330
331 clean:
332         @[ -z "$(Q)" ] || echo 'CLEAN'
333         $(Q) rm -f para_*
334         $(Q) rm -rf $(object_dir)
335
336 clean2: clean
337         @[ -z "$(Q)" ] || echo 'CLEAN2'
338         $(Q) rm -rf $(build_dir)
339 distclean: clean2 test-clean
340         @[ -z "$(Q)" ] || echo 'DISTCLEAN'
341         $(Q) rm -f Makefile autoscan.log config.status config.log
342         $(Q) rm -f GPATH GRTAGS GSYMS GTAGS
343
344 maintainer-clean: distclean
345         @[ -z "$(Q)" ] || echo 'MAINTAINER-CLEAN'
346         $(Q) rm -f *.tar.bz2 config.h configure config.h.in
347
348 install: all man
349         $(MKDIR_P) $(bindir) $(mandir)
350         $(INSTALL) -s --strip-program $(STRIP) -m 755 \
351                 $(prefixed_executables) $(bindir)
352         $(INSTALL) -m 644 $(man_pages) $(mandir)
353         $(MKDIR_P) $(vardir) >/dev/null 2>&1 || true # not fatal, so don't complain
354
355 $(tarball):
356         $(Q) rm -rf $(tarball) $(tarball_pfx)
357         $(Q) git archive --format=tar --prefix=$(tarball_pfx)/ HEAD \
358                 | tar --delete $(tarball_delete) > $(tarball_pfx).tar
359         $(Q) $(MKDIR_P) $(tarball_pfx)
360         $(Q) ./GIT-VERSION-GEN > $(tarball_pfx)/VERSION
361         $(Q) cp $(autocrap) $(tarball_pfx)
362         $(Q) tar rf $(tarball_pfx).tar $(tarball_pfx)/*
363         $(Q) bzip2 -9 $(tarball_pfx).tar
364         $(Q) ls -l $(tarball)
365         $(Q) ln -sf $(tarball) paraslash-git.tar.bz2
366         $(Q) rm -rf $(tarball_pfx)