# -*- Makefile -*-
# Mac OSX makefile for FreeImage

# This file can be generated by ./gensrclist.sh
include Makefile.srcs

# Update this based on your installed SDKs
MACOSX_SDK=$(shell xcrun -sdk macosx --show-sdk-version)
MACOSX_MIN_SDK = 10.7

# 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_X86_64 = $(shell xcrun -find clang)
CPP_X86_64 = $(shell xcrun -find clang++)

COMPILERFLAGS = -arch x86_64 -arch i386 -Wno-ctor-dtor-privacy -stdlib=libc++ -Wc++11-narrowing -Os -fexceptions -fvisibility=hidden -DNO_LCMS -fPIC -DNDEBUG -D__ANSI__ -DDISABLE_PERF_MEASUREMENT -mmacosx-version-min=$(MACOSX_MIN_SDK)

INCLUDE_X86_64 = -isysroot $(MACOSX_SYSROOT)
CFLAGS_X86_64 = $(COMPILERFLAGS) $(INCLUDE) $(INCLUDE_X86_64)

CPPFLAGS_X86_64 = $(CFLAGS_X86_64)
LIBRARIES_X86_64 = -Wl,-syslibroot $(MACOSX_SYSROOT) -mmacosx-version-min=$(MACOSX_MIN_SDK)

LIBTOOL = libtool
LIPO = lipo

TARGET = freeimage
STATICLIB = lib$(TARGET).a

HEADER = Source/FreeImage.h

.SUFFIXES: .o-x86_64
MODULES_X86_64 = $(SRCS:.c=.o-x86_64)
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
	mkdir -p Dist
	cp *.a Dist/
	cp Source/FreeImage.h Dist/

FreeImage: $(STATICLIB) 

$(STATICLIB): $(MODULES_X86_64)
	$(LIBTOOL) -o $@ $(MODULES_X86_64)

.c.o-x86_64:
	$(CC_X86_64) $(CFLAGS_X86_64) -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 $(STATICLIB) $(INSTALLDIR)
	ranlib -sf $(INSTALLDIR)/$(STATICLIB)

clean:
	rm -f core Dist/*.* u2dtmp* $(MODULES_X86_64) $(STATICLIB)

