# -*- makefile-automake -*- -*- makefile -*-
########################################################################
# Define e2tools
########################################################################

bin_PROGRAMS += e2tools

e2tools_CFLAGS =
e2tools_CPPFLAGS =
e2tools_LDADD =

# e2tools_CFLAGS   += -save-temps=obj

e2tools_CPPFLAGS += -I$(top_srcdir)/src

e2tools_CPPFLAGS += $(EXT2FS_CFLAGS)
e2tools_LDADD    += $(EXT2FS_LIBS)

e2tools_CPPFLAGS += $(COM_ERR_CFLAGS)
e2tools_LDADD    += $(COM_ERR_LIBS)

e2tools_SOURCES =
e2tools_SOURCES += %reldir%/compiler-definitions.h
e2tools_SOURCES += %reldir%/e2tools.c  %reldir%/e2tools.h
e2tools_SOURCES += %reldir%/elist.c    %reldir%/elist.h
e2tools_SOURCES += %reldir%/progress.c %reldir%/progress.h
e2tools_SOURCES += %reldir%/read.c     %reldir%/read.h
e2tools_SOURCES += %reldir%/util.c     %reldir%/util.h
e2tools_SOURCES += %reldir%/write.c    %reldir%/write.h

dist_man_MANS += %reldir%/e2tools.7

if HAVE_EXT2FS_XATTRS
# EXTRA_DIST       += %reldir%/e2chcon.1.in
# CLEANFILES       += %reldir%/e2chcon.1
# man_MANS         += %reldir%/e2chcon.1
# e2tools_list     += e2chcon
endif

e2tools_SOURCES  += %reldir%/e2tool-e2cp.c
e2tools_SOURCES  += %reldir%/e2tool-e2cp.h
dist_man_MANS    += %reldir%/e2cp.1
e2tools_list     += e2cp

e2tools_SOURCES  += %reldir%/e2tool-e2ln.c
e2tools_SOURCES  += %reldir%/e2tool-e2ln.h
dist_man_MANS    += %reldir%/e2ln.1
e2tools_list     += e2ln

e2tools_SOURCES  += %reldir%/e2tool-e2ls.c
e2tools_SOURCES  += %reldir%/e2tool-e2ls.h
EXTRA_DIST       += %reldir%/e2ls.1.in
CLEANFILES       += %reldir%/e2ls.1
man_MANS         += %reldir%/e2ls.1
e2tools_list     += e2ls
%reldir%/e2ls.1 : %reldir%/e2ls.1.in Makefile

e2tools_SOURCES  += %reldir%/e2tool-e2mkdir.c
e2tools_SOURCES  += %reldir%/e2tool-e2mkdir.h
dist_man_MANS    += %reldir%/e2mkdir.1
e2tools_list     += e2mkdir

e2tools_SOURCES  += %reldir%/e2tool-e2mv.c
e2tools_SOURCES  += %reldir%/e2tool-e2mv.h
dist_man_MANS    += %reldir%/e2mv.1
e2tools_list     += e2mv

e2tools_SOURCES  += %reldir%/e2tool-e2rm.c
e2tools_SOURCES  += %reldir%/e2tool-e2rm.h
dist_man_MANS    += %reldir%/e2rm.1
e2tools_list     += e2rm

e2tools_SOURCES  += %reldir%/e2tool-e2tail.c
e2tools_SOURCES  += %reldir%/e2tool-e2tail.h
dist_man_MANS    += %reldir%/e2tail.1
e2tools_list     += e2tail

# Put this rule after all appends to the e2tools_list variable
e2tools_SOURCES += %reldir%/e2tools-toolmap.h
BUILT_SOURCES   += %reldir%/e2tools-toolmap.c
CLEANFILES      += %reldir%/e2tools-toolmap.c
e2tools_SOURCES += %reldir%/e2tools-toolmap.c
%reldir%/e2tools-toolmap.c: Makefile
	@$(MKDIR_P) "%reldir%"
	@( \
	echo "/* autogenerated from Makefile.am */"; \
	echo "#include <stddef.h>"; \
	echo "#include \"e2tools-toolmap.h\""; \
	for tool in $(e2tools_list); do \
		echo "#include \"e2tool-$${tool}.h\""; \
	done; \
	echo "struct toolmap_element toolmap[] = {"; \
	for tool in $(e2tools_list); do \
		echo "  {\"$${tool}\", main_$${tool}},"; \
	done; \
	echo "  {NULL, NULL}"; \
	echo "};"; \
	) > %reldir%/e2tools-toolmap.c.tmp
	@if test -f %reldir%/e2tools-toolmap.c && cmp %reldir%/e2tools-toolmap.c %reldir%/e2tools-toolmap.c.tmp >/dev/null 2>&1; then \
		echo "Keeping unchanged e2tools-toolmap.c"; \
		rm -f %reldir%/e2tools-toolmap.c.tmp; \
	else \
		echo "Updating e2tools-toolmap.c"; \
		mv -f %reldir%/e2tools-toolmap.c.tmp %reldir%/e2tools-toolmap.c; \
	fi

all_targets   += e2tools-symlinks
phony_targets += e2tools-symlinks
e2tools-symlinks: e2tools$(EXEEXT)
	@for symlink in $(e2tools_list); do \
		rm -f "$${symlink}"; \
		$(LN_S) e2tools "$${symlink}" || exit 1; \
	done

clean_targets += e2tools-clean
phony_targets += e2tools-clean
e2tools-clean:
	-rm -f $(e2tools_list)

install_targets += e2tools-install
phony_targets   += e2tools-install
e2tools-install:
	cd $(DESTDIR)$(bindir) && \
	for symlink in $(e2tools_list); do \
		rm -f "$${symlink}"; \
		$(LN_S) e2tools "$${symlink}" || exit 1; \
	done

uninstall_targets += e2tools-uninstall
phony_targets     += e2tools-uninstall
e2tools-uninstall:
	-cd $(DESTDIR)$(bindir) && rm -f $(e2tools_list)


########################################################################
# End of src/Makefile-files
########################################################################
