Part 8 Informative ebuild

WARNING:
THESE ARE MY PERSONAL NOTES ON MY FIRST EBUILD.
THIS IS BY NO MEANS A USEFUL GUIDE OR ANYTHING SIMILAR TO ANYONE.
RTFM

I’ll try to write an ebuild from scratch and document the progress here.

Ebuild from scratch: Part 8 Testing & Informative ebuild

Our working ebuild is lacking information about the package.
Not going into the details, I covered these topics in the Gentoo Development Guide:

  • Messages:
    Use elog, einfo, ewarn and eeror instead of echo.
  • metadata.xml:
    In depth description of package and its use flages.
  • Changelog:
    I failed on creating this. A tool “echangelog” ism entioned, but portage doesn’t find it!
  • Additional Ebuild Functions:
    Next to src_install(), I implemented pkg_postinst(), pkg_config() and pkg_info().
    They are not necessary, but I got to know them this way.
    pkg_config() is only called by emerge –config. I give the user the option to remove some extra scripts.
    pkg_info() is called by emerge –info

I also made the target installation folder a variable, as well as the list of extra scripts.

So here’s the resulting ebuild file:

# Copyright 1999-2012 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $
EAPI=0
# project is hosted on github.com, so git-2 is needed (git is deprecated)
inherit git-2
DESCRIPTION="MMD is a superset of the Markdown syntax (more syntax features & output formats)"
HOMEPAGE="http://http://fletcherpenney.net/multimarkdown"
EGIT_REPO_URI="git://github.com/fletcher/peg-multimarkdown.git"
SRC_URI=""
LICENSE="GPL-2"
SLOT="0"
KEYWORDS="~amd64"

# custom variables
DESTINATION_DIR="usr/bin"
SCRIPTS_LIST="mmd mmd2tex mmd2opml mmd2odf"
# mmd2all mmd2pdf are excluded

src_install()
{
    insinto ${DESTINATION_DIR}
    einfo "Installing multimarkdown to ${ROOT}${DESTINATION_DIR}/multimarkdown ..."
    dobin multimarkdown || die "Install failed"
    exeinto ${DESTINATION_DIR}
    for file in ${SCRIPTS_LIST}; do
        einfo "Installing ${file} to ${ROOT}${DESTINATION_DIR}/${file} ..."
        doexe scripts/${file} || ewarn "Installation of script ${file} failed!"
    done
}

pkg_postinst()
{
    ewarn "This ebuild is in alpha state!"
    ewarn "Use it at your own risk ..."
    elog "May the moon shine upon you ..."
}

pkg_config()
{
    # these messages seem not to go to normal log, einfo does the same, does it?
    elog "Starting configuration of ${PN}"
    # check if binary executable was installed
    if [ ! -x "${ROOT}${DESTINATION_DIR}/multimarkdown" ]; then
        ewarn "Installation of ${PN} failed"
        ewarn "Missing executable in ${ROOT}${DESTINATION_DIR}/multimarkdown"
        die "Previus installation of ${PN} failed"
    else
        einfo "multimarkdown binary installed in ${ROOT}${DESTINATION_DIR}/multimarkdown, displaying version"
        einfo "*** version start"
        einfo `${ROOT}${DESTINATION_DIR}/multimarkdown -v`
        einfo "*** version end"
    fi
    # check for the extra scripts
    einfo "${PN} comes with some extra scripts. They are not necessary for the programm itself, but serve as shortcuts, see http://fletcherpenney.net/multimarkdown/use/"
    einfo "You will now be asked if you want to keep these scripts or not:"
    for file in mmd mmd2tex mmd2opml mmd2odf; do
        if [ ! -x "${ROOT}${DESTINATION_DIR}/${file}" ]; then
            elog "${file} not found in ${ROOT}${DESTINATION_DIR}/${file}, it was previously removed."
        else
            # this seems to be bash4 syntax
            elog "${file} found in ${ROOT}${DESTINATION_DIR}/${file}."
            read -e -p "Do you want to keep the script at ${ROOT}${DESTINATION_DIR}/${file} [Y/n]?" -i "Y" keep_script
            if [ "${keep_script}" == "n" ]; then
                rm ${ROOT}${DESTINATION_DIR}/${file}
                elog "Removed script at ${ROOT}${DESTINATION_DIR}/${file}"
            fi
        fi
    done
    elog "Ending configuration of ${PN}"
}

pkg_info()
{
    ${ROOT}${DESTINATION_DIR}/multimarkdown -v
}

And here’s the metadata.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE pkgmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd">
<pkgmetadata>
    <herd>no-herd</herd>
    <maintainer>
        <email>wuodan@hispeed.ch</email>
        <name>Stefan Kuhn</name>
    </maintainer>
    <longdescription lang="en">
        MultiMarkdown, or MMD, is a tool to help turn minimally marked-up plain text into well formatted documents,
        including HTML, PDF (by way of LaTeX), OPML, or OpenDocument (specifically, Flat OpenDocument or .fodt,
        which can in turn be converted into RTF, Microsoft Word, or virtually any other word-processing format).
        
        MMD is a superset of the Markdown syntax, originally created by John Gruber. It adds multiple syntax features
        (tables, footnotes, and citations, to name a few), in addition to the various output formats listed above
        (Markdown only creates HTML). Additionally, it builds in ?smart? typography for various languages
        (proper left- and right-sided quotes, for example).
        
        MultiMarkdown was originally a fork of the Markdown Perl code, but as of version 3.0 has been rewritten as a
        fork of peg-markdown by John MacFarlane, written in C. It can be compiled for any major operating system, and
        as a native binary runs much faster than the Perl version it replaces. Many thanks to John for creating a
        great program, and sharing the source with the github community. MultiMarkdown 3.0 would not be possible
        without his efforts!
    </longdescription>
</pkgmetadata>

Home: Ebuild From Scratch
Previous chapter: Part 7 Testing & Fixing Installation
Next chapter: Part 9 Use Flags, Tests & Basic Dependencies

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: