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