Skip to content
This repository has been archived by the owner on Aug 15, 2017. It is now read-only.

Commit

Permalink
Updated build to include BZip2 and XZ.
Browse files Browse the repository at this point in the history
  • Loading branch information
freakboy3742 committed Feb 23, 2016
1 parent faa5018 commit 66ca070
Show file tree
Hide file tree
Showing 2 changed files with 146 additions and 59 deletions.
203 changes: 144 additions & 59 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,102 +1,187 @@
PROJECTDIR=$(shell pwd)
PROJECT_DIR=$(shell pwd)

BUILD_NUMBER=2
BUILD_NUMBER=3

# Version of packages that will be compiled by this meta-package
PYTHON_VERSION=3.4.2
PYTHON_VER= $(basename $(PYTHON_VERSION))

OPENSSL_VERSION_NUMBER=1.0.2
OPENSSL_REVISION=d
OPENSSL_REVISION=f
OPENSSL_VERSION=$(OPENSSL_VERSION_NUMBER)$(OPENSSL_REVISION)

BZIP2_VERSION=1.0.6

XZ_VERSION=5.2.2

# OS/X build commands and flags
OSX_SDK_ROOT=$(shell xcrun --show-sdk-path)
OSX_CC=$(shell xcrun -find clang) --sysroot=$(OSX_SDK_ROOT)
SDK_ROOT=$(shell xcrun --show-sdk-path)
CC=$(shell xcrun -find clang) --sysroot=$(OSX_SDK_ROOT)

# Working directories

OPENSSL_DIR=build/openssl-$(OPENSSL_VERSION)
BZIP2_DIR=build/bzip2-$(BZIP2_VERSION)
XZ_DIR=build/xz-$(XZ_VERSION)
PYTHON_DIR=build/Python-$(PYTHON_VERSION)

all: Python-$(PYTHON_VERSION)-OSX-support.b$(BUILD_NUMBER).tar.gz
OPENSSL_FRAMEWORK=build/OpenSSL.framework
BZIP2_LIB=build/bzip2/lib/libbz2.a
XZ_LIB=build/xz/lib/liblzma.a

all: OSX

# Clean all builds
clean:
rm -rf build dist Python-$(PYTHON_VERSION)-OSX-support.b$(BUILD_NUMBER).tar.gz
rm -rf build dist

# Full clean - includes all downloaded products
distclean: clean
rm -rf downloads

Python-$(PYTHON_VERSION)-OSX-support.b$(BUILD_NUMBER).tar.gz: dist/python/bin/python$(basename $(PYTHON_VERSION))m
echo "Python-$(PYTHON_VERSION)-OSX-support.b$(BUILD_NUMBER)" > dist/VERSION
cd dist && tar zcvf ../Python-$(PYTHON_VERSION)-OSX-support.b$(BUILD_NUMBER).tar.gz python VERSION
downloads: downloads/openssl-$(OPENSSL_VERSION).tgz downloads/bzip2-$(BZIP2_VERSION).tgz downloads/xz-$(XZ_VERSION).tgz downloads/Python-$(PYTHON_VERSION).tgz

###########################################################################
# Working directories
# OpenSSL
# These build instructions adapted from the scripts developed by
# Felix Shchulze (@x2on) https://github.com/x2on/OpenSSL-for-iPhone
###########################################################################

downloads:
mkdir -p downloads

build:
mkdir -p build

dist:
mkdir -p dist

# Clean the OpenSSL project
clean-OpenSSL:
rm -rf build/openssl-$(OPENSSL_VERSION)
rm -rf build/OpenSSL
rm -rf dist/OpenSSL.framework
rm -rf build/*/openssl-$(OPENSSL_VERSION)-* \
build/*/libssl.a build/*/libcrypto.a \
build/*/OpenSSL.framework

# Download original OpenSSL source code archive.
downloads/openssl-$(OPENSSL_VERSION).tgz: downloads
downloads/openssl-$(OPENSSL_VERSION).tgz:
mkdir -p downloads
-if [ ! -e downloads/openssl-$(OPENSSL_VERSION).tgz ]; then curl --fail -L http://openssl.org/source/openssl-$(OPENSSL_VERSION).tar.gz -o downloads/openssl-$(OPENSSL_VERSION).tgz; fi
if [ ! -e downloads/openssl-$(OPENSSL_VERSION).tgz ]; then curl --fail -L http://openssl.org/source/old/$(OPENSSL_VERSION_NUMBER)/openssl-$(OPENSSL_VERSION).tar.gz -o downloads/openssl-$(OPENSSL_VERSION).tgz; fi

build/OpenSSL/lib/libssl.a: build downloads/openssl-$(OPENSSL_VERSION).tgz

# Unpack OpenSSL
$(OPENSSL_DIR)/Makefile: downloads/openssl-$(OPENSSL_VERSION).tgz
# Unpack sources
cd build && tar zxf ../downloads/openssl-$(OPENSSL_VERSION).tgz
mkdir -p build/OpenSSL
mkdir -p $(OPENSSL_DIR)
tar zxf downloads/openssl-$(OPENSSL_VERSION).tgz --strip-components 1 -C $(OPENSSL_DIR)
# Configure the build
cd build/openssl-$(OPENSSL_VERSION) && \
CC="$(OSX_CC)" ./Configure darwin64-x86_64-cc --openssldir=$(PROJECTDIR)/build/OpenSSL
cd $(OPENSSL_DIR) && \
CC="$(CC)" ./Configure darwin64-x86_64-cc --openssldir=$(PROJECT_DIR)/$(OPENSSL_DIR)

# Build OpenSSL
$(OPENSSL_DIR)/libssl.a $(OPENSSL_DIR)/libcrypto.a: $(OPENSSL_DIR)/Makefile
# Make the build
cd build/openssl-$(OPENSSL_VERSION) && CC="$(OSX_CC)" make all
# Install the build
cd build/openssl-$(OPENSSL_VERSION) && make install
cd $(OPENSSL_DIR) && \
CC="$(CC)" make all

# Build OpenSSL.framework
$(OPENSSL_FRAMEWORK): $(OPENSSL_DIR)/libssl.a $(OPENSSL_DIR)/libcrypto.a
# Create framework directory structure
mkdir -p $(OPENSSL_FRAMEWORK)/Versions/$(OPENSSL_VERSION)

# Copy the headers (use the version from the simulator because reasons)
cp -f -r $(OPENSSL_DIR)/include $(OPENSSL_FRAMEWORK)/Versions/$(OPENSSL_VERSION)/Headers

# Create the fat library
xcrun libtool -no_warning_for_no_symbols -static \
-o $(OPENSSL_FRAMEWORK)/Versions/$(OPENSSL_VERSION)/OpenSSL $^

# Create symlinks
ln -fs $(OPENSSL_VERSION) $(OPENSSL_FRAMEWORK)/Versions/Current
ln -fs Versions/Current/Headers $(OPENSSL_FRAMEWORK)
ln -fs Versions/Current/OpenSSL $(OPENSSL_FRAMEWORK)

###########################################################################
# BZip2
###########################################################################

# Clean the bzip2 project
clean-bzip2:
rm -rf build/*/bzip2-$(BZIP2_VERSION)-* \
build/*/bzip2

# Download original OpenSSL source code archive.
downloads/bzip2-$(BZIP2_VERSION).tgz:
mkdir -p downloads
if [ ! -e downloads/bzip2-$(BZIP2_VERSION).tgz ]; then curl --fail -L http://www.bzip.org/$(BZIP2_VERSION)/bzip2-$(BZIP2_VERSION).tar.gz -o downloads/bzip2-$(BZIP2_VERSION).tgz; fi

# Unpack BZip2
$(BZIP2_DIR)/Makefile: downloads/bzip2-$(BZIP2_VERSION).tgz
# Unpack sources
mkdir -p $(BZIP2_DIR)
tar zxf downloads/bzip2-$(BZIP2_VERSION).tgz --strip-components 1 -C $(BZIP2_DIR)
# Patch sources to use correct install directory
sed -ie 's#PREFIX=/usr/local#PREFIX=$(PROJECT_DIR)/build/bzip2#' $(BZIP2_DIR)/Makefile

# Build BZip2
build/bzip2/lib/libbz2.a: $(BZIP2_DIR)/Makefile
cd $(BZIP2_DIR) && make install

###########################################################################
# XZ (LZMA)
###########################################################################

# Clean the XZ project
clean-xz:
rm -rf build/*/xz-$(XZ_VERSION)-* \
build/*/xz

# Download original OpenSSL source code archive.
downloads/xz-$(XZ_VERSION).tgz:
mkdir -p downloads
if [ ! -e downloads/xz-$(XZ_VERSION).tgz ]; then curl --fail -L http://tukaani.org/xz/xz-$(XZ_VERSION).tar.gz -o downloads/xz-$(XZ_VERSION).tgz; fi

# Unpack XZ
$(XZ_DIR)/Makefile: downloads/xz-$(XZ_VERSION).tgz
# Unpack sources
mkdir -p $(XZ_DIR)
tar zxf downloads/xz-$(XZ_VERSION).tgz --strip-components 1 -C $(XZ_DIR)
# Configure the build
cd $(XZ_DIR) && \
./configure --disable-shared --enable-static --prefix=$(PROJECT_DIR)/build/xz

# Build XZ
build/xz/lib/liblzma.a: $(XZ_DIR)/Makefile
cd $(XZ_DIR) && make && make install

###########################################################################
# Python
###########################################################################

# Clean the Python project
clean-Python:
rm -rf build/Python-$(PYTHON_VERSION)
rm -rf build/python
rm -rf dist/Python.framework
rm -rf build/Python-$(PYTHON_VERSION)-host build/*/Python-$(PYTHON_VERSION)-* \
build/*/libpython$(PYTHON_VER).a build/*/pyconfig-*.h \
build/*/Python.framework

# Download original Python source code archive.
downloads/Python-$(PYTHON_VERSION).tgz: downloads
curl -L https://www.python.org/ftp/python/$(PYTHON_VERSION)/Python-$(PYTHON_VERSION).tgz > downloads/Python-$(PYTHON_VERSION).tgz
downloads/Python-$(PYTHON_VERSION).tgz:
mkdir -p downloads
if [ ! -e downloads/Python-$(PYTHON_VERSION).tgz ]; then curl -L https://www.python.org/ftp/python/$(PYTHON_VERSION)/Python-$(PYTHON_VERSION).tgz > downloads/Python-$(PYTHON_VERSION).tgz; fi

# build/Python-$(PYTHON_VERSION)/Python.framework: build dist/OpenSSL.framework downloads/Python-$(PYTHON_VERSION).tgz
dist/python/bin/python$(basename $(PYTHON_VERSION))m: build downloads/Python-$(PYTHON_VERSION).tgz build/OpenSSL/lib/libssl.a
# Unpack sources
cd build && tar zxf ../downloads/Python-$(PYTHON_VERSION).tgz
mkdir -p build/python
# Apply patches
cd build/Python-$(PYTHON_VERSION) && cp ../../patch/Python/Setup.embedded Modules/Setup.embedded
# Configure the build
cd build/Python-$(PYTHON_VERSION) && ./configure --prefix=$(PROJECTDIR)/dist/python --without-ensurepip
# Make the build
cd build/Python-$(PYTHON_VERSION) && make
# Install the build
cd build/Python-$(PYTHON_VERSION) && make install
# Prune out things that aren't needed
cd dist/python && rm -rf share include
cd dist/python/bin && rm -rf 2to3* idle* pydoc* python*-config pyvenv* python*m
cd dist/python/lib && rm -rf libpython$(basename $(PYTHON_VERSION)).a pkgconfig
cd dist/python/lib/python$(basename $(PYTHON_VERSION)); \
rm -rf *test* bsddb curses ensurepip hotshot idlelib tkinter turtledemo wsgiref \
config-$(basename $(PYTHON_VERSION))m ctypes/test distutils/tests site-packages sqlite3/test
# Make sure python always works as an executable name
cd dist/python/bin && ln -si python$(basename $(PYTHON_VERSION)) python
# Unpack Python
$(PYTHON_DIR)/Makefile: downloads/Python-$(PYTHON_VERSION).tgz
# Unpack target Python
mkdir -p $(PYTHON_DIR)
tar zxf downloads/Python-$(PYTHON_VERSION).tgz --strip-components 1 -C $(PYTHON_DIR)
# Apply target Python patches
cp -f $(PROJECT_DIR)/patch/Python/Setup.embedded $(PYTHON_DIR)/Modules/Setup.embedded
# Configure target Python
cd $(PYTHON_DIR) && ./configure --without-ensurepip --prefix=$(PROJECT_DIR)/build/python

# Build Python
$(PROJECT_DIR)/build/python/bin/python: build/OpenSSL.framework build/bzip2/lib/libbz2.a build/xz/lib/liblzma.a $(PYTHON_DIR)/Makefile
# Build target Python
cd $(PYTHON_DIR) && make all install


###########################################################################
# Packaging
###########################################################################

dist/Python-$(PYTHON_VERSION)-OSX-support.b$(BUILD_NUMBER).tar.gz: $(PROJECT_DIR)/build/python/bin/python
mkdir -p dist
tar zcvf $@ -C build python

OSX: dist/Python-$(PYTHON_VERSION)-OSX-support.b$(BUILD_NUMBER).tar.gz
2 changes: 2 additions & 0 deletions patch/Python/Setup.embedded
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#####################################################################

_bisect _bisectmodule.c
_bz2 _bz2module.c -I$(srcdir)/../bzip2/include -L$(srcdir)/../bzip2/lib -lbz2
_codecs_cn cjkcodecs/_codecs_cn.c
_codecs_hk cjkcodecs/_codecs_hk.c
_codecs_iso2022 cjkcodecs/_codecs_iso2022.c
Expand All @@ -18,6 +19,7 @@ _elementtree _elementtree.c \
_heapq _heapqmodule.c
_json _json.c
_lsprof _lsprof.o rotatingtree.c
_lzma _lzmamodule.c -I$(srcdir)/../xz/include -L$(srcdir)/../xz/lib -llzma
_md5 md5module.c
_multibytecodec cjkcodecs/multibytecodec.c
_multiprocessing _multiprocessing/multiprocessing.c _multiprocessing/semaphore.c
Expand Down

0 comments on commit 66ca070

Please sign in to comment.