project=minexpert2

# This path represents the local file even if it is a symbolic link
mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
current_dir := $(notdir $(patsubst %/,%,$(dir $(mkfile_path))))

pwd=$(CURDIR)
topDir=$(CURDIR)

okularPid=${topDir}/okular.pid

pdfFilePath=${topDir}/build/user-manual
pdfFilePathName=${pdfFilePath}/user-manual_color_en.pdf 
htmlDirPath=${topDir}/build/user-manual/html/${project}-user-manual

default: all

all: pdf_f html_f

all_f: pdf_f html_f

all_f_r: pdf_f_r html_f_r

.PHONY: reader
reader:
	okular --geometry 1268x1099-0-34 $(pdfFilePathName) & echo $$! > okular.pid

# Make the pdf file without forcing without reload
pdf:
	daps -d ${topDir}/DC-user-manual --verbosity=3 pdf
	cp -fv ${pdfFilePathName} ${pdfFilePath}/${project}-doc.pdf
	cp -fv ${pdfFilePathName} ${topDir}/${project}-doc.pdf

# Make the pdf file with forcing remaking all the targets and without reload
pdf_f:
	daps --force -d ${topDir}/DC-user-manual --verbosity=3 pdf
	cp -fv ${pdfFilePathName} ${pdfFilePath}/${project}-doc.pdf
	cp -fv ${pdfFilePathName} ${topDir}/${project}-doc.pdf

# Reload with okular variant
pdf_r: pdf
	(cd ${topDir} && qdbus org.kde.okular-$(shell cat ${okularPid}) /okular reload)
	cp -fv ${pdfFilePathName} ${pdfFilePath}/${project}-doc.pdf
	cp -fv ${pdfFilePathName} ${topDir}/${project}-doc.pdf

# Reload with okular variant
pdf_f_r: pdf_f
	(cd ${topDir} && qdbus org.kde.okular-$(shell cat ${okularPid}) /okular reload)
	cp -fv ${pdfFilePathName} ${pdfFilePath}/${project}-doc.pdf
	cp -fv ${pdfFilePathName} ${topDir}/${project}-doc.pdf

.PHONY: html
html:
	daps -d ${topDir}/DC-user-manual --verbosity=3 html --static

.PHONY: html_f
html_f: html
	daps --force -d ${topDir}/DC-user-manual --verbosity=3 html --static

.PHONY: html_r
html_r: html
	firefox-reload-page.sh

.PHONY: html_f_r
html_f_r: html_f
	firefox-reload-page.sh

package_html:
	daps -d ${topDir}/DC-user-manual package-html

check_dir:
	echo "mkfile_path: $(mkfile_path)"
	echo "current_dir: $(current_dir)"	

	if [ -d "xml" ];\
	 	then \
		echo "Not in a user manual top source directory.";\
		exit 1;\
		fi	

