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