Skip to content

Instantly share code, notes, and snippets.

@danomatika
Created July 2, 2013 17:15
Show Gist options
  • Save danomatika/5911188 to your computer and use it in GitHub Desktop.
Save danomatika/5911188 to your computer and use it in GitHub Desktop.
FreeImage Makefile for iOS updated for newer version of XCode, tested with OSX 10.8 & XCode 4.6
# Configuration for iPhone OS, builds static libs for iOS and the iOSSimulator
#
# You can make a fat lib (iOS + iOSSimulator) using lipo:
# lipo -c libfreeimage-simulator.a libfreeimage-armv7.a -o libfreeimage.a
#
# Example: build & link fat lib for armv6, armv7, armv7s, & simulator
#
# make -f Makefile.iphone
# sed -i tmp "s|ARCH_PHONE =.*|ARCH_PHONE = armv7s|" Makefile.iphone
# make -f Makefile.iphone
# sed -i tmp "s|ARCH_PHONE =.*|ARCH_PHONE = armv6|" Makefile.iphone
# make -f Makefile.iphone
# lipo -c libfreeimage-simulator.a libfreeimage-armv6.a libfreeimage-armv7.a libfreeimage-armv7s.a -o libfreeimage.a
#
include Makefile.srcs
# Update these based on your installed SDKs
IPHONEOS_SDK = 6.1
IPHONEOS_MIN_SDK = 5.1
MACOSX_SDK = 10.8
MACOSX_MIN_SDK = 10.6
# Build architectures
ARCH_SIM = i386
ARCH_PHONE = armv7
# General configuration variables:
CFLAGS = -g -O2 -Wall -Wmissing-prototypes -std=c99 -ffast-math -fno-strict-aliasing
CXXFLAGS = -g -O2 -Wall -fno-strict-aliasing
PLATFORM_SIM = iPhoneSimulator
PLATFORM_PHONE = iPhoneOS
PLATFORM_SIM_DEVELOPER_BIN_DIR = $(shell xcode-select -print-path)/Platforms/$(PLATFORM_SIM).platform/Developer/usr/bin
PLATFORM_PHONE_DEVELOPER_BIN_DIR = $(shell xcode-select -print-path)/Platforms/$(PLATFORM_PHONE).platform/Developer/usr/bin
SDKROOT_SIM = $(shell xcode-select -print-path)/Platforms/$(PLATFORM_SIM).platform/Developer/SDKs/$(PLATFORM_SIM)$(IPHONEOS_SDK).sdk
SDKROOT_PHONE = $(shell xcode-select -print-path)/Platforms/$(PLATFORM_PHONE).platform/Developer/SDKs/$(PLATFORM_PHONE)$(IPHONEOS_SDK).sdk
EXTRA_CFLAGS_SIM += -pipe -mdynamic-no-pic -fvisibility=hidden $(INCLUDE) -isysroot $(SDKROOT_SIM)
EXTRA_LDFLAGS_SIM += -isysroot $(SDKROOT_SIM) -Wl,-dead_strip
EXTRA_CFLAGS_SIM += -D__IPHONE_OS_VERSION_MIN_REQUIRED=50000 -mmacosx-version-min=$(MACOSX_MIN_SDK)
EXTRA_LDFLAGS_SIM += -mmacosx-version-min=$(MACOSX_MIN_SDK)
EXTRA_CFLAGS_PHONE += -pipe -mdynamic-no-pic -fvisibility=hidden $(INCLUDE) -isysroot $(SDKROOT_PHONE)
EXTRA_LDFLAGS_PHONE += -isysroot $(SDKROOT_PHONE) -Wl,-dead_strip
EXTRA_CFLAGS_PHONE += -miphoneos-version-min=$(IPHONEOS_MIN_SDK)
EXTRA_LDFLAGS_PHONE += -miphoneos-version-min=$(IPHONEOS_MIN_SDK)
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
CC_PHONE = $(PLATFORM_PHONE_DEVELOPER_BIN_DIR)/llvm-gcc
CFLAGS_SIM = $(CFLAGS) $(EXTRA_CFLAGS_SIM)
LDFLAGS_SIM = $(EXTRA_LDFLAGS_SIM)
CXX_SIM = $(PLATFORM_SIM_DEVELOPER_BIN_DIR)/llvm-g++
CXXFLAGS_SIM += $(EXTRA_CFLAGS_SIM) -fvisibility-inlines-hidden
LIBTOOL_SIM = $(shell xcode-select -print-path)/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++
CXXFLAGS_PHONE += $(EXTRA_CFLAGS_PHONE) -fvisibility-inlines-hidden
LIBTOOL_PHONE = $(shell xcode-select -print-path)/Platforms/$(PLATFORM_PHONE).platform/Developer/usr/bin/libtool
TARGET = freeimage
STATICLIB_SIM = lib$(TARGET)-simulator.a
STATICLIB_PHONE = lib$(TARGET)-$(ARCH_PHONE).a
HEADER = Source/FreeImage.h
.SUFFIXES: .o-simulator .o-$(ARCH_PHONE)
MODULES_PHONE = $(SRCS:.c=.o-$(ARCH_PHONE))
MODULES_PHONE := $(MODULES_PHONE:.cpp=.o-$(ARCH_PHONE))
MODULES_SIM = $(SRCS:.c=.o-simulator)
MODULES_SIM := $(MODULES_SIM:.cpp=.o-simulator)
default: all
all: dist
dist: FreeImage
cp *.a Dist
cp Source/FreeImage.h Dist
FreeImage: $(STATICLIB_SIM) $(STATICLIB_PHONE)
$(STATICLIB_SIM): $(MODULES_SIM)
$(LIBTOOL_SIM) -arch_only $(ARCH_SIM) -o $@ $(MODULES_SIM)
.c.o-simulator:
$(CC_SIM) -arch $(ARCH_SIM) $(CFLAGS_SIM) -c $< -o $@
.cpp.o-simulator:
$(CXX_SIM) -arch $(ARCH_SIM) $(CXXFLAGS_SIM) -c $< -o $@
$(STATICLIB_PHONE): $(MODULES_PHONE)
$(LIBTOOL_PHONE) -arch_only $(ARCH_PHONE) -o $@ $(MODULES_PHONE)
.c.o-$(ARCH_PHONE):
$(CC_PHONE) -arch $(ARCH_PHONE) $(CFLAGS_PHONE) -c $< -o $@
.cpp.o-$(ARCH_PHONE):
$(CXX_PHONE) -arch $(ARCH_PHONE) $(CXXFLAGS_PHONE) -c $< -o $@
clean:
rm -f core Dist/*.* u2dtmp* $(MODULES_SIM) $(MODULES_PHONE) $(STATICLIB_SIM) $(STATICLIB_PHONE)
@LZHHHTBNO
Copy link

i have a problem ,my Xcode version is 5.1.1, OSX is 10.9,how to modify makefile to compiler freeimage.
thank you very much. could you help me?

@ObjSal
Copy link

ObjSal commented Mar 9, 2017

I have forked this gist and fixed it for Xcode 7.3 at https://gist.github.com/ObjSal/46247c4b20f4d23494974816112d10e8

Hope it helps!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment