summaryrefslogtreecommitdiff
path: root/Makefile
blob: 078095befc85ef13e647ea8900bde6140ef7f79f (plain)
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
PROJECT = rabbit

DEPS = rabbitmq-common
dep_rabbitmq-common= git file:///home/dumbbell/Projects/pivotal/other-repos/rabbitmq-common master

.DEFAULT_GOAL = all

# --------------------------------------------------------------------
# Man pages.
# --------------------------------------------------------------------

DOCS_DIR     = docs
MANPAGES     = $(patsubst %.xml, %.gz, $(wildcard $(DOCS_DIR)/*.[0-9].xml))
WEB_MANPAGES = $(patsubst %.xml, %.man.xml, $(wildcard $(DOCS_DIR)/*.[0-9].xml) $(DOCS_DIR)/rabbitmq-service.xml $(DOCS_DIR)/rabbitmq-echopid.xml)
USAGES_XML   = $(DOCS_DIR)/rabbitmqctl.1.xml $(DOCS_DIR)/rabbitmq-plugins.1.xml
USAGES_ERL   = $(foreach XML, $(USAGES_XML), $(call usage_xml_to_erl, $(XML)))

# xmlto can not read from standard input, so we mess with a tmp file.
%.gz: %.xml $(DOCS_DIR)/examples-to-end.xsl
	xmlto --version | grep -E '^xmlto version 0\.0\.([0-9]|1[1-8])$$' >/dev/null || opt='--stringparam man.indent.verbatims=0' ; \
	    xsltproc --novalid $(DOCS_DIR)/examples-to-end.xsl $< > $<.tmp && \
	    xmlto -o $(DOCS_DIR) $$opt man $<.tmp && \
	    gzip -f $(DOCS_DIR)/`basename $< .xml`
	rm -f $<.tmp

# Use tmp files rather than a pipeline so that we get meaningful errors
# Do not fold the cp into previous line, it's there to stop the file being
# generated but empty if we fail
src/%_usage.erl:
	xsltproc --novalid --stringparam modulename "`basename $@ .erl`" \
		$(DOCS_DIR)/usage.xsl $< > $@.tmp
	sed -e 's/"/\\"/g' -e 's/%QUOTE%/"/g' $@.tmp > $@.tmp2
	fold -s $@.tmp2 > $@.tmp3
	mv $@.tmp3 $@
	rm $@.tmp $@.tmp2

# We rename the file before xmlto sees it since xmlto will use the name of
# the file to make internal links.
%.man.xml: %.xml $(DOCS_DIR)/html-to-website-xml.xsl
	cp $< `basename $< .xml`.xml && \
		xmlto xhtml-nochunks `basename $< .xml`.xml ; rm `basename $< .xml`.xml
	cat `basename $< .xml`.html | \
	    xsltproc --novalid $(DOCS_DIR)/remove-namespaces.xsl - | \
		xsltproc --novalid --stringparam original `basename $<` $(DOCS_DIR)/html-to-website-xml.xsl - | \
		xmllint --format - > $@
	rm `basename $< .xml`.html

define usage_xml_to_erl
$(subst __,_,$(patsubst $(DOCS_DIR)/rabbitmq%.1.xml, src/rabbit_%_usage.erl, $(subst -,_,$(1))))
endef

define usage_dep
$(call usage_xml_to_erl, $(1)):: $(1) $(DOCS_DIR)/usage.xsl
endef

$(foreach XML,$(USAGES_XML),$(eval $(call usage_dep, $(XML))))

# --------------------------------------------------------------------
# Back to main targets.
# --------------------------------------------------------------------

include erlang.mk

ebin/$(PROJECT).app:: $(USAGES_ERL)
	$(if $(strip $?),$(call compile_erl,$?))

clean:: clean-generated

clean-generated:
	$(gen_verbose) rm -f $(USAGES_ERL)

ERLC_OPTS += -I $(DEPS_DIR)/rabbitmq-common/include

ifdef INSTRUMENT_FOR_QC
ERLC_OPTS += -DINSTR_MOD=gm_qc
else
ERLC_OPTS += -DINSTR_MOD=gm
endif

ifdef CREDIT_FLOW_TRACING
ERLC_OPTS += -DCREDIT_FLOW_TRACING=true
endif

define boolean_macro
$(if $(filter true,$(1)),-D$(2))
endef

ifndef USE_SPECS
# our type specs rely on dict:dict/0 etc, which are only available in 17.0
# upwards.
USE_SPECS := $(shell erl -noshell -eval 'io:format([list_to_integer(X) || X <- string:tokens(erlang:system_info(version), ".")] >= [5,11]), halt().')
ERLC_OPTS += $(call boolean_macro,$(USE_SPECS),use_specs)
endif

ifndef USE_PROPER_QC
# PropEr needs to be installed for property checking
# http://proper.softlab.ntua.gr/
USE_PROPER_QC := $(shell erl -noshell -eval 'io:format({module, proper} =:= code:ensure_loaded(proper)), halt().')
ERLC_OPTS     += $(call boolean_macro,$(USE_PROPER_QC),use_proper_qc)
endif