libhoge.laを排除する

9.1Rくらいのシステムから引き継いだpkgなんかがあったりして無駄な苦労が絶えないうちのサーバ。
FreeBSD10 で netatalk3 を使って TimeMachine サーバにする
を参考にnetatalk3を入れなおそうとしてたら止まりました。

libtool:   error: cannot find the library '/usr/local/lib/libiconv.la' or unhandled argument '/usr/local/lib/libiconv.la'
Makefile:575: ターゲット 'afpd' のレシピで失敗しました
gmake[6]: *** [afpd] エラー 1
・
・
Stop.
make: stopped in /usr/ports/net/netatalk3
root@heliopora:/usr/ports/net/netatalk3 # 

libiconv.laが無い、またはその引数がおかしくてlibtoolがエラー。エラーメッセージをそのままぐーぐるさまに突っ込んだところ、libiconv.laをコンパイルしなおしてコピればいいという情報もあったけど、freebsd.orgのフォーラムに、"consolekit fails to compile | The FreeBSD Forums "というスレッドがあって、最後のところにこんなコメントが:

/usr/ports/UPDATING:

20140909:
  AFFECTS: users seeing build errors about missing *.la files
  AUTHOR: tijl@FreeBSD.org

  We are in the process of adjusting or, if possible, removing libtool archives
  (*.la files) from all ports because they can otherwise cause overlinking
  between packages.  This is the problem where in the dependency chain A->B->C
  an extra link is added from A to C even if A does not use C directly.  This
  makes some updates to port C expensive because then both A and B have to be
  rebuilt instead of just B.

  This is mostly behind the scenes work that you won't notice.  In fact most
  ports have already been converted.  You may however run into build errors
  about missing *.la files if a port update in the past went wrong and left
  behind *.la files with references to other *.la files that are no longer
  there.  In this case, please run the following command:

  find /usr/local/lib -name '*.la' | xargs grep -l 'libfoo\.la' | xargs pkg which
  (Replace libfoo\.la with the *.la file that is missing.)

  This command will print a list of *.la files that refer to the missing *.la
  file and what package they belong to.  First, where it says "not found in the
  datatbase", remove the *.la file.  After removing all such files, where it
  says "installed by package X", rebuild X.  Eventually the list printed by
  that command will be empty and the build error should be gone.

これでした。.laファイル(libtool archive)は依存解決で損だから廃止だよ、解決法はこちら。という内容です。
手順はこんな感じ:

  1. 問題のlibiconv.laを参照してる他の.laファイルを洗い出す。コマンドは find /usr/local/lib -name '*.la' | xargs grep -l 'libfoo\.la' | xargs pkg which です。(libfoo\.laは問題の.laファイル、今回ならlibiconv.laに置き換える)
  2. 出てきたXX.laについて、"was not found in the database"ならそのまま消す。
  3. 消し終わったら"installed by package X"のXをビルドし直す。
  4. ビルドエラーは消える。

とのことなので、さっそく実行。

find /usr/local/lib -name '*.la' | xargs grep -l 'libiconv\.la' | xargs pkg which
/usr/local/lib/libcdio.la was not found in the database
・
・
/usr/local/lib/librpmbuild.la was installed by package rpm-3.0.6_15
・
・
/usr/local/lib/gtk-2.0/2.10.0/printbackends/libprintbackend-cups.la was not found in the database
/usr/local/lib/gtk-2.0/2.10.0/engines/libpixmap.la was not found in the database

20個くらい見つかった"was not found in..."の.laファイルは全部削除。
"was installed by package..."であるところのrpm-3.0.6_15は最新のportsに無いので再ビルドできず、試しにpkg removeしてみると:

#	pkg remove rpm-3.0.6_15
Checking integrity... done (0 conflicting)
Deinstallation has been requested for the following 1 packages (of 0 packages in the universe):

Installed packages to be REMOVED:
	rpm-3.0.6_15

The operation will free 3 MiB.

Proceed with deinstalling packages? [y/N]: y
[1/1] Deinstalling rpm-3.0.6_15...
[1/1] Deleting files for rpm-3.0.6_15: 100%

依存するパッケージは無いようなので、もうそのまま削除。
なんかさらに問題が爆発したらどうしよう、と思いながらnetatalk3のディレクトリに戻ってmake install cleanしたところ、コンパイルもサクッと通ってあっというまに解決!
なんかすげースッキリしました。