Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
FreeImage Makefile for Mac OSX updated to build 32/64 bit fat libs, tested with OSX 10.8 & XCode 4.6
# Configuration for Max OSX, builds fat 32/64 bit static & dynamic libs
include Makefile.srcs
# Update this based on your installed SDKs
MACOSX_SDK = 10.8
MACOSX_MIN_SDK = 10.6
# Find SDK path via xcode-select, backwards compatible with Xcode vers < 4.5
MACOSX_SYSROOT = $(shell xcode-select -print-path)/Platforms/MacOSX.platform/Developer/SDKs/MacOSX$(MACOSX_SDK).sdk
# General configuration variables:
CC_I386 = llvm-gcc
CC_X86_64 = llvm-gcc
CPP_I386 = llvm-g++
CPP_X86_64 = llvm-g++
COMPILERFLAGS = -Os -fexceptions -fvisibility=hidden -DNO_LCMS -mmacosx-version-min=$(MACOSX_MIN_SDK)
COMPILERFLAGS_I386 = -arch i386
COMPILERFLAGS_X86_64 = -arch x86_64
COMPILERPPFLAGS = -Wno-ctor-dtor-privacy
INCLUDE +=
INCLUDE_I386 = -isysroot $(MACOSX_SYSROOT)
INCLUDE_X86_64 = -isysroot $(MACOSX_SYSROOT)
CFLAGS_I386 = $(COMPILERFLAGS) $(COMPILERFLAGS_I386) $(INCLUDE) $(INCLUDE_I386)
CFLAGS_X86_64 = $(COMPILERFLAGS) $(COMPILERFLAGS_X86_64) $(INCLUDE) $(INCLUDE_X86_64)
CPPFLAGS_I386 = $(COMPILERPPFLAGS) $(CFLAGS_I386)
CPPFLAGS_X86_64 = $(COMPILERPPFLAGS) $(CFLAGS_X86_64)
LIBRARIES_I386 = -Wl,-syslibroot $(MACOSX_SYSROOT) -mmacosx-version-min=$(MACOSX_MIN_SDK)
LIBRARIES_X86_64 = -Wl,-syslibroot $(MACOSX_SYSROOT) -mmacosx-version-min=$(MACOSX_MIN_SDK)
LIBTOOL = libtool
LIPO = lipo
TARGET = freeimage
STATICLIB = lib$(TARGET).a
SHAREDLIB = lib$(TARGET)-$(VER_MAJOR).$(VER_MINOR).dylib
LIBNAME = lib$(TARGET).$(VER_MAJOR).dylib
HEADER = Source/FreeImage.h
.SUFFIXES: .o-i386 .o-x86_64
MODULES_I386 = $(SRCS:.c=.o-i386)
MODULES_X86_64 = $(SRCS:.c=.o-x86_64)
MODULES_I386 := $(MODULES_I386:.cpp=.o-i386)
MODULES_X86_64 := $(MODULES_X86_64:.cpp=.o-x86_64)
PREFIX = /usr/local
INSTALLDIR = $(PREFIX)/lib
INCDIR = $(PREFIX)/include
default: all
all: dist
dist: FreeImage
cp *.a Dist
cp *.dylib Dist
cp Source/FreeImage.h Dist
FreeImage: $(STATICLIB) $(SHAREDLIB)
$(STATICLIB): $(STATICLIB)-i386 $(STATICLIB)-x86_64
$(LIPO) -create $(STATICLIB)-i386 $(STATICLIB)-x86_64 -output $(STATICLIB)
$(STATICLIB)-i386: $(MODULES_I386)
$(LIBTOOL) -arch_only i386 -o $@ $(MODULES_I386)
$(STATICLIB)-x86_64: $(MODULES_X86_64)
$(LIBTOOL) -arch_only x86_64 -o $@ $(MODULES_X86_64)
$(SHAREDLIB): $(SHAREDLIB)-i386 $(SHAREDLIB)-x86_64
$(LIPO) -create $(SHAREDLIB)-i386 $(SHAREDLIB)-x86_64 -output $(SHAREDLIB)
$(SHAREDLIB)-i386: $(MODULES_I386)
$(CPP_I386) -arch i386 -dynamiclib $(LIBRARIES_I386) -o $@ $(MODULES_I386)
$(SHAREDLIB)-x86_64: $(MODULES_X86_64)
$(CPP_X86_64) -arch x86_64 -dynamiclib $(LIBRARIES_X86_64) -o $@ $(MODULES_X86_64)
.c.o-i386:
$(CC_I386) $(CFLAGS_I386) -c $< -o $@
.c.o-x86_64:
$(CC_X86_64) $(CFLAGS_X86_64) -c $< -o $@
.cpp.o-i386:
$(CPP_I386) $(CPPFLAGS_I386) -c $< -o $@
.cpp.o-x86_64:
$(CPP_X86_64) $(CPPFLAGS_X86_64) -c $< -o $@
install:
install -d -m 755 -o root -g wheel $(INCDIR) $(INSTALLDIR)
install -m 644 -o root -g wheel $(HEADER) $(INCDIR)
install -m 644 -o root -g wheel $(SHAREDLIB) $(STATICLIB) $(INSTALLDIR)
ranlib -sf $(INSTALLDIR)/$(STATICLIB)
ln -sf $(SHAREDLIB) $(INSTALLDIR)/$(LIBNAME)
clean:
rm -f core Dist/*.* u2dtmp* $(MODULES_I386) $(MODULES_X86_64) $(STATICLIB) $(STATICLIB)-i386 $(SHAREDLIB) $(SHAREDLIB)-i386 $(SHAREDLIB)-x86_64
@nieder

This comment has been minimized.

Copy link

@nieder nieder commented Apr 6, 2014

This gets you the actual SDK path without making any assumptions about the structure inside the Xcode.app folder. Works with Xcode 4.6+. Also works with Xcode 3.2.6. Might work work with earlier Xcode 4 releases, but untested.

xcodebuild -version -sdk macosx$(MACOSX_SDK) Path
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment