COMMENT-main=		text based music notation system
COMMENT-docs=		lilypond documentation

VERSION=		2.24.4
REVISION-main=		0
DISTNAME=		lilypond-v${VERSION}
DISTNAME-docs=		lilypond-${VERSION}-documentation
FULLPKGNAME-main=	lilypond-${VERSION}
FULLPKGPATH-main=	print/lilypond,-main
PKGNAME-docs=		lilypond-docs-${VERSION}
CATEGORIES=		print

# For testing purposes only. Expect changes to PLIST-doc, because the
# downloaded documentation has been built with a much older version of
# texi2html.
# Don't try to build with MAKE_JOBS set to something > 1.
FLAVORS=		builddoc
FLAVOR?=

URW_V=			20200910
DISTFILES=		${DISTNAME}.tar.bz2
.if !${FLAVOR:Mbuilddoc}
DISTFILES.doc=		${DISTNAME-docs}.tar.xz
.endif
DISTFILES.urw=		urw-base35-fonts-${URW_V}.tar.gz
SUPDISTFILES.doc=	${DISTNAME-docs}.tar.xz
EXTRACT_ONLY=		${DISTFILES} ${DISTFILES.urw}

MULTI_PACKAGES=		-main -docs

HOMEPAGE=		https://lilypond.org/

MAINTAINER=		Matthias Kilian <kili@openbsd.org>

# GPLv3+, for urw-base35-fonts: AGPLv3 with font exception
PERMIT_PACKAGE=	Yes

COMPILER =		base-clang ports-gcc base-gcc

SITE_BASE=		https://gitlab.com/lilypond/lilypond/-/
SITES=			${SITE_BASE}archive/v${VERSION}/
SITES.doc=		${SITE_BASE}releases/v${VERSION}/downloads/
SITES.urw=		https://github.com/ArtifexSoftware/urw-base35-fonts/archive/${URW_V}/

# We don't use the standard autoconf mechanisms from the ports
# system, because it doesn't work for lilypond. Instead, we use
# autogen.sh and add AUTOCONV_VERSION to the environment.
AUTOCONF_VERSION=	2.69
CONFIGURE_STYLE=	gnu
CONFIGURE_SCRIPT=	autogen.sh
CONFIGURE_ENV=		AUTOCONF_VERSION=${AUTOCONF_VERSION} \
			BASH=/bin/sh \
			GREP=/usr/bin/grep \
			GUILE_FLAVOR=guile-2.2 \
			LDFLAGS=-L${LOCALBASE}/lib
CONFIGURE_ARGS+=	--disable-debugging \
			--disable-optimising \
			--disable-pipe
.if !${FLAVOR:Mbuilddoc}
CONFIGURE_ARGS+=	--disable-documentation
.endif

USE_GMAKE=		Yes
MAKE_FILE=		GNUmakefile

# Stupid fontforge writes autosave data to ~/.PfaEdit, even in
# scripting mode, so give it a HOME to stop systrace warnings.
PORTHOME=		${WRKDIR}

PKG_ARCH-docs=		*
WANTLIB-docs =
LIB_DEPENDS-docs=
RUN_DEPENDS-docs=

WANTLIB-main=		c fontconfig freetype gc glib-2.0 gobject-2.0 \
			guile-2.2 harfbuzz intl m pango-1.0 \
			pangoft2-1.0 pthread \
			${COMPILER_LIBCXX}
MODULES=		lang/python
LIB_DEPENDS-main=	devel/gettext,-runtime \
			lang/guile2 \
			devel/glib2 \
			devel/pango
RUN_DEPENDS=		print/ghostscript/gnu
BUILD_DEPENDS=		print/fontforge \
			print/t1utils \
			print/texlive/texmf \
			devel/bison \
			devel/gettext,-tools \
			devel/autoconf/${AUTOCONF_VERSION} \
			${RUN_DEPENDS}
.if ${FLAVOR:Mbuilddoc}
# rsync is used by a script for just copying things around locally.
# coreutils is used for 'cp --link ...' (see GNUmakefile.in, 154)
# (both to be fixed upstream, who is known to ignore standards since
# decades).
BUILD_DEPENDS+=		graphics/ImageMagick \
			net/rsync \
			print/texinfo \
			sysutils/coreutils \
			textproc/texi2html
.endif

SUBST_VARS+=		VERSION

ALL_TARGET=		all bytecode
INSTALL_TARGET+=	install install-bytecode
.if ${FLAVOR:Mbuilddoc}
ALL_TARGET+=		doc
INSTALL_TARGET+=	install-doc
.endif

# Extract the documentation distfiles or, when building with the
# builddoc flavor, ensure some tools from coreutils, findutils and
# texinfo packages are used.
# Remove files generated by bison to avoid some recompilations
# during fake stage.
post-extract:
.if ${FLAVOR:Mbuilddoc}
.  for p in cp find makeinfo pdftexi2dvi texi2dvi texi2pdf texindex
	@ln -s ${LOCALBASE}/bin/g$p ${WRKDIR}/bin/$p
.  endfor
.else
	@xz -cd ${FULLDISTDIR}/${DISTNAME-docs}.tar.xz | \
		pax -rs '!^\.!${WRKDIR}/docs!'
.endif
	@rm -rf ${WRKSRC}/lily/out

LILYFONTDIR=	${PREFIX}/share/lilypond/${VERSION}/fonts/otf
TEXGYREDIR=	${LOCALBASE}/share/texmf-dist/fonts/opentype/public/tex-gyre
URWDIR=		${WRKDIR}/urw-base35-fonts-${URW_V}/fonts

post-install:
.if ${FLAVOR:Mbuilddoc}
	cd ${PREFIX}/share/doc/lilypond && \
		mv html ${VERSION}
	rm -rf ${PREFIX}/info
.else
	${INSTALL_DATA_DIR} ${PREFIX}/share/doc/lilypond/${VERSION}
	umask 022 && cp -R ${WRKDIR}/docs/share/doc/lilypond/html/* \
		${PREFIX}/share/doc/lilypond/${VERSION}
	for f in ${WRKDIR}/docs/share/man/man1/*; do \
		${INSTALL_MAN} $$f ${PREFIX}/man/man1; \
	done
.endif
	for f in cursor heros schola; do \
		for s in regular bold bolditalic italic; do \
			${INSTALL_DATA} ${TEXGYREDIR}/texgyre$$f-$$s.otf \
				${LILYFONTDIR}; \
		done; \
	done
	for s in Roman BdIta Bold Italic; do \
		${INSTALL_DATA} ${URWDIR}/C059-$$s.otf ${LILYFONTDIR}; \
	done
	for f in NimbusMonoPS NimbusSans; do \
		for s in Regular Bold BoldItalic Italic; do \
			${INSTALL_DATA} ${URWDIR}/$$f-$$s.otf \
				${LILYFONTDIR}; \
		done; \
	done

# Regression tests disabled for normal builds.
.if !${FLAVOR:Mbuilddoc}
NO_TEST=		Yes
.endif

.include <bsd.port.mk>
