#***********************************************************************************************************************
# DMTF - Distributed Management Task Force, Inc. - http://www.dmtf.org
# See dsp2023_readme.txt for copyright information.
#
# makefile - part of the DMTF DSP2023 zip archive.
#
# MRP profiles makefile.
# This makefile covers the build of HTML files and picture zip files for MRP XML profiles.
# It is used for the sample profiles in DSP2023, and can also be used for your own MRP profiles.
# See dsp2023_readme.txt for a description on how to set up the build environment for MRP profiles.
#
# Supported platforms:
#   Tested on Windows.
#
# Prerequisite commands and packages:
#   make (GNU make, from CygWin)
#   rm (file removal command, from CygWin)
#   zip (GNU zip utility, from CygWin)
#   Python 2.6 or 2.7 (www.python.org, for running mrp2html.py)
#   Prince-XML 8.0 (PDF generator from HTML)
#***********************************************************************************************************************

# Directories with profile files that are to be processed by this makefile.
# The makefile will process all .mrp.xml profile files it finds there, and the picture files of all .vsd (Visio) files
# it finds there.
# Customize this variable as needed.
mrp_directories := \
    $(wildcard xmp*) \

other_directories := \
    $(wildcard dsp*) \

# dsp8029 XSLT stylesheet file to be used for the HTML file generation.
dsp8029_file := resources/dsp8029_1.0.2.xsl

# dsp8054 CSS stylesheet file to be used for the HTML file generation.
dsp8054_file := resources/dsp8054_1.0.0.css

#--- Do not customize below this line

# Base names (that is, relative path and base filename without file extension) of the MRP XML files.
# The list is created automatically by searching the directories listed in $(mrp_directories) for .mrp.xml files, one
# directory level deep. It is valid to have more than one .mrp.xml file in a directory.
mrp_basenames := $(foreach dir,$(mrp_directories),$(basename $(basename $(wildcard $(dir)/*.mrp.xml))))
other_basenames := $(foreach dir,$(other_directories),$(basename $(basename $(wildcard $(dir)/*.mrp.xml))))

# Base names (that is, relative path and base filename without file extension) of the Visio files.
# The list is created automatically by searching the directories listed in $(mrp_directories) for .vsd files, one
# directory level deep. It is valid to have more than one .vsd file in a directory.
mrp_visio_basenames := $(foreach dir,$(mrp_directories),$(basename $(wildcard $(dir)/*.vsd)))
other_visio_basenames := $(foreach dir,$(other_directories),$(basename $(wildcard $(dir)/*.vsd)))

# HTML profile files.
# The list is created automatically from the set of MRP XML files.
mrp_html_files := $(foreach bn,$(mrp_basenames),$(bn).html)
other_html_files := $(foreach bn,$(other_basenames),$(bn).html)

# PDF profile files.
# The list is created automatically from the set of MRP XML files.
mrp_pdf_files := $(foreach bn,$(mrp_basenames),$(bn).pdf)
other_pdf_files := $(foreach bn,$(other_basenames),$(bn).pdf)

# Picture files of the profiles.
# The list is created automatically from the set of Visio files.
mrp_pic_files := $(foreach bn,$(mrp_visio_basenames),$(wildcard $(bn)*.gif))
other_pic_files := $(foreach bn,$(other_visio_basenames),$(wildcard $(bn)*.gif))

# Picture ZIP files, with all picture files of the profiles.
# The list is created automatically from the set of Visio files.
mrp_pic_zip_files := $(foreach bn,$(mrp_visio_basenames),$(bn).pic.zip)
other_pic_zip_files := $(foreach bn,$(other_visio_basenames),$(bn).pic.zip)


.PHONY: clean build

mrp_build_files := $(mrp_html_files) $(mrp_pdf_files) $(mrp_pic_zip_files)
other_build_files := $(other_html_files) $(other_pdf_files) $(other_pic_zip_files)

help:
	@echo 'MRP profiles makefile'
	@echo 'Valid targets are:'
	@echo '  build   - Build the profile HTML, PDF and picture zip files for non-sample MRP profiles in this subtree.'
	@echo '  buildmrp - Build the profile HTML, PDF and picture zip files for the sample MRP profiles in this subtree.'
	@echo '  clean   - Remove any built files.'
	@echo help done.

build: $(other_build_files)
	@echo build done.

buildmrp: $(mrp_build_files)
	@echo buildmrp done.

clean:
	-rm -f $(mrp_build_files) $(other_build_files)
	@echo clean done.

%.html: %.mrp.xml $(dsp8029_file) $(dsp8054_file)
	mrp2html $< $*.html --xsltfile $(dsp8029_file) --cssurl $(dsp8054_file)

%.pdf: %.html
	-prince-xml --javascript --media=print $< -o $*.pdf

%.pic.zip: %.vsd
	@echo 'Note: The picture files (.gif) are not on the dependencies list, so use make clean if picture files have been created or modified.'
	-zip -q $@ $*_*.gif
