# Locale for German locale in Germany with Euro and date in ISO8601 format
# Contributed by Harald Harders <harald.harders@gmx.de>, 2021
SRCFILE1=	/usr/share/i18n/locales/de_DE
SRCFILE2=	/usr/share/i18n/locales/de_DE@euro
TARGETFILE1=	de_DE@iso8601-LC_TIME
TARGETFILE2=	de_DE@iso8601

all:	$(TARGETFILE1) $(TARGETFILE2)
	localedef -f UTF-8 -i $(TARGETFILE2) ./de_DE.utf8@iso8601

install:	$(TARGETFILE1) $(TARGETFILE2)
	localedef -f UTF-8 -i $(TARGETFILE2) de_DE.utf8@iso8601

clean:
	-rm $(TARGETFILE2) $(TARGETFILE1)
	-rm -r de_DE.utf8@iso8601

# Generate The time section
$(TARGETFILE1): $(SRCFILE1) de_DE@iso8601-LC_TIME.diff
	@echo "Extract the LC_TIME section from $(SRCFILE1)"
	sed -n -e "/^LC_TIME/,/END LC_TIME/p" $(SRCFILE1) > $(TARGETFILE1)
	patch $(TARGETFILE1) de_DE@iso8601-LC_TIME.diff

# Generate general file copying the contents from the original source files
$(TARGETFILE2): $(SRCFILE2)
	@echo "Change the copy source of the LC_TIME section in $(SRCFILE2)"
	sed -e '/^LC_TIME/,/END LC_TIME/s/copy "de_DE"/copy "$(TARGETFILE1)"/' \
		-e 's/^% Locale for German.*/% Locale for German locale in Germany with Euro and date in ISO8601 format/' \
		-e '/^% Contributed by.*/i% Contributed by Harald Harders <harald.harders@gmx.de>, 2021' \
		-e 's/^% Contributed by/% Based on version by/' \
		$(SRCFILE2) >> $(TARGETFILE2)

