Dependencies build scripts unification
[novacoin.git] / mingw64_deps / zlib / build.sh
index 70b5bab..7ea071e 100755 (executable)
@@ -1,16 +1,31 @@
 #!/bin/bash
 
-CROSS=$1
+TARGET_CPU=$1
+TARGET_OS=$2
 ROOT=$(pwd)
 
-if [[ ! "${CROSS}" =~ ^(aarch64|x86_64) ]]; then
-echo "Platform ${CROSS} is not supported"
+if [[ ! "${TARGET_CPU}" =~ ^(aarch64|x86_64) ]]; then
+echo "Platform ${TARGET_CPU} is not supported"
 echo "Expected either aarch64 or x86_64."
 exit 1
 fi
 
-if [[ ! $(which ${CROSS}-w64-mingw32-clang) ]]; then
-echo "llvm-mingw is not installed, please download it from https://github.com/mstorsjo/llvm-mingw/releases"
+if [[ ! "${TARGET_OS}" =~ ^(w64\-mingw32|linux\-gnu) ]]; then
+echo "Operation sysrem ${TARGET_OS} is not supported"
+echo "Expected either w64-mingw32 or linux-gnu."
+exit 1
+fi
+
+# Cross-building prefix
+CROSS=${TARGET_CPU}-${TARGET_OS}
+
+if [[ ! $(which ${CROSS}-gcc) ]]; then
+echo "Target C compiler ${CROSS}-gcc is not found"
+exit 1
+fi
+
+if [[ ! $(which ${CROSS}-g++) ]]; then
+echo "Target C++ compiler ${CROSS}-g++ is not found"
 exit 1
 fi
 
@@ -19,22 +34,31 @@ echo "make is not installed, please install buld-essential package"
 exit 1
 fi
 
+if [ "${TARGET_CPU}" == "aarch64" ]; then
+MUTEX="ARM64/gcc-assembly"
+fi
+
 # Make build directoriy
-cp -r ${ROOT}/zlib ${ROOT}/${CROSS}-w64-mingw32-build-zlib
+cp -r ${ROOT}/zlib ${ROOT}/${CROSS}-build-zlib
 
 # Stage directory
-mkdir ${ROOT}/${CROSS}-w64-mingw32
+mkdir ${ROOT}/${CROSS}
 
 # Compile zlib
-cd ${ROOT}/${CROSS}-w64-mingw32-build-zlib
-perl -i -pe "s,(PREFIX =)\$,\$1 ${CROSS}-w64-mingw32-," win32/Makefile.gcc
-perl -i -pe "s,(CFLAGS =.*)\$,\$1 -fstack-protector-all -D_FORTIFY_SOURCE," win32/Makefile.gcc
-perl -i -pe "s,(LDFLAGS =.*)\$,\$1 -fstack-protector-all," win32/Makefile.gcc
-make -j 4 -f win32/Makefile.gcc
+cd ${ROOT}/${CROSS}-build-zlib
+export CC=${CROSS}-gcc
+export CXX=${CROSS}-g++
+export LD=${CROSS}-ld
+export RANLIB=${CROSS}-ranlib
+export CFLAGS="-fstack-protector-all -D_FORTIFY_SOURCE=2"
+export CXXFLAGS=${CFLAGS}
+export LDFLAGS="-fstack-protector-all"
+${ROOT}/zlib/configure --prefix=${ROOT}/${CROSS} --static
+make -j 4
 
 # Install zlib to our cross-tools directory
-make install DESTDIR=${ROOT}/${CROSS}-w64-mingw32 INCLUDE_PATH=/include LIBRARY_PATH=/lib BINARY_PATH=/bin -f win32/Makefile.gcc
+make install
 
 # Remove build directory
 cd ${ROOT}
-rm -rf ${ROOT}/${CROSS}-w64-mingw32-build-zlib
+rm -rf ${ROOT}/${CROSS}-build-zlib