Wednesday, November 14, 2012

在 OS X 下編譯 squashfs-tools

我的環境是 Snow Leopard, 不知道在比較新的版本是不是還是這樣。

參考了 Build squashfs tools for Mac OS X 這篇描述了編譯 4.0 版的方法,不過因為我想用 4.2 的版本,所以我是手動作就是。

大致上要解決的問題包含:

  1. OS X 上未被定義的 FNM_EXTMATCH 常數
  2. 改引入 sys/sysctl.h 以供 unsquashfs.c 取得 CPU 數量
  3. OS X 上未被定義的一系列 l 開頭的 xattr 函數 (我猜應該也可以透過關閉 xattr 相關的功能避掉)

patch 丟到 Gist 上了,軟體跨平台真的是一件很藝術的事情。

diff -rupN squashfs4.2/squashfs-tools/Makefile squashfs4.2-mac/squashfs-tools/Makefile
--- squashfs4.2/squashfs-tools/Makefile 2011-03-01 04:04:15.000000000 +0800
+++ squashfs4.2-mac/squashfs-tools/Makefile 2012-11-14 15:27:31.000000000 +0800
@@ -104,7 +104,7 @@ UNSQUASHFS_OBJS = unsquashfs.o unsquash-
CFLAGS ?= -O2
CFLAGS += $(EXTRA_CFLAGS) $(INCLUDEDIR) -D_FILE_OFFSET_BITS=64 \
-D_LARGEFILE_SOURCE -D_GNU_SOURCE -DCOMP_DEFAULT=\"$(COMP_DEFAULT)\" \
- -Wall
+ -DFNM_EXTMATCH=0 -Wall
LIBS = -lpthread -lm
ifeq ($(GZIP_SUPPORT),1)
diff -rupN squashfs4.2/squashfs-tools/unsquashfs.c squashfs4.2-mac/squashfs-tools/unsquashfs.c
--- squashfs4.2/squashfs-tools/unsquashfs.c 2011-03-01 06:27:06.000000000 +0800
+++ squashfs4.2-mac/squashfs-tools/unsquashfs.c 2012-11-14 15:26:55.000000000 +0800
@@ -29,7 +29,7 @@
#include "compressor.h"
#include "xattr.h"
-#include <sys/sysinfo.h>
+#include <sys/sysctl.h>
#include <sys/types.h>
struct cache *fragment_cache, *data_cache;
diff -rupN squashfs4.2/squashfs-tools/unsquashfs_xattr.c squashfs4.2-mac/squashfs-tools/unsquashfs_xattr.c
--- squashfs4.2/squashfs-tools/unsquashfs_xattr.c 2011-02-11 23:49:24.000000000 +0800
+++ squashfs4.2-mac/squashfs-tools/unsquashfs_xattr.c 2012-11-14 15:28:25.000000000 +0800
@@ -27,6 +27,9 @@
#include <sys/xattr.h>
+#define lsetxattr(f, nam, v, len, flags) (setxattr(f, nam, v, len, flags, XATTR_NOFOLLOW))
+#define lremovexattr(f, nam) removexattr(f, nam, XATTR_NOFOLLOW)
+
extern int root_process;
void write_xattr(char *pathname, unsigned int xattr)
diff -rupN squashfs4.2/squashfs-tools/xattr.c squashfs4.2-mac/squashfs-tools/xattr.c
--- squashfs4.2/squashfs-tools/xattr.c 2011-02-11 23:49:24.000000000 +0800
+++ squashfs4.2-mac/squashfs-tools/xattr.c 2012-11-14 15:14:16.000000000 +0800
@@ -36,6 +36,9 @@
#include <stdlib.h>
#include <sys/xattr.h>
+#define llistxattr(f, buf, len) (listxattr(f, buf, len, XATTR_NOFOLLOW))
+#define lgetxattr(f, nam, buf, len) (getxattr(f, nam, buf, len, 0, XATTR_NOFOLLOW))
+
#include "squashfs_fs.h"
#include "squashfs_swap.h"
#include "mksquashfs.h"

Wednesday, October 24, 2012

在 ubuntu 12.10 上安裝 gcin

用 gcin 習慣了,所以裝好新版本第一件事情就是裝 gcin 上去。

首先刪掉 ibus 跟相關的套件:
sudo dpkg -P ibus ibus-gtk ibus-gtk3 ibus-pinyin-db-android
接著設定工具列圖示的顯示:
gsettings set com.canonical.Unity.Panel systray-whitelist "['JavaEmbeddedFrame', 'Wine', 'Update-notifier', 'gcin']"
安裝 gcin:
sudo apt-get install gcin
重設 GTK3 IM-Module 快取:
sudo /usr/lib/i386-linux-gnu/libgtk-3-0/gtk-query-immodules-3.0 --update-cache

這一步似乎是因為目前 ubuntu 所包版本 (2.7.6.1+dfsg-1) 的 post install script 漏了這步的關係,未來也許可以省掉。

設定為預設輸入法:
im-switch -s gcin

清除 cache 的部份花了很久才找到 (囧)

沒有更新 im-module cache 前,我遇到的狀況是: 在 gnome-terminal 與 gedit 怎麼弄都不能使用 Ctrl+Space 切換輸入法,按右鍵跑出來的輸入法選擇清單中也沒有 gcin 可選。

以往只要裝上 im-config 就會動,不過從作者的說法,現在這麼做反而會有問題。