
ALL_STACKS=$(shell rosstack list-names)
OTHER_STACKS=$(patsubst ecl,,$(ALL_STACKS))
STACKS=$(foreach stack,$(OTHER_STACKS),$(shell rosstack find $(stack)))

all:
	@echo ""
	@echo "Usage:"
	@echo "  make doxygen : makes the doxygen for all ecl, puts it in ./doc"
	@echo "  make upload_doxygen : uploads to the snorriheim server."
	@echo "  make graphs : generates the dot dependency graphs."
	@echo ""
	@echo "There are other package/install targets from pre-ros days."
	@echo ""


# This could be a bit smarter about actually finding what stacks should be touched.
doxygen:
	mkdir -p build
	mkdir -p doc
	cd build; cmake ../; $(MAKE)
	#$(MAKE) upload

upload_doxygen:
	@if [ -d ./build ]; then \
	  cd build; \
	  $(MAKE) upload_doxygen; \
	else \
	  echo "You need to build the docs first - run 'make'."; \
	fi

#######################################################################################
# Regenerative targets - want to clear and rebuild
#######################################################################################

doxygen:
	@if [ -d ./build ]; then \
	  rm -f doc/index.html; \
	else \
	  mkdir -p doc; \
	  mkdir -p build; \
	  cd build; \
	  cmake ..; \
	fi
	cd build; \
	$(MAKE) doxygen; \

graphs:
	@if [ -d ./build ]; then \
	  rm -f doc/ecl_package_graph.pdf; \
	else \
	  mkdir -p doc; \
	  mkdir -p build; \
	  cd build; \
	  cmake ..; \
	fi
	cd build; \
	$(MAKE) graphs; \

#######################################################################################
# Packages
#######################################################################################

package:
	@if [ -d build ]; then \
		cd build; \
		$(MAKE) package; \
	else \
		$(MAKE) all; \
		cd build; \
		$(MAKE) package; \
	fi

upload: package
	cd build; \
	$(MAKE) upload

#######################################################################################
# Utility
#######################################################################################

clean:
	rm -rf deps.gv bin *.log tmp doc build *.pdf

install:
	@if [ ! -d ./build ]; then \
	  $(MAKE); \
	fi
	cd build; \
	$(MAKE) install;

uninstall:
	@if [ -d ./build ]; then \
	  cd build; \
	  $(MAKE) uninstall; \
	else \
	  echo "You need to build the docs first so it knows what to uninstall."; \
	fi

help:
	@echo
	@echo "  make"
	@echo "  make install -> CMAKE_INSTALL_PREFIX/share/ecl/doc"
	@echo "  make uninstall"
	@echo "  make upload"
	@echo "  make doxygen [regenerates]"
	@echo "  make graphs  [regenerates]"
	@echo "  make clean"
	@echo
	@echo "  make graph"
	@echo
