toolchain: more work on all recipe + factorize include files installation
This commit is contained in:
parent
702d572fd5
commit
309a003036
6 changed files with 129 additions and 27 deletions
30
recipes/freetype/__init__.py
Normal file
30
recipes/freetype/__init__.py
Normal file
|
@ -0,0 +1,30 @@
|
|||
from toolchain import Recipe, shprint
|
||||
from os.path import join, exists
|
||||
import sh
|
||||
import shutil
|
||||
|
||||
|
||||
class FreetypeRecipe(Recipe):
|
||||
version = "2.5.5"
|
||||
url = "http://download.savannah.gnu.org/releases/freetype/freetype-{version}.tar.bz2"
|
||||
library = "objs/.libs/libfreetype.a"
|
||||
include_dir = "include"
|
||||
|
||||
def build_arch(self, arch):
|
||||
build_env = arch.get_env()
|
||||
configure = sh.Command(join(self.build_dir, "configure"))
|
||||
shprint(configure,
|
||||
"CC={}".format(build_env["CC"]),
|
||||
"LD={}".format(build_env["LD"]),
|
||||
"CFLAGS={}".format(build_env["CFLAGS"]),
|
||||
"LDFLAGS={}".format(build_env["LDFLAGS"]),
|
||||
"--prefix=/",
|
||||
"--host={}".format(arch.triple),
|
||||
"--enable-static=yes",
|
||||
"--enable-shared=no")
|
||||
shprint(sh.make, "clean")
|
||||
shprint(sh.make)
|
||||
|
||||
|
||||
recipe = FreetypeRecipe()
|
||||
|
|
@ -8,6 +8,8 @@ class LibffiRecipe(Recipe):
|
|||
version = "3.2.1"
|
||||
url = "ftp://sourceware.org/pub/libffi/libffi-{version}.tar.gz"
|
||||
library = "build/Release-{arch.sdk}/libffi.a"
|
||||
include_per_arch = True
|
||||
include_dir = "build_{arch.sdk}-{arch.arch}/include"
|
||||
|
||||
def prebuild_arch(self, arch):
|
||||
if self.has_marker("patched"):
|
||||
|
@ -29,20 +31,6 @@ class LibffiRecipe(Recipe):
|
|||
"-target", "libffi-iOS",
|
||||
"-configuration", "Release")
|
||||
|
||||
def install(self):
|
||||
for sdkarch, arch in (
|
||||
("iphoneos-arm64", "arm64"),
|
||||
("iphoneos-armv7", "armv7"),
|
||||
("iphonesimulator-i386", "i386"),
|
||||
("iphonesimulator-x86_64", "x86_64")):
|
||||
dest_dir = join(self.ctx.dist_dir, "include", arch)
|
||||
if exists(dest_dir):
|
||||
continue
|
||||
shutil.copytree(join(
|
||||
self.get_build_dir(arch),
|
||||
"build_{}/include".format(sdkarch)),
|
||||
dest_dir)
|
||||
|
||||
|
||||
recipe = LibffiRecipe()
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ class LibSDL2Recipe(Recipe):
|
|||
version = "2.0.3"
|
||||
url = "https://www.libsdl.org/release/SDL2-{version}.tar.gz"
|
||||
library = "Xcode-iOS/SDL/build/Release-{arch.sdk}/libSDL2.a"
|
||||
include_dir = "include"
|
||||
|
||||
def build_arch(self, arch):
|
||||
shprint(sh.xcodebuild,
|
||||
|
@ -19,14 +20,6 @@ class LibSDL2Recipe(Recipe):
|
|||
"-target", "libSDL",
|
||||
"-configuration", "Release")
|
||||
|
||||
def install(self):
|
||||
for arch in self.filtered_archs:
|
||||
dest_dir = join(self.ctx.include_dir, "common", "SDL2")
|
||||
if exists(dest_dir):
|
||||
shutil.rmtree(dest_dir)
|
||||
shutil.copytree(
|
||||
join(self.get_build_dir(arch.arch), "include"),
|
||||
dest_dir)
|
||||
|
||||
recipe = LibSDL2Recipe()
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ class LibSDL2ImageRecipe(Recipe):
|
|||
version = "2.0.0"
|
||||
url = "https://www.libsdl.org/projects/SDL_image/release/SDL2_image-{version}.tar.gz"
|
||||
library = "Xcode-iOS/build/Release-{arch.sdk}/libSDL2_image.a"
|
||||
include_dir = "SDL_image.h"
|
||||
depends = ["sdl2"]
|
||||
|
||||
def build_arch(self, arch):
|
||||
|
|
35
recipes/sdl2_ttf/__init__.py
Normal file
35
recipes/sdl2_ttf/__init__.py
Normal file
|
@ -0,0 +1,35 @@
|
|||
from toolchain import Recipe, shprint
|
||||
from os.path import join
|
||||
import sh
|
||||
import shutil
|
||||
|
||||
|
||||
class LibSDL2TTFRecipe(Recipe):
|
||||
version = "2.0.12"
|
||||
url = "https://www.libsdl.org/projects/SDL_ttf/release/SDL2_ttf-{version}.tar.gz"
|
||||
library = "Xcode-iOS/build/Release-{arch.sdk}/libSDL2_ttf.a"
|
||||
include_dir = "SDL_ttf.h"
|
||||
depends = ["sdl2", "freetype"]
|
||||
|
||||
def build_arch(self, arch):
|
||||
build_env = arch.get_env()
|
||||
shprint(sh.xcodebuild,
|
||||
"ONLY_ACTIVE_ARCH=NO",
|
||||
"ARCHS={}".format(arch.arch),
|
||||
"HEADER_SEARCH_PATHS={}".format(
|
||||
join(self.ctx.include_dir, "common", "SDL2")),
|
||||
"OTHER_CFLAGS={}".format(build_env["OTHER_CFLAGS"]),
|
||||
"OTHER_LDFLAGS={}".format(build_env["OTHER_LDFLAGS"]),
|
||||
"-sdk", arch.sdk,
|
||||
"-project", "Xcode-iOS/SDL_ttf.xcodeproj",
|
||||
"-target", "Static Library",
|
||||
"-configuration", "Release")
|
||||
|
||||
def install(self):
|
||||
for arch in self.filtered_archs:
|
||||
shutil.copy(
|
||||
join(self.get_build_dir(arch.arch), "SDL_ttf.h"),
|
||||
join(self.ctx.include_dir, "common", "SDL2"))
|
||||
|
||||
recipe = LibSDL2TTFRecipe()
|
||||
|
65
toolchain.py
65
toolchain.py
|
@ -43,19 +43,29 @@ class Arch(object):
|
|||
self.ctx = ctx
|
||||
|
||||
def get_env(self):
|
||||
include_dirs = [
|
||||
"-I{}/{}".format(
|
||||
self.ctx.include_dir,
|
||||
d.format(arch=self))
|
||||
for d in self.ctx.include_dirs]
|
||||
|
||||
env = {}
|
||||
env["CC"] = sh.xcrun("-find", "-sdk", self.sdk, "clang").strip()
|
||||
env["AR"] = sh.xcrun("-find", "-sdk", self.sdk, "ar").strip()
|
||||
env["LD"] = sh.xcrun("-find", "-sdk", self.sdk, "ld").strip()
|
||||
env["OTHER_CFLAGS"] = " ".join(include_dirs)
|
||||
env["OTHER_LDFLAGS"] = " ".join([
|
||||
"-L{}/{}".format(self.ctx.dist_dir, "lib"),
|
||||
])
|
||||
env["CFLAGS"] = " ".join([
|
||||
"-arch", self.arch,
|
||||
"-pipe", "-no-cpp-precomp",
|
||||
"--sysroot={}".format(self.sysroot),
|
||||
"-I{}/common".format(self.ctx.include_dir),
|
||||
"-I{}/{}".format(self.ctx.include_dir, self.arch),
|
||||
#"-I{}/common".format(self.ctx.include_dir),
|
||||
#"-I{}/{}".format(self.ctx.include_dir, self.arch),
|
||||
"-O3",
|
||||
self.version_min
|
||||
])
|
||||
] + include_dirs)
|
||||
env["LDFLAGS"] = " ".join([
|
||||
"-arch", self.arch,
|
||||
"--sysroot={}".format(self.sysroot),
|
||||
|
@ -158,6 +168,8 @@ class Context(object):
|
|||
|
||||
def __init__(self):
|
||||
super(Context, self).__init__()
|
||||
self.include_dirs = []
|
||||
|
||||
ok = True
|
||||
|
||||
sdks = sh.xcodebuild("-showsdks").splitlines()
|
||||
|
@ -245,6 +257,8 @@ class Recipe(object):
|
|||
archs = []
|
||||
depends = []
|
||||
library = None
|
||||
include_dir = None
|
||||
include_per_arch = False
|
||||
|
||||
# API available for recipes
|
||||
def download_file(self, url, filename, cwd=None):
|
||||
|
@ -347,6 +361,12 @@ class Recipe(object):
|
|||
except:
|
||||
pass
|
||||
|
||||
def get_include_dir(self):
|
||||
"""
|
||||
Return the common include dir for this recipe
|
||||
"""
|
||||
return join(self.ctx.include_dir, "common", self.name)
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
modname = self.__class__.__module__
|
||||
|
@ -373,6 +393,15 @@ class Recipe(object):
|
|||
|
||||
def init_with_ctx(self, ctx):
|
||||
self.ctx = ctx
|
||||
include_dir = None
|
||||
if self.include_dir:
|
||||
if self.include_per_arch:
|
||||
include_dir = join("{arch.arch}", self.name)
|
||||
else:
|
||||
include_dir = join("common", self.name)
|
||||
if include_dir:
|
||||
print("Include dir added: {}".format(include_dir))
|
||||
self.ctx.include_dirs.append(include_dir)
|
||||
|
||||
def execute(self):
|
||||
print("Download {}".format(self.name))
|
||||
|
@ -438,6 +467,8 @@ class Recipe(object):
|
|||
ensure_dir(dirname(static_fn))
|
||||
print("Lipo {} to {}".format(self.name, static_fn))
|
||||
self.make_lipo(static_fn)
|
||||
print("Install include files for {}".format(self.name))
|
||||
self.install_include()
|
||||
print("Install {}".format(self.name))
|
||||
self.install()
|
||||
|
||||
|
@ -467,6 +498,28 @@ class Recipe(object):
|
|||
join(self.get_build_dir(arch.arch), library)]
|
||||
shprint(sh.lipo, "-create", "-output", filename, *args)
|
||||
|
||||
def install_include(self):
|
||||
if not self.include_dir:
|
||||
return
|
||||
if self.include_per_arch:
|
||||
for arch in self.ctx.arch:
|
||||
build_dir = self.get_build_dir(arch.arch)
|
||||
include_dir = self.include_dir.format(arch=arch, ctx=self.ctx)
|
||||
src_dir = join(build_dir, include_dir)
|
||||
dest_dir = join(self.ctx.include_dir, arch.arch, self.name)
|
||||
if exists(dest_dir):
|
||||
shutil.rmtree(dest_dir)
|
||||
shutil.copytree(src_dir, dest_dir)
|
||||
else:
|
||||
arch = list(self.filtered_archs)[0]
|
||||
build_dir = self.get_build_dir(arch.arch)
|
||||
include_dir = self.include_dir.format(arch=arch, ctx=self.ctx)
|
||||
src_dir = join(build_dir, include_dir)
|
||||
dest_dir = join(self.ctx.include_dir, "common", self.name)
|
||||
if exists(dest_dir):
|
||||
shutil.rmtree(dest_dir)
|
||||
shutil.copytree(src_dir, dest_dir)
|
||||
|
||||
def install(self):
|
||||
pass
|
||||
|
||||
|
@ -511,11 +564,13 @@ def build_recipes(names, ctx):
|
|||
|
||||
build_order = list(graph.find_order())
|
||||
print("Build order is {}".format(build_order))
|
||||
for name in build_order:
|
||||
recipe = Recipe.get_recipe(name)
|
||||
recipes = [Recipe.get_recipe(name) for name in build_order]
|
||||
for recipe in recipes:
|
||||
recipe.init_with_ctx(ctx)
|
||||
for recipe in recipes:
|
||||
recipe.execute()
|
||||
|
||||
|
||||
def ensure_dir(filename):
|
||||
if not exists(filename):
|
||||
makedirs(filename)
|
||||
|
|
Loading…
Add table
Reference in a new issue