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