EXTERNALTOOLS_TOOL_MERGE = $(top_srcdir)/plugins/externaltools/scripts/gedit-tool-merge.pl

externaltools_tools_in_files =						\
	plugins/externaltools/data/build.tool.in			\
	plugins/externaltools/data/remove-trailing-spaces.tool.in	\
	plugins/externaltools/data/send-to-fpaste.tool.in

externaltools_tools_in_linux =						\
	plugins/externaltools/data/open-terminal-here.tool.in		\
	plugins/externaltools/data/run-command.tool.in

externaltools_tools_in_osx =						\
	plugins/externaltools/data/open-terminal-here-osx.tool.in

externaltools_tools_in_win32 =

externaltools_install_tools_in_files = $(externaltools_tools_in_files)

if PLATFORM_OSX
externaltools_install_tools_in_files += $(externaltools_tools_in_osx)
else
if PLATFORM_WIN32
externaltools_install_tools_in_files += $(externaltools_tools_in_win32)
else
externaltools_install_tools_in_files += $(externaltools_tools_in_linux)
endif
endif

externaltools_toolsdir = $(GEDIT_PLUGINS_DATA_DIR)/externaltools/tools
externaltools_tools_SCRIPTS = $(externaltools_install_tools_in_files:.tool.in=)

externaltools_all_tools_in_files =	\
	$(externaltools_tools_in_files)	\
	$(externaltools_tools_in_linux)	\
	$(externaltools_tools_in_osx)	\
	$(externaltools_tools_in_win32)

externaltools_all_desktop_in_files = $(externaltools_all_tools_in_files:.tool.in=.desktop.in)
externaltools_all_desktop_files = $(externaltools_all_tools_in_files:.tool.in=.desktop)
externaltools_all_tools_files = $(externaltools_all_tools_in_files:.tool.in=)

# Tools are generated by merging a script file (.tool.in) with a data file
# (.desktop), which happens to be translated using intltool.
$(externaltools_tools_SCRIPTS): %: %.tool.in %.desktop $(EXTERNALTOOLS_TOOL_MERGE)
	perl $(EXTERNALTOOLS_TOOL_MERGE) -o $@ $< $(word 2,$^)
	chmod 755 $@

EXTRA_DIST +=					\
	$(externaltools_all_desktop_in_files)	\
	$(externaltools_all_tools_in_files)

CLEANFILES +=					\
	$(externaltools_all_desktop_files)	\
	$(externaltools_all_tools_files)

# Needed when builddir != srcdir. Normally Autoconf creates the
# directory when creating the Makefile, but since gedit uses
# non-recursive make, the directory is not created, but is needed for
# generating the .desktop files.
# If the following bug is fixed, this hack can normally be removed:
# https://bugs.launchpad.net/intltool/+bug/605826
$(shell $(MKDIR_P) $(top_builddir)/plugins/externaltools/data/)
