我的環境是 Snow Leopard, 不知道在比較新的版本是不是還是這樣。
參考了 Build squashfs tools for Mac OS X 這篇描述了編譯 4.0 版的方法,不過因為我想用 4.2 的版本,所以我是手動作就是。
大致上要解決的問題包含:
- OS X 上未被定義的
FNM_EXTMATCH
常數 - 改引入
sys/sysctl.h
以供 unsquashfs.c 取得 CPU 數量 - OS X 上未被定義的一系列 l 開頭的 xattr 函數 (我猜應該也可以透過關閉 xattr 相關的功能避掉)
把 patch 丟到 Gist 上了,軟體跨平台真的是一件很藝術的事情。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |