├── LICENSE ├── README.md ├── autoframework └── iconfigure /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014, Angelo Haller 2 | 3 | Permission to use, copy, modify, and/or distribute this software for any 4 | purpose with or without fee is hereby granted, provided that the above 5 | copyright notice and this permission notice appear in all copies. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 | 15 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Autotools helpers for iOS 2 | ========================= 3 | 4 | Helper tools for cross-compilation of autotools libraries for iOS (and simulator) on OS X. 5 | All libraries are static, since iOS does not support linking of custom dynamic libraries. 6 | 7 | You will have to install `automake`, `autoconf` and `libtool` via your favorite mechanism (compile from source, homebrew, macports, ...). 8 | 9 | 10 | Usage: iconfigure 11 | ----------------- 12 | 13 | To configure a library for a specific architecture run `iconfigure` in the directory containing the 14 | *configure* script. 15 | 16 | iconfigure armv7|armv7s|arm64|i686|x86_64 17 | 18 | This will set up the environment for cross-compiling for the specified architecture. 19 | You can then proceed as usual by running `make` and `make install`. `make install` 20 | will default to install your libraries system-wide in */opt/* so that you can use them 21 | in multiple projects. 22 | 23 | All this can be configured by setting the following variables: 24 | 25 | SDKVERSION e.g.: 7.1 26 | PREFIX e.g.: /User/Home/project/staticlib 27 | 28 | And the typical compiler flags: 29 | 30 | CFLAGS CPPFLAGS CXXFLAGS LDFLAGS PKG_CONFIG_PATH 31 | 32 | For more variables and their functionality see the usage instructions and/or read 33 | the source code. 34 | 35 | For example to build a library locally in your project targeting the iOS SDK version 7.1 on armv7 run: 36 | 37 | SDKVERSION=7.1 PREFIX=/User/Home/project/staticlib iconfigure armv7 38 | make 39 | make install 40 | 41 | 42 | Usage: autoframework 43 | -------------------- 44 | 45 | To build an iOS framework for all architectures run `autoframework` in the directory containing 46 | the *configure* script. 47 | 48 | This will create two directories *Static* and *Frameworks*. *Static* will contain one 49 | subdirectory for each architecture, each containing all installation targets for that 50 | architecture. *Frameworks* will contain the resulting multiarch framework. 51 | 52 | autoframework MyLib libmylib.a 53 | 54 | As with `iconfigure` there are a few optional settings: 55 | 56 | ARCHS e.g. armv7 armv7s 57 | PREFIX e.g. /User/Home/project 58 | 59 | For example for building your framework locally for armv7 and armv7s you could run: 60 | 61 | ARCHS="armv7 armv7s" PREFIX=/User/Home/project autoframework MyLib libmylib.a 62 | 63 | 64 | External build system 65 | --------------------- 66 | 67 | While *Xcode* does not directly support *autotools* it has support for plain *Makefiles*. 68 | You can use this to build all your libraries within your project automatically. 69 | 70 | Add a new *External Build System* target to your project (*File > New > Target > OS X > Other > External Build System*). 71 | Enter a name like *StaticLibs* and create a *Makefile* in the top level of your project: 72 | 73 | ARCHS="armv7 armv7s arm64 i686 x86_64" 74 | FRAMEWORKS = Frameworks/MyLib.framework 75 | 76 | all: $(FRAMEWORKS) 77 | 78 | Frameworks/MyLib.framework: mylib 79 | cd $< && ./autogen.sh 80 | # $(PROJECT_DIR) set by Xcode 81 | # $(ARCHS) set by Xcode, but sadly does not include all target architectures 82 | cd $< && PREFIX=$(PROJECT_DIR) ARCHS=$(ARCHS) autoframework MyLib libmylib.a 83 | 84 | Be aware that Xcode itself does set the ARCHS variable to an incorrect value. We therefore 85 | have to override the value by manually specifying the desired architectures in the 86 | Makefile. 87 | 88 | Now add the new target to the dependencies of your main project and build. 89 | You should now be able to either add your libraries either by adding the 90 | desired frameworks in *Frameworks/* or by adding *Static/{include,lib}* to the 91 | paths in your main project and setting the appropriate linker flags. 92 | 93 | Depending on where you installed your autotools suite you might have to adjust the 94 | *PATH* variable in your new target. Go to: *Build Settings > + > Add User-Defined Setting* 95 | and enter *PATH* with the value *$PATH:/usr/local/bin* (or wherever your tools are 96 | located). 97 | 98 | 99 | License 100 | ------- 101 | 102 | ISC license, see the LICENSE file for more details. 103 | 104 | 105 | Origins 106 | ------- 107 | 108 | Inspired by the initial *iOS-autoconf* scripts of intlres1 and sbooth. 109 | 110 | -------------------------------------------------------------------------------- /autoframework: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | 4 | usage () { 5 | echo "Usage: [VARIABLE...] $(basename $0) framework libname" 6 | echo " framework Name of the framework to create" 7 | echo " libname Name of the .a library" 8 | echo "" 9 | echo " VARIABLEs are:" 10 | echo " ARCHS Only build for specific architectures. Default is:" 11 | echo " armv7|armv7s|arm64|i686|x86_64" 12 | echo " PREFIX Installation prefix for framework and static files." 13 | echo "" 14 | echo " All additional parameters are passed to the configure script." 15 | exit 1 16 | } 17 | 18 | # Sanity checks 19 | if [ "$#" -lt 2 ]; then 20 | usage 21 | fi 22 | 23 | ICONFIGURE="$(dirname $0)/iconfigure" 24 | 25 | FRAMEWORK=$1 26 | LIBARCHIVE=$2 27 | 28 | shift 2 29 | 30 | if [ -z "$PREFIX" ]; then 31 | PREFIX="$(pwd)" 32 | fi 33 | 34 | STATICDIR="$PREFIX/Static" 35 | FRAMEWORKDIR="$PREFIX/Frameworks/$FRAMEWORK.framework" 36 | 37 | if [ -z "$ARCHS" ]; then 38 | ARCHS="i386 x86_64 armv7 armv7s arm64" 39 | fi 40 | 41 | # Build all architectures 42 | for ARCH in $ARCHS; do 43 | make distclean || true 44 | PREFIX="$STATICDIR/$ARCH" $ICONFIGURE $ARCH $@ 45 | make 46 | make install 47 | done 48 | 49 | # Install header files 50 | PREFIX="$STATICDIR/$ARCH" $ICONFIGURE $ARCH --includedir="$FRAMEWORKDIR/Headers" $@ 51 | make 52 | make install 53 | 54 | # Create multiarch archive 55 | for ARCH in $ARCHS; do 56 | LIPOARCHS="$LIPOARCHS -arch $ARCH $STATICDIR/$ARCH/lib/$LIBARCHIVE" 57 | done 58 | lipo -create -output "$FRAMEWORKDIR/$FRAMEWORK" $LIPOARCHS 59 | 60 | echo "Success!" 61 | echo "Built $FRAMEWORK for architectures: $ARCHS" 62 | 63 | -------------------------------------------------------------------------------- /iconfigure: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | 4 | usage () { 5 | echo "Usage: [VARIABLE...] $(basename $0) architecture" 6 | echo "" 7 | echo " architecture Target architecture. [armv7|armv7s|arm64|i386|x86_64]" 8 | echo "" 9 | echo " VARIABLEs are:" 10 | echo " SDKVERSION Target a specific SDK version." 11 | echo " PREFIX Custom install prefix, useful for local installs." 12 | echo " CHOST Configure host, set if not deducable by ARCH." 13 | echo " SDK SDK target, set if not deducable by ARCH. [iphoneos|iphonesimulator]" 14 | echo "" 15 | echo " CFLAGS CPPFLAGS CXXFLAGS LDFLAGS PKG_CONFIG_PATH" 16 | echo "" 17 | echo " All additional parameters are passed to the configure script." 18 | exit 1 19 | } 20 | 21 | # Sanity checks 22 | if [ "$#" -lt 1 ]; then 23 | echo "Please supply an architecture name." 24 | usage 25 | fi 26 | 27 | if [ ! -x "./configure" ] ; then 28 | echo "No configure script found." 29 | usage 30 | fi 31 | 32 | # Build architecture 33 | export ARCH=$1 34 | 35 | # Export supplied CHOST or deduce by ARCH 36 | if [ ! -z "$CHOST" ]; then 37 | export CHOST 38 | else 39 | case $ARCH in 40 | armv7 | armv7s ) 41 | export CHOST=arm-apple-darwin* 42 | ;; 43 | arm64 ) 44 | export CHOST=aarch64-apple-darwin* 45 | ;; 46 | i386 | x86_64 ) 47 | export CHOST=$ARCH-apple-darwin* 48 | ;; 49 | * ) 50 | usage 51 | ;; 52 | esac 53 | fi 54 | 55 | # Export supplied SDK or deduce by ARCH 56 | if [ ! -z "$SDK" ]; then 57 | export SDK 58 | else 59 | case $ARCH in 60 | armv7 | armv7s | arm64 ) 61 | export SDK=iphoneos 62 | ;; 63 | i386 | x86_64 ) 64 | export SDK=iphonesimulator 65 | ;; 66 | * ) 67 | usage 68 | ;; 69 | esac 70 | fi 71 | 72 | # Export supplied SDKVERSION or use system default 73 | if [ ! -z "$SDKVERSION" ]; then 74 | SDKNAME=$(basename $(xcrun --sdk $SDK --show-sdk-platform-path) .platform) 75 | export SDKVERSION 76 | export SDKROOT=$(xcrun --sdk $SDK --show-sdk-platform-path)"/Developer/SDKs/$SDKNAME.$SDKVERSION.sdk" 77 | else 78 | export SDKVERSION=$(xcrun --sdk $SDK --show-sdk-version) # current version 79 | export SDKROOT=$(xcrun --sdk $SDK --show-sdk-path) # current version 80 | fi 81 | 82 | # Export supplied PREFIX or use default 83 | if [ ! -z "$PREFIX" ]; then 84 | export PREFIX 85 | else 86 | export PREFIX="/opt/$SDK-$SDKVERSION/$ARCH" 87 | fi 88 | 89 | # Binaries 90 | export CC=$(xcrun --sdk $SDK --find gcc) 91 | export CPP=$(xcrun --sdk $SDK --find gcc)" -E" 92 | export CXX=$(xcrun --sdk $SDK --find g++) 93 | export LD=$(xcrun --sdk $SDK --find ld) 94 | 95 | # Flags 96 | export CFLAGS="$CFLAGS -arch $ARCH -isysroot $SDKROOT -I$PREFIX/include -miphoneos-version-min=$SDKVERSION" 97 | export CPPFLAGS="$CPPFLAGS -arch $ARCH -isysroot $SDKROOT -I$PREFIX/include -miphoneos-version-min=$SDKVERSION" 98 | export CXXFLAGS="$CXXFLAGS -arch $ARCH -isysroot $SDKROOT -I$PREFIX/include" 99 | export LDFLAGS="$LDFLAGS -arch $ARCH -isysroot $SDKROOT -L$PREFIX/lib" 100 | export PKG_CONFIG_PATH="$PKG_CONFIG_PATH":"$SDKROOT/usr/lib/pkgconfig":"$PREFIX/lib/pkgconfig" 101 | 102 | # Remove script parameters 103 | shift 1 104 | 105 | # Run configure 106 | ./configure \ 107 | --prefix="$PREFIX" \ 108 | --host="$CHOST" \ 109 | --enable-static \ 110 | --disable-shared \ 111 | $@ 112 | --------------------------------------------------------------------------------