Skip to content

Instantly share code, notes, and snippets.

@ObjSal
Forked from danomatika/Makefile.iphone
Last active May 22, 2019 19:42
Show Gist options
  • Save ObjSal/46247c4b20f4d23494974816112d10e8 to your computer and use it in GitHub Desktop.
Save ObjSal/46247c4b20f4d23494974816112d10e8 to your computer and use it in GitHub Desktop.
FreeImage Makefile for iOS updated for XCode 7.3, tested with macOS 10.11.6 & XCode 7.3
#!/bin/sh
#
# Makefile.iphone builds armv7 and simulator by default
#
# Build armv7
make -f Makefile.iphone
# Build armv7s
sed "s|ARCH_PHONE =.*|ARCH_PHONE = armv7s|" Makefile.iphone > Makefile.iphone.armv7s
make -f Makefile.iphone.armv7s
# Build arm64
sed "s|ARCH_PHONE =.*|ARCH_PHONE = arm64|" Makefile.iphone > Makefile.iphone.arm64
make -f Makefile.iphone.arm64
pushd Dist
lipo -c libfreeimage-arm64.a libfreeimage-armv7.a libfreeimage-armv7s.a libfreeimage-simulator.a -o libfreeimage.a
popd
# Configuration for iPhone OS, making static libs
# this will generate both iPhone (arm) and iPhoneSimulator (i386) libs
include Makefile.srcs
CFLAGS = -std=c99 -g -O2 -Wall -Wmissing-prototypes -ffast-math -fno-strict-aliasing -D__ANSI__ -emit-llvm -Wno-c++11-narrowing -Wno-implicit-function-declaration
CXXFLAGS = -std=gnu++14 -stdlib=libc++ -D__ANSI__ -emit-llvm -Wno-c++11-narrowing -Wno-implicit-function-declaration -fvisibility-inlines-hidden
IPHONEOS_DEPLOYMENT_TARGET = 9.3
MACOSX_DEPLOYMENT_TARGET = 10.7
PLATFORM_SIM = iPhoneSimulator
PLATFORM_PHONE = iPhoneOS
ARCH_SIM = i386
ARCH_PHONE = armv7
PLATFORM_DEVELOPER_BIN_DIR = $(shell xcode-select -print-path)/Toolchains/XcodeDefault.xctoolchain/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 += -arch $(ARCH_SIM) -pipe -mdynamic-no-pic -fvisibility=hidden $(INCLUDE) -isysroot $(SDKROOT_SIM)
EXTRA_CFLAGS_SIM += -D__IPHONE_OS_VERSION_MIN_REQUIRED=20000 -mmacosx-version-min=$(MACOSX_DEPLOYMENT_TARGET)
# Xcode complains about the -mdynamic-no-pic with an Apple Mach-O Linker Warning, so removed
EXTRA_CFLAGS_PHONE += -arch $(ARCH_PHONE) -pipe -fvisibility=hidden $(INCLUDE) -isysroot $(SDKROOT_PHONE)
EXTRA_CFLAGS_PHONE += -miphoneos-version-min=$(IPHONEOS_DEPLOYMENT_TARGET)
CC = $(PLATFORM_DEVELOPER_BIN_DIR)/clang
CXX = $(PLATFORM_DEVELOPER_BIN_DIR)/clang++
LIBTOOL = $(PLATFORM_DEVELOPER_BIN_DIR)/libtool
CFLAGS_SIM = $(CFLAGS) $(EXTRA_CFLAGS_SIM)
CXXFLAGS_SIM += $(EXTRA_CFLAGS_SIM) $(CXXFLAGS)
CFLAGS_PHONE = $(CFLAGS) $(EXTRA_CFLAGS_PHONE)
CXXFLAGS_PHONE += $(EXTRA_CFLAGS_PHONE) $(CXXFLAGS)
TARGET = freeimage
STATICLIB_SIM = lib$(TARGET)-simulator.a
STATICLIB_PHONE = lib$(TARGET)-$(ARCH_PHONE).a
HEADER = Source/FreeImage.h
.SUFFIXES: .o-$(ARCH_SIM) .o-$(ARCH_PHONE)
MODULES_ARM = $(SRCS:.c=.o-$(ARCH_PHONE))
MODULES_ARM := $(MODULES_ARM:.cpp=.o-$(ARCH_PHONE))
MODULES_SIM = $(SRCS:.c=.o-$(ARCH_SIM))
MODULES_SIM := $(MODULES_SIM:.cpp=.o-$(ARCH_SIM))
default: all
all: dist
dist: FreeImage
mkdir -p Dist
cp *.a Dist/
cp Source/FreeImage.h Dist/
FreeImage: $(STATICLIB_SIM) $(STATICLIB_PHONE)
$(STATICLIB_SIM): $(MODULES_SIM)
$(LIBTOOL) -arch_only $(ARCH_SIM) -o $@ $(MODULES_SIM)
.c.o-$(ARCH_SIM):
$(CC) $(CFLAGS_SIM) -c $< -o $@
.cpp.o-$(ARCH_SIM):
$(CXX) $(CXXFLAGS_SIM) -c $< -o $@
$(STATICLIB_PHONE): $(MODULES_ARM)
$(LIBTOOL) -arch_only $(ARCH_PHONE) -o $@ $(MODULES_ARM)
.c.o-$(ARCH_PHONE):
$(CC) $(CFLAGS_PHONE) -c $< -o $@
.cpp.o-$(ARCH_PHONE):
$(CXX) $(CXXFLAGS_PHONE) -c $< -o $@
clean:
rm -f core Dist/*.* u2dtmp* $(MODULES_SIM) $(MODULES_ARM) $(STATICLIB_SIM) $(STATICLIB_PHONE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment