Skip to content

Commit 09c765d

Browse files
committed
Initial commit. Sort-of working.
0 parents  commit 09c765d

14 files changed

Lines changed: 531 additions & 0 deletions

‎.gitignore‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/working
2+
/install
3+
/package
4+
/package.tar

‎bzip2.mk‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
BZIP2_URL := http://www.bzip.org/1.0.6/bzip2-1.0.6.tar.gz
2+
BZIP2_TAR := $(call download,$(BZIP2_URL))
3+
BZIP2_EXTRACT := $(call extract,$(BZIP2_TAR))
4+
BZIP2 := $(INSTALL)/lib/libbz2.a
5+
6+
$(BZIP2): export CC = $(CROSS_CC)
7+
$(BZIP2): export PKG_CONFIG_LIBDIR = $(CROSS_PKG_CONFIG_LIBDIR)
8+
$(BZIP2): $(BZIP2_EXTRACT).extracted $(host-toolchain)
9+
$(MAKE) -C $(BZIP2_EXTRACT) -f Makefile-libbz2_so \
10+
CC=$(CROSS_CC) \
11+
AR=$(CROSS_AR) \
12+
RANLIB=$(CROSS_RANLIB)
13+
$(MAKE) -C $(BZIP2_EXTRACT) \
14+
CC=$(CROSS_CC) \
15+
AR=$(CROSS_AR) \
16+
RANLIB=$(CROSS_RANLIB) \
17+
libbz2.a
18+
cp -fd $(BZIP2_EXTRACT)/libbz2.a $(INSTALL)/lib/
19+
cp -fd $(BZIP2_EXTRACT)/libbz2.so* $(INSTALL)/lib/
20+
cp -fd $(BZIP2_EXTRACT)/bzlib.h $(INSTALL)/include
21+
22+
$(compile-host-1): $(BZIP2)

‎crossenv.mk‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
CROSSENV := $(WORKING)/crossenv
2+
CROSSENV_ACTIVATE := $(CROSSENV)/bin/activate
3+
ENV_CROSS_PYTHON := $(CROSSENV)/cross/bin/python
4+
ENV_CROSS_PIP := $(CROSSENV)/cross/bin/pip
5+
ENV_BUILD_PYTHON := $(CROSSENV)/build/bin/python
6+
ENV_BUILD_PIP := $(CROSSENV)/build/bin/pip
7+
ENV_CROSS_EXPOSE := $(CROSSENV)/bin/cross-expose
8+
9+
$(CROSSENV_ACTIVATE): $(build-python-interp) $(host-python-interp)
10+
#$(BUILD_PYTHON) -m pip install crossenv
11+
cd $(BUILD_PYTHON_INSTALL)/lib/python3.6/site-packages && ln -sf $(HOME)/crossenv/crossenv/crossenv crossenv
12+
PATH=$(COMPILE_HOST_PATH) \
13+
$(BUILD_PYTHON) -m crossenv \
14+
--sysroot=$(CROSS_SYSROOT) \
15+
--env=CPATH:=$(INSTALL)/include \
16+
--env=LIBRARY_PATH:=$(INSTALL)/lib \
17+
--env=PATH:=$(TOOLCHAIN_BIN) \
18+
--env=PKG_CONFIG_LIBDIR=$(CROSS_PKG_CONFIG_LIBDIR) \
19+
--clear \
20+
$(HOST_PYTHON) \
21+
$(CROSSENV)
22+
23+
$(crossenv): $(CROSSENV_ACTIVATE)

‎fixup.py‎

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Run with build-python
2+
3+
import subprocess
4+
import os
5+
import sys
6+
import stat
7+
import logging
8+
9+
logger = logging.getLogger(__name__)
10+
11+
def fixup_elf(path):
12+
dirname = os.path.dirname(path)
13+
rpath = os.path.relpath(LIBDIR, dirname)
14+
rpath = os.path.join('$ORIGIN', rpath)
15+
logger.info("Patching ELF %s RPATH=%s", path, rpath)
16+
subprocess.Popen([STRIP, path]).wait()
17+
subprocess.Popen(['patchelf', '--set-rpath', rpath, path]).wait()
18+
19+
def fixup_script(path):
20+
with open(path, 'rb') as fp:
21+
shebang = fp.readline()
22+
interp = shebang[2:].split(None,1)
23+
base = os.path.basename(interp[0])
24+
if interp[0] == b'/bin/sh':
25+
interp[0] = b'/system/bin/sh'
26+
elif base.startswith(b'python'):
27+
interp[0] = b'/system/bin/env ' + base
28+
else:
29+
return # no change
30+
remainder = fp.read()
31+
with open(path, 'wb') as fp:
32+
fp.write(b'#!' + b' '.join(interp) + b'\n')
33+
fp.write(remainder)
34+
logger.info("Patching script %s (interp=%s)", path, interp[0])
35+
36+
def fixup(path):
37+
with open(path, 'rb') as fp:
38+
magic = fp.read(4)
39+
if magic == b'\x7fELF':
40+
return fixup_elf(path)
41+
elif magic.startswith(b'#!'):
42+
return fixup_script(path)
43+
44+
def is_file(path):
45+
return stat.S_ISREG(os.lstat(path).st_mode)
46+
47+
def fix_all(install):
48+
for root, dirs, files in os.walk(install):
49+
for f in files:
50+
path = os.path.join(root, f)
51+
if is_file(path):
52+
fixup(path)
53+
54+
if __name__ == '__main__':
55+
if len(sys.argv) != 3:
56+
print("Usage: %s <install-dir> <strip>" % sys.argv[0])
57+
sys.exit(1)
58+
59+
logging.basicConfig(level=logging.INFO)
60+
INSTALL = sys.argv[1]
61+
LIBDIR = os.path.join(INSTALL, 'lib')
62+
STRIP = sys.argv[2]
63+
fix_all(INSTALL)

‎freetype.mk‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
FREETYPE_URL := https://downloads.sourceforge.net/project/freetype/freetype2/2.9/freetype-2.9.tar.bz2
2+
FREETYPE_TAR := $(call download,$(FREETYPE_URL))
3+
FREETYPE_EXTRACT := $(call extract,$(FREETYPE_TAR))
4+
FREETYPE := $(INSTALL)/lib/libfreetype.a
5+
6+
$(FREETYPE_EXTRACT)/config.mk: $(FREETYPE_EXTRACT).extracted $(host-toolchain) \
7+
$(compile-host-1)
8+
cd $(dir $@) \
9+
&& ./configure \
10+
--prefix=$(INSTALL) \
11+
--host=$(HOST) \
12+
--build=$(BUILD) \
13+
--with-png=no \
14+
CFLAGS="$(CROSS_CFLAGS)" \
15+
CPPFLAGS="$(CROSS_CPPFLAGS) -I$(INSTALL)/include" \
16+
LDFLAGS="$(CROSS_CPPFLAGS) -L$(INSTALL)/lib" \
17+
CC=$(CROSS_CC) \
18+
PKG_CONFIG_LIBDIR=$(CROSS_PKG_CONFIG_LIBDIR) \
19+
ZLIB_CFLAGS= \
20+
ZLIB_LIBS="-lz" \
21+
BZIP2_CFLAGS= \
22+
BZIP2_LIBS="-lbz2" \
23+
LIBPNG_CFLAGS= \
24+
LIBPNG_LIBS="-lpng"
25+
26+
$(FREETYPE): $(FREETYPE_EXTRACT)/config.mk
27+
PKG_CONFIG_LIBDIR=$(CROSS_PKG_CONFIG_LIBDIR) \
28+
$(MAKE) -C $(FREETYPE_EXTRACT) LIBPNG_LIBS=
29+
$(MAKE) -C $(FREETYPE_EXTRACT) install
30+
31+
$(compile-host-2): $(FREETYPE)

‎functions.mk‎

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
define _download-to-file
2+
$(1): $$(make-dirs)
3+
mkdir -p $$(dir $$@)
4+
curl -L $(2) > $$@
5+
_retval := $(1)
6+
endef
7+
8+
define download-to-file
9+
$(eval $(call _download-to-file,$(1),$(2)))$(_retval)
10+
endef
11+
12+
define download-to
13+
$(call download-to-file,$(1)/$(notdir $(2)),$(2))
14+
endef
15+
16+
define download
17+
$(call download-to,$(WORKING),$(1))
18+
endef
19+
20+
KNOWN_TAR_EXTENSIONS := %.tar.gz %.tar.bz2 %.tar.xz %.tgz %.tar
21+
22+
define archive-basename
23+
$(strip \
24+
$(foreach ext,$(KNOWN_TAR_EXTENSIONS) %.zip,\
25+
$(patsubst $(ext),%,$(filter $(ext),$(notdir $(1)))) \
26+
) \
27+
)
28+
endef
29+
30+
define _extract-to
31+
_base := $(if $(3),$(3),$$(call archive-basename,$(2)))
32+
ifneq ($$(filter %.zip,$(2)),)
33+
_cmd := unzip -qo
34+
else ifneq ($$(filter $$(KNOWN_TAR_EXTENSIONS),$(2)),)
35+
_cmd := tar xf
36+
else
37+
$$(error Don't know how to extract $(2))
38+
endif
39+
40+
_retval := $(1)/$$(_base)
41+
$$(_retval): _cmd := $$(_cmd)
42+
$$(_retval): $(2) $$(make-dirs)
43+
mkdir -p $$(dir $$@)
44+
cd $$(dir $$@) && $$(_cmd) $$(abspath $$<)
45+
touch $$@
46+
47+
$$(_retval).extracted: | $$(_retval)
48+
touch $$@
49+
50+
endef
51+
52+
# 1 - destination directory
53+
# 2 - archive path
54+
# 3 - optional alternate archive base name. Default based on path
55+
define extract-to
56+
$(eval $(call _extract-to,$(1),$(2),$(3)))$(_retval)
57+
endef
58+
59+
# 1 - archive path
60+
# 2 - optional alternate archive base name. Default based on path
61+
define extract
62+
$(call extract-to,$(WORKING),$(1),$(2))
63+
endef
64+
65+
# 1 - name
66+
define _define-one-stage
67+
$(1) := $$(STAGE_MARKERS)/$(1)
68+
$(1): $$($(1))
69+
.PHONY: $(1)
70+
endef
71+
72+
define define-stage
73+
$(foreach stage,$(1),$(eval $(call _define-one-stage,$(stage))))
74+
endef
75+
76+
$(STAGE_MARKERS)/%: | $(STAGE_MARKERS)
77+
touch $@
78+

‎libffi.mk‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#LIBFFI_URL := https://sourceware.org/pub/libffi/libffi-3.2.1.tar.gz
2+
LIBFFI_URL := https://github.com/atgreen/libffi/archive/59d44242e15d2979291fe6793ddfb2681b7480ef.zip
3+
LIBFFI_TAR := $(call download,$(LIBFFI_URL))
4+
#LIBFFI_EXTRACT := $(call extract,$(LIBFFI_TAR))
5+
LIBFFI_EXTRACT := $(call extract,$(LIBFFI_TAR),libffi-59d44242e15d2979291fe6793ddfb2681b7480ef)
6+
LIBFFI := $(INSTALL)/lib/libffi.a
7+
8+
$(LIBFFI_EXTRACT)/configure: $(LIBFFI_EXTRACT).extracted
9+
cd $(dir $@) && autoreconf --install
10+
11+
$(LIBFFI_EXTRACT)/Makefile: $(LIBFFI_EXTRACT)/configure $(host-toolchain)
12+
cd $(dir $@) \
13+
&& ./configure \
14+
--prefix=$(INSTALL) \
15+
--host=$(HOST) \
16+
--build=$(BUILD)
17+
18+
$(LIBFFI): export CC = $(CROSS_CC)
19+
$(LIBFFI): export PKG_CONFIG_LIBDIR = $(CROSS_PKG_CONFIG_LIBDIR)
20+
$(LIBFFI): $(LIBFFI_EXTRACT)/Makefile
21+
$(MAKE) -C $(LIBFFI_EXTRACT)
22+
$(MAKE) -C $(LIBFFI_EXTRACT) install
23+
24+
$(compile-host-1): $(LIBFFI)

‎libjpeg.mk‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
JPEG_URL := http://www.ijg.org/files/jpegsrc.v9b.tar.gz
2+
JPEG_TAR := $(call download,$(JPEG_URL))
3+
JPEG_EXTRACT := $(call extract,$(JPEG_TAR),jpeg-9b)
4+
JPEG_BUILDDIR := $(WORKING)/jpeg-builddir
5+
JPEG_LIB := $(INSTALL)/lib/libjpeg.a
6+
7+
$(JPEG_BUILDDIR)/Makefile: $(JPEG_EXTRACT) $(host-toolchain) | $(JPEG_BUILDDIR)
8+
cd $(dir $@) && $(JPEG_EXTRACT)/configure \
9+
--host=$(HOST) \
10+
--prefix=$(INSTALL) \
11+
CC=$(CROSS_CC) \
12+
PKG_CONFIG_LIBDIR=$(CROSS_PKG_CONFIG_LIBDIR)
13+
14+
$(JPEG_LIB): $(JPEG_BUILDDIR)/Makefile
15+
$(MAKE) -C $(JPEG_BUILDDIR)
16+
$(MAKE) -C $(JPEG_BUILDDIR) install
17+
18+
$(JPEG_BUILDDIR):
19+
mkdir -p $@
20+
21+
$(compile-host-1): $(JPEG_LIB)

‎openssl.mk‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
OPENSSL_URL := https://www.openssl.org/source/openssl-1.1.0g.tar.gz
2+
OPENSSL_TAR := $(call download,$(OPENSSL_URL))
3+
OPENSSL_EXTRACT := $(call extract,$(OPENSSL_TAR))
4+
OPENSSL_LIB := $(INSTALL)/lib/libssl.a
5+
6+
$(OPENSSL_EXTRACT)/Makefile: $(OPENSSL_EXTRACT).extracted $(host-toolchain)
7+
cd $(dir $@) \
8+
&& sed -i 's/-mandroid//' Configurations/10-main.conf \
9+
&& ./Configure \
10+
--prefix=$(INSTALL) \
11+
android-armeabi
12+
13+
$(OPENSSL_LIB): export CC = $(CROSS_CC)
14+
$(OPENSSL_LIB): export CROSS_SYSROOT = $(HOST_SYSROOT)
15+
$(OPENSSL_LIB): $(OPENSSL_EXTRACT)/Makefile
16+
$(MAKE) -C $(OPENSSL_EXTRACT)
17+
$(MAKE) -C $(OPENSSL_EXTRACT) install_dev
18+
19+
$(compile-host-1): $(OPENSSL_LIB)

‎package.mk‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
PACKAGE_WORKING := $(TOP)/package
2+
PACKAGE := $(TOP)/package.tar
3+
FIXUP := $(TOP)/fixup.py
4+
5+
$(package): $(PACKAGE)
6+
$(PACKAGE): $(host-python-modules)
7+
rm -rf $(PACKAGE_WORKING)
8+
cp -rd $(INSTALL) $(PACKAGE_WORKING)
9+
$(BUILD_PYTHON) $(FIXUP) $(PACKAGE_WORKING) $(TOOLCHAIN_BIN)/$(CROSS_STRIP)
10+
tar -C $(dir $(PACKAGE_WORKING)) -cf $@ $(notdir $(PACKAGE_WORKING)) \
11+
--exclude=*.la \
12+
--exclude=*.a \
13+
--exclude=test \
14+
--exclude=tests \
15+
--exclude=man \
16+
--exclude=pkgconfig \
17+
--transform='s!^[.]/!package/!'

0 commit comments

Comments
 (0)