Skip to content

Instantly share code, notes, and snippets.

@dan
Created September 18, 2009 15:13
Show Gist options
  • Save dan/189101 to your computer and use it in GitHub Desktop.
Save dan/189101 to your computer and use it in GitHub Desktop.
Makefile for building FreeImage on OS X
# -*- Makefile -*-
# Mac OSX makefile for FreeImage
# This file can be generated by ./gensrclist.sh
include Makefile.srcs
# General configuration variables:
CC_X86_64 = gcc-4.2
CC_I386 = gcc-4.2
CPP_X86_64 = g++-4.2
CPP_I386 = g++-4.2
COMPILERFLAGS = -Os -fexceptions -fvisibility=hidden
COMPILERFLAGS_X86_64 = -arch x86_64
COMPILERFLAGS_I386 = -arch i386
COMPILERPPFLAGS = -Wno-ctor-dtor-privacy
INCLUDE +=
INCLUDE_X86_64 = -isysroot /Developer/SDKs/MacOSX10.6.sdk
INCLUDE_I386 = -isysroot /Developer/SDKs/MacOSX10.6.sdk
CFLAGS_X86_64 = $(COMPILERFLAGS) $(COMPILERFLAGS_X86_64) $(INCLUDE) $(INCLUDE_X86_64)
CFLAGS_I386 = $(COMPILERFLAGS) $(COMPILERFLAGS_I386) $(INCLUDE) $(INCLUDE_I386)
CPPFLAGS_X86_64 = $(COMPILERPPFLAGS) $(CFLAGS_X86_64)
CPPFLAGS_I386 = $(COMPILERPPFLAGS) $(CFLAGS_I386)
LIBRARIES_X86_64 = -Wl,-syslibroot /Developer/SDKs/MacOSX10.6.sdk
LIBRARIES_I386 = -Wl,-syslibroot /Developer/SDKs/MacOSX10.6.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-x86_64 .o-i386
MODULES_X86_64 = $(SRCS:.c=.o-x86_64)
MODULES_I386 = $(SRCS:.c=.o-i386)
MODULES_X86_64 := $(MODULES_X86_64:.cpp=.o-x86_64)
MODULES_I386 := $(MODULES_I386:.cpp=.o-i386)
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)-x86_64 $(STATICLIB)-i386
$(LIPO) -create $(STATICLIB)-x86_64 $(STATICLIB)-i386 -output $(STATICLIB)
$(STATICLIB)-x86_64: $(MODULES_X86_64)
$(LIBTOOL) -arch_only x86_64 -o $@ $(MODULES_X86_64)
$(STATICLIB)-i386: $(MODULES_I386)
$(LIBTOOL) -arch_only i386 -o $@ $(MODULES_I386)
$(SHAREDLIB): $(SHAREDLIB)-x86_64 $(SHAREDLIB)-i386
$(LIPO) -create $(SHAREDLIB)-x86_64 $(SHAREDLIB)-i386 -output $(SHAREDLIB)
$(SHAREDLIB)-x86_64: $(MODULES_X86_64)
$(CPP_X86_64) -arch x86_64 -dynamiclib $(LIBRARIES_X86_64) -o $@ $(MODULES_X86_64)
$(SHAREDLIB)-i386: $(MODULES_I386)
$(CPP_I386) -arch i386 -dynamiclib $(LIBRARIES_I386) -o $@ $(MODULES_I386)
.c.o-x86_64:
$(CC_X86_64) $(CFLAGS_X86_64) -c $< -o $@
.c.o-i386:
$(CC_I386) $(CFLAGS_I386) -c $< -o $@
.cpp.o-x86_64:
$(CPP_X86_64) $(CPPFLAGS_X86_64) -c $< -o $@
.cpp.o-i386:
$(CPP_I386) $(CPPFLAGS_I386) -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_X86_64) $(MODULES_I386) $(STATICLIB) $(STATICLIB)-x86_64 $(STATICLIB)-i386 $(SHAREDLIB) $(SHAREDLIB)-x86_64 $(SHAREDLIB)-i386
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment