makefile for iOS 5.1 (osx 10.7, xcode 4.3)

Help
Josh
2012-04-08
2012-10-31
  • Josh

    Josh - 2012-04-08

    I've been trying to build free image for an iOS 5.1 device and I had to modify
    the makefile since some of the paths appear to have changed for Xcode 4.3. I
    didn't see anything in the forums about this so I'll post my modified makefile
    here:

    The main differences are:
    1) tools are in /Applications/Xcode.app/Contents/Developer instead of
    /Developer
    2) (some) gcc tools are named llvm-*

    # Configuration for iPhone OS, making static libs
    # this will generate both iPhone (arm) and iPhoneSimulator (i686) libs
    
    include Makefile.srcs
    
    CFLAGS =  -g -O2 -Wall -Wmissing-prototypes -std=c99 -ffast-math -fno-strict-aliasing
    CXXFLAGS =  -g -O2 -Wall -fno-strict-aliasing
    
    GCC_VERSION = 4.2
    IPHONEOS_DEPLOYMENT_TARGET = 5.1
    MACOSX_DEPLOYMENT_TARGET = 10.7
    
    PLATFORM_SIM = iPhoneSimulator
    PLATFORM_PHONE = iPhoneOS
    
    ARCH_SIM = i686
    ARCH_PHONE = armv7
    
    Developer=/Applications/Xcode.app/Contents/Developer
    PLATFORM_SIM_DEVELOPER_BIN_DIR = $(Developer)/Platforms/$(PLATFORM_SIM).platform/Developer/usr/bin
    PLATFORM_PHONE_DEVELOPER_BIN_DIR = $(Developer)/Platforms/$(PLATFORM_PHONE).platform/Developer/usr/bin
    
    SDKROOT_SIM = $(Developer)/Platforms/$(PLATFORM_SIM).platform/Developer/SDKs/$(PLATFORM_SIM)$(IPHONEOS_DEPLOYMENT_TARGET).sdk
    SDKROOT_PHONE = $(Developer)/Platforms/$(PLATFORM_PHONE).platform/Developer/SDKs/$(PLATFORM_PHONE)$(IPHONEOS_DEPLOYMENT_TARGET).sdk
    
    EXTRA_CFLAGS_SIM += -arch $(ARCH_SIM) -pipe -mdynamic-no-pic -fvisibility=hidden $(INCLUDE) -isysroot $(SDKROOT_SIM)
    EXTRA_LDFLAGS_SIM += -arch $(ARCH_SIM) -isysroot $(SDKROOT_SIM) -Wl,-dead_strip
    EXTRA_CFLAGS_SIM += -D__IPHONE_OS_VERSION_MIN_REQUIRED=20000 -mmacosx-version-min=$(MACOSX_DEPLOYMENT_TARGET)
    EXTRA_LDFLAGS_SIM += -mmacosx-version-min=$(MACOSX_DEPLOYMENT_TARGET)
    
    EXTRA_CFLAGS_PHONE += -arch $(ARCH_PHONE) -pipe -mdynamic-no-pic -fvisibility=hidden $(INCLUDE) -isysroot $(SDKROOT_PHONE)
    EXTRA_LDFLAGS_PHONE += -arch $(ARCH_PHONE) -isysroot $(SDKROOT_PHONE) -Wl,-dead_strip
    EXTRA_CFLAGS_PHONE += -miphoneos-version-min=$(IPHONEOS_DEPLOYMENT_TARGET)
    EXTRA_LDFLAGS_PHONE += -miphoneos-version-min=$(IPHONEOS_DEPLOYMENT_TARGET)
    
    AR_SIM = $(PLATFORM_SIM_DEVELOPER_BIN_DIR)/ar
    AR_PHONE = $(PLATFORM_PHONE_DEVELOPER_BIN_DIR)/ar
    
    CC_SIM = $(PLATFORM_SIM_DEVELOPER_BIN_DIR)/llvm-gcc-$(GCC_VERSION)
    CC_PHONE = $(PLATFORM_PHONE_DEVELOPER_BIN_DIR)/llvm-gcc-$(GCC_VERSION)
    
    CFLAGS_SIM = $(CFLAGS) $(EXTRA_CFLAGS_SIM)
    LDFLAGS_SIM = $(EXTRA_LDFLAGS_SIM)
    CXX_SIM = $(PLATFORM_SIM_DEVELOPER_BIN_DIR)/llvm-g++-$(GCC_VERSION)
    CXXFLAGS_SIM += $(EXTRA_CFLAGS_SIM) -fvisibility-inlines-hidden
    LIBTOOL_SIM = $(Developer)/Platforms/$(PLATFORM_SIM).platform/Developer/usr/bin/libtool
    
    CFLAGS_PHONE = $(CFLAGS) $(EXTRA_CFLAGS_PHONE)
    LDFLAGS_PHONE += $(EXTRA_LDFLAGS_PHONE)
    CXX_PHONE = $(PLATFORM_PHONE_DEVELOPER_BIN_DIR)/llvm-g++-$(GCC_VERSION)
    CXXFLAGS_PHONE += $(EXTRA_CFLAGS_PHONE) -fvisibility-inlines-hidden
    LIBTOOL_PHONE = $(Developer)/Platforms/$(PLATFORM_PHONE).platform/Developer/usr/bin/libtool
    
    TARGET = freeimage
    STATICLIB_SIM = lib$(TARGET)-iphonesimulator.a
    STATICLIB_PHONE = lib$(TARGET)-iphone.a
    HEADER = Source/FreeImage.h
    
    .SUFFIXES: .o-i686 .o-arm
    MODULES_ARM = $(SRCS:.c=.o-arm)
    MODULES_ARM := $(MODULES_ARM:.cpp=.o-arm)
    MODULES_i686 = $(SRCS:.c=.o-i686)
    MODULES_i686 := $(MODULES_i686:.cpp=.o-i686)
    
    default: all
    
    all: dist
    
    dist: FreeImage
        cp *.a Dist
        cp Source/FreeImage.h Dist
    
    FreeImage: $(STATICLIB_SIM) $(STATICLIB_PHONE)
    
    $(STATICLIB_SIM): $(MODULES_i686)
        $(LIBTOOL_SIM) -arch_only i686 -o $@ $(MODULES_i686)
    
    .c.o-i686:
        $(CC_SIM) $(CFLAGS_SIM) -c $< -o $@
    
    .cpp.o-i686:
        $(CXX_SIM) $(CXXFLAGS_SIM) -c $< -o $@
    
    $(STATICLIB_PHONE): $(MODULES_ARM)
        $(LIBTOOL_PHONE) -arch_only armv6 -o $@ $(MODULES_ARM)
    
    .c.o-arm:
        $(CC_PHONE) $(CFLAGS_PHONE) -c $< -o $@
    
    .cpp.o-arm:
        $(CXX_PHONE) $(CXXFLAGS_PHONE) -c $< -o $@
    
    clean:
        rm -f core Dist/*.* u2dtmp* $(MODULES_i686) $(MODULES_ARM) $(STATICLIB_SIM) $(STATICLIB_PHONE)
    
     
  • Josh

    Josh - 2012-04-08

    oops: apparently I forgot to change a line:

    $(STATICLIB_PHONE): $(MODULES_ARM)
        $(LIBTOOL_PHONE) -arch_only armv6 -o $@ $(MODULES_ARM)
    

    should be

    $(STATICLIB_PHONE): $(MODULES_ARM)
        $(LIBTOOL_PHONE) -arch_only armv7 -o $@ $(MODULES_ARM)
    
     
  • Xenux

    Xenux - 2012-05-31

    Thanks for your code! It's works perfect with xcode 4.3.

    However, there's a mistake:

    $(STATICLIB_PHONE): $(MODULES_ARM)
    $(LIBTOOL_PHONE) -arch_only armv6 -o $@ $(MODULES_ARM)

    must be replaced by:

    $(STATICLIB_PHONE): $(MODULES_ARM)
    $(LIBTOOL_PHONE) -arch_only $(ARCH_PHONE) -o $@ $(MODULES_ARM)

     
  • w2moon

    w2moon - 2012-06-18

    when use this lib,i got errors:

    Undefined symbols for architecture armv7:
    "ZNSolsEm", referenced from:
    ZN3Imf12_GLOBALN_121checkIsNullTerminatedILm256EEEvRATKcPS2_ in
    libfreeimage-iphone.a(ImfHeader.o-arm)
    ZN3Imf12_GLOBALN_121checkIsNullTerminatedILm256EEEvRATKcPS2_ in
    libfreeimage-iphone.a(ImfChannelListAttribute.o-arm)
    "
    ZnwmRKSt9nothrow_t", referenced from:
    FreeImage_Initialise in libfreeimage-iphone.a(Plugin.o-arm)
    _FreeImage_SetMetadata in libfreeimage-iphone.a(BitmapAccess.o-arm)
    _FreeImage_CloneMetadata in libfreeimage-iphone.a(BitmapAccess.o-arm)
    _FreeImage_AllocateHeaderT in libfreeimage-iphone.a(BitmapAccess.o-arm)
    _FreeImage_Clone in libfreeimage-iphone.a(BitmapAccess.o-arm)
    ZL4OpenP11FreeImageIOPvi in libfreeimage-iphone.a(PluginGIF.o-arm)
    ZL4LoadP11FreeImageIOPviiS1
    in libfreeimage-iphone.a(PluginGIF.o-arm)
    ...
    "ZTVN10cxxabiv121vmi_class_type_infoE", referenced from:
    ZTIN3Iex7BaseExcE in libfreeimage-iphone.a(IexBaseExc.o-arm)
    NOTE: a missing vtable usually means the first non-inline virtual member
    function has no definition.
    "ZNSsC2ERKSs", referenced from:
    ZN3Iex7BaseExcC2ERKSs in libfreeimage-iphone.a(IexBaseExc.o-arm)
    "ZNKSs4dataEv", referenced from:
    ZN11StringTable10DecompressEPhPi in libfreeimage-iphone.a(PluginGIF.o-arm)
    ZNK3Imf6Header7writeToERNS_7OStreamEb in libfreeimage-
    iphone.a(ImfHeader.o-arm)
    "
    Znwm", referenced from:
    __ZN10PluginList7AddNodeEPFvP6PluginiEPvPKcS6_S6_S6_ in libfreeimage-
    iphone.a(Plugin.o-arm)
    ...

     

Log in to post a comment.