Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Add Xcode-iPhoneOS/rakefile which can be used to build SDL.framework …

…from the commandline

This is the rakefile from Andrey Nesterov, but slightly modified.
Use the following command:
  $ rake -f Xcode-iPhoneOS/rakefile
The resulting framework is placed in the ./build directory.
  • Loading branch information
keestux committed Sep 27, 2011
1 parent f98d6e7 commit 6c30f329df00719a57d4f6c110593cc5e5ee8460
Showing with 219 additions and 0 deletions.
  1. +219 −0 Xcode-iPhoneOS/rakefile
@@ -0,0 +1,219 @@
# ------------------------------------------------------------------------------
# Builds a SDL framework for the iOS
# Copyright (c) 2011 Andrey Nesterov
# See LICENSE for licensing information
# ------------------------------------------------------------------------------
#
# Creates a pseudo-framework which contains a universal library that can be used
# on a iOS and in the iOS simulator
#
# ------------------------------------------------------------------------------
#
# To configure the script, define:
# Conf configuration, symbol (:release or :debug)
# SDK version number of the iOS SDK, symbol (e.g. :"4.3")
# Arch architecture for the device's library, symbol (e.g. :armv6 or :armv7)
#
# ------------------------------------------------------------------------------

# --- Configure ----------------------------------------------------------------
module Configure
Conf = :release
SDK = :"4.3"
Arch = :armv7
end

# --- Constants ----------------------------------------------------------------
module Global
RootDir = Dir.pwd
SourceDir = "#{RootDir}"
BuildDir = "#{RootDir}/build"
end

# --- Common -------------------------------------------------------------------
module Builder
def get_sources(from, to)
refresh_dir to
yield from, to
end

def build_library(project, dest, target, conf, sdk, arch)
print "\n"
dest = library_bundle_path(dest, conf, sdk, arch)
sdk, arch = compute_platform(sdk, arch)
conf = configuration(conf)

refresh_dir dest
refresh_dir "#{dest}.build"

proj_dir, proj_fname = File.split project
cd proj_dir
args = Array.new()
args.push("xcodebuild")
args.push("-project #{proj_fname}")
args.push("-sdk #{sdk}")
args.push("-configuration \"#{conf}\"")
args.push("-target \"#{target}\"")
# NATIVE_ARCH has no effect
#args.push("NATIVE_ARCH=#{arch.to_str}")
args.push("-arch #{arch.to_str}")
args.push("TARGETED_DEVICE_FAMILY=2") # 2 => iPad, 1 => iPhone
args.push("BUILT_PRODUCTS_DIR=\"build\"")
args.push("CONFIGURATION_BUILD_DIR=\"#{dest}\"")
args.push("CONFIGURATION_TEMP_DIR=\"#{dest}.build\"")
cmd = args.join(' ')
#print "\n"
print "#{cmd}\n"
`#{cmd}`
end

def build_framework_library(frameworkLib, deviceLib, simulatorLib)
print "\n"
refresh_dir File.dirname frameworkLib
cmd = "lipo -create #{deviceLib} #{simulatorLib} -o #{frameworkLib}"
print "#{cmd}\n"
`#{cmd}`
end

def build_framework(name, version, identifier, dest, headers, project, target, conf, sdk, arch)
libFileName = "lib#{name}.a";
libFilePath = "#{dest}/universal-#{conf}/#{libFileName}"

build_library(project, dest, target, conf, sdk, arch);
build_library(project, dest, target, conf, sdk, :i386);

build_framework_library(
libFilePath,
"#{library_bundle_path(dest, conf, sdk, arch)}/#{libFileName}",
"#{library_bundle_path(dest, conf, sdk, :i386)}/#{libFileName}"
)
# Static library has version A
create_framework(name, "A", identifier, dest, headers, libFilePath)
end

def create_framework(name, version, identifier, dest, headers, lib)
print "\n"
frameworkVersion = version
frameworkBundle = framework_bundle_path(dest, name)

# creating framework's directories
refresh_dir frameworkBundle
mkdir "#{frameworkBundle}/Versions"
mkdir "#{frameworkBundle}/Versions/#{frameworkVersion}"
mkdir "#{frameworkBundle}/Versions/#{frameworkVersion}/Resources"
mkdir "#{frameworkBundle}/Versions/#{frameworkVersion}/Headers"
mkdir "#{frameworkBundle}/Versions/#{frameworkVersion}/Documentation"

# creating framework's symlinks
`ln -s "#{frameworkVersion}" "#{frameworkBundle}/Versions/Current"`
`ln -s "Versions/Current/Headers" "#{frameworkBundle}/Headers"`
`ln -s "Versions/Current/Resources" "#{frameworkBundle}/Resources"`
`ln -s "Versions/Current/Documentation" "#{frameworkBundle}/Documentation"`
`ln -s "Versions/Current/#{File.basename lib}" "#{frameworkBundle}/#{name}"`

# copying lib
cp lib, "#{frameworkBundle}/Versions/#{frameworkVersion}"

# copying the header files. Copy everything found in the headers directory.
FileList["#{headers}/*.h"].each do |source|
cp source, "#{frameworkBundle}/Headers"
end

# creating plist
File.open("#{frameworkBundle}/Resources/Info.plist", "w") do |f|
f.puts '<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">'
f.puts "\
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>#{name}</string>
<key>CFBundleIdentifier</key>
<string>#{identifier}</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>#{version}</string>
</dict>
</plist>"
end
end

def library_bundle_path(path, conf, sdk, arch)
sdk, arch = compute_platform(sdk, arch)
"#{path}/#{sdk}-#{conf}"
end

def framework_bundle_path(path, name)
"#{path}/#{name}.framework"
end

def configuration(conf)
conf.to_s
end

def compute_platform(sdk, arch)
return [sdk, arch] if arch.class == String
[arch == :i386 ? "iphonesimulator" + sdk.to_s : "iphoneos" + sdk.to_s, arch.to_s]
end

def refresh_dir(path)
rm_rf path if FileTest.exists? path
mkdir_p path
end

private :configuration, :compute_platform, :refresh_dir
end

class InstanceBuilder
class Instance
extend Builder
end

def InstanceBuilder.message(text)
tailSize = 75 - text.length;
puts "--- #{text} #{'-' * (tailSize < 0 ? 0 : tailSize)}"
end
end

# --- SDL ----------------------------------------------------------------------
class SDL < InstanceBuilder
SourceDir = "#{Global::SourceDir}"
BuildDir = "#{Global::BuildDir}"

def SDL.build_framework(conf, sdk, arch)
message "Building SDL"
Instance.build_framework(
"SDL",
"1.3",
"org.libsdl",
BuildDir,
"#{SourceDir}/include",
"#{SourceDir}/Xcode-iPhoneOS/SDL/SDLiPhoneOS.xcodeproj",
"libSDL",
conf,
sdk,
arch
)
end

def Instance.configuration(conf)
case conf
when :release
"Release"
when :debug
"Debug"
end
end
end

# --- Tasks --------------------------------------------------------------------
task :default do
SDL.build_framework Configure::Conf, Configure::SDK, Configure::Arch
end

0 comments on commit 6c30f32

Please sign in to comment.