|
| 1 | +########################################################################### |
| 2 | +# NumPy |
| 3 | +########################################################################### |
| 4 | + |
| 5 | +NUMPY_VERSION=1.9.1 |
| 6 | +NUMPY_CONFIG=BLAS=None LAPACK=None ATLAS=None |
| 7 | + |
| 8 | +# Download original numpy source code archive. |
| 9 | +downloads/numpy-$(NUMPY_VERSION).tgz: |
| 10 | + mkdir -p downloads |
| 11 | + # if [ ! -e downloads/numpy-$(NUMPY_VERSION).tgz ]; then curl --fail -L https://github.com/numpy/numpy/releases/download/v$(NUMPY_VERSION)/numpy-$(NUMPY_VERSION).tar.gz -o downloads/numpy-$(NUMPY_VERSION).tgz; fi |
| 12 | + if [ ! -e downloads/numpy-$(NUMPY_VERSION).tgz ]; then curl --fail -L https://github.com/numpy/numpy/archive/v$(NUMPY_VERSION).tar.gz -o downloads/numpy-$(NUMPY_VERSION).tgz; fi |
| 13 | + |
| 14 | +define build-numpy-target |
| 15 | +NUMPY-CFLAGS-$1=$$(CFLAGS-$2) |
| 16 | +NUMPY-CC-$1=xcrun --sdk $$(SDK-$1) clang \ |
| 17 | + -arch $$(ARCH-$1) \ |
| 18 | + --sysroot=$$(SDK_ROOT-$1) \ |
| 19 | + $$(NUMPY_CFLAGS-$1) |
| 20 | + |
| 21 | +build/$2/packages/numpy/build/temp.$1-$(PYTHON_VER)/libpymath.a: build/$2/packages/numpy |
| 22 | + cd build/$2/packages/numpy && \ |
| 23 | + CC="$$(NUMPY-CC-$1)" \ |
| 24 | + CFLAGS="$$(NUMPY-CFLAGS-$1)" \ |
| 25 | + $(NUMPY_CONFIG) \ |
| 26 | + _PYTHON_HOST_PLATFORM=$1 \ |
| 27 | + $(HOST_PYTHON) setup.py build_ext |
| 28 | + |
| 29 | +build/$2/packages/numpy/build/temp.$1-$(PYTHON_VER)/libnumpy.a: build/$2/packages/numpy/build/temp.$1-$(PYTHON_VER)/libpymath.a |
| 30 | + cd build/$2/packages/numpy/build/temp.$1-$(PYTHON_VER) && \ |
| 31 | + xcrun --sdk $$(SDK-$1) ar -q libnumpy.a `find . -name "*.o"` |
| 32 | + |
| 33 | +numpy-$1: build/$2/packages/numpy/build/temp.$1-$(PYTHON_VER)/libnumpy.a |
| 34 | + |
| 35 | +endef |
| 36 | + |
| 37 | +define build-numpy |
| 38 | +$$(foreach target,$$(TARGETS-$1),$$(eval $$(call build-numpy-target,$$(target),$1))) |
| 39 | + |
| 40 | +build/$1/packages/numpy: downloads/numpy-$(NUMPY_VERSION).tgz |
| 41 | + # Unpack numpy sources |
| 42 | + mkdir -p build/$1/packages/numpy |
| 43 | + tar zxf downloads/numpy-$(NUMPY_VERSION).tgz --strip-components 1 -C build/$1/packages/numpy |
| 44 | + # Apply patch |
| 45 | + cd build/$1/packages/numpy && patch -p1 -i $(PROJECT_DIR)/patch/numpy/numpy.patch |
| 46 | + # Install requirements for compiling Numpy |
| 47 | + $(HOST_PIP) install cython |
| 48 | + |
| 49 | +ifeq ($1,macOS) |
| 50 | +# Use the macOS build as a reference installation |
| 51 | +# Just install the source as-is into the dist/app_packages directory |
| 52 | +# Then clean out all the binary artefacts |
| 53 | + |
| 54 | +dist/app_packages/numpy: dist/app_packages build/$1/packages/numpy |
| 55 | + cd build/$1/packages/numpy && \ |
| 56 | + $(NUMPY_CONFIG) $(HOST_PIP) install --target $(PROJECT_DIR)/dist/app_packages . |
| 57 | + find build/$1/packages/numpy -name "*.so" -exec rm {} \; |
| 58 | + |
| 59 | +numpy-$1: dist/app_packages/numpy |
| 60 | + |
| 61 | +else |
| 62 | +# For all other platforms, run the numpy build for each target architecture |
| 63 | + |
| 64 | +dist/$1/libnumpy.a: $(foreach target,$(TARGETS-$1),numpy-$(target)) |
| 65 | + mkdir -p dist/$1 |
| 66 | + xcrun lipo -create -output dist/$1/libnpymath.a $(foreach target,$(TARGETS-$1),build/$1/packages/numpy/build/temp.$(target)-$(PYTHON_VER)/libnpymath.a) |
| 67 | + xcrun lipo -create -output dist/$1/libnpysort.a $(foreach target,$(TARGETS-$1),build/$1/packages/numpy/build/temp.$(target)-$(PYTHON_VER)/libnpysort.a) |
| 68 | + xcrun lipo -create -output dist/$1/libnumpy.a $(foreach target,$(TARGETS-$1),build/$1/packages/numpy/build/temp.$(target)-$(PYTHON_VER)/libnumpy.a) |
| 69 | + |
| 70 | +numpy-$1: dist/$1/libnumpy.a |
| 71 | + |
| 72 | +endif |
| 73 | +endef |
| 74 | + |
| 75 | +# Call build-numpy for each packaged OS target |
| 76 | +$(foreach os,$(OS),$(eval $(call build-numpy,$(os)))) |
| 77 | + |
| 78 | +# Main entry point |
| 79 | +numpy: pip $(foreach os,$(OS),numpy-$(os)) |
0 commit comments