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