PageRenderTime 146ms CodeModel.GetById 60ms app.highlight 35ms RepoModel.GetById 45ms app.codeStats 1ms

/imagemagick_compile.sh

https://github.com/fleitz/imagemagick_lib_iphone
Shell | 585 lines | 373 code | 129 blank | 83 comment | 22 complexity | 9d9005ae3e1ed41b11859cb6182eef3d MD5 | raw file
  1#!/bin/bash
  2
  3# Author: Claudio Marforio
  4# e-mail: marforio@gmail.com
  5# date: 21.03.2011
  6
  7# Script to make static libraries (jpeg + png + tiff) and ImageMagick
  8# the libraries will be conbined into i386 + armv6 + armv7 static
  9# libraries to be used inside an XCODE project for iOS development
 10
 11# The directory structure has to be:
 12# ./cross_compile/ImageMagick-VERSION/ <- ImageMagick top directory
 13#       |        /IMDelegataes/	       <- Some delegates: jpeg + png + tiff
 14#       |           |-jpeg-8c/         <- jpeg-8c -- no need to patch it
 15#       |           |-libpng-1.4.5     <- png lib -- no need to patch it
 16#       |           |-tiff-3.9.4       <- tiff lib -- no need to patch it
 17#       |- ...	 <- we don't care what's here! :)
 18
 19# If you don't have this directory structure you can either create it
 20# or try change around the script
 21
 22# If everything works correctly you will end up with a folder called
 23# IMPORT_ME in your working directory (i.e. .) ready to be imported
 24# into XCode change this line if you want for everything to be
 25# exported somewhere else
 26
 27FINAL_DIR=`pwd`/IMPORT_ME/
 28
 29if [[ $# != 1 ]]; then
 30	echo "imagemagick_compile.sh takes 1 argument: the version of ImageMagick that you want to compile!"
 31	echo "USAGE: imagemagick_compile.sh 6.6.8-5"
 32	exit
 33fi
 34
 35IM_VERSION="$1"
 36IM_DIR="$(pwd)/ImageMagick-$IM_VERSION"
 37IM_DELEGATES_DIR="${IM_DIR}/IMDelegates/"
 38
 39if [ -d $IM_DELEGATES_DIR ]; then
 40	:;
 41else
 42	echo "[INFO] IMDelegates folder not found, copying over"
 43	cp -r "$(pwd)/IMDelegates" "$IM_DIR/IMDelegates"
 44fi
 45
 46JPEG_DIR="$IM_DIR/IMDelegates/jpeg-8c"
 47PNG_DIR="$IM_DIR/IMDelegates/libpng-1.4.5"
 48TIFF_DIR="$IM_DIR/IMDelegates/tiff-3.9.4"
 49
 50OUTPUT_FILE="$(pwd)/imagemagick_log_$(date +%s)"
 51
 52# Architectures and versions
 53ARCH_SIM="i386"
 54ARCH_IPHONE="armv7s"
 55ARCH_IPHONE6="armv7"
 56GCC_VERSION="4.2.1"
 57MIN_IPHONE_VERSION="6.0"
 58IPHONE_SDK_VERSION="6.0"
 59MACOSX_SDK_VERSION="10.5"
 60IPHONE="armv7 + armv7s"
 61
 62# Set this to where you want the libraries to be placed (if dir is not present it will be created):
 63TARGET_LIB_DIR=$(pwd)/tmp_target
 64LIB_DIR=$TARGET_LIB_DIR/im_libs
 65JPEG_LIB_DIR=$TARGET_LIB_DIR/libjpeg
 66PNG_LIB_DIR=$TARGET_LIB_DIR/libpng
 67TIFF_LIB_DIR=$TARGET_LIB_DIR/libtiff
 68IM_LIB_DIR=$TARGET_LIB_DIR/imagemagick
 69
 70# Set the build directories
 71mkdir -p $TARGET_LIB_DIR
 72mkdir -p $LIB_DIR/include/im_config
 73mkdir -p $LIB_DIR/include/jpeg
 74mkdir -p $LIB_DIR/include/magick
 75mkdir -p $LIB_DIR/include/png
 76mkdir -p $LIB_DIR/include/tiff
 77mkdir -p $LIB_DIR/include/wand
 78for i in "jpeg" "png" "tiff"; do
 79	for j in $ARCH_IPHONE $ARCH_IPHONE6 $ARCH_SIM; do
 80		mkdir -p $LIB_DIR/${i}_${j}_dylib
 81	done
 82done
 83mkdir -p $JPEG_LIB_DIR
 84mkdir -p $PNG_LIB_DIR
 85mkdir -p $TIFF_LIB_DIR
 86
 87# General folders where you have the iPhone compiler + tools
 88export DEVROOT="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer"
 89export SDKROOT="${DEVROOT}/SDKs/iPhoneOS${IPHONE_SDK_VERSION}.sdk"
 90export MACOSXROOT="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator${IPHONE_SDK_VERSION}.sdk"
 91export CLANGROOT="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain"
 92# Compiler flags and config arguments - IPHONE
 93COMMON_IPHONE_LDFLAGS="-arch $ARCH_IPHONE -L$SDKROOT/usr/lib/"
 94COMMON_IPHONE6_LDFLAGS="-arch $ARCH_IPHONE6 -L$SDKROOT/usr/lib/"
 95COMMON_IPHONE_CFLAGS="-arch $ARCH_IPHONE -miphoneos-version-min=$MIN_IPHONE_VERSION -pipe -Os -isysroot $SDKROOT \
 96-I$SDKROOT/usr/include -I$SDKROOT/usr/lib/gcc/arm-apple-darwin10/$GCC_VERSION/include/"
 97COMMON_IPHONE6_CFLAGS="-arch $ARCH_IPHONE6 -miphoneos-version-min=$MIN_IPHONE_VERSION -pipe -Os -isysroot $SDKROOT \
 98-I$SDKROOT/usr/include -I$SDKROOT/usr/lib/gcc/arm-apple-darwin10/$GCC_VERSION/include/"
 99
100COMMON_SIM_LDFLAGS="-L$MACOSXROOT/usr/lib"
101COMMON_SIM_CFLAGS="-I$MACOSXROOT/usr/include -I$MACOSXROOT/usr/lib/gcc/i686-apple-darwin10/$GCC_VERSION/include/"
102
103IM_LDFLAGS="-L$LIB_DIR/jpeg_${ARCH_IPHONE}_dylib/ -L$LIB_DIR/png_${ARCH_IPHONE}_dylib/ -L$LIB_DIR/tiff_${ARCH_IPHONE}_dylib/ -L$LIB_DIR"
104IM_LDFLAGS6="-L$LIB_DIR/jpeg_${ARCH_IPHONE6}_dylib/ -L$LIB_DIR/png_${ARCH_IPHONE6}_dylib/ -L$LIB_DIR/tiff_${ARCH_IPHONE6}_dylib/ -L$LIB_DIR"
105IM_LDFLAGS_SIM="-L$LIB_DIR/jpeg_${ARCH_SIM}_dylib/ -L$LIB_DIR/png_${ARCH_SIM}_dylib/ -L$LIB_DIR/tiff_${ARCH_SIM}_dylib/ -L$LIB_DIR"
106IM_IFLAGS="$COMMON_SIM_CFLAGS -I$LIB_DIR/include/jpeg -I$LIB_DIR/include/png -I$LIB_DIR/include/tiff"
107
108############    HACK    ############
109# ImageMagick requires this header (crt_externals.h), that doesn't
110# exist for the iPhone - Just copying it make things compile/work
111if [ -e $SDKROOT/usr/include/crt_externs.h ]; then
112	:;
113else
114	echo "[INFO] need to copy crt_externals.h for compilation, please enter sudo password"
115  sudo cp "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator${IPHONE_SDK_VERSION}.sdk/usr/include/crt_externs.h" \
116		"$SDKROOT/usr/include/crt_externs.h"
117fi
118############    END    ############
119
120###################################
121############    PNG    ############
122###################################
123
124function png() {
125
126echo ""
127echo "[+ PNG: $1]"
128cd $PNG_DIR
129
130LIBPATH_png=libpng14.a
131LIBPATH_png_dylib=libpng14.dylib
132
133if [ "$1" == "$IPHONE" ]; then ## ARMV7 ##
134
135U_CC=$CC
136U_CFLAGS=$CFLAGS
137U_LD=$LD
138U_LDFLAGS=$LDFLAGS
139U_CPP=$CPP
140U_CPPFLAGS=$CPPFLAGS
141
142export LDFLAGS="$COMMON_IPHONE_LDFLAGS"
143export CFLAGS="$COMMON_IPHONE_CFLAGS"
144
145echo "[|- CONFIG ${ARCH_IPHONE}]"
146./configure prefix=$PNG_LIB_DIR CC=$CLANGROOT/usr/bin/clang --enable-shared --enable-static \
147CC=$CLANGROOT/usr/bin/clang LD=$DEVROOT/usr/bin/ld --host=arm-apple-darwin >> $OUTPUT_FILE 2>&1
148
149echo "[|- CC ${ARCH_IPHONE}]"
150make -j2 >> $OUTPUT_FILE 2>&1
151echo "[|- INSTALL ${ARCH_IPHONE}]"
152make install >> $OUTPUT_FILE 2>&1
153
154# cp the static + shared library
155cp $PNG_LIB_DIR/lib/$LIBPATH_png $LIB_DIR/libpng.a.$ARCH_IPHONE
156cp $PNG_LIB_DIR/lib/$LIBPATH_png_dylib $LIB_DIR/png_${ARCH_IPHONE}_dylib/libpng.dylib
157
158echo "[|- CLEAN ${ARCH_IPHONE}]"
159make distclean >> $OUTPUT_FILE 2>&1
160
161## ARMV6 ##
162export LDFLAGS="$COMMON_IPHONE6_LDFLAGS"
163export CFLAGS="$COMMON_IPHONE6_CFLAGS"
164
165echo "[|- CONFIG ${ARCH_IPHONE6}]"
166./configure prefix=$PNG_LIB_DIR CC=$CLANGROOT/usr/bin/clang --enable-shared --enable-static \
167CC=$CLANGROOT/usr/bin/clang LD=$DEVROOT/usr/bin/ld --host=arm-apple-darwin >> $OUTPUT_FILE 2>&1
168
169echo "[|- CC ${ARCH_IPHONE6}]"
170make -j2 >> $OUTPUT_FILE 2>&1
171make install >> $OUTPUT_FILE 2>&1
172
173# cp the static + shared library
174cp $PNG_LIB_DIR/lib/$LIBPATH_png $LIB_DIR/libpng.a.$ARCH_IPHONE6
175cp $PNG_LIB_DIR/lib/$LIBPATH_png_dylib $LIB_DIR/png_${ARCH_IPHONE6}_dylib/libpng.dylib
176
177echo "[|- CLEAN ${ARCH_IPHONE6}]"
178make distclean >> $OUTPUT_FILE 2>&1
179
180elif [ "$1" == "$ARCH_SIM" ]; then ## INTEL ##
181
182# Set up environment
183export CC=$U_CC
184export CFLAGS="$COMMON_SIM_CFLAGS -arch $ARCH_SIM"
185export LD=$U_LD
186export LDFLAGS="$U_LDFLAGS" #export LDFLAGS="$COMMON_SIM_LDFLAGS $U_LDFLAGS"
187export CPP=$U_CPP
188export CPPFLAGS=$U_CPPFLAGS
189
190echo "[|- CONFIG $ARCH_SIM]"
191./configure prefix=$PNG_LIB_DIR CC=$CLANGROOT/usr/bin/clang --enable-shared --enable-static \
192--host=i686-apple-darwin10 >> $OUTPUT_FILE 2>&1
193
194echo "[|- CC $ARCH_SIM]"
195make -j2 >> $OUTPUT_FILE 2>&1
196make install >> $OUTPUT_FILE 2>&1
197
198# cp the static library
199cp $PNG_LIB_DIR/lib/$LIBPATH_png $LIB_DIR/libpng.a.$ARCH_SIM
200cp $PNG_LIB_DIR/lib/$LIBPATH_png_dylib $LIB_DIR/png_${ARCH_SIM}_dylib/libpng.dylib
201# cp the include/* files
202cp $PNG_LIB_DIR/include/libpng14/* $LIB_DIR/include/png/
203
204echo "[|- CLEAN $ARCH_SIM]"
205make distclean >> $OUTPUT_FILE 2>&1
206
207echo "[|- COMBINE $ARCH_IPHONE $ARCH_IPHONE6 $ARCH_SIM]"
208# combine the static libraries for i386 and arm
209$DEVROOT/usr/bin/lipo -arch $ARCH_IPHONE $LIB_DIR/libpng.a.$ARCH_IPHONE \
210	-arch $ARCH_IPHONE6 $LIB_DIR/libpng.a.$ARCH_IPHONE6 \
211	-arch $ARCH_SIM $LIB_DIR/libpng.a.$ARCH_SIM -create -output $LIB_DIR/libpng.a
212
213fi
214
215echo "[+ DONE: $1]"
216
217} ## END PNG LIBRARY ##
218
219###################################
220############    JPEG   ############
221###################################
222
223function jpeg() {
224
225echo ""
226echo "[+ JPEG: $1]"
227cd $JPEG_DIR
228
229LIBPATH_jpeg=libjpeg.a
230LIBNAME_jpeg=`basename $LIBPATH_jpeg`
231
232if [ "$1" == "$IPHONE" ]; then ## ARMV7 ##
233
234U_CC=$CC
235U_CFLAGS=$CFLAGS
236U_LD=$LD
237U_LDFLAGS=$LDFLAGS
238U_CPP=$CPP
239U_CPPFLAGS=$CPPFLAGS
240
241export LDFLAGS="$COMMON_IPHONE_LDFLAGS"
242export CFLAGS="$COMMON_IPHONE_CFLAGS"
243
244echo "[|- CONFIG $ARCH_IPHONE]"
245./configure prefix=$JPEG_LIB_DIR --enable-shared --enable-static \
246CC=$CLANGROOT/usr/bin/clang LD=$DEVROOT/usr/bin/ld --host=arm-apple-darwin >> $OUTPUT_FILE 2>&1
247
248echo "[|- CC $ARCH_IPHONE]"
249make -j2 >> $OUTPUT_FILE 2>&1
250make install >> $OUTPUT_FILE 2>&1
251
252# cp the static + shared library
253cp $JPEG_LIB_DIR/lib/$LIBPATH_jpeg $LIB_DIR/$LIBNAME_jpeg.$ARCH_IPHONE
254cp $JPEG_LIB_DIR/lib/libjpeg.dylib $LIB_DIR/jpeg_${ARCH_IPHONE}_dylib/libjpeg.dylib
255
256echo "[|- CLEAN $ARCH_IPHONE]"
257make distclean >> $OUTPUT_FILE 2>&1
258
259## ARMV6 ##
260export LDFLAGS="$COMMON_IPHONE6_LDFLAGS"
261export CFLAGS="$COMMON_IPHONE6_CFLAGS"
262
263echo "[|- CONFIG $ARCH_IPHONE6]"
264./configure prefix=$JPEG_LIB_DIR --enable-shared --enable-static \
265CC=$CLANGROOT/usr/bin/clang LD=$DEVROOT/usr/bin/ld --host=arm-apple-darwin >> $OUTPUT_FILE 2>&1
266
267echo "[|- CC $ARCH_IPHONE6]"
268make -j2 >> $OUTPUT_FILE 2>&1
269make install >> $OUTPUT_FILE 2>&1
270
271# cp the static + shared library
272cp $JPEG_LIB_DIR/lib/$LIBPATH_jpeg $LIB_DIR/$LIBNAME_jpeg.$ARCH_IPHONE6
273cp $JPEG_LIB_DIR/lib/libjpeg.dylib $LIB_DIR/jpeg_${ARCH_IPHONE6}_dylib/libjpeg.dylib
274
275echo "[|- CLEAN $ARCH_IPHONE6]"
276make distclean >> $OUTPUT_FILE 2>&1
277
278elif [ "$1" == "$ARCH_SIM" ]; then ## INTEL ##
279
280# Use default environment
281export CC=$U_CC
282export CFLAGS="$COMMON_SIM_CFLAGS -arch $ARCH_SIM"
283export LD=$U_LD
284export LDFLAGS="$U_LDFLAGS" #export LDFLAGS="$COMMON_SIM_LDFLAGS -arch $ARCH_SIM"
285export CPP=$U_CPP
286export CPPFLAGS=$U_CPPFLAGS
287
288echo "[|- CONFIG $ARCH_SIM]"
289./configure prefix=$JPEG_LIB_DIR CC=$CLANGROOT/usr/bin/clang --enable-shared \
290--enable-static --host=i686-apple-darwin10 >> $OUTPUT_FILE 2>&1
291
292echo "[|- CC $ARCH_SIM]"
293make -j2 >> $OUTPUT_FILE 2>&1
294make install >> $OUTPUT_FILE 2>&1
295
296# cp the static library
297cp $JPEG_LIB_DIR/lib/$LIBPATH_jpeg $LIB_DIR/$LIBNAME_jpeg.$ARCH_SIM
298cp $JPEG_LIB_DIR/lib/libjpeg.dylib $LIB_DIR/jpeg_${ARCH_SIM}_dylib/libjpeg.dylib
299# cp the include/* files
300cp $JPEG_LIB_DIR/include/*.h $LIB_DIR/include/jpeg/
301
302echo "[|- CLEAN $ARCH_SIM]"
303make distclean >> $OUTPUT_FILE 2>&1
304
305# combine the static libraries for i386 and arm
306echo "[|- COMBINE $ARCH_IPHONE $ARCH_IPHONE6 $ARCH_SIM]"
307$DEVROOT/usr/bin/lipo -arch $ARCH_IPHONE $LIB_DIR/$LIBNAME_jpeg.$ARCH_IPHONE \
308	-arch $ARCH_IPHONE6 $LIB_DIR/$LIBNAME_jpeg.$ARCH_IPHONE6 \
309	-arch $ARCH_SIM $LIB_DIR/$LIBNAME_jpeg.$ARCH_SIM -create -output $LIB_DIR/$LIBNAME_jpeg
310
311fi
312
313echo "[+ DONE: $1]"
314
315} ## END JPEG LIBRARY ##
316
317###################################
318#############    TIFF    ##########
319###################################
320
321function tiff() {
322
323echo ""
324echo "[+ TIFF: $1]"
325cd $TIFF_DIR
326
327LIBPATH_tiff=libtiff.a
328LIBNAME_tiff=`basename $LIBPATH_tiff`
329
330if [ "$1" == "$IPHONE" ]; then ##  ARM	 ##
331
332U_CC=$CC
333U_CFLAGS=$CFLAGS
334U_LD=$LD
335U_LDFLAGS=$LDFLAGS
336U_CPP=$CPP
337U_CPPFLAGS=$CPPFLAGS
338
339export LDFLAGS="$COMMON_IPHONE_LDFLAGS"
340export CFLAGS="$COMMON_IPHONE_CFLAGS"
341
342echo "[|- CONFIG $ARCH_IPHONE]"
343./configure prefix=$TIFF_LIB_DIR CC=$CLANGROOT/usr/bin/clang \
344LD=$DEVROOT/usr/bin/ld --host=arm-apple-darwin --disable-cxx >> $OUTPUT_FILE 2>&1
345
346echo "[|- CC $ARCH_IPHONE]"
347make -j2 >> $OUTPUT_FILE 2>&1
348make install >> $OUTPUT_FILE 2>&1
349
350# cp the static + shared library
351cp $TIFF_LIB_DIR/lib/$LIBPATH_tiff $LIB_DIR/$LIBNAME_tiff.$ARCH_IPHONE
352cp $TIFF_LIB_DIR/lib/libtiff.3.dylib $LIB_DIR/tiff_${ARCH_IPHONE}_dylib/libtiff.dylib
353
354echo "[|- CLEAN $ARCH_IPHONE]"
355make distclean >> $OUTPUT_FILE 2>&1
356
357## ARMV6 ##
358export LDFLAGS="$COMMON_IPHONE6_LDFLAGS"
359export CFLAGS="$COMMON_IPHONE6_CFLAGS"
360
361echo "[|- CONFIG $ARCH_IPHONE6]"
362./configure prefix=$TIFF_LIB_DIR CC=$CLANGROOT/usr/bin/clang \
363LD=$DEVROOT/usr/bin/ld --host=arm-apple-darwin --disable-cxx >> $OUTPUT_FILE 2>&1
364
365echo "[|- CC $ARCH_IPHONE6]"
366make -j2 >> $OUTPUT_FILE 2>&1
367make install >> $OUTPUT_FILE 2>&1
368
369# cp the static + shared library
370cp $TIFF_LIB_DIR/lib/$LIBPATH_tiff $LIB_DIR/$LIBNAME_tiff.$ARCH_IPHONE6
371cp $TIFF_LIB_DIR/lib/libtiff.3.dylib $LIB_DIR/tiff_${ARCH_IPHONE6}_dylib/libtiff.dylib
372
373echo "[|- CLEAN $ARCH_IPHONE6]"
374make distclean >> $OUTPUT_FILE 2>&1
375
376elif [ "$1" == "$ARCH_SIM" ]; then ##  INTEL  ##
377
378# Use default environment
379export CC=$U_CC
380export CFLAGS="$COMMON_SIM_CFLAGS -arch $ARCH_SIM"
381export LD=$U_LD
382export LDFLAGS="$U_LDFLAGS" #export LDFLAGS="$COMMON_SIM_LDFLAGS $U_LDFLAGS"
383export CPP=$U_CPP
384export CPPFLAGS=$U_CPPFLAGS
385
386echo "[|- CONFIG $ARCH_SIM]"
387./configure prefix=$TIFF_LIB_DIR CC=$CLANGROOT/usr/bin/clang --host=i686-apple-darwin10 \
388--disable-cxx >> $OUTPUT_FILE 2>&1
389
390echo "[|- CC $ARCH_SIM]"
391make -j2 >> $OUTPUT_FILE 2>&1
392make install >> $OUTPUT_FILE 2>&1
393
394# cp the static library
395cp $TIFF_LIB_DIR/lib/$LIBPATH_tiff $LIB_DIR/$LIBNAME_tiff.$ARCH_SIM
396cp $TIFF_LIB_DIR/lib/libtiff.3.dylib $LIB_DIR/tiff_${ARCH_SIM}_dylib/libtiff.dylib
397
398# cp the include/* files
399cp $TIFF_LIB_DIR/include/*.h $LIB_DIR/include/tiff/
400
401echo "[|- CLEAN $ARCH_SIM]"
402make distclean >> $OUTPUT_FILE 2>&1
403
404# combine the static libraries for i386 and arm
405echo "[|- COMBINE $ARCH_IPHONE $ARCH_IPHONE6 $ARCH_SIM]"
406$DEVROOT/usr/bin/lipo -arch $ARCH_IPHONE $LIB_DIR/$LIBNAME_tiff.$ARCH_IPHONE \
407	-arch $ARCH_IPHONE6 $LIB_DIR/$LIBNAME_tiff.$ARCH_IPHONE6 \
408	-arch $ARCH_SIM $LIB_DIR/$LIBNAME_tiff.$ARCH_SIM -create -output $LIB_DIR/$LIBNAME_tiff
409
410fi
411
412echo "[+ DONE $1]"
413
414} ## END TIFF LIBRARY ##
415
416###################################
417############    IMAGEMAGICK    ####
418###################################
419
420function im() {
421
422echo ""
423echo "[+ IM: $1]"
424cd $IM_DIR
425
426# static library that will be generated
427LIBPATH_static=$IM_LIB_DIR/lib/libMagickCore.a
428LIBNAME_static=`basename $LIBPATH_static`
429LIBPATH_static2=$IM_LIB_DIR/lib/libMagickWand.a
430LIBNAME_static2=`basename $LIBPATH_static2`
431
432if [ "$1" == "$IPHONE" ]; then ##  ARM	 ##
433
434# Save relevant environment
435U_CC=$CC
436U_CFLAGS=$CFLAGS
437U_LD=$LD
438U_LDFLAGS=$LDFLAGS
439U_CPP=$CPP
440U_CPPFLAGS=$CPPFLAGS
441
442export LDFLAGS="$IM_LDFLAGS $COMMON_IPHONE_LDFLAGS"
443export CFLAGS="$COMMON_IPHONE_CFLAGS $IM_IFLAGS -DHAVE_J1=0 -DTARGET_OS_IPHONE -DMAGICKCORE_WORDS_BIGENDIAN"
444export CXXFLAGS="-Wall -W -D_THREAD_SAFE -DHAVE_J1=0 -DTARGET_OS_IPHONE -DMAGICKCORE_WORDS_BIGENDIAN"
445
446# configure to have the static libraries
447echo "[|- CONFIG $ARCH_IPHONE]"
448./configure prefix=$IM_LIB_DIR CC=$CLANGROOT/usr/bin/clang LD=$DEVROOT/usr/bin/ld \
449--host=arm-apple-darwin --disable-largefile --with-quantum-depth=8 --without-magick-plus-plus \
450--without-perl --without-x --disable-shared --disable-openmp --without-bzlib --without-freetype >> $OUTPUT_FILE 2>&1
451
452# compile ImageMagick
453echo "[|- CC $ARCH_IPHONE]"
454make -j2 >> $OUTPUT_FILE 2>&1
455make install >> $OUTPUT_FILE 2>&1
456
457# copy the CORE + WAND libraries -- ARM version
458cp $LIBPATH_static $LIB_DIR/$LIBNAME_static.$ARCH_IPHONE
459cp $LIBPATH_static2 $LIB_DIR/$LIBNAME_static2.$ARCH_IPHONE
460
461# clean the ImageMagick build
462echo "[| CLEAN $ARCH_IPHONE]"
463make distclean >> $OUTPUT_FILE 2>&1
464
465## ARMV6 ##
466export CFLAGS="$COMMON_IPHONE6_CFLAGS $IM_IFLAGS -DHAVE_J1=0 -DTARGET_OS_IPHONE -DMAGICKCORE_WORDS_BIGENDIAN"
467export LDFLAGS="$IM_LDFLAGS6 $COMMON_IPHONE6_LDFLAGS"
468
469# configure to have the static libraries
470echo "[|- CONFIG $ARCH_IPHONE6]"
471./configure prefix=$IM_LIB_DIR CC=$CLANGROOT/usr/bin/clang LD=$DEVROOT/usr/bin/ld \
472--host=arm-apple-darwin --disable-largefile --with-quantum-depth=8 --without-magick-plus-plus \
473--without-perl --without-x --disable-shared --disable-openmp --without-bzlib --without-freetype >> $OUTPUT_FILE 2>&1
474
475# compile ImageMagick
476echo "[|- CC $ARCH_IPHONE6]"
477make -j2 >> $OUTPUT_FILE 2>&1
478make install >> $OUTPUT_FILE 2>&1
479
480# copy the CORE + WAND libraries -- ARM version
481cp $LIBPATH_static $LIB_DIR/$LIBNAME_static.$ARCH_IPHONE6
482cp $LIBPATH_static2 $LIB_DIR/$LIBNAME_static2.$ARCH_IPHONE6
483
484# copy the wand/ + core/ headers
485cp $IM_LIB_DIR/include/ImageMagick/magick/* $LIB_DIR/include/magick/
486cp $IM_LIB_DIR/include/ImageMagick/wand/* $LIB_DIR/include/wand/
487
488# copy configuration files needed for certain functions
489cp $IM_LIB_DIR/etc/ImageMagick/*.xml $LIB_DIR/include/im_config/
490cp $IM_LIB_DIR/share/ImageMagick-*/*.xml $LIB_DIR/include/im_config/
491
492# clean the ImageMagick build
493echo "[|- CLEAN $ARCH_IPHONE6]"
494make distclean >> $OUTPUT_FILE 2>&1
495
496elif [ "$1" == "$ARCH_SIM" ]; then ##  INTEL  ##
497
498# Use default environment
499export CC=$U_CC
500export LDFLAGS="-isysroot $MACOSXROOT -mmacosx-version-min=10.6 $IM_LDFLAGS_SIM"
501export CFLAGS="-arch $ARCH_SIM -isysroot $MACOSXROOT -mmacosx-version-min=10.6 $IM_IFLAGS -DHAVE_J1=0 -DTARGET_OS_IPHONE -DMAGICKCORE_WORDS_BIGENDIAN"
502export LD=$U_LD
503export CPP=$U_CPP
504export CPPFLAGS="$U_CPPFLAGS $U_LDFLAGS $IM_IFLAGS -DHAVE_J1=0 -DTARGET_OS_IPHONE -DMAGICKCORE_WORDS_BIGENDIAN"
505
506# configure with standard parameters
507echo "[|- CONFIG $ARCH_SIM]"
508./configure prefix=$IM_LIB_DIR CC=$CLANGROOT/usr/bin/clang --host=i686-apple-darwin10 \
509--disable-largefile --with-quantum-depth=8 --without-magick-plus-plus --without-perl --without-x \
510--disable-shared --disable-openmp --without-bzlib --without-freetype --without-threads >> $OUTPUT_FILE 2>&1
511
512# compile ImageMagick
513echo "[|- CC $ARCH_SIM]"
514make -j2 >> $OUTPUT_FILE 2>&1
515make install >> $OUTPUT_FILE 2>&1
516
517# copy the CORE + WAND libraries -- INTEL version
518cp $LIBPATH_static $LIB_DIR/$LIBNAME_static.$ARCH_SIM
519cp $LIBPATH_static2 $LIB_DIR/$LIBNAME_static2.$ARCH_SIM
520
521# clean the ImageMagick build
522echo "[|- CLEAN $ARCH_SIM]"
523make distclean >> $OUTPUT_FILE 2>&1
524
525# combine the two generated libraries to be used both in the simulator and in the device
526echo "[|- COMBINE (libMagickCore) $ARCH_IPHONE $ARCH_IPHONE6 $ARCH_SIM]"
527$DEVROOT/usr/bin/lipo -arch $ARCH_IPHONE $LIB_DIR/$LIBNAME_static.$ARCH_IPHONE \
528	-arch $ARCH_IPHONE6 $LIB_DIR/$LIBNAME_static.$ARCH_IPHONE6 \
529	-arch $ARCH_SIM $LIB_DIR/$LIBNAME_static.$ARCH_SIM -create -output $LIB_DIR/$LIBNAME_static
530
531echo "[|- COMBINE (libMagickWand) $ARCH_IPHONE $ARCH_IPHONE6 $ARCH_SIM]"	
532$DEVROOT/usr/bin/lipo -arch $ARCH_IPHONE $LIB_DIR/$LIBNAME_static2.$ARCH_IPHONE \
533	-arch $ARCH_IPHONE6 $LIB_DIR/$LIBNAME_static2.$ARCH_IPHONE6 \
534	-arch $ARCH_SIM $LIB_DIR/$LIBNAME_static2.$ARCH_SIM -create -output $LIB_DIR/$LIBNAME_static2
535
536fi
537
538echo "[+ DONE: IM]"
539
540} ## END IMAGEMAGICK LIBRARY ##
541
542function structure_for_xcode() {
543	echo ""
544	echo "[+ XCODE]"
545	if [ -e $FINAL_DIR ]; then
546		echo "[|- RM $FINAL_DIR]"
547		rm -rf "$FINAL_DIR"*
548	else
549		echo "[|- MKDIR: $FINAL_DIR]"
550		mkdir -p "$FINAL_DIR"
551	fi
552	echo "[|- CP]"
553	cp -r ${LIB_DIR}/include/ ${FINAL_DIR}include/
554	cp $LIB_DIR/*.a "$FINAL_DIR"
555	echo "[+ DONE: XCODE]"
556}
557
558# function used to produce .zips for the ImageMagick ftp site maintained by me (Claudio Marforio)
559function zip_for_ftp() {
560	echo ""
561	echo "[+ ZIP]"
562	if [ -e $FINAL_DIR ]; then
563		tmp_dir="$(pwd)/TMP_IM"
564		cp -R $FINAL_DIR $tmp_dir
565		ditto -c -k -rsrc "$tmp_dir" "iOSMagick-${IM_VERSION}-libs.zip" && echo "[|- CREATED W/ libs]"
566		rm $tmp_dir/libjpeg.a $tmp_dir/libpng.a $tmp_dir/libtiff.a
567		rm -rf $tmp_dir/include/jpeg/ $tmp_dir/include/png/ $tmp_dir/include/tiff/
568		ditto -c -k -rsrc "$tmp_dir" "iOSMagick-${IM_VERSION}.zip" && echo "[|- CREATED W/O libs]"
569		rm -rf $tmp_dir
570	else
571		echo "[* ERROR, $FINAL_DIR not present..."
572	fi
573	echo "[+ DONE: ZIP]"
574}
575
576png "$IPHONE"
577png "$ARCH_SIM" 
578jpeg "$IPHONE"
579jpeg "$ARCH_SIM"
580tiff "$IPHONE"
581tiff "$ARCH_SIM"
582im "$IPHONE"
583im "$ARCH_SIM"
584structure_for_xcode
585# zip_for_ftp # used only by me (Claudio Marforio) to upload to the IM ftp :)