[MacPorts] #12504: RFE: a possible build process for a universal libjpeg

MacPorts noreply at macports.org
Fri Aug 8 08:18:16 PDT 2008


#12504: RFE: a possible build process for a universal libjpeg
-------------------------------+--------------------------------------------
  Reporter:  nmb at wartburg.edu  |       Owner:  waqar at macports.org
      Type:  enhancement       |      Status:  closed            
  Priority:  Normal            |   Milestone:  Port Enhancements 
 Component:  ports             |     Version:  1.5.2             
Resolution:  fixed             |    Keywords:  universal         
-------------------------------+--------------------------------------------
Old description:

> I found the following script which builds a universal version of libjpeg.
> It does this by building a PPC and a i386 version and lipo'ing them
> together.  This came from http://www.omnigroup.com/mailman/archive
> /macosx-dev/2007-May.txt
>
> #!/bin/sh
> #
> #       jpeg-build-univ
> #
> #       Script to crteate universal binary version of libjpeg.
> #
> #   ? 2006 Alan Staniforth
> #
> #       Version 2.0
> #
> #       Invoke thus:
> #
> #       jpeg-build-univ [-h] | [-v] | [-i] [-p prefix] [-s sdk] [-n] [-k]
> #
> #       where   prefix is the install root for the libraries.
> #
> #       Version 2.0:
> #               Source download incorporated.
> #               Reverted to using MacOSX10.3.9.sdk as the default SDK for
> PPC
> #               Targets 10.2 for ppc, 10.4 for i386.
>
> ### Set up.
> # Set trap to allow abort on signal:
> trap 'echo "Interrupted by signal" >&2; exit' 1 2 3 15
> # Defaults
> BUILD_UNIV_VERS=2.0
> INSTALL_PREFIX="/usr/local"
> SDK_PPC="MacOSX10.3.9.sdk"
> DO_INSTALL=0
> DO_DLOAD=1
> NO_SUDO=0
>
> ### Handle optional parameters
> if test $# -ne 0 ; then
>  ### Options
>  while test $# -gt 0;
>  do
>   case "$1" in
>    -*) FLAG="$1"
>     case "$FLAG" in
>      -h)
>       ### Usage information
>       echo "Usage: jpeg-build-univ [-h]"
>       echo "Usage: jpeg-build-univ [-v]"
>       echo "Usage: jpeg-build-univ [-i] [-p prefix] [-s sdk]"
>       echo ""
>       echo "Options:"
>       echo "    -h : Print this usage summary."
>       echo "    -v : Print tool version."
>       echo "    -i : Install as well as build."
>       echo "    -k : Skip download of source."
>       echo "    -n : Don't use sudo when installing."
>       echo "    -p prefix : install root for the built libraries and
> support"
>       echo "                files. Default is /usr/local"
>       echo "    -s sdk : the Mac OS X SDK you want GCC to use for PPC
> code. "
>       echo "             Default is MacOSX10.3.9.sdk"
>       echo ""
>       exit
>      ;;
>      -v)
>       ### version
>       echo "$BUILD_UNIV_VERS"
>      ;;
>      -p)
>       ### install prefix specified
>       shift
>       if test "${1##*/}" = "" ; then
>        INSTALL_PREFIX="${1%*/}"
>       else
>        INSTALL_PREFIX="${1}"
>       fi
>       if !(test -d "${INSTALL_PREFIX}") ; then
>        echo "${INSTALL_PREFIX} does not exist or is not a directory"
>        exit
>       fi
>      ;;
>      -s)
>       ### ppc sdk specified
>       shift
>       SDK_PPC="${1}"
>      ;;
>      -i)
>       ### install the built libray and headers (make can't be used)
>       DO_INSTALL=1
>      ;;
>      -n)
>       ### No sudo
>       NO_SUDO=1
>      ;;
>      -k)
>       ### skip download
>       DO_DLOAD=0
>      ;;
>      -*) echo "Usage: "$1" not understood!"
>       echo "Use jpeg-build-univ -h for usage information"
>       break
>      ;;
>     esac
>    ;;
>   esac
>   shift
>  done
> fi
>
> ### Get the source:
> if test $DO_DLOAD -ne 0 ; then
>  ### Download source from uunet.
>  echo "jpeg-build-univ:     Getting the libjpeg source..."
>  curl ftp://ftp.uu.net/graphics/jpeg/jpegsrc.v6b.tar.gz -o
> "jpegsrc.v6b.tar.gz"
> else
>     echo "jpeg-build-univ:     Skipping source download..."
> fi
>
> ### Extract the source:
> echo "jpeg-build-univ:     Expanding the source tarball..."
> tar -zxpf jpegsrc.v6b.tar.gz
>
> ### Do set-up
> echo "jpeg-build-univ:     Setting up..."
> # Change to the directory
> cd jpeg-6b
> cp /usr/share/libtool/config.sub .
> cp /usr/share/libtool/config.guess .
> # check if a relative install path was passed
> FIRSTCHAR=${INSTALL_PREFIX:0:1}
> if test $FIRSTCHAR != "/" ; then
>  INSTALL_PREFIX="../${INSTALL_PREFIX}"
> fi
> # Ensure the support dirs exits
> mkdir -p build/ppc
> mkdir -p build/i386
>
> ### Tidy up
> echo "jpeg-build-univ:     Cleaning..."
> rm -f build/ppc/*
> rm -f build/i386/*
> if test -f Makefile ; then make distclean >/dev/null ; fi
> if test -f Makefile.ppc ; then rm -f Makefile.ppc ; fi
> if test -f Makefile.i386 ; then rm -f Makefile.i386 ; fi
>
> ### Configure
> echo "jpeg-build-univ:     Configuring..."
> env CFLAGS="-O3 -g -isysroot /Developer/SDKs/$SDK_PPC -arch ppc"
> LDFLAGS="-Wl,-syslibroot,/Developer/SDKs/$SDK_PPC"    ./configure
> --prefix="${INSTALL_PREFIX}" --enable-shared --disable-dependency-
> tracking >/dev/null
>
> ### Create the PPC Makefile
> echo "jpeg-build-univ:     Creating PPC Makefile..."
> sed -e s/"CC= gcc"/"CC= \${ENVP} gcc"/ \
>  -e '21i\
>  ENVP= GCC_VERSION=3.3 MACOSX_DEPLOYMENT_TARGET=10.2
>  ' \
>  Makefile > Makefile.ppc
>
> ### Create the i386 Makefile
> echo "jpeg-build-univ:     Creating i386 Makefile..."
> sed -e s/"-arch ppc"/"-arch i386"/ \
>  -e s/"CC= gcc"/"CC= \${ENVP} gcc"/ \
>  -e s/"${SDK_PPC}"/"MacOSX10.4u.sdk"/ \
>  -e '21i\
>  ENVP= MACOSX_DEPLOYMENT_TARGET=10.4
>  ' \
>  Makefile > Makefile.i386
> rm ./Makefile
>
> ### Generate the i386 code
> echo "jpeg-build-univ:     Generating i386..."
> cp Makefile.i386 Makefile
> #make clean >/dev/null
> #make libjpeg.la >/dev/null
> make >/dev/null
> mv .libs/*.a build/i386/
>
> ### Generate the PPC code
> echo "jpeg-build-univ:     Generating PPC..."
> cp Makefile.ppc Makefile
>  make clean >/dev/null
> #make libjpeg.la >/dev/null
> make >/dev/null
> mv .libs/*.a build/ppc/
>
> ### Build the universal libs
> echo "jpeg-build-univ:     Building universal library..."
>
> ### Build a list of actual libraries
> cd ./build/ppc
> FLIST=`ls *.a`
> LIBLIST=""
> for f in $FLIST ; do
>     if !(test -L $f) ; then
>         LIBLIST="$LIBLIST $f"
>     fi
> done
> cd ../..
>
> for f in $LIBLIST ; do
>     if test -f ./build/i386/$f ; then
>         lipo -create ./build/*/$f -output .libs/$f
>         echo "jpeg-build-univ:     `file $f`"
>         echo "jpeg-build-univ:     $f is now universal."
>     else
>         echo "jpeg-build-univ:     $f is missing from build/i386, no
> universal binary built."
>     fi
> done
>
> if test $DO_INSTALL -ne 0 ; then
>     echo "jpeg-build-univ:     Installing..."
>  if test $NO_SUDO -ne 0 ; then
>   make install
>  else
>   sudo make install
>     fi
> else
>     echo "jpeg-build-univ:  type \"make install\" to install."
> fi
>
> ### And exit...
> exit

New description:

 I found the following script which builds a universal version of libjpeg.
 It does this by building a PPC and a i386 version and lipo'ing them
 together.  This came from http://www.omnigroup.com/mailman/archive/macosx-
 dev/2007-May.txt

 {{{
 #!/bin/sh
 #
 #       jpeg-build-univ
 #
 #       Script to crteate universal binary version of libjpeg.
 #
 #   ? 2006 Alan Staniforth
 #
 #       Version 2.0
 #
 #       Invoke thus:
 #
 #       jpeg-build-univ [-h] | [-v] | [-i] [-p prefix] [-s sdk] [-n] [-k]
 #
 #       where   prefix is the install root for the libraries.
 #
 #       Version 2.0:
 #               Source download incorporated.
 #               Reverted to using MacOSX10.3.9.sdk as the default SDK for
 PPC
 #               Targets 10.2 for ppc, 10.4 for i386.

 ### Set up.
 # Set trap to allow abort on signal:
 trap 'echo "Interrupted by signal" >&2; exit' 1 2 3 15
 # Defaults
 BUILD_UNIV_VERS=2.0
 INSTALL_PREFIX="/usr/local"
 SDK_PPC="MacOSX10.3.9.sdk"
 DO_INSTALL=0
 DO_DLOAD=1
 NO_SUDO=0

 ### Handle optional parameters
 if test $# -ne 0 ; then
  ### Options
  while test $# -gt 0;
  do
   case "$1" in
    -*) FLAG="$1"
     case "$FLAG" in
      -h)
       ### Usage information
       echo "Usage: jpeg-build-univ [-h]"
       echo "Usage: jpeg-build-univ [-v]"
       echo "Usage: jpeg-build-univ [-i] [-p prefix] [-s sdk]"
       echo ""
       echo "Options:"
       echo "    -h : Print this usage summary."
       echo "    -v : Print tool version."
       echo "    -i : Install as well as build."
       echo "    -k : Skip download of source."
       echo "    -n : Don't use sudo when installing."
       echo "    -p prefix : install root for the built libraries and
 support"
       echo "                files. Default is /usr/local"
       echo "    -s sdk : the Mac OS X SDK you want GCC to use for PPC
 code. "
       echo "             Default is MacOSX10.3.9.sdk"
       echo ""
       exit
      ;;
      -v)
       ### version
       echo "$BUILD_UNIV_VERS"
      ;;
      -p)
       ### install prefix specified
       shift
       if test "${1##*/}" = "" ; then
        INSTALL_PREFIX="${1%*/}"
       else
        INSTALL_PREFIX="${1}"
       fi
       if !(test -d "${INSTALL_PREFIX}") ; then
        echo "${INSTALL_PREFIX} does not exist or is not a directory"
        exit
       fi
      ;;
      -s)
       ### ppc sdk specified
       shift
       SDK_PPC="${1}"
      ;;
      -i)
       ### install the built libray and headers (make can't be used)
       DO_INSTALL=1
      ;;
      -n)
       ### No sudo
       NO_SUDO=1
      ;;
      -k)
       ### skip download
       DO_DLOAD=0
      ;;
      -*) echo "Usage: "$1" not understood!"
       echo "Use jpeg-build-univ -h for usage information"
       break
      ;;
     esac
    ;;
   esac
   shift
  done
 fi

 ### Get the source:
 if test $DO_DLOAD -ne 0 ; then
  ### Download source from uunet.
  echo "jpeg-build-univ:     Getting the libjpeg source..."
  curl ftp://ftp.uu.net/graphics/jpeg/jpegsrc.v6b.tar.gz -o
 "jpegsrc.v6b.tar.gz"
 else
     echo "jpeg-build-univ:     Skipping source download..."
 fi

 ### Extract the source:
 echo "jpeg-build-univ:     Expanding the source tarball..."
 tar -zxpf jpegsrc.v6b.tar.gz

 ### Do set-up
 echo "jpeg-build-univ:     Setting up..."
 # Change to the directory
 cd jpeg-6b
 cp /usr/share/libtool/config.sub .
 cp /usr/share/libtool/config.guess .
 # check if a relative install path was passed
 FIRSTCHAR=${INSTALL_PREFIX:0:1}
 if test $FIRSTCHAR != "/" ; then
  INSTALL_PREFIX="../${INSTALL_PREFIX}"
 fi
 # Ensure the support dirs exits
 mkdir -p build/ppc
 mkdir -p build/i386

 ### Tidy up
 echo "jpeg-build-univ:     Cleaning..."
 rm -f build/ppc/*
 rm -f build/i386/*
 if test -f Makefile ; then make distclean >/dev/null ; fi
 if test -f Makefile.ppc ; then rm -f Makefile.ppc ; fi
 if test -f Makefile.i386 ; then rm -f Makefile.i386 ; fi

 ### Configure
 echo "jpeg-build-univ:     Configuring..."
 env CFLAGS="-O3 -g -isysroot /Developer/SDKs/$SDK_PPC -arch ppc"
 LDFLAGS="-Wl,-syslibroot,/Developer/SDKs/$SDK_PPC"    ./configure
 --prefix="${INSTALL_PREFIX}" --enable-shared --disable-dependency-tracking
 >/dev/null

 ### Create the PPC Makefile
 echo "jpeg-build-univ:     Creating PPC Makefile..."
 sed -e s/"CC= gcc"/"CC= \${ENVP} gcc"/ \
  -e '21i\
  ENVP= GCC_VERSION=3.3 MACOSX_DEPLOYMENT_TARGET=10.2
  ' \
  Makefile > Makefile.ppc

 ### Create the i386 Makefile
 echo "jpeg-build-univ:     Creating i386 Makefile..."
 sed -e s/"-arch ppc"/"-arch i386"/ \
  -e s/"CC= gcc"/"CC= \${ENVP} gcc"/ \
  -e s/"${SDK_PPC}"/"MacOSX10.4u.sdk"/ \
  -e '21i\
  ENVP= MACOSX_DEPLOYMENT_TARGET=10.4
  ' \
  Makefile > Makefile.i386
 rm ./Makefile

 ### Generate the i386 code
 echo "jpeg-build-univ:     Generating i386..."
 cp Makefile.i386 Makefile
 #make clean >/dev/null
 #make libjpeg.la >/dev/null
 make >/dev/null
 mv .libs/*.a build/i386/

 ### Generate the PPC code
 echo "jpeg-build-univ:     Generating PPC..."
 cp Makefile.ppc Makefile
  make clean >/dev/null
 #make libjpeg.la >/dev/null
 make >/dev/null
 mv .libs/*.a build/ppc/

 ### Build the universal libs
 echo "jpeg-build-univ:     Building universal library..."

 ### Build a list of actual libraries
 cd ./build/ppc
 FLIST=`ls *.a`
 LIBLIST=""
 for f in $FLIST ; do
     if !(test -L $f) ; then
         LIBLIST="$LIBLIST $f"
     fi
 done
 cd ../..

 for f in $LIBLIST ; do
     if test -f ./build/i386/$f ; then
         lipo -create ./build/*/$f -output .libs/$f
         echo "jpeg-build-univ:     `file $f`"
         echo "jpeg-build-univ:     $f is now universal."
     else
         echo "jpeg-build-univ:     $f is missing from build/i386, no
 universal binary built."
     fi
 done

 if test $DO_INSTALL -ne 0 ; then
     echo "jpeg-build-univ:     Installing..."
  if test $NO_SUDO -ne 0 ; then
   make install
  else
   sudo make install
     fi
 else
     echo "jpeg-build-univ:  type \"make install\" to install."
 fi

 ### And exit...
 exit
 }}}

-- 
Ticket URL: <http://trac.macports.org/ticket/12504#comment:7>
MacPorts <http://www.macports.org/>
Ports system for Mac OS


More information about the macports-tickets mailing list