Ports

portsnap

/etc/portsnap.conf

ミラーサイトを国内サーバに変更
#SERVERNAME=portsnap.FreeBSD.org
SERVERNAME=portsnap.allbsd.org
日本語以外の言語別PortsをPorts Treeに含めない
#REFUSE arabic chinese french german hebrew hungarian japanese
#REFUSE korean polish portuguese russian ukrainian vietnamese
REFUSE arabic chinese french german hebrew hungarian
REFUSE korean polish portuguese russian ukrainian vietnamese

Ports Tree Update

初回
# portsnap fetch extract update
2回目以降
# portsnap fetch update
cronに登録
# vi /etc/crontab
# PortsTree Update
0       3       *       *       *       root    /usr/sbin/portsnap cron && /usr/sbin/portsnap update > /dev/null

make.conf

Ports用の設定は、切り分けてインクルードする。

/etc/make.conf
_PORTSDIR=${.CURDIR:C@^${PORTSDIR}@@}

FORCE_MAKE_JOBS=YES
MAKE_JOBS_NUMBER=6

.if ${_PORTSDIR:M/databases/mysql5*} || \
    ${_PORTSDIR:M/databases/mariadb}
WITH_CHARSET=utf8
WITH_COLLATION=utf8_general_ci
WITH_XCHARSET=all
BUILD_OPTIMIZED=yes
BUILD_STATIC=yes
.endif

.if ${_PORTSDIR:M/japanese/MT}
DB_DIR=/home/mysql/movabletype
.endif

.if ${_PORTSDIR:M/archivers/libmspack*} || \
    ${_PORTSDIR:M/net/tightvnc*} || \
    ${_PORTSDIR:M/print/ghostscript8*} || \
    ${_PORTSDIR:M/devel/directfb*} || \
    ${_PORTSDIR:M/devel/gdb6*} || \
    ${_PORTSDIR:M/devel/seed*} || \
    ${_PORTSDIR:M/net/mDNSResponder*} || \
    ${_PORTSDIR:M/net-mgmt/zabbix-agent*} || \
    ${_PORTSDIR:M/x11/xfce4-conf*} || \
    ${_PORTSDIR:M/security/cyrus-sasl2*} || \
    ${_PORTSDIR:M/databases/sqlite2*} || \
    ${_PORTSDIR:M/java/openjdk*} || \
    ${_PORTSDIR:M/devel/icu}
DISABLE_MAKE_JOBS=YES
.endif

.if ${_PORTSDIR:M/textproc/docproj*}
JADETEX=no
.endif

.if ${_PORTSDIR:M/editors/vim}
NO_GUI=yes
.endif
個別指定しているPortsは旧鯖での実績から追加した物だが、今後、この部分は随時更新予定。

portmaster

世間一般ではportupdateがまだまだ主流かと思うが、私はportmasterを常用している。
インストールはこちらを参照。
以降、ports関連のインストール等はportmasterの利用を前提する。

Use Clang

Config

PortsのビルドにLLVM-Clangを使用する。
LLVM-Clangのインストールはこちらを参照。
Clangでのビルドに問題があるportsはGCC4.5.xを使用。それでもうまくいかない場合はデフォルトのGCC4.2.1を使用する。

/etc/make.conf.ports
.if !${_PORTSDIR:M/lang/gcc4*} && \
    !${_PORTSDIR:M/lang/clang} && \
    !${_PORTSDIR:M/www/squid*}
PORTS_CC=clang
.endif

.if ${_PORTSDIR:M/lang/php5} || \
    ${_PORTSDIR:M/lang/ruby*} || \
    ${_PORTSDIR:M/lang/python*} || \
    ${_PORTSDIR:M/devel/boost*} || \
    ${_PORTSDIR:M/devel/glib20} || \
    ${_PORTSDIR:M/graphics/liblqr-1} || \
    ${_PORTSDIR:M/graphics/gdk-pixbuf2} || \
    ${_PORTSDIR:M/textproc/silvercity} || \
    ${_PORTSDIR:M/databases/mysql*-server} || \
    ${_PORTSDIR:M/security/nmap} || \
    ${_PORTSDIR:M/x11-toolkits/tk85} || \
    ${_PORTSDIR:M/databases/tdb} || \
    ${_PORTSDIR:M/devel/icu} || \
    ${_PORTSDIR:M/net/libnet} || \
    ${_PORTSDIR:M/databases/mariadb} || \
    ${_PORTSDIR:M/www/rubygem-passenger} || \
    ${_PORTSDIR:M/devel/pecl-intl} || \
    ${_PORTSDIR:M/archivers/p7zip} || \
    ${_PORTSDIR:M/japanese/uim-anthy} || \
    ${_PORTSDIR:M/multimedia/mp4v2} || \
    ${_PORTSDIR:M/multimedia/ffmpeg}
PORTS_CC=gcc45
.endif

Patch for Mk

PORTS_CCを指定するため、/usr/ports/Mk以下のmkファイルに下記のパッチをそれぞれ適用する。

bsd.port.mk.diff
--- bsd.port.mk.orig	2010-06-07 20:49:31.892381628 +0300
+++ bsd.port.mk	2010-06-16 14:15:36.476947201 +0300
@@ -1161,6 +1161,7 @@
 INDEXDIR?=		${PORTSDIR}
 
 .include "${PORTSDIR}/Mk/bsd.commands.mk"
+.include "${PORTSDIR}/Mk/bsd.compiler.mk"
 
 #
 # DESTDIR section to start a chrooted process if invoked with DESTDIR set
bsd.gcc.mk.diff
--- bsd.gcc.mk.orig	2010-06-22 14:35:46.984179821 +0300
+++ bsd.gcc.mk	2010-06-16 12:58:30.346843024 +0300
@@ -204,6 +204,10 @@
 CFLAGS+=		-Wl,-rpath=${LOCALBASE}/lib/${_GCC_BUILD_DEPENDS}
 LDFLAGS+=		-Wl,-rpath=${LOCALBASE}/lib/${_GCC_BUILD_DEPENDS}
 .   endif
+.  else
+# Selected version is in base system.
+CC=				gcc
+CXX=			g++
 .  endif
 . endif
 .endfor
bsd.compiler.mk.diff
--- /dev/null	2010-06-22 14:41:17.000000000 +0300
+++ bsd.compiler.mk	2010-06-16 15:09:35.421902630 +0300
@@ -0,0 +1,54 @@
+# Set the defaults
+PORTS_CC?=	gcc
+# PORTS_CXX should only be set if PORTS_CC is neither gcc nor clang
+PORTS_CXX?=	g++
+
+.if defined(NO_USE_CC)
+.undef USE_CC
+.undef USE_GCC
+.endif
+
+# Handle USE_CC
+.if defined(USE_CC)
+# Check if port requires specific compiler
+.if !empty(USE_CC:Mgcc*) && empty(USE_CC:Mclang*)
+PORTS_CC=	gcc
+.elif !empty(USE_CC:Mclang*) && empty(USE_CC:Mgcc*)
+PORTS_CC=	clang
+.endif
+.endif
+
+# Handle PORTS_CC
+# GCC
+.if !empty(PORTS_CC:M*gcc*) || defined(USE_GCC)
+# These are set early so that USE_GCC can override it later if neccessary.
+CC=			${PORTS_CC}
+CXX=		${PORTS_CC:S/cc/++/}
+
+# USE_CC wants GCC from base system.
+.if defined(USE_CC) && !empty(USE_CC:Mgcc)
+CC=			gcc
+CXX=		g++
+
+# Translate USE_CC to USE_GCC if the former is defined.
+.elif defined(USE_CC) && !empty(USE_CC:Mgcc*)
+USE_GCC=	${USE_CC:Mgcc*:S/gcc//}
+.endif
+
+# If USE_GCC is defined, doesn't require specific version and accepts version
+# from PORTS_CC, override USE_GCC with version from PORTS_CC.
+.if defined(USE_GCC) && !empty(USE_GCC:M*+) && !empty(PORTS_CC:Mgcc??)
+. if ${PORTS_CC:C/gcc([0-9])([0-9])/\1.\2/} > ${USE_GCC:S/+//}
+USE_GCC=${PORTS_CC:C/gcc([0-9])([0-9])/\1.\2/}
+. endif
+.endif
+
+# Clang
+.elif !empty(PORTS_CC:Mclang*)
+CC=			clang
+CXX=		clang++
+.else
+# PORTS_CC is set to something weird
+CC=			${PORTS_CC}
+CXX=		${PORTS_CXX}
+.endif
パッチを適用
# patch bsd.compiler.mk bsd.compiler.mk.diff
Hmm...  Looks like a unified diff to me...
The text leading up to this was:
--------------------------
|--- /dev/null  2010-06-22 14:41:17.000000000 +0300
|+++ bsd.compiler.mk    2010-06-16 15:09:35.421902630 +0300
--------------------------
(Creating file bsd.compiler.mk...)
Patching file bsd.compiler.mk using Plan A...
Hunk #1 succeeded at 1.
done
# patch bsd.gcc.mk bsd.gcc.mk.diff
Hmm...  Looks like a unified diff to me...
The text leading up to this was:
--------------------------
|--- bsd.gcc.mk.orig    2010-06-22 14:35:46.984179821 +0300
|+++ bsd.gcc.mk 2010-06-16 12:58:30.346843024 +0300
--------------------------
Patching file bsd.gcc.mk using Plan A...
Hunk #1 succeeded at 192 (offset -12 lines).
done
# patch bsd.port.mk bsd.port.mk.diff
Hmm...  Looks like a unified diff to me...
The text leading up to this was:
--------------------------
|--- bsd.port.mk.orig   2010-06-07 20:49:31.892381628 +0300
|+++ bsd.port.mk        2010-06-16 14:15:36.476947201 +0300
--------------------------
Patching file bsd.port.mk using Plan A...
Hunk #1 succeeded at 1154 with fuzz 1 (offset -7 lines).
done

Parallel Download

Portsの求めるソースコード等のダウンロードを並列で行うことで高速化する。

AxelをPortsからインストール
# portmaster ftp/axel
                                               lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk
                                               x                      Options for axel 2.4_1                        x
                                               x lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk x
                                               x x                  [X] NLS    I18N support                       x x
                                               x x                  [ ] DEBUG  Debugging support                  x x
                                               x x                                                                x x
                                               x x                                                                x x
                                               x x                                                                x x
                                               x x                                                                x x
                                               x x                                                                x x
                                               x x                                                                x x
                                               x x                                                                x x
                                               x x                                                                x x
                                               x x                                                                x x
                                               x x                                                                x x
                                               x x                                                                x x
                                               x x                                                                x x
                                               x x                                                                x x
                                               tqmqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqjqu
                                               x                       [  OK  ]       Cancel                        x
                                               mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj
make.confの設定
FETCH_CMD=axel
FETCH_BEFORE_ARGS= -n 10 -a
DISABLE_SIZE=yes