#
#                             IPSTB Project
#                   ---------------------------------
#
# Copyright (C) 2007 NXP Semiconductors B.V.
# All Rights Reserved.
#
# Filename: NaturalDocs/Makefile
#
# Rev Date       Author      Comments
#-------------------------------------------------------------------------------
#   2 20061117   batelaan    Renamed from etc/makefiledoc.mk. Made into a package.
#   3 20070822   batelaan    Don't append .mk if already in filename.
#                            SDE2 currently not well documented, so exclude.

# File: NaturalDocs/Makefile
# Generates HTML docs for the Makefiles.
#
# See:-
# - <makefiledoc.gen>
# - <makefiledoc>

include $(PRJROOT)/etc/first.mk

$(eval $(PKG_START))

PKG:=NaturalDocs
NaturalDocs_VERSION:=1.35
NaturalDocs_UNTARINSIDE:=true
NaturalDocs_SKIPBUILD:=true

$(eval $(PKG_SETUP_VARS))

$(call PKG_DEFINE_TARGETS,help clean untar patch)

help::
	@echo "makefiledoc.gen	- Generates HTML docs for makefiles."
	@echo "makefiledoc	- Calls makefiledoc.gen and views (using htmlview) result."

# Define: MAKEFILEDOCS_INPUT_DIRS_EXCLUDE
# Input directories not to scan by target <makefiledoc>.
#
# Value: $(wildcard ${<PRJROOT>}build*) ${<BUILDROOT>} ${<_TMROOT>}/sde ${<SDE2_PROJECTS>}
MAKEFILEDOCS_INPUT_DIRS_EXCLUDE = \
  $(wildcard $(PRJROOT)/build*) \
  $(BUILDROOT) \
  $(_TMROOT)/sde \
  $(foreach d,$(SDE2_PROJECTS),$d/comps $d/intfs $d/apps $d/types)

# Define: MAKEFILEDOC_OUTPUT_DIR
# Output directory for for target <makefiledoc>.
#
# Default value: ${<BUILDROOT>}/makefiledoc
MAKEFILEDOC_OUTPUT_DIR = $(BUILDROOT)/makefiledoc

# Define: MAKEFILEDOC_FIND_ALL_MAKEFILES
# Command to find all Makefile's in ${<PRJROOT>}, but not below
# ${<MAKEFILEDOCS_INPUT_DIRS_EXCLUDE>}..
MAKEFILEDOC_FIND_ALL_MAKEFILES = \
  cd $(PRJROOT) && \
  find . $(foreach d,$(MAKEFILEDOCS_INPUT_DIRS_EXCLUDE),-path $(d:$(PRJROOT)/%=./%) -prune -o) -name "[mM]akefile" -print -o -name "*.mk" -print

# Target: makefiledoc.setuptmp
# Setup temp directory used by target <makefiledoc>.
makefiledoc.setuptmp: NaturalDocs.patch
	rm -rf $(BUILDROOT)/makefiledoc.tmp
	mkdir -p $(BUILDROOT)/makefiledoc.tmp/Makefiles
	cd $(BUILDROOT)/makefiledoc.tmp/Makefiles && \
	  ($(MAKEFILEDOC_FIND_ALL_MAKEFILES) | tar --files-from=- --create --dereference --file -) | tar xvf -
	find $(BUILDROOT)/makefiledoc.tmp/Makefiles -type f \( ! -name '*.mk' \) -exec mv '{}' '{}.mk' ';'

# Target: makefiledoc.gen
# Generates HTML docs for makefiles.
#
# See also:-
# <makefiledoc> <MAKEFILEDOC_OUTPUT_DIR> <MAKEFILEDOCS_INPUT_DIRS_EXCLUDE>
makefiledoc.gen: makefiledoc.setuptmp
	rm -rf $(MAKEFILEDOC_OUTPUT_DIR)
	mkdir -p $(MAKEFILEDOC_OUTPUT_DIR)
	perl $(NaturalDocs_BUILDDIR)/NaturalDocs -i $(BUILDROOT)/makefiledoc.tmp/Makefiles \
	  -o HTML $(MAKEFILEDOC_OUTPUT_DIR) -p $(BUILDROOT)/makefiledoc.tmp
	rm -rf $(BUILDROOT)/makefiledoc.tmp

# Target: makefiledoc
# Generates and views (using htmlview program) HTML docs for makefiles.
#
# See also:-
# <makefiledoc.gen>
makefiledoc: makefiledoc.gen
	htmlview 'file:$(MAKEFILEDOC_OUTPUT_DIR)/index.html' &

include $(PRJROOT)/etc/last.mk
