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