build: Combine rules for object files.
[paraslash.git] / Makefile.in
1 prefix := @prefix@
2 exec_prefix := @exec_prefix@
3
4 BINDIR := @bindir@
5 VARDIR := /var/paraslash
6 MANDIR := @datarootdir@/man/man1
7 PACKAGE_VERSION := @PACKAGE_VERSION@
8 INSTALL := @install@
9 STRIP := $(CROSS_COMPILE)strip
10 HOSTCC ?= cc
11 executables := $(addprefix para_, @executables@)
12 ggo_descriptions_declared := @ggo_descriptions_declared@
13 object_executable_matrix := @object_executable_matrix@
14
15
16 GENGETOPT := @gengetopt@
17 HELP2MAN := @help2man@
18 MKDIR_P := mkdir -p
19
20 speex_cppflags := @speex_cppflags@
21 opus_cppflags := @opus_cppflags@
22 arch_cppflags := @arch_cppflags@
23 osl_cppflags := @osl_cppflags@
24 id3tag_cppflags := @id3tag_cppflags@
25 openssl_cppflags := @openssl_cppflags@
26 ogg_cppflags := @ogg_cppflags@
27 mad_cppflags := @mad_cppflags@
28 faad_cppflags := @faad_cppflags@
29 curses_cppflags := @curses_cppflags@
30 ao_cppflags := @ao_cppflags@
31
32 id3tag_ldflags := @id3tag_ldflags@
33 ogg_ldflags := @ogg_ldflags@
34 vorbis_ldflags := @vorbis_ldflags@
35 speex_ldflags := @speex_ldflags@
36 opus_ldflags := @opus_ldflags@
37 faad_ldflags := @faad_ldflags@
38 mad_ldflags := @mad_ldflags@
39 flac_ldflags := @flac_ldflags@
40 oss_ldflags := @oss_ldflags@
41 alsa_ldflags := @alsa_ldflags@
42 ao_ldflags := @ao_ldflags@
43 readline_ldflags := @readline_ldflags@
44 samplerate_ldflags := @samplerate_ldflags@
45 osl_ldflags := @osl_ldflags@
46 openssl_ldflags := @openssl_ldflags@
47 gcrypt_ldflags := @gcrypt_ldflags@
48 socket_ldflags := @socket_ldflags@
49 nsl_ldflags := @nsl_ldflags@
50 curses_ldflags := @curses_ldflags@
51 core_audio_ldflags := @core_audio_ldflags@
52
53 build_date := $(shell date)
54 uname_s := $(shell uname -s 2>/dev/null || echo "UNKNOWN_OS")
55 uname_rs := $(shell uname -rs)
56 cc_version := $(shell $(CC) --version | head -n 1)
57
58 GIT_VERSION := $(shell ./GIT-VERSION-GEN git-version.h)
59
60 m4_ggo_dir := m4/gengetopt
61 test_dir := t
62 ifeq ("$(origin O)", "command line")
63         build_dir := $(O)
64 else
65         build_dir := build
66 endif
67 ggo_dir := $(build_dir)/ggo
68 object_dir := $(build_dir)/objects
69 dep_dir := $(build_dir)/deps
70 man_dir := $(build_dir)/man/man1
71 cmdline_dir := $(build_dir)/cmdline
72 m4depdir := $(build_dir)/m4deps
73 help2man_dir := $(build_dir)/help2man
74 hostbin_dir := $(build_dir)/host/bin
75
76 DEBUG_CPPFLAGS += -g -Wunused -Wundef -W
77 DEBUG_CPPFLAGS += -Wredundant-decls
78 DEBUG_CPPFLAGS += -Wall -Wno-sign-compare -Wno-unknown-pragmas
79 DEBUG_CPPFLAGS += -Wformat-security
80 DEBUG_CPPFLAGS += -Wmissing-format-attribute
81
82 ifeq ($(uname_s),Linux)
83         CPPFLAGS += -fdata-sections -ffunction-sections
84         LDFLAGS += -Wl,--gc-sections
85         CPPFLAGS += -Wstrict-prototypes
86         CPPFLAGS += -Wshadow
87         # causes warnings on *BSD for the feature test macros
88         CPPFLAGS += -Wunused-macros
89 endif
90 CPPFLAGS += -Os
91 CPPFLAGS += -Wuninitialized
92 CPPFLAGS += -Wchar-subscripts
93 CPPFLAGS += -DBINDIR='"$(BINDIR)"'
94 CPPFLAGS += -DBUILD_DATE='"$(build_date)"'
95 CPPFLAGS += -DUNAME_RS='"$(uname_rs)"'
96 CPPFLAGS += -DCC_VERSION='"$(cc_version)"'
97 CPPFLAGS += -Werror-implicit-function-declaration
98 CPPFLAGS += -Wmissing-noreturn
99 CPPFLAGS += -Wbad-function-cast
100 CPPFLAGS += -fno-strict-aliasing
101 CPPFLAGS += -DMAIN_INPUT_FILE_IS_$(*F)
102 CPPFLAGS += $(arch_cppflags)
103 CPPFLAGS += -I/usr/local/include
104 CPPFLAGS += -I$(cmdline_dir)
105 CPPFLAGS += $(osl_cppflags)
106
107 LDFLAGS += @clock_gettime_ldflags@
108
109 man_pages := $(patsubst %, $(man_dir)/%.1, $(executables))
110
111 autocrap := config.h.in configure
112 tarball_pfx := @PACKAGE_TARNAME@-$(PACKAGE_VERSION)
113 tarball_delete := $(addprefix $(tarball_pfx)/,\
114         web .changelog_before_cvs .changelog_cvs .gitignore)
115 tarball := @PACKAGE_TARNAME@-$(PACKAGE_VERSION).tar.bz2
116
117 # To put more focus on warnings, be less verbose as default
118 # Use 'make V=1' to see the full commands
119 ifeq ("$(origin V)", "command line")
120         Q :=
121 else
122         Q := @
123 endif
124
125 .PHONY: dep all clean distclean maintainer-clean install man tarball
126 all: dep $(executables) $(man_pages)
127 dep: $(deps)
128 man: $(man_pages)
129 tarball: $(tarball)
130
131 $(object_dir) $(man_dir) $(ggo_dir) $(cmdline_dir) $(dep_dir) $(m4depdir) \
132                 $(help2man_dir) $(hostbin_dir):
133         $(Q) $(MKDIR_P) $@
134
135 -include $(m4_ggo_dir)/makefile
136
137 # When in doubt, use brute force (Ken Thompson)
138 TOUPPER = \
139 $(subst a,A,$(subst b,B,$(subst c,C,$(subst d,D,$(subst e,E,\
140 $(subst f,F,$(subst g,G,$(subst h,H,$(subst i,I,$(subst j,J,\
141 $(subst k,K,$(subst l,L,$(subst m,M,$(subst n,N,$(subst o,O,\
142 $(subst p,P,$(subst q,Q,$(subst r,R,$(subst s,S,$(subst t,T,\
143 $(subst u,U,$(subst v,V,$(subst w,W,$(subst x,X,$(subst y,Y,\
144 $(subst z,Z,$1))))))))))))))))))))))))))
145
146 %_command_list.h: %.cmd %.c
147         @[ -z "$(Q)" ] || echo 'GEN $@'
148         $(Q) ./command_util.sh h < $< >$@
149 %_command_list.man: %.cmd %.c
150         @[ -z "$(Q)" ] || echo 'GEN $@'
151         $(Q) ./command_util.sh man < $< > $@
152 %_completion.h: %.cmd %.c
153         @[ -z "$(Q)" ] || echo 'GEN $@'
154         $(Q) ./command_util.sh compl $(strip $(call TOUPPER,$(*F)))_COMPLETERS \
155                 $(strip $(call TOUPPER,$(*F)))_COMMANDS < $< > $@
156
157 server_command_list.h server_command_list.man server_completion.h: command.c
158 afs_command_list.h afs_command_list.man afs_completion.h: afs.c aft.c attribute.c
159 audiod_command_list.h audiod_command_list.man audiod_completion.h: audiod_command.c
160
161 server_command_lists_man = server_command_list.man afs_command_list.man
162 $(man_dir)/para_server.1: $(help2man_dir)/para_server $(server_command_lists_man) | $(man_dir)
163         @[ -z "$(Q)" ] || echo 'MAN $<'
164         $(Q) opts="`for i in $(server_command_lists_man); do printf "%s\n" "-i $$i"; done`"; \
165         $(HELP2MAN) $$opts ./$< > $@
166
167 $(man_dir)/para_audiod.1: $(help2man_dir)/para_audiod audiod_command_list.man | $(man_dir)
168         @[ -z "$(Q)" ] || echo 'MAN $<'
169         $(Q) $(HELP2MAN) -N -i audiod_command_list.man ./$< > $@
170
171 $(man_dir)/para_play.1: $(help2man_dir)/para_play play_command_list.man | $(man_dir)
172         @[ -z "$(Q)" ] || echo 'MAN $<'
173         $(Q) $(HELP2MAN) -N -i play_command_list.man ./$< > $@
174
175 $(man_dir)/%.1: $(help2man_dir)/% | $(man_dir)
176         @[ -z "$(Q)" ] || echo 'MAN $<'
177         $(Q) $(HELP2MAN) -N ./$< > $@
178
179 $(hostbin_dir)/error2: error2.c | $(hostbin_dir)
180         @[ -z "$(Q)" ] || echo 'HCC $<'
181         $(Q) $(HOSTCC) -o $@ $<
182 error2.h: $(hostbin_dir)/error2
183         @[ -z "$(Q)" ] || echo 'ER2 $<'
184         @echo "$(object_executable_matrix)" | $< > $@
185
186 $(object_dir)/%.o: %.c | $(object_dir)
187 $(object_dir)/opus%.o: CPPFLAGS += $(opus_cppflags)
188 $(object_dir)/gui%.o: CPPFLAGS += $(curses_cppflags)
189 $(object_dir)/spx%.o: CPPFLAGS += $(speex_cppflags)
190 $(object_dir)/%.cmdline.o: CPPFLAGS += -Wno-unused-function
191
192 $(object_dir)/mp3_afh.o: CPPFLAGS += $(id3tag_cppflags)
193 $(object_dir)/crypt.o: CPPFLAGS += $(openssl_cppflags)
194 $(object_dir)/mp3dec_filter.o: CPPFLAGS += $(mad_cppflags)
195 $(object_dir)/compress_filter.o: CPPFLAGS += -O3
196 $(object_dir)/ao_write.o: CPPFLAGS += $(ao_cppflags)
197
198 $(object_dir)/aacdec_filter.o \
199 $(object_dir)/aac_common.o \
200 $(object_dir)/aac_afh.o \
201 : CPPFLAGS += $(faad_cppflags)
202
203 $(object_dir)/spx_common.o \
204 $(object_dir)/spxdec_filter.o \
205 $(object_dir)/spx_afh.o \
206 $(object_dir)/oggdec_filter.o \
207 $(object_dir)/ogg_afh.o \
208 $(object_dir)/ogg_afh_common.o \
209 : CPPFLAGS += $(ogg_cppflags)
210
211 $(object_dir)/%.o: %.c | $(object_dir)
212         @[ -z "$(Q)" ] || echo 'CC $<'
213         $(Q) $(CC) -c -o $@ $(CPPFLAGS) $(DEBUG_CPPFLAGS) $<
214
215 $(object_dir)/%.cmdline.o: $(cmdline_dir)/%.cmdline.c $(cmdline_dir)/%.cmdline.h | $(object_dir)
216         @[ -z "$(Q)" ] || echo 'CC $<'
217         $(Q) $(CC) -c $(CPPFLAGS) -Wno-unused-function -o $@ $<
218
219 $(object_dir)/%.o: %.c | $(object_dir)
220         @[ -z "$(Q)" ] || echo 'CC $<'
221         $(Q) $(CC) -c -o $@ $(CPPFLAGS) $(DEBUG_CPPFLAGS) $<
222
223 $(dep_dir)/%.cmdline.d: $(cmdline_dir)/%.cmdline.c | $(dep_dir)
224         @[ -z "$(Q)" ] || echo 'DEP $<'
225         $(Q) ./depend.sh $(dep_dir) $(object_dir) $(cmdline_dir) \
226                 $(CPPFLAGS) $< > $@
227
228 $(dep_dir)/%.d: %.c | $(dep_dir)
229         @[ -z "$(Q)" ] || echo 'DEP $<'
230         $(Q) ./depend.sh $(dep_dir) $(object_dir) $(cmdline_dir) \
231                 $(CPPFLAGS) $< > $@
232
233 # sort removes duplicate words, which is all we need here
234 all_objs := $(sort @recv_objs@ @filter_objs@ @client_objs@ @gui_objs@ \
235         @audiod_objs@ @audioc_objs@ @fade_objs@ @server_objs@ \
236         @write_objs@ @afh_objs@ @play_objs@)
237 deps := $(addprefix $(dep_dir)/, $(all_objs:.o=.d))
238 m4_deps := $(addprefix $(m4depdir)/, $(addsuffix .m4d, @executables@))
239
240 recv_objs := $(addprefix $(object_dir)/, @recv_objs@)
241 filter_objs := $(addprefix $(object_dir)/, @filter_objs@)
242 client_objs := $(addprefix $(object_dir)/, @client_objs@)
243 gui_objs := $(addprefix $(object_dir)/, @gui_objs@)
244 audiod_objs := $(addprefix $(object_dir)/, @audiod_objs@)
245 audioc_objs := $(addprefix $(object_dir)/, @audioc_objs@)
246 fade_objs := $(addprefix $(object_dir)/, @fade_objs@)
247 server_objs := $(addprefix $(object_dir)/, @server_objs@)
248 write_objs := $(addprefix $(object_dir)/, @write_objs@)
249 afh_objs := $(addprefix $(object_dir)/, @afh_objs@)
250 play_objs := $(addprefix $(object_dir)/, @play_objs@)
251
252 ifeq ($(findstring clean, $(MAKECMDGOALS)),)
253 -include $(deps)
254 -include $(m4_deps)
255 endif
256
257 para_recv para_afh para_play para_server: LDFLAGS += $(id3tag_ldflags)
258 para_write para_play para_audiod: LDFLAGS += $(ao_ldflags) $(core_audio_ldflags)
259 para_client para_audioc para_play : LDFLAGS += $(readline_ldflags)
260 para_server: LDFLAGS += $(osl_ldflags)
261 para_gui: LDFLAGS += $(curses_ldflags)
262 para_server \
263 para_client \
264 para_audiod \
265 :LDFLAGS += \
266         $(openssl_ldflags) \
267         $(gcrypt_ldflags)
268
269 para_audiod \
270 para_filter \
271 para_play \
272 : LDFLAGS += \
273         $(mad_ldflags) \
274         $(samplerate_ldflags) \
275         -lm
276
277 para_write \
278 para_play \
279 para_audiod \
280 para_fade \
281 : LDFLAGS += \
282         $(oss_ldflags) \
283         $(alsa_ldflags)
284
285 para_server \
286 para_filter \
287 para_audiod \
288 para_play \
289 para_afh \
290 para_recv \
291 : LDFLAGS += \
292         $(ogg_ldflags) \
293         $(vorbis_ldflags) \
294         $(speex_ldflags) \
295         $(opus_ldflags) \
296         $(faad_ldflags) \
297         $(flac_ldflags)
298
299 para_server \
300 para_client \
301 para_audioc \
302 para_audiod \
303 para_recv \
304 : LDFLAGS += \
305         $(socket_ldflags) $(nsl_ldflags)
306
307 para_recv: $(recv_objs)
308         @[ -z "$(Q)" ] || echo 'LD $@'
309         $(Q) $(CC) $(recv_objs) -o $@ $(LDFLAGS)
310
311 para_filter: $(filter_objs)
312         @[ -z "$(Q)" ] || echo 'LD $@'
313         $(Q) $(CC) $(filter_objs) -o $@ $(LDFLAGS)
314
315 para_client: $(client_objs)
316         @[ -z "$(Q)" ] || echo 'LD $@'
317         $(Q) $(CC) -o $@ $(client_objs) $(LDFLAGS)
318
319 para_gui: $(gui_objs)
320         @[ -z "$(Q)" ] || echo 'LD $@'
321         $(Q) $(CC) -o $@ $(gui_objs) $(LDFLAGS)
322
323 para_audiod: $(audiod_objs)
324         @[ -z "$(Q)" ] || echo 'LD $@'
325         $(Q) $(CC) -o $@ $(audiod_objs) $(LDFLAGS)
326
327 para_audioc: $(audioc_objs)
328         @[ -z "$(Q)" ] || echo 'LD $@'
329         $(Q) $(CC) -o $@ $(audioc_objs) $(LDFLAGS)
330
331 para_fade: $(fade_objs)
332         @[ -z "$(Q)" ] || echo 'LD $@'
333         $(Q) $(CC) -o $@ $(fade_objs) $(LDFLAGS)
334
335 para_server: $(server_objs)
336         @[ -z "$(Q)" ] || echo 'LD $@'
337         $(Q) $(CC) -o $@ $(server_objs) $(LDFLAGS)
338
339 para_write: $(write_objs)
340         @[ -z "$(Q)" ] || echo 'LD $@'
341         $(Q) $(CC) -o $@ $(write_objs) $(LDFLAGS)
342
343 para_afh: $(afh_objs)
344         @[ -z "$(Q)" ] || echo 'LD $@'
345         $(Q) $(CC) -o $@ $(afh_objs) $(LDFLAGS)
346
347 para_play: $(play_objs)
348         @[ -z "$(Q)" ] || echo 'LD $@'
349         $(Q) $(CC) -o $@ $(play_objs) $(LDFLAGS)
350
351 clean:
352         @[ -z "$(Q)" ] || echo 'CLEAN'
353         $(Q) rm -f $(executables)
354         $(Q) rm -rf $(object_dir)
355
356 clean2: clean
357         @[ -z "$(Q)" ] || echo 'CLEAN2'
358         $(Q) rm -f *_command_list.* *_completion.h
359         $(Q) rm -rf $(build_dir)
360 distclean: clean2 test-clean
361         @[ -z "$(Q)" ] || echo 'DISTCLEAN'
362         $(Q) rm -f Makefile autoscan.log config.status config.log
363         $(Q) rm -rf autom4te.cache
364         $(Q) rm -f GPATH GRTAGS GSYMS GTAGS
365
366 maintainer-clean: distclean
367         rm -f *.tar.bz2 config.h configure config.h.in
368         rm -rf web_sync
369
370 install: all man
371         $(MKDIR_P) $(BINDIR) $(MANDIR)
372         $(INSTALL) -s --strip-program $(STRIP) -m 755 $(executables) $(BINDIR)
373         $(INSTALL) -m 644 $(man_pages) $(MANDIR)
374         $(MKDIR_P) $(VARDIR) >/dev/null 2>&1 || true # not fatal, so don't complain
375
376 $(tarball):
377         rm -rf $(tarball_pfx).tar.bz2 $(tarball_pfx)
378         git archive --format=tar --prefix=$(tarball_pfx)/ HEAD \
379                 | tar --delete $(tarball_delete) > $(tarball_pfx).tar
380         $(MKDIR_P) $(tarball_pfx)
381         ./GIT-VERSION-GEN > $(tarball_pfx)/VERSION
382         cp -r $(autocrap) $(tarball_pfx)
383         tar rf $(tarball_pfx).tar $(tarball_pfx)/*
384         bzip2 -9 $(tarball_pfx).tar
385         ls -l $(tarball_pfx).tar.bz2
386         rm -rf $(tarball_pfx)
387 include $(test_dir)/makefile.test