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