# release: update-latest-release (commit) tag

LOCALES = ja

ACLOCAL_AMFLAGS = -I m4
AUTOMAKE_OPTIONS = 1.9.6
SUBDIRS =					\
	build					\
	include					\
	vendor					\
	lib					\
	plugins					\
	src					\
	examples				\
	test					\
	benchmark				\
	packages				\
	data					\
	tools					\
	doc
EXTRA_DIST =					\
	CMakeLists.txt				\
	README.md				\
	base_version				\
	bindings				\
	bundled_lz4_version			\
	bundled_mecab_naist_jdic_version	\
	bundled_mecab_version			\
	bundled_rapidjson_version		\
	bundled_xxhash_version			\
	config.h.cmake				\
	gpg_uid					\
	nginx_version				\
	version-gen.sh
pkgdata_DATA = COPYING

pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = groonga.pc
if GRN_WITH_APACHE_ARROW
pkgconfig_DATA += groonga-arrow.pc
endif

.PHONY: FORCE

FORCE:

$(srcdir)/version.sh: FORCE
	cd "$(srcdir)" && $(SHELL) version-gen.sh

include $(srcdir)/version.sh

dist-hook:
	echo "$(GRN_VERSION)" > $(distdir)/version
	cd $(distdir) && autoreconf --install --force && find . -name autom4te.cache | xargs rm -fr

benchmark:
	cd test/benchmark && $(MAKE) benchmark

tag:
	cd $(top_srcdir) && git tag v$(VERSION) -a -m 'Groonga $(VERSION)!!!'

echo-version:
	@echo $(VERSION)

update-latest-release: misc
	@if test -z "$(OLD_RELEASE)"; then	\
	  echo "\$$(OLD_RELEASE) is missing";	\
	  exit 1;				\
	fi
	@if test -z "$(OLD_RELEASE_DATE)"; then		\
	  echo "\$$(OLD_RELEASE_DATE) is missing";	\
	  exit 1;					\
	fi
	@if test -z "$(NEW_RELEASE_DATE)"; then		\
	  echo "\$$(NEW_RELEASE_DATE) is missing";	\
	  exit 1;					\
	fi
	cd $(top_srcdir) &&					\
	  misc/update-latest-release.rb				\
	  $(PACKAGE) $(OLD_RELEASE) $(OLD_RELEASE_DATE)		\
	  $(VERSION) $(NEW_RELEASE_DATE)			\
	  doc/source/install.rst				\
	  doc/source/install/*.rst				\
	  doc/locale/*/LC_MESSAGES/install.po			\
	  $(GROONGA_ORG_PATH)/_config.yml
	cd $(top_srcdir)/packages &&		\
	  $(RUBY) -S rake version:update	\
	    RELEASE_DATE=$(NEW_RELEASE_DATE)
	cd $(top_srcdir) &&			\
	  git add 				\
	    doc/source/install.rst 		\
	    doc/source/install/*.rst		\
	    packages/debian/changelog		\
	    packages/yum/groonga.spec.in &&	\
	  git commit -m "doc package: update version info to ${VERSION} - ${NEW_RELEASE_DATE}"

update-po:
	@for lang in $(LOCALES); do						\
	  (cd $(top_srcdir)/doc/locale/$$lang/LC_MESSAGES && $(MAKE) update)	\
	done

update-document:
	@if test -z "$(GROONGA_ORG_PATH)"; then				\
	  echo "\$$(GROONGA_ORG_PATH) is missing";			\
	  echo "add --with-groonga-org-path in configure";	\
	  exit 1;							\
	fi
	rm -rf tmp-doc
	mkdir tmp-doc
	(cd doc && $(MAKE) clean-html)
	(cd doc && $(MAKE) install docdir=$(abs_builddir)/tmp-doc/install)
	rm -rf $(GROONGA_ORG_PATH)/docs
	mv tmp-doc/install/en/html $(GROONGA_ORG_PATH)/docs
	rm -rf tmp-doc/install/en
	for locale in $$(cd tmp-doc/install/; echo *); do	\
	  dest_base_dir=$(GROONGA_ORG_PATH)/$${locale};		\
	  mkdir -p $${dest_base_dir};				\
	  dest_dir=$${dest_base_dir}/docs;			\
	  rm -rf $${dest_dir};					\
	  mv tmp-doc/install/$${locale}/html $${dest_dir};	\
	done


update-version:
	@if test -z "$(NEW_VERSION)"; then	\
	  echo "\$$(NEW_VERSION) is missing";	\
	  exit 1;				\
	fi
	@echo -n $(NEW_VERSION) > $(srcdir)/base_version

update-files:
	cd doc && $(MAKE) update-files
	cd data/html && $(MAKE) update-files

update-mruby:
	cd vendor/mruby && make update

update-nginx:
	@if test -z "$(NEW_NGINX_VERSION)"; then	\
	  echo "\$$(NEW_NGINX_VERSION) is missing";	\
	  exit 1;					\
	fi
	cd $(top_srcdir)/vendor && ./update_nginx.sh $(NEW_NGINX_VERSION)

misc:
	@if test -z "$(CUTTER_SOURCE_PATH)"; then \
	  echo "\$$(CUTTER_SOURCE_PATH) is missing"; \
	  exit 1; \
	fi
	ln -s "$(CUTTER_SOURCE_PATH)/misc" misc

