きりかノート 3冊め

おあそびプログラミング

ファイルをコピーするだけの Portfile は意外とめんどう

IdeoType がおもしろそうなので、作者の人のところ を参考にしながら野良 Portfile の作業中。

現行の元データとなる XHTML を処理するための DTD ファイルはローカルにおいておいたほうがよいらしいので、docbook-xml を参考に

  • インストール先は ${prefix}/share/xml/
  • カタログを ${prefix}/etc/xml/catalog に作成
    • システムに入ってる /usr/bin/xsltproc を使うなら、環境変数 XML_CATALOG_FILES の指定が必要
    • macports の xsltproc (port:libxslt に含まれる) を使うなら不要

としてみた。

おおざっぱに言って MacPorts でのソフトウェアインストールは

  1. fetch
  2. extract
  3. configure
  4. build
  5. destroot
  6. install
  7. activate

という流れになっているのだけど、今回はファイルをとってきて目的の場所に置くだけなので、

  • extract で展開せず、コピーだけする
  • configure でなにもしない
  • build でなにもしない

ということになる。

いま手元の svn に入ってるのは、こんな Portfile。extract をいじるところがムダに記述が多い気がする。もっとスマートに書けないものだろうか。

 % port cat xhtml-math11-dtd
# $Id: $
PortSystem 1.0

name xhtml-math11-dtd
categories textproc
version 20010221
description A prototype extension of XHTML 1.1 incorporating MathML 2.0.

maintainers kimuraw

set yyyy_vers [string range ${version} 0 3]
master_sites http://www.w3.org/TR/${yyyy_vers}/REC-MathML2-${version}/dtd
distfiles xhtml-math11-f.dtd
dist_subdir ${name}-${version}

checksums md5 4ef2a51a44492ec4e29897384b4684dd \
rmd160 a6b5fcf50e43263efb5c219fc60e9f1b6068777d \
sha1 0139a871a902f533f991c39f106acdcfa8741ac5

extract.mkdir yes
extract.cmd cp
extract.pre_args {}
extract.post_args ${worksrcpath}

use_configure no
build {}

set xml_destdir ${prefix}/share/xml/xhtml/1.1

destroot {
xinstall -d ${destroot}${xml_destdir}
xinstall -m 0644 ${worksrcpath}/${distfiles} ${destroot}${xml_destdir}
}

depends_run port:xmlcatmgr

# copy from textproc/docbook-xml-4.5
post-activate {
set catalog.xml ${prefix}/etc/xml/catalog
set dtd_file ${xml_destdir}/${distfiles}

# Make the directory if it doesn't exist
if {![file exists ${prefix}/etc/xml]} {
xinstall -m 755 -d ${prefix}/etc/xml
}

# Create the catalog file if it doesn't exist
if {![file exists ${catalog.xml}]} {
system "xmlcatmgr create -c ${catalog.xml}"
}

set xml.id "-//W3C//DTD XHTML 1.1 plus MathML 2.0//EN"

# Add the uri entry to the catalog if it doesn't exist
if {[catch {exec xmlcatmgr lookup ${xml.id}}]} {
ui_msg "add catalog ${dtd_file}"
system "xmlcatmgr add public \'${xml.id}\' file://${dtd_file}"
}

# Once MacPorts does get a post-deactivate hook, this should change to
# auto-detect whether or not the user's installed version has the hook, and
# only print the message if it doesn't.
ui_msg \
"######################################################################"
ui_msg "# As MacPorts does not currently have a post-deactivate hook,\
\n# you will need to ensure that you manually remove the catalog\
\n# entry for this port when you uninstall it. To do so, run\
\n# \"xmlcatmgr remove public \'${xml.id}\'\"."
ui_msg \
"######################################################################"
}