# This file is part of the project https://github.com/openSUSE/doc-kit
# DO NOT EDIT THIS FILE DOWNSTREAM. IT MAY BE OVERWRITTEN BY AN UPDATE.
#
# Copyright (c) 2014 Rick Salevsky <rsalevsky@suse.de>
# Copyright (c) 2014, 2015, 2016 Karl Eichwalder <ke@suse.de>
# Copyright (c) 2015, 2016, 2017, 2018, 2019 Stefan Knorr <sknorr@suse.de>
# Copyright (c) 2020, 2021, 2023, 2024 Lukas Kucharczyk <lkucharczyk@suse.com>
#


# AsciiDoc conditional text (e.g. for "to be released" information during beta).
LIFECYCLE_VALID := beta maintained unmaintained
ifndef LIFECYCLE
  LIFECYCLE := maintained
endif
ifneq "$(LIFECYCLE)" "$(filter $(LIFECYCLE),$(LIFECYCLE_VALID))"
  override LIFECYCLE := maintained
endif

# valid values are:
# micro
PRODUCT_VERSION ?= micro

dc_file := DC-release-notes-$(PRODUCT_VERSION)
mainfile  := adoc/release-notes-$(PRODUCT_VERSION).adoc

daps_command := daps

xsltproc_command := xsltproc \
  --stringparam generate.toc "/article toc" \
  --stringparam generate.section.toc.level 0 \
  --stringparam section.autolabel 1 \
  --stringparam section.label.includes.component.label 2 \
  --stringparam variablelist.as.blocks 1 \
  --stringparam toc.section.depth 2 \
  --stringparam toc.max.depth 3 \
  --stringparam show.comments 0 \
  --xinclude \
  --nonet


src_files := $(wildcard adoc/*.adoc adoc/*.xml)

daps_xslt_rn_dir := /usr/share/daps/daps-xslt/relnotes

profile_params := --adocattr lifecycle=$(LIFECYCLE)
text_params    :=

# files to be created:
profile_result       := build/.profiled/noprofile/release-notes-$(PRODUCT_VERSION).xml
text_result          := build/release-notes-$(PRODUCT_VERSION)/release-notes-$(PRODUCT_VERSION).txt
yast_html_result_dir := build/release-notes-$(PRODUCT_VERSION)/yast-html
yast_html_result     := $(yast_html_result_dir)/release-notes.html


.PHONY: all clean html pdf single-html text validate yast-html 

all: validate single-html yast-html pdf text html

#----------------

clean:
	rm -rf build/

#----------------

html: $(dc_file) $(src_files)
	$(daps_command) -d $< -vv $(profile_params) html --param="toc.section.depth=2"

#----------------

pdf: $(dc_file) $(src_files)
	$(daps_command) -d $< -vv $(profile_params) pdf

#----------------

single-html: $(dc_file) $(src_files)
	$(daps_command) -d $< -vv $(profile_params) html --single --param="toc.section.depth=2"

#----------------

# We need the text in ASCII to avoid issues when this is shown in text-only
# YaST.
text: $(text_result)
	iconv -f UTF-8 -t ASCII//TRANSLIT -o /dev/stdout $< > $<.tmp
	mv $<.tmp $<
$(text_result): $(dc_file) $(src_files)
	$(daps_command) -d $< -vv $(profile_params) text $(text_params)

#----------------

validate: $(dc_file) $(src_files)
	$(daps_command) -d $< -vv $(profile_params) --adocattr attribute-missing=warn validate

#----------------

yast-html: $(yast_html_result)

$(yast_html_result): $(profile_result)
	mkdir -p $(yast_html_result_dir)
	$(xsltproc_command) $(daps_xslt_rn_dir)/yast.xsl $< > $@ 2>/dev/null
	@echo "Created $@ for YaST HTML target."

$(profile_result): $(dc_file) $(src_files)
	$(daps_command) -vv -d $< $(profile_params) profile

serve:
# needs Python 3.7 for the --directory argument
	python3 -m http.server --directory $$(find . -iname index.html -exec dirname {} \;)
	




