diff --git a/contrib/buildForMac b/contrib/buildForMac index d6b2f92b..57488afd 100755 --- a/contrib/buildForMac +++ b/contrib/buildForMac @@ -1,92 +1,61 @@ #!/bin/bash ## -# buildForMac -# example: contrib/buildForMac --disable-shared +# buildForMac +# example: contrib/buildForMac --[dis|en]able-shared # -# On Lion: -# contrib/buildForMac --with-zlib=/usr/lib -# 11 == `uname -a | cut '-d ' -f 3 | cut '-d.' -f 1` +## +## +# test OS level (L=9 SL==10 Lion = 11, ML=12) LION="" -(echo $OSTYPE | grep 11) > /dev/null -if [ $? == 0 ]; then +let os=$(uname -a | cut -d' ' -f 3 | cut -d'.' -f 1) +if [ $(( os >= 11 )) ]; then LION="--with-zlib=/usr/lib" fi -# b=`basename "${PWD}"` - if [ ! -d contrib ]; then echo "you are in the wrong directory - please run $0 in the main directory (which includes contrib and src)" exit 1 fi -TARGET="MACOSX_DEPLOYMENT_TARGET=10.5" -version=`grep EXIV2_LTVERSION config/config.mk | cut "-d " -f 3 | cut -d: -f 1` -lib=libexiv2.$version.dylib - -echo -echo ----------------------------- -echo version = $version -echo lib = $lib -echo ----------------------------- -echo - -app=exiv2 -LIB=./src/.libs/$lib -APP=./src/.libs/$app - -for option in "$@" ; do - if [ "$option" == --disable-shared ]; then - lib=libexiv2.a - LIB=./src/.libs/$lib - APP=./src/$app - fi -done - -props() { - ls -alt $* - lipo -info $* - otool -L $* - echo ---------------------- -} - +if [ -z $TARGET ]; then export TARGET="MACOSX_DEPLOYMENT_TARGET=10.5" ; fi +# version=$(grep EXIV2_LTVERSION config/config.mk | cut "-d " -f 3 | cut -d: -f 1) +# lib=libexiv2.$version.dylib build() { make clean ./configure CFLAGS="$arch" CXXFLAGS="$arch" LDFLAGS="$arch -L${PWD}/xmpsdk/src" OBJCFLAGS="$arch" OBJCXXFLAGS="$arch" $TARGET $LION "$@" - make CFLAGS="$arch" CXXFLAGS="$arch" LDFLAGS="$arch -L${PWD}/xmpsdk/src" OBJCFLAGS="$arch" OBJCXXFLAGS="$arch" $TARGET + make CFLAGS="$arch" CXXFLAGS="$arch" LDFLAGS="$arch -L${PWD}/xmpsdk/src" OBJCFLAGS="$arch" OBJCXXFLAGS="$arch" $TARGET all + # make CFLAGS="$arch" CXXFLAGS="$arch" LDFLAGS="$arch -L${PWD}/xmpsdk/src" OBJCFLAGS="$arch" OBJCXXFLAGS="$arch" $TARGET samples if [ "$?" != "0" ]; then echo build failed exit fi - props $APP - props $LIB } +## +# build one architecture at a time for arch in '-arch i386' '-arch x86_64' ; do - if [ "$arch" == "-arch i386" ]; then - build "$@" - rm -rf app.i386 lib.i386 - cp $APP app.i386 - cp $LIB lib.i386 - elif [ "$arch" == "-arch x86_64" ]; then - build "$@" - rm -rf app.x86_64 lib.x86_64 - cp $APP app.x86_64 - cp $LIB lib.x86_64 - fi + echo arch = $arch + a=${arch:5:100} + build "$@" + + ## + # copy .libs to .arch + for d in $(find . -name ".libs" -type d); do + D=$(dirname $d)/.$a +# echo -------------- +# echo d = $d D = $D +# echo -------------- + ditto $d $D + done done -LIB=./src/.libs/$lib -APP=./src/.libs/$app - -env $TARGET lipo -arch i386 lib.i386 -arch x86_64 lib.x86_64 -create -output $LIB -env $TARGET lipo -arch i386 app.i386 -arch x86_64 app.x86_64 -create -output $APP - -props $LIB -props $APP +## +# combine the builds into a universal +$(dirname $0)/makeUniversal # That's all Folks! ## diff --git a/contrib/makeUniversal b/contrib/makeUniversal new file mode 100755 index 00000000..c1063cfa --- /dev/null +++ b/contrib/makeUniversal @@ -0,0 +1,28 @@ +#!/bin/bash + +## +# makeUniversal - combine .i386 and .x86_64 build results into .libs +# this script is called by buildForMac +## + +## +# search for directories called .x86_64 +# run every file and lipo .x86_64/file .x86_64/file -> .libs/file +for D in $(find . -name ".x86_64"); do + for F in $(find $(dirname $D)/.x86_64 -type f); do + f=$(echo $F | sed -E -e "s/.x86_64/.i386/") + U=$(echo $F | sed -E -e "s/.x86_64/.libs/") + if [[ -e $f && -e $F ]]; then + # echo $F $f -> $U + lipo -arch i386 $f -arch x86_64 $F -create -output $U + if [ $? != '0' ]; then + echo FAILED lipo -arch i386 $f -arch x86_64 $F -create -output $U + else + echo $U $(lipo -info $U|sed -E -e "s/Architectures in the fat file://" -e "s/ are:/ : /") $(stat $U | cut -d' ' -f 2) + fi + fi + done +done + +# That's all Folks! +##