File: Makefile.rules

package info (click to toggle)
liquidsoap 1.1.1-7.2
  • links: PTS, VCS
  • area: main
  • in suites: sid, stretch
  • size: 4,568 kB
  • ctags: 4,447
  • sloc: ml: 34,126; python: 956; makefile: 630; sh: 493; perl: 258; lisp: 62; ansic: 43; ruby: 8
file content (270 lines) | stat: -rw-r--r-- 7,921 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
## -*- mode: makefile -*-

.PHONY: all all-subdirs all-local
.PHONY: all-auto all-auto-ocaml-prog clean-buildings
.PHONY: clean clean-subdirs clean-local
.PHONY: install install-subdirs install-local
.PHONY: dist tarball dist-subdirs dist-local
.PHONY: doc doc-local doc-subdirs doc-auto

include $(top_srcdir)/Makefile.defs

all: all-local all-subdirs all-auto
install: install-local install-subdirs
clean: clean-subdirs clean-local clean-buildings
	rm -f *.~ *.orig *.cmo *.cmi *.cmx *.cma *.cmxa *.cmxs *.o *.so *.a *.annot
doc: doc-local doc-subdirs doc-auto

# Those rules must be bound

all-local:
install-local:
clean-local:

# Recursions

all-subdirs:
	@for dir in $(SUBDIRS) ; do \
		$(MAKE) -C $$dir all || exit $$? ; \
	done

install-subdirs:
	@for dir in $(SUBDIRS) ; do \
		$(MAKE) -C $$dir install || exit $$? ; \
	done

clean-subdirs:
	-@for dir in $(SUBDIRS) ; do \
		$(MAKE) -C $$dir clean || exit $$? ; \
	done

doc-subdirs:
	-@for dir in $(SUBDIRS) ; do \
		$(MAKE) -C $$dir doc || exit $$? ; \
	done

#
# Automatic buildings
#
##############################################################################

clean-buildings:
	@if test -f auto_clean ; then \
		cat auto_clean | xargs rm -f ; \
		rm -f auto_clean ; \
	fi
ifdef ocaml_tests
	rm -f *_depend
endif
ifdef ocaml_progs
	rm -f *_depend
	rm -f $(ocaml_progs)$(EXEEXT)
endif

all-auto: all-auto-ocaml-prog

all-auto-ocaml-prog:
	@for prog in $(ocaml_progs) $(if $(BUILD_TESTS),$(ocaml_tests)) ; do \
		$(MAKE) PROG=$$prog $$prog$(EXEEXT) || exit $$? ; \
	done

ifdef PROG
$(PROG)_mly=$(wildcard $($(PROG)_sources:.ml=.mly))
$(PROG)_headers=$(wildcard $($(PROG)_sources:.ml=.mli)) $($(PROG)_mly:.mly=.mli)
# Grab program-specific flags
_OCAML_CFLAGS=$($(PROG)_ocamlcflags)
_OCAML_LFLAGS=$($(PROG)_ocamllflags)

-include $(PROG)_depend

# Include plugin sources for dependencies computation..
plugins_sources=
$(foreach plug,$($(PROG)_PLUGINS),$(eval plugins_sources+=$($(plug)_sources)))

$(PROG)_depend: $($(PROG)_sources) $($(PROG)_headers) $(plugins_sources)
	$(V)echo OCAMLDEP
	$(V)$(OCAMLDEP) $(_DEP_OPTS) $(DEP_OPTS) \
		$($(PROG)_sources) $($(PROG)_headers) $(plugins_sources) > $@

dll$(PROG).so: $($(PROG)_c_files:.c=.o)
	$(V)echo OCAMLMKLIB -o dll$(PROG).so
	$(V)$(OCAMLMKLIB) -o $(PROG) $($(PROG)_c_files:.c=.o)

ifdef $(PROG)_c_files
  ifeq ($(BYTE),yes)
    ifeq ($(NO_CUSTOM),yes)
        c_objs=dll$(PROG).so $($(PROG)_c_files:.c=.o)
        c_link=-dllib dll$(PROG).so
    else
      c_objs=$($(PROG)_c_files:.c=.o)
      c_link=-custom $($(PROG)_c_files:.c=.o)
    endif
  else
    c_objs=$($(PROG)_c_files:.c=.o)
    c_link=$(c_objs)
  endif
endif

$(PROG)$(EXEEXT): $($(PROG)_sources:.ml=.$(o)) $(c_objs) $($(PROG)_PLUGINS:%=plugins/%.$(s))
	$(V)echo $(OCAMLCOMP) -o $(PROG)$(EXEEXT)
	$(V)$(OCAMLC) -o $(PROG)$(EXEEXT) \
		$(_OCAML_CFLAGS) $(OCAML_CFLAGS) \
		$(_OCAML_LFLAGS) $(OCAML_LFLAGS) \
		$($(PROG)_sources:.ml=.$(o)) \
		$(c_link)
endif

# Compute C dependencies
# Apparently, dynamic modules cannot
# use the custom mode..
plug_c_link = \
$(if $($(1)_c_sources),\
 $(if $(BYTE),\
   $(eval $(1)_clink = dllliquidsoap_$(1).so),\
   $(eval $(1)_clink = $$($(1)_c_sources:.c=.o))))
$(foreach plug,$($(PROG)_PLUGINS),$(call plug_c_link,$(plug)))
plug_c_objs = \
$(if $($(1)_c_sources),\
 $(if $(BYTE),\
    $(eval $(1)_c_objs = $$($(1)_c_sources:.c=.o) plugins/dllliquidsoap_$(1).so),\
    $(eval $(1)_c_objs = $$($(1)_c_sources:.c=.o))))
$(foreach plug,$($(PROG)_PLUGINS),$(call plug_c_objs,$(plug)))

# Compute plugins dependencies
plug_deps = \
$(eval plugins/$(1).$$(s): $$($(1)_sources:.ml=.$$(o)) $$($(1)_c_objs))
$(foreach plug,$($(PROG)_PLUGINS),$(call plug_deps,$(plug)))

# Compute plugins dependencies that are not already
# linked with liquidsoap
plug_packages = \
  $(if $(findstring $(2),$($(PROG)_ocamllflags) $($(PROG)_ocamlcflags)),$(eval $(1)_dontlink += $(2)),$(eval $(1)_ocamllflags += -package $(2)))
$(foreach plug,$($(PROG)_PLUGINS),\
    $(foreach package,$($(plug)_packages),$(call plug_packages,$(plug),$(package))))

# In order to avoid loading multiple times
# the same module, we need to avoid the following
# link:
vorbis_dontlink += ogg
speex_dontlink += ogg
theora_dontlink += ogg
schroedinger_dontlink += ogg
flac_dontlink += ogg
flac_ogg_dontlink += ogg flac
lastfm_dontlink += xmlm xmlplaylist

# Lo name is too generic for the above test to pass
lo_dontlink =
lo_ocamllflags += -package lo

# Here is how compilation of .ml files work:
# We concatenate all {C,L}FLAGS for .ml compilation.
# However, when linking the final objects, we seperate them back.
_OCAML_ALL_CFLAGS=$(_OCAML_CFLAGS)
_OCAML_ALL_LFLAGS=$(_OCAML_LFLAGS)
$(foreach plug,$($(PROG)_PLUGINS),$(eval _OCAML_ALL_CFLAGS+=$($(plug)_ocamlcflags)))
$(foreach plug,$($(PROG)_PLUGINS),$(eval _OCAML_ALL_CFLAGS+=$($(plug)_packages:%=-package %)))
$(foreach plug,$($(PROG)_PLUGINS),$(eval _OCAML_ALL_LFLAGS+=$($(plug)_ocamllflags)))

plugins/%.$(s):
	$(V)echo $(OCAMLCOMP) ${shared_flag} $@
	$(V)$(OCAMLC) ${shared_flag} -linkpkg $($*_ocamlcflags) $($*_ocamllflags) \
		$($*_clink) $($*_sources:.ml=.$(o)) -dontlink "$($*_dontlink)" -o $@

plugins/dllliquidsoap_%.so:
	$(V)echo OCAMLMKLIB -o plugins/dllliquidsoap_$*.so
	$(V)$(OCAMLMKLIB) -o plugins/liquidsoap_$* $($*_c_sources:.c=.o)

%.ml: %.camlp4
	$(V)echo CAMLP4O $<
	$(V)$(CAMLP4O) -printer Camlp4OCamlPrinter -impl $< > $@

%.ml: %.mll
	@echo $(@:.ml=.mli) $(@:.mli=.ml) >> auto_clean
	$(V)echo OCAMLLEX $<
	$(V)$(OCAMLLEX) $<
%.ml %.mli: %.mly
	@echo $(@:.ml=.mli) $(@:.mli=.ml) >> auto_clean
	$(V)echo OCAMLYACC $<
	$(V)$(OCAMLYACC) $<

%.$(o): %.ml
	$(V)echo $(OCAMLCOMP) -c $<
	$(V)$(OCAMLC) $(_OCAML_ALL_CFLAGS) $(OCAML_CFLAGS) -c $<
%.$(i): %.mli
	$(V)echo $(OCAMLCOMP) -c $<
	$(V)$(OCAMLC) $(_OCAML_ALL_CFLAGS) $(OCAML_CFLAGS) -c $<

%.o: %.c
	$(V)echo CC -c $<
	$(V)$(CC) $(CFLAGS) -c $< -o $@

#
# dist
#
##############################################################################

dist-subdirs:
	for dir in $(SUBDIRS) ; do \
		mkdir $(DDIR)/$$dir || exit $$? ; \
		DDIR="../$(DDIR)/$$dir" $(MAKE) -C $$dir dist-local \
		|| exit $$? ; \
	done

dist-local: dist-subdirs
ifdef DISTFILES
	cp $(DISTFILES) $(DDIR)
endif
ifdef DISTDIRS
	cp -rfL $(DISTDIRS) $(DDIR)
endif
	find $(DDIR) -name .svn | while read i; do rm -rf "$$i"; done
	find $(DDIR) -name .git | while read i; do rm -rf "$$i"; done

dist:
	@a=`cd $(top_srcdir) ; pwd ` ; b=`pwd` ; [ "eq$$a" = "eq$$b" ] \
		|| (echo You must be at toplevel to invoke make dist. \
			&& exit $$?)
	rm -rf $(DISTDIR)
	mkdir $(DISTDIR)
	DDIR=$(DISTDIR) $(MAKE) dist-local

configure: configure.ac install-sh
	./bootstrap
	./configure-with-options || ./configure

tarball: configure pre-distclean dist
	tar cjf $(DISTDIR).tar.bz2 $(DISTDIR)
	rm -rf $(DISTDIR)

#
# Documentation
#
###############################################################################

ifdef PROG

# Extract the -I and -package options from the ocaml_cflags,
# but not those coming from e.g. -ccopt "-I.. -fPIC"
_OCAML_DFLAGS=$(shell echo '$(_OCAML_CFLAGS) $(OCAML_CFLAGS)' | perl -pe '$$opt = "" ; s/"[^"]*"//g ; s/(-I\s*\S+|-package\s*\S+)/my $$a = $$1 ; if ($$a =~ m:-package\s*(\S)(\S+):) { $$opt="$$opt $$a -hide ".(uc $$1).$$2 } else { $$opt="$$opt $$a" }/eg ; $$_ = $$opt')
_OCAML_DFILES=$(shell echo $($(PROG)_doc_sources) | perl -pe 's/[^\s]+\.[co]//g')
_OCAML_DFILES_H=$(wildcard $(_OCAML_DFILES:.ml=.mli))

$(top_srcdir)/autodoc/$(PROG)/index.html: $($(PROG)_doc_sources)
	mkdir -p $(top_srcdir)/autodoc/$(PROG)
	$(OCAMLFIND) ocamldoc -stars -sort -html -d $(top_srcdir)/autodoc/$(PROG) \
	-t $(PROG) -I +threads \
	$(OCAML_DFLAGS) $(_OCAML_DFLAGS) $(_OCAML_DFILES) $(_OCAML_DFILES_H)

endif

ifdef ocaml_progs
doc-auto: all-auto-ocaml-prog
	for prog in $(ocaml_progs) ; do \
		PROG=$$prog $(MAKE) $(top_srcdir)/autodoc/$$prog/index.html \
                || exit $$? ; \
	done
endif

doc-clean:
	rm -rf $(top_srcdir)/autodoc/*