Gentoo Portage

說實在話, 我相當不習慣portage限制很多阿…..

portage最主要的工具有兩個: emergeebuild.
在debian上, 關係就如apt-get與dpkg的相依性.
所以以下, 為了我自己看方便, 只列出與apt相似的指令(在怎麼說, apt比較習慣)
1. emerge: 最主要的ports管理程式, 如果只是裝裝東西, 找找東西之類的, 用這個就夠了

(1) emerge –sync(emerge –websync): 即apt-get update. 設定檔在/etc/make.conf
(2)
emerge –search “pkg_name": 即apt-cache search “pkg_name" or FreeBSD下的make search name="pkg_name"
(3) emerge “pkg_name": 即apt-get install “pkg_name"
(4) emerge –unmerge “pkg_name": 即apt-get remove “pkg_name"

2. ebuild: 建立 or 安裝一個ebuild(ports), 可以將emerge想成ebuild的frontend

(1) 一個正常的ebuild file如下 (以rstatd-4.0.1.ebuild為例): (also “man 5 ebuild")

#版權宣告, Header請自己加

# Copyright announcement.

# Please add “$Header: $" after

  1. Copyright 1999-2006 Gentoo Foundation
  2. Distributed under the terms of the GNU General Public License v2
  3. $Header: $

# package 描述

# Package Description
DESCRIPTION="rpc.rstatd – remotely view many system load related parameters"
HOMEPAGE="http://sourceforge.net/projects/rstatd/"
# package的source uri, 與BSD不同的是, package source是從各package的維護網頁抓下來

  1. 所以一定要附有該uri, 不然找不到source

# package’s source uri. The difference between BSD is, package source is obtained from package’s homepage, so this line is needed.
SRC_URI="mirror://sourceforge/${PN}/rpc.${P}.tar.gz"
# license授權方式

# license warrenty
LICENSE="GPL-2″
# 設定有幾個不同版本的package可同時存在, 通常設定"0″

# How many different versions of packages can exist together.
SLOT="0″

  1. Gentoo 著名的keyword限制, 以避免某些非官方認可的packages裝上系統.
  2. 當然可以自己強迫安裝, 修改/etc/portage/package.keywords.
  3. 以本例來說, 加入 net-misc/rstatd ~x86

# Keyword permission, to avoid some non-official packages installed.

# But, you can install with force, by modifying /etc/portage/package.keywords.

# in here, I added “net-mist/rstatd-x86″
KEYWORDS="~x86 ~amd64″

  1. list of USE flags

IUSE=""

  1. compile時, 需要與哪些packages相依

# Dependency of this package, for link only
DEPEND=""

  1. Runtime時, 需要與哪些packages相依, “!"代表不與某package相依.

# Runtime Dependency
RDEPEND="!net-misc/netkit-rusers"

  1. 暫存build directory

# Temporary directory
S="${WORKDIR}/rpc.${P}"

  1. 需要安裝的source, 必須有S這參數宣告過
  2. 寫法類似Makefile, 不過有些keywords, 請man

# Needed source, please have “S" declared

# This like Makefile, but it uses some keywords, please have man it for details.
src_install() {
emake DESTDIR="${D}" install || die “emake install failed"
doinitd ${FILESDIR}/rstatd || die “doinitd failed"

doman rpc.rstatd.8 rstatd.8 rup.1 rsysinfo.1
dodoc ChangeLog README
}

(2) 建立一完整package並整合到portage tree步驟如下: (以category/pkg為例)

<1> 編寫category/pkg.ebuild檔案, 並幫其放到/usr/portage之適當目錄下
<2> 切到該目錄, ebuild pkg.ebuild digest, 這樣會產生Manifest檔, 與files/digest-pkg-ver. 這是相當重要的, 因為emerge在install package時會依賴這些檔案.
<3> ebuild pkg.ebuild fetch: 抓取pkg的source
<4> ebuild pkg.ebuild unpack; ebuild pkg.ebuild compile: 解壓source, 並且compile.
<5> ebuild pkg.ebuild install: 安裝compile完的obj files.
<6> ebuild pkg.ebuild qmerge: 將pkg整合到portage tree.
(p.s: <3>~<6>可用ebuild pkg.ebuild merge完成之)
<7> 若要建立package or rpm: ebuild pkg.ebuild package(rpm)

(3) 這樣, 你就有自己獨創的portage source tree了. 以後要重裝, 可透過emerge處理.
更多訊息, 可man 5 ebuild, man emerge.

廣告