]> git.tuebingen.mpg.de Git - paraslash.git/blob - Makefile.real
paraslash 0.7.3
[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 .ONESHELL:
10 .SHELLFLAGS := -ec
11
12 LOGLEVELS := LL_DEBUG,LL_INFO,LL_NOTICE,LL_WARNING,LL_ERROR,LL_CRIT,LL_EMERG
13 SEVERITIES := \"debug\",\"info\",\"notice\",\"warning\",\"error\",\"crit\",\"emerg\"
14 vardir := /var/paraslash
15 mandir := $(datarootdir)/man/man1
16 MKDIR_P := mkdir -p
17 prefixed_executables := $(addprefix para_, $(executables))
18
19 build_date := $(shell date)
20 uname_s := $(shell uname -s 2>/dev/null || echo "UNKNOWN_OS")
21 uname_rs := $(shell uname -rs)
22 cc_version := $(shell $(CC) --version | head -n 1)
23 GIT_VERSION := $(shell ./GIT-VERSION-GEN git-version.h)
24 COPYRIGHT_YEAR := 2022
25
26 ifeq ("$(origin O)", "command line")
27         build_dir := $(O)
28 else
29         build_dir := build
30 endif
31 object_dir := $(build_dir)/objects
32 dep_dir := $(build_dir)/deps
33 man_dir := $(build_dir)/man/man1
34 m4depdir := $(build_dir)/m4deps
35 lls_suite_dir := $(build_dir)/lls
36 lls_m4_dir := m4/lls
37 test_dir := t
38 yy_src_dir = yy
39 yy_build_dir = $(build_dir)/yy
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) $(mixer_objs) $(server_objs) \
44         $(write_objs) $(afh_objs) $(play_objs))
45 deps := $(addprefix $(dep_dir)/, $(all_objs:.o=.d))
46 deps += $(addprefix $(dep_dir)/, mp.bison.d mp.flex.d)
47
48 afh_objs += afh.lsg.o
49 audioc_objs += audioc.lsg.o
50 audiod_objs += $(addsuffix _cmd.lsg.o, recv filter audiod write) \
51         client.lsg.o audiod.lsg.o
52 client_objs += client.lsg.o
53 mixer_objs += mixer.lsg.o
54 filter_objs += filter_cmd.lsg.o filter.lsg.o
55 gui_objs += gui.lsg.o
56 play_objs += $(addsuffix _cmd.lsg.o, recv filter play write) play.lsg.o
57 recv_objs += recv_cmd.lsg.o recv.lsg.o
58 server_objs += server_cmd.lsg.o server.lsg.o
59 upgrade_db_objs += upgrade_db.lsg.o
60 write_objs += write_cmd.lsg.o write.lsg.o
61
62 cmd_suites := $(addsuffix _cmd, audiod server play recv filter write)
63 suites := $(addprefix $(lls_suite_dir)/, $(cmd_suites) $(executables))
64 m4_lls_deps := $(addsuffix .m4d, $(suites))
65 lsg_h := $(addsuffix .lsg.h, $(suites))
66
67 # flex/bison objects and headers are only needed if para_server is built
68 ifeq ("$(findstring server, $(executables))", "server")
69         server_objs += mp.flex.o mp.bison.o
70         yy_h := $(yy_build_dir)/mp.bison.h
71 endif
72
73 # now prefix all objects with object dir
74 recv_objs := $(addprefix $(object_dir)/, $(recv_objs))
75 filter_objs := $(addprefix $(object_dir)/, $(filter_objs))
76 client_objs := $(addprefix $(object_dir)/, $(client_objs))
77 gui_objs := $(addprefix $(object_dir)/, $(gui_objs))
78 audiod_objs := $(addprefix $(object_dir)/, $(audiod_objs))
79 audioc_objs := $(addprefix $(object_dir)/, $(audioc_objs))
80 mixer_objs := $(addprefix $(object_dir)/, $(mixer_objs))
81 server_objs := $(addprefix $(object_dir)/, $(server_objs))
82 upgrade_db_objs := $(addprefix $(object_dir)/, $(upgrade_db_objs))
83 write_objs := $(addprefix $(object_dir)/, $(write_objs))
84 afh_objs := $(addprefix $(object_dir)/, $(afh_objs))
85 play_objs := $(addprefix $(object_dir)/, $(play_objs))
86
87 man_pages := $(patsubst %, $(man_dir)/%.1, $(prefixed_executables))
88
89 autocrap := config.h.in configure
90 tarball_pfx := $(PACKAGE_TARNAME)-$(GIT_VERSION)
91 tarball_delete := $(addprefix $(tarball_pfx)/, web .gitignore)
92 tarball := $(tarball_pfx).tar.xz
93
94 all: $(prefixed_executables) $(man_pages)
95 .PHONY: all mostlyclean clean distclean maintainer-clean install \
96         install-strip man dist tarball
97
98 man: $(man_pages)
99
100 include $(lls_m4_dir)/makefile
101 include $(test_dir)/makefile.test
102 include $(yy_src_dir)/makefile
103 ifeq ($(findstring clean, $(MAKECMDGOALS)),)
104 -include $(deps)
105 -include $(m4_lls_deps)
106 endif
107
108 $(object_dir) $(man_dir) $(dep_dir) $(m4depdir) $(lls_suite_dir) \
109         $(yy_build_dir):
110         @$(MKDIR_P) $@
111
112 CPPFLAGS += -DBINDIR='"$(bindir)"'
113 CPPFLAGS += -DCOPYRIGHT_YEAR='"$(COPYRIGHT_YEAR)"'
114 CPPFLAGS += -DBUILD_DATE='"$(build_date)"'
115 CPPFLAGS += -DLOGLEVELS='$(LOGLEVELS)'
116 CPPFLAGS += -DSEVERITIES=$(SEVERITIES)
117 CPPFLAGS += -DUNAME_RS='"$(uname_rs)"'
118 CPPFLAGS += -DCC_VERSION='"$(cc_version)"'
119 CPPFLAGS += -I$(lls_suite_dir)
120 CPPFLAGS += -I$(yy_build_dir)
121 CPPFLAGS += $(lopsub_cppflags)
122
123 STRICT_CFLAGS += -fno-strict-aliasing
124 STRICT_CFLAGS += -g
125 STRICT_CFLAGS += -Os
126 STRICT_CFLAGS += -Wundef -W -Wuninitialized
127 STRICT_CFLAGS += -Wchar-subscripts
128 STRICT_CFLAGS += -Werror-implicit-function-declaration
129 STRICT_CFLAGS += -Wmissing-noreturn
130 STRICT_CFLAGS += -Wbad-function-cast
131 STRICT_CFLAGS += -Wredundant-decls
132 STRICT_CFLAGS += -Wno-sign-compare -Wno-unknown-pragmas
133 STRICT_CFLAGS += -Wdeclaration-after-statement
134 STRICT_CFLAGS += -Wformat -Wformat-security -Wmissing-format-attribute
135
136 ifeq ($(ENABLE_UBSAN), yes)
137         STRICT_CFLAGS += -fsanitize=undefined
138         LDFLAGS += -lubsan
139 endif
140
141 ifeq ($(uname_s),Linux)
142         # these cause warnings on *BSD
143         CPPFLAGS += -Wunused-macros
144         STRICT_CFLAGS += -fdata-sections -ffunction-sections
145         STRICT_CFLAGS += -Wstrict-prototypes
146         STRICT_CFLAGS += -Wshadow
147         STRICT_CFLAGS += -Wunused -Wall
148         LDFLAGS += -Wl,--gc-sections
149 endif
150
151 cc-option = $(shell \
152         $(CC) $(1) -Werror -c -x c /dev/null -o /dev/null > /dev/null 2>&1 \
153         && echo "$(1)" \
154 )
155
156 STRICT_CFLAGS += $(call cc-option, -Wformat-signedness)
157 STRICT_CFLAGS += $(call cc-option, -Wdiscarded-qualifiers)
158
159 # To put more focus on warnings, be less verbose as default
160 # Use 'make V=1' to see the full commands
161 ifeq ("$(origin V)", "command line")
162         SAY =
163 else
164         SAY = @echo '$(strip $(1))'
165 endif
166
167 audiod_commands := $(addprefix $(lls_suite_dir)/, \
168         $(addsuffix _cmd.lsg.man, audiod recv filter write))
169 filter_commands := $(lls_suite_dir)/filter_cmd.lsg.man
170 play_commands := $(lls_suite_dir)/play_cmd.lsg.man
171 recv_commands := $(lls_suite_dir)/recv_cmd.lsg.man
172 server_commands := $(lls_suite_dir)/server_cmd.lsg.man
173 write_commands := $(lls_suite_dir)/write_cmd.lsg.man
174
175 $(man_dir)/para_audiod.1: $(audiod_commands)
176 $(man_dir)/para_filter.1: $(filter_commands)
177 $(man_dir)/para_play.1: $(play_commands)
178 $(man_dir)/para_recv.1: $(recv_commands)
179 $(man_dir)/para_server.1: $(server_commands)
180 $(man_dir)/para_write.1: $(write_commands)
181
182 $(man_dir)/para_audiod.1: all_commands := $(audiod_commands)
183 $(man_dir)/para_filter.1: all_commands := $(filter_commands)
184 $(man_dir)/para_play.1: all_commands := $(play_commands)
185 $(man_dir)/para_recv.1: all_commands := $(recv_commands)
186 $(man_dir)/para_server.1: all_commands := $(server_commands)
187 $(man_dir)/para_write.1: all_commands := $(write_commands)
188
189 $(man_dir)/para_%.1: $(lls_suite_dir)/%.lsg.man \
190                 $(lls_m4_dir)/copyright.m4 | $(man_dir)
191         $(call SAY, LLSMAN $<)
192         cat $< $(all_commands) > $@
193         $(M4) -D COPYRIGHT_YEAR=$(COPYRIGHT_YEAR) $(lls_m4_dir)/copyright.m4 >> $@
194
195 $(object_dir)/%.o: %.c | $(object_dir)
196
197 $(object_dir)/opus%.o: CPPFLAGS += $(opus_cppflags)
198 $(object_dir)/gui.o $(object_dir)/gui%.o \
199 : CPPFLAGS += $(curses_cppflags)
200 $(object_dir)/spx%.o: CPPFLAGS += $(speex_cppflags)
201 $(object_dir)/flac%.o: CPPFLAGS += $(flac_cppflags)
202
203 $(object_dir)/mp3_afh.o: CPPFLAGS += $(id3tag_cppflags)
204 $(object_dir)/openssl.o: CPPFLAGS += $(openssl_cppflags)
205 $(object_dir)/gcrypt.o: CPPFLAGS += $(gcrypt_cppflags)
206 $(object_dir)/ao_write.o: CPPFLAGS += $(ao_cppflags)
207 $(object_dir)/alsa%.o: CPPFLAGS += $(alsa_cppflags)
208
209 $(object_dir)/interactive.o \
210 : CPPFLAGS += $(readline_cppflags)
211
212 $(object_dir)/resample_filter.o \
213 : CPPFLAGS += $(samplerate_cppflags)
214
215 $(object_dir)/oss_write.o \
216 : CPPFLAGS += $(oss_cppflags)
217
218 $(object_dir)/ao_write.o \
219 : CPPFLAGS += $(ao_cppflags) $(pthread_cppflags)
220
221 $(object_dir)/mp3dec_filter.o \
222 : CPPFLAGS += $(mad_cppflags)
223
224 $(object_dir)/aacdec_filter.o \
225 $(object_dir)/aac_afh.o \
226 : CPPFLAGS += $(faad_cppflags)
227
228 $(object_dir)/ogg_afh.o \
229 $(object_dir)/oggdec_filter.o \
230 : CPPFLAGS += $(vorbis_cppflags)
231
232 $(object_dir)/spx_common.o \
233 $(object_dir)/spxdec_filter.o \
234 $(object_dir)/spx_afh.o \
235 $(object_dir)/oggdec_filter.o \
236 $(object_dir)/ogg_afh.o \
237 $(object_dir)/ogg_afh_common.o \
238 $(object_dir)/opus%.o \
239 : CPPFLAGS += $(ogg_cppflags)
240
241 $(object_dir)/afs.o \
242 $(object_dir)/aft.o \
243 $(object_dir)/attribute.o \
244 $(object_dir)/blob.o  \
245 $(object_dir)/mood.o \
246 $(object_dir)/playlist.o \
247 $(object_dir)/score.o \
248 $(object_dir)/server.o \
249 $(object_dir)/vss.o \
250 $(object_dir)/command.o \
251 $(object_dir)/http_send.o \
252 $(object_dir)/dccp_send.o \
253 $(object_dir)/udp_send.o \
254 $(object_dir)/send_common.o \
255 $(object_dir)/mm.o \
256 : CPPFLAGS += $(osl_cppflags)
257
258 $(object_dir)/compress_filter.o: CFLAGS += -O3
259
260 $(object_dir)/%.o: %.c | $(object_dir) $(dep_dir) $(lsg_h) $(yy_h)
261         $(call SAY, CC $<)
262         $(CC) -c -o $@ -MMD -MF $(dep_dir)/$(*F).d -MT $@ $(CPPFLAGS) \
263                 $(STRICT_CFLAGS) $(CFLAGS) $<
264
265 para_recv para_afh para_play para_server: LDFLAGS += $(id3tag_ldflags)
266 para_write para_play para_audiod \
267 : LDFLAGS += $(ao_ldflags) $(pthread_ldflags)
268 para_client para_audioc para_play : LDFLAGS += $(readline_ldflags)
269 para_server para_upgrade_db: LDFLAGS += $(osl_ldflags)
270 para_gui: LDFLAGS += $(curses_ldflags)
271 para_server \
272 para_client \
273 para_audiod \
274 :LDFLAGS += \
275         $(crypto_ldflags)
276
277 para_audiod \
278 para_filter \
279 para_play \
280 : LDFLAGS += \
281         $(mad_ldflags) \
282         $(faad_ldflags) \
283         $(samplerate_ldflags) \
284         -lm
285
286 para_mixer: LDFLAGS += -lm
287
288 para_write \
289 para_play \
290 para_audiod \
291 para_mixer \
292 : LDFLAGS += \
293         $(oss_ldflags) \
294         $(alsa_ldflags)
295
296 para_afh \
297 para_audioc \
298 para_audiod \
299 para_client \
300 para_mixer \
301 para_filter \
302 para_gui \
303 para_play \
304 para_recv \
305 para_server \
306 para_upgrade_db \
307 para_write \
308 : LDFLAGS += $(lopsub_ldflags)
309
310 para_server \
311 para_filter \
312 para_audiod \
313 para_play \
314 para_afh \
315 para_recv \
316 : LDFLAGS += \
317         $(ogg_ldflags) \
318         $(vorbis_ldflags) \
319         $(speex_ldflags) \
320         $(opus_ldflags) \
321         $(faad_ldflags) \
322         $(flac_ldflags)
323
324 para_afh para_recv para_server para_play: LDFLAGS += $(iconv_ldflags)
325
326 $(foreach exe,$(executables),$(eval para_$(exe): $$($(exe)_objs)))
327 $(prefixed_executables):
328         $(call SAY, LD $@)
329         $(CC) $^ -o $@ $(LDFLAGS)
330
331 mostlyclean:
332         $(call SAY, MOSTLYCLEAN)
333         rm -f para_*
334         rm -rf $(object_dir)
335 clean: mostlyclean
336         $(call SAY, CLEAN)
337         rm -rf $(build_dir)
338 distclean: clean
339         $(call SAY, DISTCLEAN)
340         rm -f Makefile autoscan.log config.status config.log
341         rm -f config.h configure config.h.in
342 maintainer-clean: distclean
343         $(call SAY, MAINTAINER-CLEAN)
344         rm -f *.tar.bz2 *.tar.xz
345         rm -f GPATH GRTAGS GSYMS GTAGS
346
347 INSTALL ?= install
348 INSTALL_PROGRAM ?= $(INSTALL)
349 INSTALL_DATA ?= $(INSTALL) -m 644
350 ifneq ($(findstring strip, $(MAKECMDGOALS)),)
351         strip_option := -s
352 endif
353
354 install install-strip: all man
355         $(MKDIR_P) $(DESTDIR)$(bindir) $(DESTDIR)$(mandir)
356         $(INSTALL) $(strip_option) $(prefixed_executables) $(DESTDIR)$(bindir)
357         $(INSTALL_DATA) $(man_pages) $(DESTDIR)$(mandir)
358         $(MKDIR_P) $(DESTDIR)$(vardir) >/dev/null 2>&1 || true # not fatal, so don't complain
359
360 $(tarball) dist tarball:
361         $(call SAY, DIST)
362         rm -rf $(tarball) $(tarball_pfx)
363         git archive --format=tar --prefix=$(tarball_pfx)/ HEAD \
364            | tar --delete $(tarball_delete) > $(tarball_pfx).tar
365         $(MKDIR_P) $(tarball_pfx)
366         ./GIT-VERSION-GEN > $(tarball_pfx)/VERSION
367         cp $(autocrap) $(tarball_pfx)
368         tar rf $(tarball_pfx).tar $(tarball_pfx)/*
369         xz -9 $(tarball_pfx).tar
370         ls -l $(tarball)
371         ln -sf $(tarball) paraslash-git.tar.xz
372         rm -rf $(tarball_pfx)