From 46fdcfc3a3a1a5ad5b9a103a0afb80c7545069d8 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Mon, 13 Jul 2009 13:43:57 +0000 Subject: [PATCH] Create build scripts for Win64 somewhat equilavent to the Win32 ones git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@8978 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/win32/build-cross-mingw-w64 | 122 ++++++++++ bacula/src/win32/build-depkgs-mingw-w64 | 287 ++++++++++++++++++++++++ bacula/technotes | 2 + 3 files changed, 411 insertions(+) create mode 100755 bacula/src/win32/build-cross-mingw-w64 create mode 100755 bacula/src/win32/build-depkgs-mingw-w64 diff --git a/bacula/src/win32/build-cross-mingw-w64 b/bacula/src/win32/build-cross-mingw-w64 new file mode 100755 index 0000000000..11f2c17b2f --- /dev/null +++ b/bacula/src/win32/build-cross-mingw-w64 @@ -0,0 +1,122 @@ +#!/bin/bash -e +# +# Script to help build the mingw cross compile tool chain for Win64 +# This typically needs a lot of hand tweaking to get everything to +# work. We build this only on Ubuntu Hardy, and it is unlikely +# to work on any other Linux version without significant changes +# to the patch files... You are on your own here. +# +HST=x86_64-pc-linux +TGT=x86_64-pc-mingw32 +RT=mingw-w64 +mkdir -p ../../../cross-tools +cd ../../../cross-tools +PF=`pwd`/$RT +BD=`pwd`/build +SRC=`pwd`/source +cd - +DIRS="$SRC $PF $PF/$TGT $BD $BD/binutils $BD/binutils/build-$HST $BD/gcc-svn $BD/gcc-svn/build-$HST $BD/mingw $BD/mingw/build-$HST" +baseopts="--prefix=$PF --with-sysroot=$PF --target=$TGT" +j="-j3" + +#Option defaults +build="true" +update="true" +out=/dev/null + +binutilsver=binutils-2.19 +dlbinutils=http://ftp.gnu.org/gnu/binutils/$binutilsver.tar.bz2 +gccver=gcc-4.3.2 +dlgcc=http://ftp.gnu.org/gnu/gcc/$gccver/$gccver.tar.bz2 +mingwver=mingw-w64-snapshot-20081115 +dlmingw64=http://garr.dl.sourceforge.net/sourceforge/mingw-w64/$mingwver.tar.bz2 +#Third part packages +gmpver=gmp-4.2.4 +gmp=ftp://ftp.gnu.org/gnu/gmp/${gmpver}.tar.bz2 +mpfrver=mpfr-2.3.2 +mpfr=http://www.mpfr.org/mpfr-current/${mpfrver}.tar.bz2 +url=http://www.bacula.org/cross-tools + +echo "Check sources" +mkdir -p $SRC +cd $SRC + +for i in $binutilsver $gccver $mpfrver $gmpver $mingwver +do + if [ ! -f $i.tar.bz2 ]; then + echo "Download $i" + wget $url/$i.tar.bz2 + fi +done + +tar xf $mingwver.tar.bz2 +mv trunk/mingw-* . +tar cfj mingw-w64-crt.tar.bz2 mingw-w64-crt +tar cfj mingw-w64-headers.tar.bz2 mingw-w64-headers +rm -rf mingw-w64-crt mingw-w64-headers trunk + +if [ $update = "true" ]; then + echo "Creating directory tree:" + echo "$PF -- sysroot directory tree" + echo "$BD -- build directory tree" + echo "" + + for i in $DIRS; do + [ -d $i ] && echo "Warning: $i preexisting, skipping directory creation" || mkdir $i + done + [ -h $PF/mingw ] || ln -s $TGT $PF/mingw + + echo "Downloading binutils.." && cd $BD/binutils + rm -rf binutils + tar xf $SRC/binutils-2.19.tar.bz2 + mv binutils-* src + + echo "Downloading gcc.." && cd $BD/gcc-svn +# svn -q checkout svn://gcc.gnu.org/svn/gcc/trunk gcc -r $gccrev + rm -rf gcc + tar xf $SRC/gcc-4.3.2.tar.bz2 + mv gcc-* gcc + + echo "Downloading additional required libraries for gcc.." + cd gcc + rm -rf gmp + tar xf $SRC/gmp-4.2.4.tar.bz2 + mv gmp-* gmp + + rm -rf mpfr + tar xf $SRC/mpfr-2.3.2.tar.bz2 + mv mpfr-* mpfr + cd .. + + echo "Downloading crt and headers.." + cd $BD/mingw + tar xf $SRC/mingw-w64-headers.tar.bz2 + tar xf $SRC/mingw-w64-crt.tar.bz2 + cp -prf mingw-w64-headers/include $PF/$TGT/include + + echo "Root setup complete." +fi + +if [ $build = "true" ]; then + echo "Compiling binutils.." && cd $BD/binutils/build-$HST + ../src/configure $baseopts > $out && make -s $j > $out && make install > $out || exit 1 + + echo "Compiling bootstrap gcc.." && cd $BD/gcc-svn/build-$HST + ../gcc/configure $baseopts > $out && make -s $j all-gcc > $out && make install-gcc > $out || exit 1 + export PATH=$PF/bin:$PATH + + echo "Compiling crt.." && cd $BD/mingw/build-$HST + ../mingw-w64-crt/configure --prefix=$PF --with-sysroot=$PF --host=$TGT > $out && make -s $j > $out && make install > $out || exit 1 + + echo "Compiling full gcc.." && cd $BD/gcc-svn/build-$HST + make -s $j > $out && make install > $out || exit 1 + + cd $PF + echo "Done building." +fi + +cd $PF/bin +for i in x86_64-pc-mingw32-* +do + ln -s $i ${i##x86_64-pc-} +done diff --git a/bacula/src/win32/build-depkgs-mingw-w64 b/bacula/src/win32/build-depkgs-mingw-w64 new file mode 100755 index 0000000000..3bc822092c --- /dev/null +++ b/bacula/src/win32/build-depkgs-mingw-w64 @@ -0,0 +1,287 @@ +#!/bin/sh +# +# This file may help you build the dependency packages that +# are needed to cross compile the Win64 bit version of the Bacula +# File daemon. This file is provided as is, and we don't guarantee +# that it will work. We run it only on Ubuntu Hardy. Trying to use +# it on any other GNU/Linux distro will probably require changes. +# +# This file is driven by the parameters that are defined in +# the file External-mingw-w64 +# + +usage() +{ + echo "usage: $0 [-h] [-C] [] [] ..." + echo " -h Displays this usage" + echo " -C Clobbers (overwrites) the source code by " + echo " reextracting the archive and reapplying the" + echo " patches." + echo "" + echo " Optional dependency, If none are given then all" + echo " of them will be built." + echo "" + echo "Valid dependencies are:" + grep -v '^#' < External-mingw-w64 | cut -d'|' -f1 | cut -d'_' -f1 | tr A-Z a-z | sort -u | awk '{ print " " $1 }' +} + +CLOBBER_SOURCE= + +while getopts "hHC" opt; do + case ${opt} in + H|h|\?) usage;exit 1;; + C) CLOBBER_SOURCE=true;; + esac +done + +[ ${OPTIND} -gt 1 ] && shift `expr ${OPTIND} - 1` + +cwd=`pwd` +cd `dirname $0` +SCRIPT_DIR=`pwd` + +cd ../../.. +TOP_DIR=`pwd` + +if [ -e ${TOP_DIR}/cross-tools/mingw-w64/bin/x86_64-pc-mingw32-gcc ] +then + cd ${TOP_DIR}/cross-tools/mingw-w64/bin + BIN_DIR=`pwd` +else + echo "The GCC cross compiler isn\'t installed." + echo "You must run build-win64-cross-tools first" + exit 1 +fi + +[ ! -e ${TOP_DIR}/depkgs-mingw-w64 ] && mkdir ${TOP_DIR}/depkgs-mingw-w64 +cd ${TOP_DIR}/depkgs-mingw-w64 +DEPPKG_DIR=`pwd` + +export PATH=${BIN_DIR}:${PATH} + +[ ! -e bin ] && mkdir bin +[ ! -e src ] && mkdir src +[ ! -e include ] && mkdir include +[ ! -e lib ] && mkdir lib + +OLD_IFS=${IFS};IFS="|"; +while read package url dir mkd; do + echo "Got package ${package}" + case ${package} in + \#*) ;; + *) eval "URL_${package}=${url};DIR_${package}=${dir};MKD_${package}=${mkd}";; + esac +done < ${SCRIPT_DIR}/External-mingw-w64 +IFS=${OLD_IFS};unset OLD_IFS + +get_source() +{ + URL=$1 + SRC_DIR=$2 + MAKE_DIR=$3 + echo "Processing ${URL}" + ARCHIVE=`basename ${URL}` + + case ${ARCHIVE} in + *.tar.gz) ARCHIVER="tar xzf"; [ -z "${SRC_DIR}" ] && SRC_DIR=`expr "${ARCHIVE}" : '\(.*\)\.tar\.gz'`;; + *.tar.bz2) ARCHIVER="tar xjf"; [ -z "${SRC_DIR}" ] && SRC_DIR=`expr "${ARCHIVE}" : '\(.*\)\.tar\.bz2'`;; + *.zip) ARCHIVER="unzip -q"; [ -z "${SRC_DIR}" ] && SRC_DIR=`expr "${ARCHIVE}" : '\(.*\)\.zip'`;; + *.exe) ARCHIVER=""; [ -z "${SRC_DIR}" ] && SRC_DIR=`expr "${ARCHIVE}" : '\(.*\)\.zip'`;; + *) echo Unsupported archive type - $ARCHIVE; exit 1;; + esac + + cd ${DEPPKG_DIR}/src + + if [ ! -e "${ARCHIVE}" ] + then + echo Downloading "${URL}" + if wget --passive-ftp "${URL}" + then + : + else + echo Unable to download ${ARCHIVE} + exit 1 + fi + fi + + [ -z "${ARCHIVER}" ] && return 0 + + if [ ! -e "${SRC_DIR}" -o "${CLOBBER_SOURCE}" = "true" ] + then + rm -rf ${SRC_DIR} + echo Extracting ${ARCHIVE} + if [ "${MAKE_DIR}" = "true" ] + then + mkdir ${SRC_DIR} + cd ${SRC_DIR} + ${ARCHIVER} ../${ARCHIVE} > ../${ARCHIVE}.log 2>&1 + else + ${ARCHIVER} ${ARCHIVE} > ${ARCHIVE}.log 2>&1 + cd ${SRC_DIR} + fi + return 0 + fi + + cd ${SRC_DIR} + return 1 +} + +parse_output() +{ + sed -ne '/\\$/N' -e 's/\\\n//' -e 's/\t\+/ /g' -e 's/ \+/ /g' \ + -e '/ error: /p' \ + -e "s%.*Entering directory[ ]\\+.${DEPPKG_DIR}/\\([^ ]\+\).%Entering \\1%p" \ + -e "s%.*Leaving directory[ ]\\+.${DEPPKG_DIR}/\\([^ ]\+.\).%Leaving \\1%p" \ + -e '/gcc \|g\+\+ \|ar /!d' \ + -e 's/ \(\.\.\/\)\+/ /g' \ + -e 's/.* \([^ ]\+\(\.c\|\.cpp\|\.cc\|\.cxx\)\)\( .*\|\)$/Compiling \1/p' \ + -e 's/.* \([^ ]\+\.s\)\( .*\|\)$/Assembling \1/p' \ + -e 's/.*ar [^ ]\+ \([^ ]\+\)\(\( [^ ]\+\.o\)\+\)/Updating \1 -\2/p' \ + -e 's/.* -o \([^ ]\+\)\( .*\|\)$/Linking \1/p' +} + +do_patch() +{ + PATCH_FILE=${SCRIPT_DIR}/patches/$1; shift + + if patch -f -p0 "$@" >>patch.log < ${PATCH_FILE} + then + : + else + echo "Patch failed - Check `pwd`/patch.log" > /dev/tty + exit 1 + fi +} + +do_make() +{ + if make -f "$@" 2>&1 + then + : + else + echo "Make failed - Check `pwd`/make.log" > /dev/tty + exit 1 + fi | tee -a make.log | parse_output +} + +process_zlib() +{ + if get_source "${URL_ZLIB}" "${DIR_ZLIB}" "${MKD_ZLIB}" + then + echo "Patching zlib" + >patch.log + do_patch zlib.patch + fi + echo Building zlib + > make.log + do_make win32/Makefile.mingw32 PREFIX=${DEPPKG_DIR} all + echo Installing zlib + do_make win32/Makefile.mingw32 PREFIX=${DEPPKG_DIR} install +} + +process_pcre() +{ + if get_source "${URL_PCRE}" "${DIR_PCRE}" "${MKD_PCRE}" + then + echo Patching PCRE + >patch.log + do_patch pcre.patch + echo Configuring PCRE + ./configure CC_FOR_BUILD=gcc \ + CXX_FOR_BUILD=g++ \ + --host=x86_64-pc-mingw32 \ + --prefix=${DEPPKG_DIR} \ + --enable-utf8 \ + --enable-unicode-properties >make.log 2>&1 + fi + echo Building PCRE + do_make Makefile PREFIX=${DEPPKG_DIR} all + echo Installing PCRE + do_make Makefile PREFIX=${DEPPKG_DIR} install +} + +process_db() +{ + if get_source "${URL_DB}" "${DIR_DB}" "${MKD_DB}" + then + echo No Patch + fi + cd build_unix + ../dist/configure --host=x86_64-pc-mingw32 --enable-mingw --prefix=${DEPPKG_DIR} + > make.log + echo Building DB + do_make Makefile + echo Installing DB + do_make Makefile install_setup install_include install_lib +} + +process_pthreads() +{ + if get_source "${URL_PTHREADS}" "${DIR_PTHREADS}" "${MKD_PTHREADS}" + then + echo Patching pthreads + >patch.log + do_patch pthreads-w64.patch + fi + echo Building pthreads + > make.log + do_make GNUmakefile GCE + echo Installing pthreads + rm -rf ${DEPPKG_DIR}/include/pthreads + mkdir ${DEPPKG_DIR}/include/pthreads + cp -p *.h ${DEPPKG_DIR}/include/pthreads + cp -p *.dll ${DEPPKG_DIR}/bin + cp -p *.a ${DEPPKG_DIR}/lib +} + +process_openssl() +{ + if get_source "${URL_OPENSSL}" "${DIR_OPENSSL}" "${MKD_OPENSSL}" + then + echo Patching openssl + >patch.log + do_patch openssl-w64.patch + echo Configuring openssl + echo ./Configure --prefix=${DEPPKG_DIR} \ + shared zlib-dynamic no-dso no-hw \ + threads \ + --with-zlib-include=${DEPPKG_DIR}/include \ + mingw64 + ./Configure --prefix=${DEPPKG_DIR} \ + shared zlib-dynamic no-dso no-hw \ + threads \ + --with-zlib-include=${DEPPKG_DIR}/include \ + mingw64 > make.log 2>&1 + fi + echo Building openssl + perl util/mkdef.pl 32 libeay no-static-engine >ms/libeay32.def + perl util/mkdef.pl 32 ssleay >ms/ssleay32.def + perl util/mkdef.pl crypto ssl NT update + sed -i 's/CC=/CC=mingw32-gcc #/' crypto/comp/Makefile + sed -i 's/AR=/AR=mingw32-ar r #/' crypto/comp/Makefile + sed -i "s:^CFLAGS=:CFLAGS= -I${DEPPKG_DIR}/include:" crypto/comp/Makefile + + do_make Makefile all + cd engines + touch lib4758cca.bad libaep.bad libatalla.bad libcswift.bad libchil.bad libgmp.bad libnuron.bad libsureware.bad libubsec.bad libcapi.bad + cd .. + do_make Makefile all + echo Installing openssl + do_make Makefile install_sw install + cp *.dll ${DEPPKG_DIR}/bin +} + +if [ "$#" -eq 0 ] +then + process_zlib + process_pcre + process_pthreads + process_openssl +else + for dependency in "$@" + do + eval "process_${dependency}" + done +fi +#vss +#Need to download from Microsoft diff --git a/bacula/technotes b/bacula/technotes index b9e81e1252..424a97e2c4 100644 --- a/bacula/technotes +++ b/bacula/technotes @@ -2,6 +2,8 @@ General: +13Jul09 +kes Create build scripts for Win64 somewhat equilavent to the Win32 ones. 10Jul09 ebl Print correct JobId in bls, should fix #1331 kes Apply python detect patch from Bastian Friedrich -- 2.39.5