summaryrefslogtreecommitdiff
blob: 6653a46813c8577f328d83f599a9905a516b346a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
# Copyright 1999-2012 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

EAPI=2

inherit git-2 eutils

DESCRIPTION="MMD is a superset of the Markdown syntax (more syntax features & output formats)"
HOMEPAGE="http://fletcherpenney.net/multimarkdown"
SRC_URI=""

EGIT_REPO_URI="git://github.com/fletcher/${PN}.git"

LICENSE="|| ( GPL-2 MIT )"
SLOT="0"
KEYWORDS="~amd64 ~x86"
IUSE="shortcuts doc perl-conversions latex xslt test"

DEPEND="
	doc? (
		dev-lang/perl
		latex? (
			dev-tex/latexmk
		)
	)
	test? (
		dev-lang/perl
		app-text/htmltidy
	)"
RDEPEND="
	perl-conversions? ( dev-lang/perl )
	xslt? ( dev-libs/libxslt )
	latex? ( ${CATEGORY}/${PN}-latex-support )
"
# peg-multimarkdown-latex-support is is not included as git sub-module
# it requires a separate git clone thus a separate pkg
if use test || use xslt || use perl-conversions || use doc; then
	EGIT_HAS_SUBMODULES="Y"
fi

# custom variables
DEST_DIR_EXE="/usr/bin"
DEST_DIR_XSLT_TEMPL="/usr/share/${PN}/XSLT/"

# known file collision with sys-fs/mtools on file /usr/bin/mmd
# this is not fatal, the script is only a simple shortcut, so we just skip the
# file ... mmd2all  mmd2pdf are also excluded (todo re-test them)
SHORTCUTS_LIST="mmd2tex mmd2opml mmd2odf"

# mmd2RTF.pl : not included. RTF support is not official
# and would use "Apples textutil package" ...
# MMD-Support/Utilities/{ table_cleanup.pl mmd_merge.pl}
# also not added. Seem to be internal scripts, some tests for mmd_merge.pl
# failed.
PERLSCRIPTS_LIST="mmd2XHTML.pl mmd2LaTeX.pl mmd2OPML.pl mmd2ODF.pl"

# prep_tufte.sh is not included, it would require perl and seems old
XSLTSCRIPTS_LIST="mmd-xslt mmd2tex-xslt opml2html opml2mmd opml2tex"

pkg_setup()
{
	# detect FEATURES with "nodoc" as this will prevent doc from being installed
	if use doc && has nodoc $FEATURES; then
		die "FEATURES contains \"nodoc\" thus the \"doc\" flag cannot be used"
	fi
}

src_prepare()
{	# ./Makefile patches ./peg-0.1.4/Makefile
	# this does not work if the Makefile was already patched
	# so this step from Makefile is done here
	# (easier then patching .patch file)
	cp -r peg-0.1.4 peg; \
	epatch -p1 peg-memory-fix.patch; \
	epatch -p1 peg-exe-ext.patch || die "Patching of ${PN} failed!"
	# now patch cflags
	epatch "${FILESDIR}/${P}-cflags.patch"

	if use xslt; then
		einfo "XSLT support requires patching of some scripts (path to XSLT templates)"
		epatch "${FILESDIR}/${P}-xslt.patch" || die "Patching of XSLT scripts for ${PN} failed!"
	fi

	if use doc; then
		epatch "${FILESDIR}/${P}-doc.patch" || die "Patching of Makefile for ${PN} failed!"
	fi
	# rename a file to avoid an error when testing
	if use test && [ -f "MarkdownTest/MultiMarkdownTests/BibTex.text" ]; then
		einfo "Renaming file BibTex.text to BibTeX.text ..."
		mv "MarkdownTest/MultiMarkdownTests/BibTex.text" "MarkdownTest/MultiMarkdownTests/BibTeX.text"
	fi
}

src_compile() {
	if [ -f Makefile ] || [ -f GNUmakefile ] || [ -f makefile ]; then
		emake || die "emake failed"
		# compile documentation
		if use doc; then
			einfo "Compiling documentation ..."
			emake docs || die "emake docs failed!"
			if use latex; then
				emake docs-latex || die "emake docs-latex failed!"
			fi
			einfo "Done compiling documentation."
		fi
	fi
}

src_test()
{
	einfo "Now running tests for package ${PN}"
	einfo "It is considered \"normal\" for some tests to fail, but at least one should pass ..."
	for test_phase in test mmd-test compat-test latex-test ; do
		# only run the latex test with latex use flag
		if [ "$test_phase" != "latex-test" ] || use latex ; then
			if emake -j1 $test_phase -n &> /dev/null; then
				einfo ">>> Test phase 2 [${test_phase}]: ${CATEGORY}/${PF}"
				if ! emake -j1 $test_phase; then
					has test $FEATURES && die "Make ${test_phase} failed. See above for details."
				fi
			fi
		fi
	done
	einfo "Done running tests for package ${PN}"
}

src_install()
{
	insinto ${DEST_DIR_EXE}
	einfo "Installing multimarkdown binary to ${DEST_DIR_EXE}/multimarkdown ..."
	dobin multimarkdown || die "Install failed"

	# USE flag based installation
	# install shortcuts
	if use shortcuts ; then
		einfo "Installing shortcuts for ${PN}"
		exeinto ${DEST_DIR_EXE}
		for file in ${SHORTCUTS_LIST}; do
			# einfo "Installing ${file} to ${DEST_DIR_EXE}/${file} ..."
			doexe scripts/${file} || die "Installation of script ${file} failed!"
		done
	fi

	#install documentation
	if use doc; then
		einfo "Installing documentation for ${PN}"
		dohtml manual/*.html || die "Installation of documentation failed!"
		if use latex; then
			dodoc manual/*.pdf || die "Installation of LaTeX documentation failed!"
		fi
	fi

	# install perl-conversion scripts
	if use perl-conversions ; then
		einfo "Installing perl-conversion scripts for ${PN}"
		exeinto ${DEST_DIR_EXE}
		for file in ${PERLSCRIPTS_LIST}; do
			local file_path=`find Support/ -name "${file}"`
			# einfo "Installing ${file} to ${DEST_DIR_EXE}/${file} ..."
			doexe "${file_path}" || die "Installation of script ${file} failed!"
		done
	fi

	# install latex support
	# nothing to do, it's all in the plugin pkg

	# install xslt support
	if use xslt ; then
		einfo "Installing XSLT templates for ${PN} to ${DEST_DIR_XSLT_TEMPL}"
		insinto ${DEST_DIR_XSLT_TEMPL}
		doins Support/XSLT/* || die "Installation of XSLT templates failed!"
		einfo "Installing XSLT scripts for ${PN}"
		exeinto ${DEST_DIR_EXE}
		for file in ${XSLTSCRIPTS_LIST}; do
			local file_path=`find Support/ -name "${file}"`
			einfo "Installing ${file} to ${DEST_DIR_EXE}/${file} ..."
			doexe ${file_path} || die "Installation of script ${file} failed!"
		done
	fi
}

pkg_postinst()
{
	elog ""
	elog "*** ${PN} was successfully installed. ***"
	elog "Type \"multimarkdown -h\" or \"multimarkdown file.txt\" to start using it."
	if use shortcuts; then
		elog "The following additional shortcuts were also installed:"
		elog "${SHORTCUTS_LIST}."
		elog "The shortcut \"mmd\" was not installed due to known file"
		elog "collision with sys-fs/mtools on file /usr/bin/mmd"
	fi
	if use perl-conversions; then
		elog "The following additional conversion shortcuts were also installed:"
		elog "${PERLSCRIPTS_LIST}"
	fi
	if use xslt; then
		elog "The following additional XSLT conversion shortcuts were also installed:"
		elog "${XSLTSCRIPTS_LIST}."
	fi
	if use doc; then
		elog "The html documentation was installed, normally it goes to:"
		elog "/usr/share/doc/${PF}/html/"
		if use latex; then
			elog "The pdf documentation was also installed, normally it goes to:"
			elog "/usr/share/doc/${PF}/"
		fi
	fi
	elog ""
}

pkg_info()
{
	einfo "`${ROOT}${DEST_DIR_EXE}/multimarkdown -v`"
}