以为 WWDC 会更新 MBP,没想到居然没有;于是给手头这台上了点年纪的 MBP 换了块 SSD 硬盘,准备坚持到明年 MBP 出新了。于是就要重装系统,顺便就试试 Mavericks 做为日用系统了。
没想到费劲装上 MacPorts 之后,装 MacVim 顺顺当当的,装 python27 (2.7.5) +universal 却如此费劲。先是 configure 阶段检测不到需要的 ipv6 编程接口,只得在 Portfile 里 append --disable-ipv6,编译又说 this platform's pyconfig.h needs to define PY_FORMAT_LONG_LONG,好吧进 work 目录给 pyconfig.h 加上:
#ifndef PY_FORMAT_LONG_LONG
#define PY_FORMAT_LONG_LONG "ll"
#endif
接下来
/usr/bin/clang -arch x86_64 -arch i386 -isysroot / -L/opt/local/lib -L/opt/local/lib/db46 -arch x86_64 -arch i386 -DPYTHONFRAMEWORK='"Python"' -o pythonw ./Tools/pythonw.c -I.. -I./../Include ../Python.framework/Versions/2.7/Python
In file included from ./Tools/pythonw.c:18:
./../Include/Python.h:33:10: fatal error: 'stdio.h' file not found
#include <stdio.h>
^
好吧,stdio.h 在这里:
/Applications/Xcode5-DP2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/
python27 port 以为 sysroot 是 / 是不科学的,/Applications/Xcode5-DP2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/ 才科学嘛。于是进到 /opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_tarballs_ports_lang_python27/python27/work/Python-2.7.5/Mac 里试了一下:
sudo /usr/bin/clang -arch x86_64 -arch i386 -isysroot /Applications/Xcode5-DP2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/ -L/opt/local/lib -L/opt/local/lib/db46 -arch x86_64 -arch i386 -DPYTHONFRAMEWORK='"Python"' -o pythonw ./Tools/pythonw.c -I.. -I./../Include ../Python.framework/Versions/2.7/Python
果然没事了。
如此看来,前面那些奇怪的问题,应该也是 sysroot 引起的吧。让我们从 Portfile 里就指定一个正确的 sysroot 好了,找到:
variant universal {
patchfiles-append patch-configure-universal.diff
post-patch {
reinplace \
"s|__UNIVERSAL_ARCHFLAGS__|${configure.universal_cflags}|" \
${worksrcpath}/configure
}
if {${configure.sdkroot} != ""} {
configure.args-append --enable-universalsdk=${configure.sdkroot}
} else {
configure.args-append --enable-universalsdk=/
}
}
改成
variant universal {
patchfiles-append patch-configure-universal.diff
post-patch {
reinplace \
"s|__UNIVERSAL_ARCHFLAGS__|${configure.universal_cflags}|" \
${worksrcpath}/configure
}
if {${configure.sdkroot} != ""} {
configure.args-append --enable-universalsdk=${configure.sdkroot}
} else {
configure.args-append --enable-universalsdk=/Applications/Xcode5-DP2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk
}
}
sudo port install python27 +universal
搞定。
这个问题在 apple-gcc42 上同样存在。所以,还得搞清楚为什么 configure.sdkroot 没有呢?xcode-select 是能够给出正确的 sdkroot path 的,etc/macport.conf 里的注释也是对的。sigh,tcl 已经有 10 年没碰了,早忘光了。