1AC_DEFUN([YELP_HELP_INIT],
2[
3AC_REQUIRE([AC_PROG_LN_S])
4m4_pattern_allow([AM_V_at])
5m4_pattern_allow([AM_V_GEN])
6m4_pattern_allow([AM_DEFAULT_VERBOSITY])
7
8YELP_LC_MEDIA_LINKS=true
9YELP_LC_DIST=true
10
11for yelpopt in [$1]; do
12  case $yelpopt in
13    lc-media-links)    YELP_LC_MEDIA_LINKS=true ;;
14    no-lc-media-links) YELP_LC_MEDIA_LINKS= ;;
15    lc-dist)           YELP_LC_DIST=true ;;
16    no-lc-dist)        YELP_LC_DIST= ;;
17    *) AC_MSG_ERROR([Unrecognized [YELP_HELP_INIT] option $yelpopt"]) ;;
18  esac
19done;
20AC_SUBST([YELP_LC_MEDIA_LINKS])
21AC_SUBST([YELP_LC_DIST])
22
23AC_ARG_WITH([help-dir],
24            AS_HELP_STRING([--with-help-dir=DIR],
25                           [path where help files are installed]),,
26            [with_help_dir='${datadir}/help'])
27HELP_DIR="$with_help_dir"
28AC_SUBST(HELP_DIR)
29
30AC_ARG_VAR([ITSTOOL], [Path to the `itstool` command])
31AC_CHECK_PROG([ITSTOOL], [itstool], [itstool])
32if test x"$ITSTOOL" = x; then
33  AC_MSG_ERROR([itstool not found])
34fi
35
36AC_ARG_VAR([XMLLINT], [Path to the `xmllint` command])
37AC_CHECK_PROG([XMLLINT], [xmllint], [xmllint])
38if test x"$XMLLINT" = x; then
39  AC_MSG_ERROR([xmllint not found])
40fi
41
42YELP_HELP_RULES='
43HELP_ID ?=
44HELP_POT ?=
45HELP_FILES ?=
46HELP_EXTRA ?=
47HELP_MEDIA ?=
48HELP_LINGUAS ?=
49
50_HELP_LINGUAS = $(if $(filter environment,$(origin LINGUAS)),$(filter $(LINGUAS),$(HELP_LINGUAS)),$(HELP_LINGUAS))
51_HELP_POTFILE = $(if $(HELP_POT),$(HELP_POT),$(if $(HELP_ID),$(HELP_ID).pot))
52_HELP_POFILES = $(if $(HELP_ID),$(foreach lc,$(_HELP_LINGUAS),$(lc)/$(lc).po))
53_HELP_MOFILES = $(patsubst %.po,%.mo,$(_HELP_POFILES))
54_HELP_C_FILES = $(foreach f,$(HELP_FILES),C/$(f))
55_HELP_C_EXTRA = $(foreach f,$(HELP_EXTRA),C/$(f))
56_HELP_C_MEDIA = $(foreach f,$(HELP_MEDIA),C/$(f))
57_HELP_LC_FILES = $(foreach lc,$(_HELP_LINGUAS),$(foreach f,$(HELP_FILES),$(lc)/$(f)))
58_HELP_LC_STAMPS = $(foreach lc,$(_HELP_LINGUAS),$(lc)/$(lc).stamp)
59
60_HELP_DEFAULT_V = $(if $(AM_DEFAULT_VERBOSITY),$(AM_DEFAULT_VERBOSITY),1)
61_HELP_V = $(if $(V),$(V),$(_HELP_DEFAULT_V))
62_HELP_LC_VERBOSE = $(_HELP_LC_VERBOSE_$(_HELP_V))
63_HELP_LC_VERBOSE_ = $(_HELP_LC_VERBOSE_$(_HELP_DEFAULT_V))
64_HELP_LC_VERBOSE_0 = @echo "  GEN    "$(dir [$]@);
65
66all: $(_HELP_C_FILES) $(_HELP_C_EXTRA) $(_HELP_C_MEDIA) $(_HELP_LC_FILES) $(_HELP_POFILES)
67
68.PHONY: pot
69pot: $(_HELP_POTFILE)
70$(_HELP_POTFILE): $(_HELP_C_FILES) $(_HELP_C_EXTRA) $(_HELP_C_MEDIA)
71	$(AM_V_GEN)if test -d "C"; then d=; else d="$(srcdir)/"; fi; \
72	$(ITSTOOL) -o "[$]@" $(foreach f,$(_HELP_C_FILES),"$${d}$(f)")
73
74.PHONY: repo
75repo: $(_HELP_POTFILE)
76	$(AM_V_at)for po in $(_HELP_POFILES); do \
77	  if test "x[$](_HELP_V)" = "x0"; then echo "  GEN    $${po}"; fi; \
78	  msgmerge -q -o "$${po}" "$${po}" "$(_HELP_POTFILE)"; \
79	done
80
81$(_HELP_POFILES):
82	$(AM_V_at)if ! test -d "$(dir [$]@)"; then mkdir "$(dir [$]@)"; fi
83	$(AM_V_at)if test ! -f "[$]@" -a -f "$(srcdir)/[$]@"; then cp "$(srcdir)/[$]@" "[$]@"; fi
84	$(AM_V_GEN)if ! test -f "[$]@"; then \
85	  (cd "$(dir [$]@)" && \
86	    $(ITSTOOL) -o "$(notdir [$]@).tmp" $(_HELP_C_FILES) && \
87	    mv "$(notdir [$]@).tmp" "$(notdir [$]@)"); \
88	else \
89	  (cd "$(dir [$]@)" && \
90	    $(ITSTOOL) -o "$(notdir [$]@).tmp" $(_HELP_C_FILES) && \
91	    msgmerge -o "$(notdir [$]@)" "$(notdir [$]@)" "$(notdir [$]@).tmp" && \
92	    rm "$(notdir [$]@).tmp"); \
93	fi
94
95$(_HELP_MOFILES): %.mo: %.po
96	$(AM_V_at)if ! test -d "$(dir [$]@)"; then mkdir "$(dir [$]@)"; fi
97	$(AM_V_GEN)msgfmt -o "[$]@" "$<"
98
99$(_HELP_LC_FILES): $(_HELP_LINGUAS)
100$(_HELP_LINGUAS): $(_HELP_LC_STAMPS)
101$(_HELP_LC_STAMPS): %.stamp: %.mo
102$(_HELP_LC_STAMPS): $(_HELP_C_FILES) $(_HELP_C_EXTRA)
103	$(AM_V_at)if ! test -d "$(dir [$]@)"; then mkdir "$(dir [$]@)"; fi
104	$(_HELP_LC_VERBOSE)if test -d "C"; then d="../"; else d="$(abs_srcdir)/"; fi; \
105	mo="$(dir [$]@)$(patsubst %/$(notdir [$]@),%,[$]@).mo"; \
106	if test -f "$${mo}"; then mo="../$${mo}"; else mo="$(abs_srcdir)/$${mo}"; fi; \
107	(cd "$(dir [$]@)" && $(ITSTOOL) -m "$${mo}" $(foreach f,$(_HELP_C_FILES),$${d}/$(f))) && \
108	touch "[$]@"
109
110.PHONY: clean-help
111mostlyclean-am: $(if $(HELP_ID),clean-help)
112clean-help:
113	rm -f $(_HELP_LC_FILES) $(_HELP_LC_STAMPS) $(_HELP_MOFILES)
114
115EXTRA_DIST ?=
116EXTRA_DIST += $(_HELP_C_EXTRA) $(_HELP_C_MEDIA)
117EXTRA_DIST += $(if $(YELP_LC_DIST),$(foreach lc,$(HELP_LINGUAS),$(lc)/$(lc).stamp))
118EXTRA_DIST += $(foreach lc,$(HELP_LINGUAS),$(lc)/$(lc).po)
119EXTRA_DIST += $(foreach f,$(HELP_MEDIA),$(foreach lc,$(HELP_LINGUAS),$(wildcard $(lc)/$(f))))
120
121distdir: distdir-help-files
122distdir-help-files: $(_HELP_LC_FILES)
123	@for lc in C $(if $(YELP_LC_DIST),$(HELP_LINGUAS)) ; do \
124	  $(MKDIR_P) "$(distdir)/$$lc"; \
125	  for file in $(HELP_FILES); do \
126	    if test -f "$$lc/$$file"; then d=./; else d=$(srcdir)/; fi; \
127	    cp -p "$$d$$lc/$$file" "$(distdir)/$$lc/" || exit 1; \
128	  done; \
129	done; \
130
131.PHONY: check-help
132check: check-help
133check-help:
134	for lc in C $(_HELP_LINGUAS); do \
135	  if test -d "$$lc"; \
136	    then d=; \
137	    xmlpath="$$lc"; \
138	  else \
139	    d="$(srcdir)/"; \
140	    xmlpath="$$lc:$(srcdir)/$$lc"; \
141	  fi; \
142	  for page in $(HELP_FILES); do \
143	    echo "$(XMLLINT) --nonet --noout --noent --path $$xmlpath --xinclude $$d$$lc/$$page"; \
144	    $(XMLLINT) --nonet --noout --noent --path "$$xmlpath" --xinclude "$$d$$lc/$$page"; \
145	  done; \
146	done
147
148
149.PHONY: install-help
150install-data-am: $(if $(HELP_ID),install-help)
151install-help: $(_HELP_LC_FILES)
152	@for lc in C $(_HELP_LINGUAS); do \
153	  $(mkinstalldirs) "$(DESTDIR)$(HELP_DIR)/$$lc/$(HELP_ID)" || exit 1; \
154	done
155	@for lc in C $(_HELP_LINGUAS); do for f in $(HELP_FILES); do \
156	  if test -f "$$lc/$$f"; then d=; else d="$(srcdir)/"; fi; \
157	  helpdir="$(DESTDIR)$(HELP_DIR)/$$lc/$(HELP_ID)/"; \
158	  if ! test -d "$$helpdir"; then $(mkinstalldirs) "$$helpdir"; fi; \
159	  echo "$(INSTALL_DATA) $$d$$lc/$$f $$helpdir`basename $$f`"; \
160	  $(INSTALL_DATA) "$$d$$lc/$$f" "$$helpdir`basename $$f`" || exit 1; \
161	done; done
162	@for f in $(_HELP_C_EXTRA); do \
163	  lc=`dirname "$$f"`; lc=`basename "$$lc"`; \
164	  if test -f "$$f"; then d=; else d="$(srcdir)/"; fi; \
165	  helpdir="$(DESTDIR)$(HELP_DIR)/$$lc/$(HELP_ID)/"; \
166	  if ! test -d "$$helpdir"; then $(mkinstalldirs) "$$helpdir"; fi; \
167	  echo "$(INSTALL_DATA) $$d$$f $$helpdir`basename $$f`"; \
168	  $(INSTALL_DATA) "$$d$$f" "$$helpdir`basename $$f`" || exit 1; \
169	done
170	@for f in $(HELP_MEDIA); do \
171	  for lc in C $(_HELP_LINGUAS); do \
172	    if test -f "$$lc$$f"; then d=; else d="$(srcdir)/"; fi; \
173	    helpdir="$(DESTDIR)$(HELP_DIR)/$$lc/$(HELP_ID)/"; \
174	    mdir=`dirname "$$f"`; \
175	    if test "x$mdir" = "x."; then mdir=""; fi; \
176	    if ! test -d "$$helpdir$$mdir"; then $(mkinstalldirs) "$$helpdir$$mdir"; fi; \
177	    if test -f "$$d$$lc/$$f"; then \
178	      echo "$(INSTALL_DATA) $$d$$lc/$$f $$helpdir$$f"; \
179	      $(INSTALL_DATA) "$$d$$lc/$$f" "$$helpdir$$f" || exit 1; \
180	    elif test "x$$lc" != "xC"; then \
181	      if test "x$(YELP_LC_MEDIA_LINKS)" != "x"; then \
182	        echo "$(LN_S) -f $(HELP_DIR)/C/$(HELP_ID)/$$f $$helpdir$$f"; \
183	        $(LN_S) -f "$(HELP_DIR)/C/$(HELP_ID)/$$f" "$$helpdir$$f" || exit 1; \
184	      fi; \
185	    fi; \
186	  done; \
187	done
188
189.PHONY: uninstall-help
190uninstall-am: $(if $(HELP_ID),uninstall-help)
191uninstall-help:
192	for lc in C $(_HELP_LINGUAS); do for f in $(HELP_FILES); do \
193	  helpdir="$(DESTDIR)$(HELP_DIR)/$$lc/$(HELP_ID)/"; \
194	  echo "rm -f $$helpdir`basename $$f`"; \
195	  rm -f "$$helpdir`basename $$f`"; \
196	done; done
197	@for f in $(_HELP_C_EXTRA); do \
198	  lc=`dirname "$$f"`; lc=`basename "$$lc"`; \
199	  helpdir="$(DESTDIR)$(HELP_DIR)/$$lc/$(HELP_ID)/"; \
200	  echo "rm -f $$helpdir`basename $$f`"; \
201	  rm -f "$$helpdir`basename $$f`"; \
202	done
203	@for f in $(HELP_MEDIA); do \
204	  for lc in C $(_HELP_LINGUAS); do \
205	    helpdir="$(DESTDIR)$(HELP_DIR)/$$lc/$(HELP_ID)/"; \
206	    echo "rm -f $$helpdir$$f"; \
207	    rm -f "$$helpdir$$f"; \
208	  done; \
209	done;
210'
211AC_SUBST([YELP_HELP_RULES])
212m4_ifdef([_AM_SUBST_NOTMAKE], [_AM_SUBST_NOTMAKE([YELP_HELP_RULES])])
213])
214