PageRenderTime 51ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 1ms

/core/macfuse_buildtool.sh

http://macfuse.googlecode.com/
Shell | 1706 lines | 1307 code | 276 blank | 123 comment | 167 complexity | e7f38310d7d964670562fb52cc388149 MD5 | raw file
Possible License(s): Apache-2.0, BSD-3-Clause, GPL-2.0
  1. #! /bin/bash
  2. # Copyright (C) 2008-2009 Google. All Rights Reserved.
  3. #
  4. # Amit Singh <singh@>
  5. # Repurposes code from several earlier scripts by Ted Bonkenburg.
  6. #
  7. PATH=/Developer/usr/sbin:/Developer/usr/bin:/Developer/Tools:/Developer/Applications:/sbin:/usr/sbin:/bin:/usr/bin
  8. export PATH
  9. # Configurables
  10. #
  11. # Beware: GNU libtool cannot handle directory names containing whitespace.
  12. # Therefore, do not set M_CONF_TMPDIR to such a directory.
  13. #
  14. readonly M_CONF_TMPDIR=/tmp
  15. readonly M_CONF_PRIVKEY=/etc/macfuse/private.der
  16. # Other constants
  17. #
  18. readonly M_PROGDESC="MacFUSE build tool"
  19. readonly M_PROGNAME=macfuse_buildtool
  20. readonly M_PROGVERS=1.0
  21. readonly M_DEFAULT_VALUE=__default__
  22. readonly M_CONFIGURATIONS="Debug Release" # default is Release
  23. readonly M_PLATFORMS="10.4 10.5 10.6" # default is native
  24. readonly M_PLATFORMS_REALISTIC="10.4 10.5"
  25. readonly M_TARGETS="clean dist examples lib libsrc reload smalldist swconfigure"
  26. readonly M_TARGETS_WITH_PLATFORM="examples lib libsrc smalldist swconfigure"
  27. readonly M_DEFAULT_PLATFORM="$M_DEFAULT_VALUE"
  28. readonly M_DEFAULT_TARGET="$M_DEFAULT_VALUE"
  29. readonly M_XCODE_VERSION_REQUIRED=3.1.1
  30. # Globals
  31. #
  32. declare m_args=
  33. declare m_active_target=""
  34. declare m_configuration=Release
  35. declare m_developer=0
  36. declare m_osname=""
  37. declare m_platform="$M_DEFAULT_PLATFORM"
  38. declare m_release=""
  39. declare m_shortcircuit=0
  40. declare m_srcroot=""
  41. declare m_srcroot_platformdir=""
  42. declare m_stderr=/dev/stderr
  43. declare m_stdout=/dev/stdout
  44. declare m_suprompt=" invalid "
  45. declare m_target="$M_DEFAULT_TARGET"
  46. declare m_usdk_dir=""
  47. declare m_version_tiger=""
  48. declare m_version_leopard=""
  49. declare m_version_snowleopard=""
  50. declare m_xcode_version=
  51. # Other implementation details
  52. #
  53. readonly M_FSBUNDLE_NAME=fusefs.fs
  54. readonly M_INSTALL_RESOURCES_DIR=Install_resources
  55. readonly M_KEXT_ID=com.google.filesystems.fusefs
  56. readonly M_KEXT_NAME=fusefs.kext
  57. readonly M_KEXT_SYMBOLS=fusefs-symbols
  58. readonly M_LIBFUSE_SRC=fuse-current.tar.gz
  59. readonly M_LIBFUSE_PATCH=fuse-current-macosx.patch
  60. readonly M_LOGPREFIX=MacFUSEBuildTool
  61. readonly M_MACFUSE_PRODUCT_ID=com.google.filesystems.fusefs
  62. readonly M_PKGNAME_CORE="MacFUSE Core.pkg"
  63. readonly M_PKGNAME=MacFUSE.pkg
  64. readonly M_WANTSU="needs the Administrator password"
  65. readonly M_WARNING="*** Warning"
  66. function m_help()
  67. {
  68. cat <<__END_HELP_CONTENT
  69. $M_PROGDESC version $M_PROGVERS
  70. Copyright (C) 2008 Google. All Rights Reserved.
  71. Usage:
  72. $M_PROGNAME [-dhqsv] [-c configuration] [-p platform] -t target
  73. * configuration is one of: $M_CONFIGURATIONS (default is $m_configuration)
  74. * platform is one of: $M_PLATFORMS (default is the host's platform)
  75. * target is one of: $M_TARGETS
  76. * platforms can only be specified for: $M_TARGETS_WITH_PLATFORM
  77. The target keywords mean the following:
  78. clean clean all targets
  79. dist create a multiplatform distribution package
  80. examples build example file systems (e.g. fusexmp_fh and hello)
  81. lib build the user-space library (e.g. to run fusexmp_fh)
  82. libsrc unpack and patch the user-space library source
  83. reload rebuild and reload the kernel extension
  84. smalldist create a platform-specific distribution package
  85. swconfigure configure software (e.g. sshfs) for compilation
  86. Other options are:
  87. -d create a developer prerelease package instead of a regular release
  88. -q enable quiet mode (suppresses verbose build output)
  89. -s enable shortcircuit mode (useful for testing the build mechanism itself)
  90. -v report version numbers and quit
  91. __END_HELP_CONTENT
  92. return 0
  93. }
  94. # m_version()
  95. #
  96. function m_version
  97. {
  98. echo "$M_PROGDESC version $M_PROGVERS"
  99. m_set_platform
  100. m_set_srcroot "$m_platform"
  101. local mv_platform_dirs=`ls -d "$m_srcroot"/core/10.*`
  102. for i in $mv_platform_dirs
  103. do
  104. local mv_release=`awk '/#define[ \t]*MACFUSE_VERSION_LITERAL/ {print $NF}' "$i/fusefs/common/fuse_version.h"`
  105. if [ ! -z "$mv_release" ]
  106. then
  107. echo "Platform source '$i': MacFUSE version $mv_release"
  108. fi
  109. done
  110. return 0
  111. }
  112. # m_log(msg)
  113. #
  114. function m_log()
  115. {
  116. printf "%-30s: %s\n" "$M_LOGPREFIX($m_active_target)" "$*"
  117. }
  118. # m_warn(msg)
  119. #
  120. function m_warn()
  121. {
  122. echo "$M_WARNING: $*"
  123. }
  124. # m_exit_on_error(errmsg)
  125. #
  126. function m_exit_on_error()
  127. {
  128. if [ "$?" != 0 ]
  129. then
  130. local retval=$?
  131. echo "$M_LOGPREFIX($m_active_target) failed: $1" 1>&2
  132. exit $retval
  133. fi
  134. # NOTREACHED
  135. }
  136. # m_set_suprompt(msg)
  137. #
  138. function m_set_suprompt()
  139. {
  140. m_suprompt="$M_LOGPREFIX($m_active_target) $M_WANTSU $*: "
  141. }
  142. # m_set_srcroot([platform])
  143. #
  144. function m_set_srcroot()
  145. {
  146. local macfuse_dir=""
  147. local is_absolute_path=`echo "$0" | cut -c1`
  148. if [ "$is_absolute_path" == "/" ]
  149. then
  150. macfuse_dir="`dirname $0`/.."
  151. else
  152. macfuse_dir="`pwd`/`dirname $0`/.."
  153. fi
  154. pushd . > /dev/null
  155. cd "$macfuse_dir" || exit 1
  156. macfuse_dir=`pwd`
  157. popd > /dev/null
  158. m_srcroot="$macfuse_dir"
  159. if [ "x$1" != "x" ] && [ "$1" != "$M_DEFAULT_PLATFORM" ]
  160. then
  161. m_srcroot_platformdir="$m_srcroot/core/$1"
  162. if [ ! -d "$m_srcroot_platformdir" ]
  163. then
  164. m_srcroot_platformdir="$M_DEFAULT_VALUE"
  165. m_warn "directory '$m_srcroot/$1' does not exist."
  166. fi
  167. fi
  168. return 0
  169. }
  170. # m_set_platform()
  171. #
  172. function m_set_platform()
  173. {
  174. local retval=0
  175. if [ "$m_platform" == "$M_DEFAULT_PLATFORM" ]
  176. then
  177. m_platform=`sw_vers -productVersion | cut -d . -f 1,2`
  178. fi
  179. # XXX For now
  180. if [ "$m_platform" == "10.6" ]
  181. then
  182. m_platform="10.5"
  183. fi
  184. case "$m_platform" in
  185. 10.4*)
  186. m_osname="Tiger"
  187. m_usdk_dir="/Developer/SDKs/MacOSX10.4u.sdk"
  188. ;;
  189. 10.5*)
  190. m_osname="Leopard"
  191. m_usdk_dir="/Developer/SDKs/MacOSX10.5.sdk"
  192. ;;
  193. 10.6*)
  194. m_osname="Snow Leopard"
  195. m_usdk_dir="/Developer/SDKs/MacOSX10.6.sdk"
  196. ;;
  197. *)
  198. m_osname="Unknown"
  199. m_usdk_dir=""
  200. retval=1
  201. ;;
  202. esac
  203. return $retval
  204. }
  205. # m_build_pkg(pkgversion, install_srcroot, install_payload, pkgname, output_dir)
  206. #
  207. function m_build_pkg()
  208. {
  209. local bp_pkgversion=$1
  210. local bp_install_srcroot=$2
  211. local bp_install_payload=$3
  212. local bp_pkgname=$4
  213. local bp_output_dir=$5
  214. local bp_infoplist_in="$bp_install_srcroot/Info.plist.in"
  215. local bp_infoplist_out="$bp_output_dir/Info.plist"
  216. local bp_descriptionplist="$bp_install_srcroot/Description.plist"
  217. # Fix up the Info.plist
  218. #
  219. sed -e "s/MACFUSE_VERSION_LITERAL/$bp_pkgversion/g" \
  220. < "$bp_infoplist_in" > "$bp_infoplist_out"
  221. m_exit_on_error "cannot finalize Info.plist for package '$bp_pkgname'."
  222. # Get rid of .svn files from M_INSTALL_RESOURCES_DIR
  223. #
  224. (tar -C "$bp_install_srcroot" --exclude '.svn' -cpvf - \
  225. "$M_INSTALL_RESOURCES_DIR" | tar -C "$bp_output_dir/" \
  226. -xpvf - >$m_stdout 2>$m_stderr)>$m_stdout 2>$m_stderr
  227. m_exit_on_error "cannot migrate resources from '$M_INSTALL_RESOURCES_DIR'."
  228. # Make the package
  229. m_set_suprompt "to run packagemaker"
  230. sudo -p "$m_suprompt" \
  231. packagemaker -build -p "$bp_output_dir/$bp_pkgname" \
  232. -f "$bp_install_payload" -b "$M_CONF_TMPDIR" -ds -v \
  233. -r "$bp_output_dir/$M_INSTALL_RESOURCES_DIR" -i "$bp_infoplist_out" \
  234. -d "$bp_descriptionplist" >$m_stdout 2>$m_stderr
  235. m_exit_on_error "cannot create package '$bp_pkgname'."
  236. return 0
  237. }
  238. # Prepare the user-space library source
  239. #
  240. function m_handler_libsrc()
  241. {
  242. m_active_target="libsrc"
  243. m_set_platform
  244. m_set_srcroot "$m_platform"
  245. local lib_dir="$m_srcroot"/core/"$m_platform"/libfuse
  246. if [ ! -d "$lib_dir" ]
  247. then
  248. false
  249. m_exit_on_error "cannot access directory '$lib_dir'."
  250. fi
  251. local kernel_dir="$m_srcroot"/core/"$m_platform"/fusefs
  252. if [ ! -d "$kernel_dir" ]
  253. then
  254. false
  255. m_exit_on_error "cannot access directory '$kernel_dir'."
  256. fi
  257. local package_dir=`tar -tzvf "$lib_dir/$M_LIBFUSE_SRC" | head -1 | awk '{print $NF}'`
  258. if [ "x$package_dir" == "x" ]
  259. then
  260. false
  261. m_exit_on_error "cannot determine MacFUSE library version."
  262. fi
  263. local package_name=`basename "$package_dir"`
  264. if [ "x$package_name" == "x" ]
  265. then
  266. false
  267. m_exit_on_error "cannot determine MacFUSE library version."
  268. fi
  269. rm -rf "$M_CONF_TMPDIR/$package_name"
  270. if [ "$1" == "clean" ]
  271. then
  272. local retval=$?
  273. m_log "cleaned (platform $m_platform)"
  274. return $retval
  275. fi
  276. m_log "initiating Universal build for $m_platform"
  277. tar -C "$M_CONF_TMPDIR" -xzvf "$lib_dir/$M_LIBFUSE_SRC" \
  278. >$m_stdout 2>$m_stderr
  279. m_exit_on_error "cannot untar MacFUSE library source from '$M_LIBFUSE_SRC'."
  280. cd "$M_CONF_TMPDIR/$package_name"
  281. m_exit_on_error "cannot access MacFUSE library source in '$M_CONF_TMPDIR/$package_name'."
  282. m_log "preparing library source"
  283. patch -p1 < "$lib_dir/$M_LIBFUSE_PATCH" >$m_stdout 2>$m_stderr
  284. m_exit_on_error "cannot patch MacFUSE library source."
  285. echo >$m_stdout
  286. m_log "succeeded, results in '$M_CONF_TMPDIR/$package_name'."
  287. echo >$m_stdout
  288. return 0
  289. }
  290. # Build the user-space library
  291. #
  292. function m_handler_lib()
  293. {
  294. m_active_target="lib"
  295. m_set_platform
  296. m_set_srcroot "$m_platform"
  297. local lib_dir="$m_srcroot"/core/"$m_platform"/libfuse
  298. if [ ! -d "$lib_dir" ]
  299. then
  300. false
  301. m_exit_on_error "cannot access directory '$lib_dir'."
  302. fi
  303. local kernel_dir="$m_srcroot"/core/"$m_platform"/fusefs
  304. if [ ! -d "$kernel_dir" ]
  305. then
  306. false
  307. m_exit_on_error "cannot access directory '$kernel_dir'."
  308. fi
  309. local package_dir=`tar -tzvf "$lib_dir/$M_LIBFUSE_SRC" | head -1 | awk '{print $NF}'`
  310. if [ "x$package_dir" == "x" ]
  311. then
  312. false
  313. m_exit_on_error "cannot determine MacFUSE library version."
  314. fi
  315. local package_name=`basename "$package_dir"`
  316. if [ "x$package_name" == "x" ]
  317. then
  318. false
  319. m_exit_on_error "cannot determine MacFUSE library version."
  320. fi
  321. rm -rf "$M_CONF_TMPDIR/$package_name"
  322. if [ "$1" == "clean" ]
  323. then
  324. local retval=$?
  325. m_log "cleaned (platform $m_platform)"
  326. return $retval
  327. fi
  328. m_log "initiating Universal build for $m_platform"
  329. tar -C "$M_CONF_TMPDIR" -xzvf "$lib_dir/$M_LIBFUSE_SRC" \
  330. >$m_stdout 2>$m_stderr
  331. m_exit_on_error "cannot untar MacFUSE library source from '$M_LIBFUSE_SRC'."
  332. cd "$M_CONF_TMPDIR/$package_name"
  333. m_exit_on_error "cannot access MacFUSE library source in '$M_CONF_TMPDIR/$package_name'."
  334. m_log "preparing library source"
  335. patch -p1 < "$lib_dir/$M_LIBFUSE_PATCH" >$m_stdout 2>$m_stderr
  336. m_exit_on_error "cannot patch MacFUSE library source."
  337. m_log "configuring library source"
  338. /bin/sh ./darwin_configure.sh "$kernel_dir" >$m_stdout 2>$m_stderr
  339. m_exit_on_error "cannot configure MacFUSE library source for compilation."
  340. m_log "running make"
  341. make -j2 >$m_stdout 2>$m_stderr
  342. m_exit_on_error "make failed while compiling the MacFUSE library."
  343. echo >$m_stdout
  344. m_log "succeeded, results in '$M_CONF_TMPDIR/$package_name'."
  345. echo >$m_stdout
  346. return 0
  347. }
  348. # Rebuild and reload the kernel extension
  349. #
  350. function m_handler_reload()
  351. {
  352. m_active_target="reload"
  353. # Argument validation would have ensured that we use native platform
  354. # for this target.
  355. m_set_platform
  356. m_set_srcroot "$m_platform"
  357. local kernel_dir="$m_srcroot/core/$m_platform/fusefs"
  358. if [ ! -d "$kernel_dir" ]
  359. then
  360. false
  361. m_exit_on_error "cannot access directory '$kernel_dir'."
  362. fi
  363. if [ -e "$M_CONF_TMPDIR/$M_KEXT_NAME" ]
  364. then
  365. m_set_suprompt "to remove old MacFUSE kext"
  366. sudo -p "$m_suprompt" rm -rf "$M_CONF_TMPDIR/$M_KEXT_NAME"
  367. m_exit_on_error "cannot remove old copy of MacFUSE kext."
  368. fi
  369. if [ -e "$M_CONF_TMPDIR/$M_KEXT_SYMBOLS" ]
  370. then
  371. m_set_suprompt "to remove old copy of MacFUSE kext symbols"
  372. sudo -p "$m_suprompt" rm -rf "$M_CONF_TMPDIR/$M_KEXT_SYMBOLS"
  373. m_exit_on_error "cannot remove old copy of MacFUSE kext symbols."
  374. fi
  375. if [ "$1" == "clean" ]
  376. then
  377. rm -rf "$kernel_dir/build/"
  378. local retval=$?
  379. m_log "cleaned (platform $m_platform)"
  380. return $retval
  381. fi
  382. m_log "initiating kernel extension rebuild/reload for $m_platform"
  383. kextstat -l -b "$M_KEXT_ID" | grep "$M_KEXT_ID" >/dev/null 2>/dev/null
  384. if [ "$?" == "0" ]
  385. then
  386. m_log "unloading kernel extension"
  387. m_set_suprompt "to unload MacFUSE kext"
  388. sudo -p "$m_suprompt" \
  389. kextunload -v -b "$M_KEXT_ID" >$m_stdout 2>$m_stderr
  390. m_exit_on_error "cannot unload kext '$M_KEXT_ID'."
  391. fi
  392. cd "$kernel_dir"
  393. m_exit_on_error "failed to access the kext source directory '$kernel_dir'."
  394. m_log "rebuilding kext"
  395. xcodebuild -configuration Debug -target fusefs >$m_stdout 2>$m_stderr
  396. m_exit_on_error "xcodebuild cannot build configuration Debug for target fusefs."
  397. mkdir "$M_CONF_TMPDIR/$M_KEXT_SYMBOLS"
  398. m_exit_on_error "cannot create directory for MacFUSE kext symbols."
  399. cp -R "$kernel_dir/build/Debug/$M_KEXT_NAME" "$M_CONF_TMPDIR/$M_KEXT_NAME"
  400. m_exit_on_error "cannot copy newly built MacFUSE kext."
  401. m_set_suprompt "to set permissions on newly built MacFUSE kext"
  402. sudo -p "$m_suprompt" chown -R root:wheel "$M_CONF_TMPDIR/$M_KEXT_NAME"
  403. m_exit_on_error "cannot set permissions on newly built MacFUSE kext."
  404. m_log "reloading kext"
  405. m_set_suprompt "to load newly built MacFUSE kext"
  406. sudo -p "$m_suprompt" \
  407. kextload -s "$M_CONF_TMPDIR/$M_KEXT_SYMBOLS" \
  408. -v "$M_CONF_TMPDIR/$M_KEXT_NAME" >$m_stdout 2>$m_stderr
  409. m_exit_on_error "cannot load newly built MacFUSE kext."
  410. echo >$m_stdout
  411. m_log "checking status of kernel extension"
  412. kextstat -l -b "$M_KEXT_ID"
  413. echo >$m_stdout
  414. echo >$m_stdout
  415. m_log "succeeded, results in '$M_CONF_TMPDIR'."
  416. echo >$m_stdout
  417. return 0
  418. }
  419. # Build examples from the user-space MacFUSE library
  420. #
  421. function m_handler_examples()
  422. {
  423. m_active_target="examples"
  424. m_set_platform
  425. m_set_srcroot "$m_platform"
  426. local lib_dir="$m_srcroot"/core/"$m_platform"/libfuse
  427. if [ ! -d "$lib_dir" ]
  428. then
  429. false
  430. m_exit_on_error "cannot access directory '$lib_dir'."
  431. fi
  432. local kernel_dir="$m_srcroot"/core/"$m_platform"/fusefs
  433. if [ ! -d "$kernel_dir" ]
  434. then
  435. false
  436. m_exit_on_error "cannot access directory '$kernel_dir'."
  437. fi
  438. local package_dir=`tar -tzvf "$lib_dir/$M_LIBFUSE_SRC" | head -1 | awk '{print $NF}'`
  439. if [ "x$package_dir" == "x" ]
  440. then
  441. false
  442. m_exit_on_error "cannot determine MacFUSE library version."
  443. fi
  444. local package_name=`basename "$package_dir"`
  445. if [ "x$package_name" == "x" ]
  446. then
  447. false
  448. m_exit_on_error "cannot determine MacFUSE library version."
  449. fi
  450. rm -rf "$M_CONF_TMPDIR/$package_name"
  451. if [ "$1" == "clean" ]
  452. then
  453. local retval=$?
  454. m_log "cleaned (platform $m_platform)"
  455. return $retval
  456. fi
  457. m_log "initiating Universal build for $m_platform"
  458. tar -C "$M_CONF_TMPDIR" -xzvf "$lib_dir/$M_LIBFUSE_SRC" \
  459. >$m_stdout 2>$m_stderr
  460. m_exit_on_error "cannot untar MacFUSE library source from '$M_LIBFUSE_SRC'."
  461. cd "$M_CONF_TMPDIR/$package_name"
  462. m_exit_on_error "cannot access MacFUSE library source in '$M_CONF_TMPDIR/$package_name'."
  463. m_log "preparing library source"
  464. patch -p1 < "$lib_dir/$M_LIBFUSE_PATCH" >$m_stdout 2>$m_stderr
  465. m_exit_on_error "cannot patch MacFUSE library source."
  466. m_log "configuring library source"
  467. /bin/sh ./darwin_configure_ino64.sh "$kernel_dir" >$m_stdout 2>$m_stderr
  468. m_exit_on_error "cannot configure MacFUSE library source for compilation."
  469. cd example
  470. m_exit_on_error "cannot access examples source."
  471. local me_installed_lib="/usr/local/lib/libfuse_ino64.la"
  472. if [ "$m_platform" == "10.4" ]
  473. then
  474. me_installed_lib="/usr/local/lib/libfuse.la"
  475. fi
  476. perl -pi -e "s#../lib/libfuse.la#$me_installed_lib#g" Makefile
  477. m_exit_on_error "failed to prepare example source for build."
  478. m_log "running make"
  479. make -j2 >$m_stdout 2>$m_stderr
  480. m_exit_on_error "make failed while compiling the MacFUSE examples."
  481. echo >$m_stdout
  482. m_log "succeeded, results in '$M_CONF_TMPDIR/$package_name/example'."
  483. echo >$m_stdout
  484. return 0
  485. }
  486. # Build a multiplatform distribution package
  487. #
  488. function m_handler_dist()
  489. {
  490. m_active_target="dist"
  491. if [ "$1" == "clean" ]
  492. then
  493. for m_p in $M_PLATFORMS_REALISTIC
  494. do
  495. m_platform="$m_p"
  496. m_handler_smalldist clean
  497. done
  498. m_active_target="dist"
  499. m_set_platform
  500. m_set_srcroot "$m_platform"
  501. rm -rf "$m_srcroot/core/autoinstaller/build"
  502. m_log "cleaned internal subtarget autoinstaller"
  503. rm -rf "$m_srcroot/core/prefpane/build"
  504. m_log "cleaned internal subtarget prefpane"
  505. m_release=`awk '/#define[ \t]*MACFUSE_VERSION_LITERAL/ {print $NF}' "$m_srcroot/core/$m_platform/fusefs/common/fuse_version.h" | cut -d . -f 1,2`
  506. if [ ! -z "$m_release" ]
  507. then
  508. if [ -e "$M_CONF_TMPDIR/macfuse-$m_release" ]
  509. then
  510. m_set_suprompt "to remove previous output packages"
  511. sudo -p "$m_suprompt" rm -rf "$M_CONF_TMPDIR/macfuse-$m_release"
  512. m_log "cleaned any previous output packages in '$M_CONF_TMPDIR'"
  513. fi
  514. fi
  515. return 0
  516. fi
  517. m_log "initiating Universal build of MacFUSE"
  518. m_set_platform
  519. m_set_srcroot "$m_platform"
  520. m_log "configuration is '$m_configuration'"
  521. if [ "$m_developer" == "0" ]
  522. then
  523. m_log "packaging flavor is 'Mainstream'"
  524. else
  525. m_log "packaging flavor is 'Developer Prerelease'"
  526. fi
  527. m_log "locating MacFUSE private key"
  528. if [ ! -f "$M_CONF_PRIVKEY" ]
  529. then
  530. false
  531. m_exit_on_error "cannot find MacFUSE private key in '$M_CONF_PRIVKEY'."
  532. fi
  533. # Autoinstaller
  534. #
  535. local md_ai_builddir="$m_srcroot/core/autoinstaller/build"
  536. if [ "$m_shortcircuit" != "1" ]
  537. then
  538. rm -rf "$md_ai_builddir"
  539. # ignore any errors
  540. fi
  541. m_log "building the MacFUSE autoinstaller"
  542. pushd "$m_srcroot/core/autoinstaller" >/dev/null 2>/dev/null
  543. m_exit_on_error "cannot access the autoinstaller source."
  544. xcodebuild -configuration "$m_configuration" -target "Build All" \
  545. >$m_stdout 2>$m_stderr
  546. m_exit_on_error "xcodebuild cannot build configuration $m_configuration for subtarget autoinstaller."
  547. popd >/dev/null 2>/dev/null
  548. local md_ai="$md_ai_builddir/$m_configuration/autoinstall-macfuse-core"
  549. if [ ! -x "$md_ai" ]
  550. then
  551. false
  552. m_exit_on_error "cannot find autoinstaller '$md_ai'."
  553. fi
  554. local md_plistsigner="$md_ai_builddir/$m_configuration/plist_signer"
  555. if [ ! -x "$md_plistsigner" ]
  556. then
  557. false
  558. m_exit_on_error "cannot find plist signer '$md_plistsigner'."
  559. fi
  560. # Create platform-Specific MacFUSE subpackages
  561. #
  562. for m_p in $M_PLATFORMS_REALISTIC
  563. do
  564. pushd . >/dev/null 2>/dev/null
  565. m_active_target="dist"
  566. m_platform="$m_p"
  567. m_log "building platform $m_platform"
  568. m_handler_smalldist
  569. popd >/dev/null 2>/dev/null
  570. done
  571. # Build the preference pane
  572. #
  573. local md_pp_builddir="$m_srcroot/core/prefpane/build"
  574. if [ "$m_shortcircuit" != "1" ]
  575. then
  576. rm -rf "$md_pp_builddir"
  577. # ignore any errors
  578. fi
  579. m_log "building the MacFUSE prefpane"
  580. pushd "$m_srcroot/core/prefpane" >/dev/null 2>/dev/null
  581. m_exit_on_error "cannot access the prefpane source."
  582. xcodebuild -configuration "$m_configuration" -target "MacFUSE" \
  583. >$m_stdout 2>$m_stderr
  584. m_exit_on_error "xcodebuild cannot build configuration $m_configuration for subtarget prefpane."
  585. popd >/dev/null 2>/dev/null
  586. local md_pp="$md_pp_builddir/$m_configuration/MacFUSE.prefPane"
  587. if [ ! -d "$md_pp" ]
  588. then
  589. false
  590. m_exit_on_error "cannot find preference pane."
  591. fi
  592. cp "$md_ai" "$md_pp/Contents/MacOS"
  593. m_exit_on_error "cannot copy the autoinstaller to the prefpane bundle."
  594. # Build the container
  595. #
  596. m_active_target="dist"
  597. m_release=`awk '/#define[ \t]*MACFUSE_VERSION_LITERAL/ {print $NF}' "$m_srcroot/core/$m_platform/fusefs/common/fuse_version.h" | cut -d . -f 1,2`
  598. m_exit_on_error "cannot get MacFUSE release version."
  599. local md_macfuse_out="$M_CONF_TMPDIR/macfuse-$m_release"
  600. local md_macfuse_root="$md_macfuse_out/pkgroot/"
  601. if [ -e "$md_macfuse_out" ]
  602. then
  603. m_set_suprompt "to remove a previously built container package"
  604. sudo -p "$m_suprompt" rm -rf "$md_macfuse_out"
  605. # ignore any errors
  606. fi
  607. m_log "initiating distribution build"
  608. local md_platforms=""
  609. local md_platform_dirs=`ls -d "$M_CONF_TMPDIR"/macfuse-core-*${m_release}.* | paste -s -`
  610. m_log "found payloads $md_platform_dirs"
  611. for i in $md_platform_dirs
  612. do
  613. local md_tmp_versions=${i#*core-}
  614. local md_tmp_release_version=${md_tmp_versions#*-}
  615. local md_tmp_os_version=${md_tmp_versions%-*}
  616. md_platforms="${md_platforms},${md_tmp_os_version}=${i}/$M_PKGNAME_CORE"
  617. case "$md_tmp_os_version" in
  618. 10.4)
  619. m_version_tiger=$md_tmp_release_version
  620. ;;
  621. 10.5)
  622. m_version_leopard=$md_tmp_release_version
  623. ;;
  624. 10.6)
  625. m_version_snowleopard=$md_tmp_release_version
  626. ;;
  627. esac
  628. m_log "adding [ '$md_tmp_os_version', '$md_tmp_release_version' ]"
  629. done
  630. m_log "building '$M_PKGNAME'"
  631. mkdir "$md_macfuse_out"
  632. m_exit_on_error "cannot create directory '$md_macfuse_out'."
  633. mkdir "$md_macfuse_root"
  634. m_exit_on_error "cannot create directory '$md_macfuse_root'."
  635. m_log "copying generic container package payload"
  636. mkdir -p "$md_macfuse_root/Library/PreferencePanes"
  637. m_exit_on_error "cannot make directory '$md_macfuse_root/Library/PreferencePanes'."
  638. cp -R "$md_pp" "$md_macfuse_root/Library/PreferencePanes/"
  639. m_exit_on_error "cannot copy the prefpane to '$md_macfuse_root/Library/PreferencePanes/'."
  640. m_set_suprompt "to chown '$md_macfuse_root/'."
  641. sudo -p "$m_suprompt" chown -R root:wheel "$md_macfuse_root/"
  642. local md_srcroot="$m_srcroot/core/packaging/macfuse"
  643. local md_infoplist_in="$md_srcroot/Info.plist.in"
  644. local md_infoplist_out="$md_macfuse_out/Info.plist"
  645. local md_descriptionplist="$md_srcroot/Description.plist"
  646. local md_install_resources="$md_macfuse_out/$M_INSTALL_RESOURCES_DIR"
  647. # Get rid of .svn files from M_INSTALL_RESOURCES_DIR
  648. #
  649. (tar -C "$md_srcroot" --exclude '.svn' -cpvf - \
  650. "$M_INSTALL_RESOURCES_DIR" | tar -C "$md_macfuse_out" -xpvf - \
  651. >$m_stdout 2>$m_stderr)>$m_stdout 2>$m_stderr
  652. # Copy subpackage platform directories under Resources
  653. #
  654. local md_pkg_size=0
  655. local md_saved_ifs="$IFS"
  656. IFS=","
  657. for i in $md_platforms
  658. do
  659. if [ x"$i" == x"" ]
  660. then
  661. continue; # Skip empty/bogus comma-item
  662. fi
  663. local md_tmp_os_version=${i%%=*}
  664. local md_tmp_core_pkg=${i##*=}
  665. local md_tmp_core_pkg_dir=$(dirname "$md_tmp_core_pkg")
  666. local md_tmp_core_pkg_name=$(basename "$md_tmp_core_pkg")
  667. local md_tmp_pkg_dst="$md_install_resources/$md_tmp_os_version"
  668. local md_tmp_new_size=$(defaults read "$md_tmp_core_pkg/Contents/Info" IFPkgFlagInstalledSize)
  669. if [ -z "$md_tmp_new_size" ]
  670. then
  671. m_warn "unable to read package size from '$md_tmp_core_pkg'."
  672. fi
  673. if [ $md_tmp_new_size -gt $md_pkg_size ]
  674. then
  675. md_pkg_size=$md_tmp_new_size
  676. fi
  677. mkdir "$md_tmp_pkg_dst"
  678. m_exit_on_error "cannot make package subdirectory '$md_tmp_pkg_dst'."
  679. m_set_suprompt "to add platform-specific package to container"
  680. (sudo -p "$m_suprompt" tar -C "$md_tmp_core_pkg_dir" -cpvf - "$md_tmp_core_pkg_name" | sudo -p "$m_suprompt" tar -C "$md_tmp_pkg_dst" -xpvf - >$m_stdout 2>$m_stderr)>$m_stdout 2>$m_stderr
  681. m_exit_on_error "cannot add package."
  682. done
  683. IFS="$md_saved_ifs"
  684. # XXX For now, make 10.5 also valid for 10.6
  685. #
  686. if [ -d "$md_install_resources/10.5" ]
  687. then
  688. ln -s "10.5" "$md_install_resources/10.6"
  689. fi
  690. # Throw in the autoinstaller
  691. #
  692. cp "$md_ai" "$md_install_resources"
  693. m_exit_on_error "cannot copy '$md_ai' to '$md_install_resources'."
  694. # Fix up the container's Info.plist
  695. #
  696. sed -e "s/MACFUSE_PKG_VERSION_LITERAL/$m_release/g" \
  697. -e "s/MACFUSE_PKG_INSTALLED_SIZE/$md_pkg_size/g" \
  698. < "$md_infoplist_in" > "$md_infoplist_out"
  699. m_exit_on_error "cannot fix the Info.plist of the container package."
  700. # Create the big package
  701. #
  702. m_set_suprompt "to run packagemaker for the container package"
  703. sudo -p "$m_suprompt" \
  704. packagemaker -build -p "$md_macfuse_out/$M_PKGNAME" \
  705. -f "$md_macfuse_root" -b "$M_CONF_TMPDIR" -ds -v \
  706. -r "$md_install_resources" -i "$md_infoplist_out" \
  707. -d "$md_descriptionplist" >$m_stdout 2>$m_stderr
  708. m_exit_on_error "cannot create container package '$M_PKGNAME'."
  709. # Create the distribution volume
  710. #
  711. local md_volume_name="MacFUSE $m_release"
  712. local md_scratch_dmg="$md_macfuse_out/macfuse-scratch.dmg"
  713. hdiutil create -layout NONE -megabytes 10 -fs HFS+ \
  714. -volname "$md_volume_name" "$md_scratch_dmg" >$m_stdout 2>$m_stderr
  715. m_exit_on_error "cannot create scratch MacFUSE disk image."
  716. # Attach/mount the volume
  717. #
  718. hdiutil attach -private -nobrowse "$md_scratch_dmg" >$m_stdout 2>$m_stderr
  719. m_exit_on_error "cannot attach scratch MacFUSE disk image."
  720. # Create the .engine_install file
  721. #
  722. local md_volume_path="/Volumes/$md_volume_name"
  723. local md_engine_install="$md_volume_path/.engine_install"
  724. cat > "$md_engine_install" <<__END_ENGINE_INSTALL
  725. #!/bin/sh -p
  726. /usr/sbin/installer -pkg "\$1/$M_PKGNAME" -target /
  727. __END_ENGINE_INSTALL
  728. chmod +x "$md_engine_install"
  729. m_exit_on_error "cannot set permissions on autoinstaller engine file."
  730. # For backward compatibility, we need a .keystone_install too
  731. #
  732. ln -s ".engine_install" "$md_volume_path/.keystone_install"
  733. # ignore any errors
  734. # Copy over the package
  735. #
  736. cp -pRX "$md_macfuse_out/$M_PKGNAME" "$md_volume_path"
  737. if [ $? -ne 0 ]
  738. then
  739. hdiutil detach "$md_volume_path" >$m_stdout 2>$m_stderr
  740. false
  741. m_exit_on_error "cannot copy '$M_PKGNAME' to scratch disk image."
  742. fi
  743. # Set the custom icon
  744. #
  745. cp -pRX "$md_install_resources/.VolumeIcon.icns" \
  746. "$md_volume_path/.VolumeIcon.icns"
  747. m_exit_on_error "cannot copy custom volume icon to scratch disk image."
  748. /Developer/Tools/SetFile -a C "$md_volume_path"
  749. m_exit_on_error "cannot set custom volume icon on scratch disk image."
  750. # Copy over the license file
  751. #
  752. cp "$md_install_resources/License.rtf" "$md_volume_path/License.rtf"
  753. m_exit_on_error "cannot copy MacFUSE license to scratch disk image."
  754. # Copy over the CHANGELOG.txt file
  755. #
  756. cp "$m_srcroot/CHANGELOG.txt" "$md_volume_path/CHANGELOG.txt"
  757. m_exit_on_error "cannot copy MacFUSE CHANGELOG to scratch disk image."
  758. # Detach the volume.
  759. hdiutil detach "$md_volume_path" >$m_stdout 2>$m_stderr
  760. if [ $? -ne 0 ]
  761. then
  762. false
  763. m_exit_on_error "cannot detach volume '$md_volume_path'."
  764. fi
  765. # Convert to a read-only compressed dmg
  766. #
  767. local md_dmg_name="MacFUSE-$m_release.dmg"
  768. local md_dmg_path="$md_macfuse_out/$md_dmg_name"
  769. hdiutil convert -imagekey zlib-level=9 -format UDZO "$md_scratch_dmg" \
  770. -o "$md_dmg_path" >$m_stdout 2>$m_stderr
  771. m_exit_on_error "cannot finalize MacFUSE distribution disk image."
  772. rm -f "$md_scratch_dmg"
  773. # ignore any errors
  774. m_log "creating autoinstaller rules"
  775. # Make autoinstaller rules file
  776. #
  777. local md_dmg_hash=$(openssl sha1 -binary "$md_dmg_path" | openssl base64)
  778. local md_dmg_size=$(stat -f%z "$md_dmg_path")
  779. local md_rules_plist="$md_macfuse_out/DeveloperRelease.plist"
  780. local md_download_url="http://macfuse.googlecode.com/svn/releases/developer/$md_dmg_name"
  781. if [ "$m_developer" == "0" ]
  782. then
  783. md_rules_plist="$md_macfuse_out/CurrentRelease.plist"
  784. md_download_url="http://macfuse.googlecode.com/svn/releases/$md_dmg_name"
  785. fi
  786. cat > "$md_rules_plist" <<__END_RULES_PLIST
  787. <?xml version="1.0" encoding="UTF-8"?>
  788. <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "https://www.apple.com/DTDs/PropertyList-1.0.dtd">
  789. <plist version="1.0">
  790. <dict>
  791. <key>Rules</key>
  792. <array>
  793. <dict>
  794. <key>ProductID</key>
  795. <string>$M_MACFUSE_PRODUCT_ID</string>
  796. <key>Predicate</key>
  797. <string>SystemVersion.ProductVersion beginswith "10.6" AND Ticket.version != "$m_version_leopard"</string>
  798. <key>Version</key>
  799. <string>$m_version_leopard</string>
  800. <key>Codebase</key>
  801. <string>$md_download_url</string>
  802. <key>Hash</key>
  803. <string>$md_dmg_hash</string>
  804. <key>Size</key>
  805. <string>$md_dmg_size</string>
  806. </dict>
  807. <dict>
  808. <key>ProductID</key>
  809. <string>$M_MACFUSE_PRODUCT_ID</string>
  810. <key>Predicate</key>
  811. <string>SystemVersion.ProductVersion beginswith "10.5" AND Ticket.version != "$m_version_leopard"</string>
  812. <key>Version</key>
  813. <string>$m_version_leopard</string>
  814. <key>Codebase</key>
  815. <string>$md_download_url</string>
  816. <key>Hash</key>
  817. <string>$md_dmg_hash</string>
  818. <key>Size</key>
  819. <string>$md_dmg_size</string>
  820. </dict>
  821. <dict>
  822. <key>ProductID</key>
  823. <string>$M_MACFUSE_PRODUCT_ID</string>
  824. <key>Predicate</key>
  825. <string>SystemVersion.ProductVersion beginswith "10.4" AND Ticket.version != "$m_version_tiger"</string>
  826. <key>Version</key>
  827. <string>$m_version_tiger</string>
  828. <key>Codebase</key>
  829. <string>$md_download_url</string>
  830. <key>Hash</key>
  831. <string>$md_dmg_hash</string>
  832. <key>Size</key>
  833. <string>$md_dmg_size</string>
  834. </dict>
  835. </array>
  836. </dict>
  837. </plist>
  838. __END_RULES_PLIST
  839. # Sign the output rules
  840. #
  841. m_log "signing autoinstaller rules"
  842. m_set_suprompt "to sign the rules file"
  843. sudo -p "$m_suprompt" \
  844. "$md_plistsigner" --sign --key "$M_CONF_PRIVKEY" \
  845. "$md_rules_plist" >$m_stdout 2>$m_stderr
  846. m_exit_on_error "cannot sign the rules file '$md_rules_plist' with key '$M_CONF_PRIVKEY'."
  847. echo >$m_stdout
  848. m_log "succeeded, results in '$md_macfuse_out'."
  849. echo >$m_stdout
  850. return 0
  851. }
  852. # Build a platform-specific distribution package
  853. #
  854. function m_handler_smalldist()
  855. {
  856. m_active_target="smalldist"
  857. m_set_platform
  858. m_set_srcroot "$m_platform"
  859. local lib_dir="$m_srcroot"/core/"$m_platform"/libfuse
  860. if [ ! -d "$lib_dir" ]
  861. then
  862. false
  863. m_exit_on_error "cannot access directory '$lib_dir'."
  864. fi
  865. local kernel_dir="$m_srcroot"/core/"$m_platform"/fusefs
  866. if [ ! -d "$kernel_dir" ]
  867. then
  868. false
  869. m_exit_on_error "cannot access directory '$kernel_dir'."
  870. fi
  871. if [ "$m_shortcircuit" != "1" ]
  872. then
  873. rm -rf "$kernel_dir/build/"
  874. rm -rf "$m_srcroot/core/sdk-objc/build/"
  875. fi
  876. local ms_os_version="$m_platform"
  877. local ms_macfuse_version=`awk '/#define[ \t]*MACFUSE_VERSION_LITERAL/ {print $NF}' "$kernel_dir"/common/fuse_version.h`
  878. m_exit_on_error "cannot get platform-specific MacFUSE version."
  879. local ms_macfuse_out="$M_CONF_TMPDIR/macfuse-core-$ms_os_version-$ms_macfuse_version"
  880. local ms_macfuse_build="$ms_macfuse_out/build/"
  881. local ms_macfuse_root="$ms_macfuse_out/pkgroot/"
  882. if [ "$m_shortcircuit" != "1" ]
  883. then
  884. if [ -e "$ms_macfuse_out" ]
  885. then
  886. m_set_suprompt "to remove a previously built platform-specific package"
  887. sudo -p "$m_suprompt" rm -rf "$ms_macfuse_out"
  888. m_exit_on_error "failed to clean up previous platform-specific MacFUSE build."
  889. fi
  890. if [ -e "$M_CONF_TMPDIR/macfuse-core-$ms_os_version-"* ]
  891. then
  892. m_warn "removing unrecognized version of platform-specific package"
  893. m_set_suprompt "to remove unrecognized version of platform-specific package"
  894. sudo -p "$m_suprompt" rm -rf "$M_CONF_TMPDIR/macfuse-core-$ms_os_version-"*
  895. m_exit_on_error "failed to clean up unrecognized version of platform-specific package."
  896. fi
  897. else
  898. if [ -e "$ms_macfuse_out/$M_PKGNAME_CORE" ]
  899. then
  900. echo >$m_stdout
  901. m_log "succeeded (shortcircuited), results in '$ms_macfuse_out'."
  902. echo >$m_stdout
  903. return 0
  904. fi
  905. fi
  906. if [ "$1" == "clean" ]
  907. then
  908. local retval=$?
  909. m_log "cleaned (platform $m_platform)"
  910. return $retval
  911. fi
  912. m_log "initiating Universal build for $m_platform"
  913. cd "$kernel_dir"
  914. m_exit_on_error "failed to access the kext source directory '$kernel_dir'."
  915. m_log "building MacFUSE kernel extension and tools"
  916. if [ "$m_developer" == "0" ]
  917. then
  918. xcodebuild -configuration "$m_configuration" -target All >$m_stdout 2>$m_stderr
  919. else
  920. xcodebuild MACFUSE_BUILD_FLAVOR=Beta -configuration "$m_configuration" -target All >$m_stdout 2>$m_stderr
  921. fi
  922. m_exit_on_error "xcodebuild cannot build configuration $m_configuration."
  923. # Go for it
  924. local ms_project_dir="$kernel_dir"
  925. local ms_built_products_dir="$kernel_dir/build/$m_configuration/"
  926. if [ ! -d "$ms_built_products_dir" ]
  927. then
  928. m_exit_on_error "cannot find built products directory."
  929. fi
  930. if [ "$m_platform" == "10.4" ]
  931. then
  932. ms_macfuse_system_dir="/System"
  933. else
  934. ms_macfuse_system_dir=""
  935. fi
  936. mkdir -p "$ms_macfuse_build"
  937. m_exit_on_error "cannot make new build directory '$ms_macfuse_build'."
  938. mkdir -p "$ms_macfuse_root"
  939. m_exit_on_error "cannot make directory '$ms_macfuse_root'."
  940. mkdir -p "$ms_macfuse_root$ms_macfuse_system_dir/Library/Filesystems/"
  941. m_exit_on_error "cannot make directory '$ms_macfuse_root$ms_macfuse_system_dir/Library/Filesystems/'."
  942. mkdir -p "$ms_macfuse_root/Library/Frameworks/"
  943. m_exit_on_error "cannot make directory '$ms_macfuse_root/Library/Frameworks/'."
  944. mkdir -p "$ms_macfuse_root/usr/local/lib/"
  945. m_exit_on_error "cannot make directory '$ms_macfuse_root/usr/local/lib/'."
  946. mkdir -p "$ms_macfuse_root/usr/local/include/"
  947. m_exit_on_error "cannot make directory '$ms_macfuse_root/usr/local/include/'."
  948. mkdir -p "$ms_macfuse_root/usr/local/lib/pkgconfig/"
  949. m_exit_on_error "cannot make directory '$ms_macfuse_root/usr/local/lib/pkgconfig/'."
  950. local ms_bundle_dir_generic="/Library/Filesystems/$M_FSBUNDLE_NAME"
  951. local ms_bundle_dir="$ms_macfuse_root$ms_macfuse_system_dir/$ms_bundle_dir_generic"
  952. local ms_bundle_support_dir="$ms_bundle_dir/Support"
  953. cp -pRX "$ms_built_products_dir/$M_FSBUNDLE_NAME" "$ms_bundle_dir"
  954. m_exit_on_error "cannot copy '$M_FSBUNDLE_NAME' to destination."
  955. mkdir -p "$ms_bundle_support_dir"
  956. m_exit_on_error "cannot make directory '$ms_bundle_support_dir'."
  957. cp -pRX "$ms_built_products_dir/$M_KEXT_NAME" "$ms_bundle_support_dir/$M_KEXT_NAME"
  958. m_exit_on_error "cannot copy '$M_KEXT_NAME' to destination."
  959. cp -pRX "$ms_built_products_dir/load_fusefs" "$ms_bundle_support_dir/load_fusefs"
  960. m_exit_on_error "cannot copy 'load_fusefs' to destination."
  961. cp -pRX "$ms_built_products_dir/mount_fusefs" "$ms_bundle_support_dir/mount_fusefs"
  962. m_exit_on_error "cannot copy 'mount_fusefs' to destination."
  963. cp -pRX "$m_srcroot/core/$m_platform/packaging/macfuse-core/uninstall-macfuse-core.sh" "$ms_bundle_support_dir/uninstall-macfuse-core.sh"
  964. m_exit_on_error "cannot copy 'uninstall-macfuse-core.sh' to destination."
  965. ln -s "/Library/PreferencePanes/MacFUSE.prefPane/Contents/MacOS/autoinstall-macfuse-core" "$ms_bundle_support_dir/autoinstall-macfuse-core"
  966. m_exit_on_error "cannot create legacy symlink '$ms_bundle_support_dir/autoinstall-macfuse-core'".
  967. if [ "$m_platform" == "10.4" ]
  968. then
  969. mkdir -p "$ms_macfuse_root/Library/Filesystems"
  970. ln -s "$ms_macfuse_system_dir/$ms_bundle_dir_generic" "$ms_macfuse_root/$ms_bundle_dir_generic"
  971. fi
  972. # Build the user-space MacFUSE library
  973. #
  974. m_log "building user-space MacFUSE library"
  975. tar -C "$ms_macfuse_build" -xzf "$lib_dir/$M_LIBFUSE_SRC" \
  976. >$m_stdout 2>$m_stderr
  977. m_exit_on_error "cannot untar MacFUSE library source from '$M_LIBFUSE_SRC'."
  978. cd "$ms_macfuse_build"/fuse*
  979. m_exit_on_error "cannot access MacFUSE library source in '$ms_macfuse_build/fuse*'."
  980. patch -p1 < "$lib_dir/$M_LIBFUSE_PATCH" >$m_stdout 2>$m_stderr
  981. m_exit_on_error "cannot patch MacFUSE library source."
  982. /bin/sh ./darwin_configure.sh "$kernel_dir" >$m_stdout 2>$m_stderr
  983. m_exit_on_error "cannot configure MacFUSE library source for compilation."
  984. make -j2 >$m_stdout 2>$m_stderr
  985. m_exit_on_error "make failed while compiling the MacFUSE library."
  986. make install DESTDIR="$ms_macfuse_root" >$m_stdout 2>$m_stderr
  987. m_exit_on_error "cannot prepare library build for installation."
  988. ln -s libfuse.dylib "$ms_macfuse_root/usr/local/lib/libfuse.0.dylib"
  989. m_exit_on_error "cannot create compatibility symlink."
  990. rm -f "ms_macfuse_root"/usr/local/lib/*ulockmgr*
  991. # ignore any errors
  992. rm -f "ms_macfuse_root"/usr/local/include/*ulockmgr*
  993. # ignore any errors
  994. # Now build again, if necessary, with 64-bit inode support
  995. #
  996. # ino64 is not supported on Tiger
  997. if [ "$m_platform" != "10.4" ]
  998. then
  999. m_log "building user-space MacFUSE library (ino64)"
  1000. cd "$ms_macfuse_build"/fuse*/lib
  1001. m_exit_on_error "cannot access MacFUSE library (ino64) source in '$ms_macfuse_build/fuse*/lib'."
  1002. make clean >$m_stdout 2>$m_stderr
  1003. m_exit_on_error "make failed while compiling the MacFUSE library (ino64)."
  1004. perl -pi -e 's#libfuse#libfuse_ino64#g' Makefile
  1005. m_exit_on_error "failed to prepare MacFUSE library (ino64) for compilation."
  1006. perl -pi -e 's#-D__FreeBSD__=10#-D__DARWIN_64_BIT_INO_T=1 -D__FreeBSD__=10#g' Makefile
  1007. m_exit_on_error "failed to prepare MacFUSE library (ino64) for compilation."
  1008. make -j2 >$m_stdout 2>$m_stderr
  1009. m_exit_on_error "make failed while compiling the MacFUSE library (ino64)."
  1010. make install DESTDIR="$ms_macfuse_root" >$m_stdout 2>$m_stderr
  1011. m_exit_on_error "cannot prepare MacFUSE library (ino64) build for installation."
  1012. rm -f "$ms_macfuse_root"/usr/local/lib/*ulockmgr*
  1013. # ignore any errors
  1014. rm -f "$ms_macfuse_root"/usr/local/include/*ulockmgr*
  1015. # ignore any errors
  1016. # generate dsym
  1017. dsymutil "$ms_macfuse_root"/usr/local/lib/libfuse.dylib
  1018. m_exit_on_error "cannot generate debugging information for libfuse."
  1019. dsymutil "$ms_macfuse_root"/usr/local/lib/libfuse_ino64.dylib
  1020. m_exit_on_error "cannot generate debugging information for libfuse_ino64."
  1021. fi # ino64 on > Tiger
  1022. # Build MacFUSE.framework
  1023. #
  1024. m_log "building MacFUSE Objective-C SDK"
  1025. cd "$ms_project_dir/../../sdk-objc"
  1026. m_exit_on_error "cannot access Objective-C SDK directory."
  1027. rm -rf build/
  1028. m_exit_on_error "cannot remove previous build of MacFUSE.framework."
  1029. if [ "$m_platform" == "10.4" ]
  1030. then
  1031. xcodebuild -configuration "$m_configuration" -target "MacFUSE-$ms_os_version" "MACFUSE_BUILD_ROOT=$ms_macfuse_root" "MACFUSE_BUNDLE_VERSION_LITERAL=$ms_macfuse_version" "CUSTOM_CFLAGS=-DMACFUSE_TARGET_OS=MAC_OS_X_VERSION_10_4" >$m_stdout 2>$m_stderr
  1032. else
  1033. xcodebuild -configuration "$m_configuration" -target "MacFUSE-$ms_os_version" "MACFUSE_BUILD_ROOT=$ms_macfuse_root" "MACFUSE_BUNDLE_VERSION_LITERAL=$ms_macfuse_version" >$m_stdout 2>$m_stderr
  1034. fi
  1035. m_exit_on_error "xcodebuild cannot build configuration '$m_configuration'."
  1036. cp -pRX build/"$m_configuration"/*.framework "$ms_macfuse_root/Library/Frameworks/"
  1037. m_exit_on_error "cannot copy 'MacFUSE.framework' to destination."
  1038. if [ "$m_platform" != "10.4" ]
  1039. then
  1040. mv "$ms_macfuse_root"/usr/local/lib/*.dSYM "$ms_macfuse_root"/Library/Frameworks/MacFUSE.framework/Resources/Debug/
  1041. mkdir -p "$ms_macfuse_root/Library/Application Support/Developer/Shared/Xcode/Project Templates"
  1042. m_exit_on_error "cannot create directory for Xcode templates."
  1043. ln -s "/Library/Frameworks/MacFUSE.framework/Resources/ProjectTemplates/" "$ms_macfuse_root/Library/Application Support/Developer/Shared/Xcode/Project Templates/MacFUSE"
  1044. m_exit_on_error "cannot create symlink for Xcode templates."
  1045. fi
  1046. m_set_suprompt "to chown '$ms_macfuse_root/*'"
  1047. sudo -p "$m_suprompt" chown -R root:wheel "$ms_macfuse_root"/*
  1048. m_exit_on_error "cannot chown '$ms_macfuse_root/*'."
  1049. m_set_suprompt "to setuid 'load_fusefs'"
  1050. sudo -p "$m_suprompt" chmod u+s "$ms_bundle_support_dir/load_fusefs"
  1051. m_exit_on_error "cannot setuid 'load_fusefs'."
  1052. m_set_suprompt "to chown '$ms_macfuse_root/Library/'"
  1053. sudo -p "$m_suprompt" chown root:admin "$ms_macfuse_root/Library/"
  1054. m_exit_on_error "cannot chown '$ms_macfuse_root/Library/'."
  1055. m_set_suprompt "to chown '$ms_macfuse_root/Library/Frameworks/"
  1056. sudo -p "$m_suprompt" \
  1057. chown -R root:admin "$ms_macfuse_root/Library/Frameworks/"
  1058. m_exit_on_error "cannot chown '$ms_macfuse_root/Library/Frameworks/'."
  1059. m_set_suprompt "to chmod '$ms_macfuse_root/Library/Frameworks/'"
  1060. sudo -p "$m_suprompt" chmod 0775 "$ms_macfuse_root/Library/Frameworks/"
  1061. m_exit_on_error "cannot chmod '$ms_macfuse_root/Library/Frameworks/'."
  1062. m_set_suprompt "to chmod '$ms_macfuse_root/Library/'"
  1063. sudo -p "$m_suprompt" chmod 1775 "$ms_macfuse_root/Library/"
  1064. m_exit_on_error "cannot chmod '$ms_macfuse_root/Library/'."
  1065. m_set_suprompt "to chmod files in '$ms_macfuse_root/usr/local/lib/'"
  1066. sudo -p "$m_suprompt" \
  1067. chmod -h 755 `find "$ms_macfuse_root/usr/local/lib" -type l`
  1068. m_exit_on_error "cannot chmod files in '$ms_macfuse_root/usr/local/lib/'."
  1069. m_set_suprompt "to chmod files in '$ms_macfuse_root/Library/Frameworks/'"
  1070. sudo -p "$m_suprompt" \
  1071. chmod -h 755 `find "$ms_macfuse_root/Library/Frameworks/" -type l`
  1072. # no exit upon error
  1073. cd "$ms_macfuse_root"
  1074. m_exit_on_error "cannot access directory '$ms_macfuse_root'."
  1075. # Create the MacFUSE Installer Package
  1076. #
  1077. m_log "building installer package for $m_platform"
  1078. m_build_pkg "$ms_macfuse_version" "$m_srcroot/core/$m_platform/packaging/macfuse-core" "$ms_macfuse_root" "$M_PKGNAME_CORE" "$ms_macfuse_out"
  1079. m_exit_on_error "cannot create '$M_PKGNAME_CORE'."
  1080. echo >$m_stdout
  1081. m_log "succeeded, results in '$ms_macfuse_out'."
  1082. echo >$m_stdout
  1083. return 0
  1084. }
  1085. function m_handler_swconfigure()
  1086. {
  1087. m_active_target="swconfigure"
  1088. m_set_platform
  1089. m_set_srcroot "$m_platform"
  1090. local lib_dir="$m_srcroot"/core/"$m_platform"/libfuse
  1091. if [ ! -d "$lib_dir" ]
  1092. then
  1093. false
  1094. m_exit_on_error "cannot access directory '$lib_dir'."
  1095. fi
  1096. local kernel_dir="$m_srcroot"/core/"$m_platform"/fusefs
  1097. if [ ! -d "$kernel_dir" ]
  1098. then
  1099. false
  1100. m_exit_on_error "cannot access directory '$kernel_dir'."
  1101. fi
  1102. local current_dir=`pwd`
  1103. local current_product=`basename "$current_dir"`
  1104. local extra_cflags=""
  1105. local architectures=""
  1106. if [ "$m_platform" == "10.4" ]
  1107. then
  1108. extra_cflags="-mmacosx-version-min=10.4"
  1109. architectures="-arch i386 -arch ppc"
  1110. else
  1111. architectures="-arch i386 -arch ppc"
  1112. fi
  1113. local common_cflags="-O0 -g $architectures -isysroot $m_usdk_dir -I/usr/local/include"
  1114. local common_ldflags="-Wl,-syslibroot,$m_usdk_dir $architectures -L/usr/local/lib"
  1115. local final_cflags="$common_cflags $extra_cflags"
  1116. local final_ldflags="$common_ldflags"
  1117. local retval=1
  1118. # For pkg-config and such
  1119. PATH=$PATH:/usr/local/sbin:/usr/local/bin
  1120. export PATH
  1121. # We have some special cases for current_product
  1122. case "$current_product" in
  1123. gettext*)
  1124. m_log "Configuring Universal build of gettext for Mac OS X \"$m_osname\""
  1125. CFLAGS="$final_cflags -D_POSIX_C_SOURCE=200112L" LDFLAGS="$final_ldflags -fno-common" ./configure --prefix=/usr/local --disable-dependency-tracking --with-libiconv-prefix="$m_usdk_dir"/usr
  1126. retval=$?
  1127. ;;
  1128. glib*)
  1129. m_log "Configuring Universal build of glib for Mac OS X \"$m_osname\""
  1130. CFLAGS="$final_cflags" LDFLAGS="$final_ldflags" ./configure --prefix=/usr/local --disable-dependency-tracking --enable-static
  1131. retval=$?
  1132. ;;
  1133. pkg-config*)
  1134. m_log "Configuring Universal build of pkg-config for Mac OS X \"$m_osname\""
  1135. CFLAGS="$final_cflags" LDFLAGS="$final_ldflags" ./configure --prefix=/usr/local --disable-dependency-tracking
  1136. ;;
  1137. *sshfs*)
  1138. m_log "Configuring Universal build of sshfs for Mac OS X \"$m_osname\""
  1139. CFLAGS="$final_cflags -D__FreeBSD__=10 -DDARWIN_SEMAPHORE_COMPAT -DSSH_NODELAY_WORKAROUND" LDFLAGS="$final_ldflags" ./configure --prefix=/usr/local --disable-dependency-tracking
  1140. ;;
  1141. *)
  1142. m_log "Configuring Universal build of generic software for Mac OS X \"$m_osname\""
  1143. CFLAGS="$final_cflags" LDFLAGS="$final_ldflags" ./configure --prefix=/usr/local --disable-dependency-tracking
  1144. ;;
  1145. esac
  1146. return $retval
  1147. }
  1148. # --
  1149. function m_validate_xcode()
  1150. {
  1151. m_xcode_version=`xcodebuild -version | head -1 | grep Xcode | awk '{print $NF}'`
  1152. if [ $? != 0 ] || [ -z "$m_xcode_version" ]
  1153. then
  1154. echo "failed to determine Xcode version."
  1155. exit 2
  1156. fi
  1157. local mvs_xcode_major=`echo $m_xcode_version | cut -d . -f 1`
  1158. local mvs_xcode_minor=`echo $m_xcode_version | cut -d . -f 2`
  1159. if [ -z $mvs_xcode_minor ]
  1160. then
  1161. mvs_xcode_minor=0
  1162. fi
  1163. local mvs_xcode_rev=`echo $m_xcode_version | cut -d . -f 3`
  1164. if [ -z $mvs_xcode_rev ]
  1165. then
  1166. mvs_xcode_rev=0
  1167. fi
  1168. local mvs_have=$(( $mvs_xcode_major * 100 + $mvs_xcode_minor * 10 + $mvs_xcode_rev ))
  1169. mvs_xcode_major=`echo $M_XCODE_VERSION_REQUIRED | cut -d . -f 1`
  1170. mvs_xcode_minor=`echo $M_XCODE_VERSION_REQUIRED | cut -d . -f 2`
  1171. if [ -z $mvs_xcode_minor ]
  1172. then
  1173. mvs_xcode_minor=0
  1174. fi
  1175. mvs_xcode_rev=`echo $M_XCODE_VERSION_REQUIRED | cut -d . -f 3`
  1176. if [ -z $mvs_xcode_rev ]
  1177. then
  1178. mvs_xcode_rev=0
  1179. fi
  1180. local mvs_want=$(( $mvs_xcode_major * 100 + $mvs_xcode_minor * 10 + $mvs_xcode_rev ))
  1181. if [ $mvs_have -lt $mvs_want ]
  1182. then
  1183. echo "Xcode version $M_XCODE_VERSION_REQUIRED or higher is required to build MacFUSE."
  1184. exit 2
  1185. fi
  1186. m_active_target="preflight"
  1187. m_log "Xcode version $m_xcode_version found (minimum requirement is $M_XCODE_VERSION_REQUIRED)"
  1188. return 0
  1189. }
  1190. function m_validate_input()
  1191. {
  1192. local mvi_found=
  1193. local mvi_good=
  1194. # Validate scratch directory
  1195. if [ ! -d "$M_CONF_TMPDIR" ] || [ ! -w "$M_CONF_TMPDIR" ]
  1196. then
  1197. echo "M_CONF_TMPDIR (currently '$M_CONF_TMPDIR') must be set to a writeable directory."
  1198. exit 2
  1199. fi
  1200. # Validate if platform was specified when it shouldn't have been
  1201. #
  1202. if [ "$m_platform" != "$M_DEFAULT_PLATFORM" ]
  1203. then
  1204. mvi_found="0"
  1205. for m_p in $M_TARGETS_WITH_PLATFORM
  1206. do
  1207. if [ "$m_target" == "$m_p" ]
  1208. then
  1209. mvi_found="1"
  1210. break
  1211. fi
  1212. done
  1213. if [ "$mvi_found" == "0" ]
  1214. then
  1215. echo "Unknown argument or invalid combination of arguments."
  1216. echo "Try $0 -h for help."
  1217. exit 2
  1218. fi
  1219. fi
  1220. # Validate platform
  1221. if [ "$m_platform" != "$M_DEFAULT_PLATFORM" ]
  1222. then
  1223. mvi_good="0"
  1224. for m_p in $M_PLATFORMS
  1225. do
  1226. if [ "$m_platform" == "$m_p" ]
  1227. then
  1228. mvi_good="1"
  1229. break
  1230. fi
  1231. done
  1232. if [ "$mvi_good" == "0" ]
  1233. then
  1234. echo "Unknown platform '$m_platform'."
  1235. echo "Valid platforms are: $M_PLATFORMS."
  1236. exit 2
  1237. fi
  1238. fi
  1239. # Validate target
  1240. #
  1241. if [ "$m_target" != "$M_DEFAULT_TARGET" ]
  1242. then
  1243. mvi_good="0"
  1244. for m_t in $M_TARGETS
  1245. do
  1246. if [ "$m_target" == "$m_t" ]
  1247. then
  1248. mvi_good="1"
  1249. break
  1250. fi
  1251. done
  1252. if [ "$mvi_good" == "0" ]
  1253. then
  1254. echo "Unknown target '$m_target'."
  1255. echo "Valid targets are: $M_TARGETS."
  1256. exit 2
  1257. fi
  1258. fi
  1259. # Validate configuration
  1260. #
  1261. mvi_good="0"
  1262. for m_c in $M_CONFIGURATIONS
  1263. do
  1264. if [ "$m_configuration" == "$m_c" ]
  1265. then
  1266. mvi_good="1"
  1267. break
  1268. fi
  1269. done
  1270. if [ "$mvi_good" == "0" ]
  1271. then
  1272. echo "Unknown configuration '$m_configuration'."
  1273. echo "Valid configurations are: $M_CONFIGURATIONS."
  1274. exit 2
  1275. fi
  1276. if [ "$m_shortcircuit" == "1" ] && [ "$m_target" == "clean" ]
  1277. then
  1278. echo "Cleaning cannot be shortcircuited!"
  1279. exit 2
  1280. fi
  1281. return 0
  1282. }
  1283. function m_read_input()
  1284. {
  1285. m_args=`getopt c:dhp:qst:v $*`
  1286. if [ $? != 0 ]
  1287. then
  1288. echo "Try $0 -h for help."
  1289. exit 2
  1290. fi
  1291. set -- $m_args
  1292. for m_i
  1293. do
  1294. case "$m_i" in
  1295. -c)
  1296. m_configuration="$2"
  1297. shift
  1298. shift
  1299. ;;
  1300. -d)
  1301. m_developer=1
  1302. shift
  1303. ;;
  1304. -h)
  1305. m_help
  1306. exit 0
  1307. ;;
  1308. -p)
  1309. m_platform="$2"
  1310. shift
  1311. shift
  1312. ;;
  1313. -q)
  1314. m_stderr=/dev/null
  1315. m_stdout=/dev/null
  1316. shift
  1317. ;;
  1318. -s)
  1319. m_shortcircuit="1"
  1320. shift
  1321. ;;
  1322. -t)
  1323. m_target="$2"
  1324. shift
  1325. shift
  1326. ;;
  1327. -v)
  1328. m_version
  1329. exit 0
  1330. shift
  1331. ;;
  1332. --)
  1333. shift
  1334. break
  1335. ;;
  1336. esac
  1337. done
  1338. }
  1339. function m_handler()
  1340. {
  1341. case "$m_target" in
  1342. "clean")
  1343. m_handler_examples clean
  1344. m_handler_lib clean
  1345. m_handler_reload clean
  1346. m_handler_dist clean
  1347. ;;
  1348. "dist")
  1349. m_validate_xcode
  1350. m_handler_dist
  1351. ;;
  1352. "examples")
  1353. m_handler_examples
  1354. ;;
  1355. "lib")
  1356. m_handler_lib
  1357. ;;
  1358. "libsrc")
  1359. m_handler_libsrc
  1360. ;;
  1361. "reload")
  1362. m_validate_xcode
  1363. m_handler_reload
  1364. ;;
  1365. "smalldist")
  1366. m_validate_xcode
  1367. m_handler_smalldist
  1368. ;;
  1369. "swconfigure")
  1370. m_handler_swconfigure
  1371. ;;
  1372. *)
  1373. echo "Try $0 -h for help."
  1374. ;;
  1375. esac
  1376. }
  1377. # main()
  1378. # {
  1379. m_read_input $*
  1380. m_validate_input
  1381. m_handler
  1382. exit $?
  1383. # }