Blame env/debian-7-64bit/files/install-mingw.sh

89a23b
#!/bin/bash
89a23b
89a23b
set -e
89a23b
89a23b
VER_BINUTILS="2.29.1"
89a23b
DIR_BINUTILS="binutils-$VER_BINUTILS"
89a23b
ARH_BINUTILS="$DIR_BINUTILS.tar.xz"
89a23b
URL_BINUTILS="https://ftp.gnu.org/gnu/binutils/$ARH_BINUTILS"
89a23b
89a23b
VER_GCC="7.2.0"
89a23b
DIR_GCC="gcc-$VER_GCC"
89a23b
ARH_GCC="$DIR_GCC.tar.xz"
89a23b
URL_GCC="https://ftp.gnu.org/gnu/gcc/gcc-$VER_GCC/$ARH_GCC"
89a23b
89a23b
VER_MINGW="5.0.3"
89a23b
DIR_MINGW="mingw-w64-v$VER_MINGW"
89a23b
ARH_MINGW="$DIR_MINGW.tar.bz2"
89a23b
URL_MINGW="https://sourceforge.net/projects/mingw-w64/files/mingw-w64/mingw-w64-release/$ARH_MINGW"
89a23b
89a23b
VER_ICONV="1.15"
89a23b
DIR_ICONV="libiconv-$VER_ICONV"
89a23b
ARH_ICONV="$DIR_ICONV.tar.gz"
89a23b
URL_ICONV="https://ftp.gnu.org/pub/gnu/libiconv/$ARH_ICONV"
89a23b
89a23b
VER_GETTEXT="0.19.7"
89a23b
DIR_GETTEXT="gettext-$VER_GETTEXT"
89a23b
ARH_GETTEXT="$DIR_GETTEXT.tar.gz"
89a23b
URL_GETTEXT="https://ftp.gnu.org/pub/gnu/gettext/$ARH_GETTEXT"
89a23b
89a23b
89a23b
THREADS=`nproc`
89a23b
INITIAL_PATH="$PATH"
89a23b
COMMAND="$0"
89a23b
89a23b
89a23b
if [ "$1" == "host_install" ]; then
89a23b
    PATH="/usr/local/$2/sys-root/bin:$PATH" make install
89a23b
    exit
89a23b
fi
89a23b
89a23b
89a23b
download() {
89a23b
    mkdir -p "install-mingw/download"
89a23b
    cd       "install-mingw/download"
89a23b
    if [ ! -f "done" ]; then
89a23b
        echo && echo "download" && echo
89a23b
89a23b
        wget -c --no-cookies --max-redirect 40 "$URL_BINUTILS"
89a23b
        wget -c --no-cookies --max-redirect 40 "$URL_GCC"
89a23b
        wget -c --no-cookies --max-redirect 40 "$URL_MINGW"
89a23b
        wget -c --no-cookies --max-redirect 40 "$URL_ICONV"
89a23b
        wget -c --no-cookies --max-redirect 40 "$URL_GETTEXT"
89a23b
89a23b
        tar -xf "../download/$ARH_BINUTILS"
89a23b
        tar -xf "../download/$ARH_GCC"
89a23b
        tar -xf "../download/$ARH_MINGW"
89a23b
        tar -xf "../download/$ARH_ICONV"
89a23b
        tar -xf "../download/$ARH_GETTEXT"
89a23b
89a23b
        touch "done"
89a23b
    fi
89a23b
    cd ../..
89a23b
}
89a23b
89a23b
install_binutils() {
89a23b
    local ARCH="$1"
89a23b
    mkdir -p "install-mingw/build/binutils-$ARCH"
89a23b
    cd       "install-mingw/build/binutils-$ARCH"
89a23b
    if [ ! -f "done" ]; then
89a23b
        echo && echo "install binutils $ARCH" && echo
89a23b
        if [ ! -f "configure.done" ]; then
89a23b
            "../../download/$DIR_BINUTILS/configure" \
89a23b
                --target="$ARCH" \
89a23b
                --disable-multilib \
89a23b
                --with-sysroot="/usr/local/$ARCH/sys-root" \
89a23b
                --prefix="/usr/local/$ARCH/sys-root"
89a23b
            touch "configure.done"
89a23b
        fi
89a23b
        make -j$THREADS || make
89a23b
        sudo make install
89a23b
        touch "done"
89a23b
    fi
89a23b
    cd ../../..
89a23b
}
89a23b
89a23b
install_headers() {
89a23b
    local ARCH="$1"
89a23b
    mkdir -p "install-mingw/build/headers-$ARCH"
89a23b
    cd       "install-mingw/build/headers-$ARCH"
89a23b
    if [ ! -f "done" ]; then
89a23b
        echo && echo "install headers $ARCH" && echo
89a23b
        if [ ! -f "configure.done" ]; then
89a23b
            "../../download/$DIR_MINGW/mingw-w64-headers/configure" \
89a23b
                --host="$ARCH" \
89a23b
                --prefix="/usr/local/$ARCH/sys-root"
89a23b
            touch "configure.done"
89a23b
        fi
89a23b
        make -j$THREADS || make
89a23b
        sudo make install
89a23b
        pushd "/usr/local/$ARCH/sys-root"
89a23b
        sudo ln -s . mingw
89a23b
        popd
89a23b
        touch "done"
89a23b
    fi
89a23b
    cd ../../..
89a23b
}
89a23b
89a23b
install_gcc() {
89a23b
    local ARCH="$1"
89a23b
    mkdir -p "install-mingw/build/gcc-$ARCH"
89a23b
    cd       "install-mingw/build/gcc-$ARCH"
89a23b
    if [ ! -f "gcc.done" ]; then
89a23b
        echo && echo "install gcc $ARCH" && echo
89a23b
        if [ ! -f "configure.done" ]; then
89a23b
            "../../download/$DIR_GCC/configure" \
89a23b
                --target="$ARCH" \
89a23b
                --disable-multilib \
89a23b
                --enable-shared \
b727d1
                --enable-threads=posix \
89a23b
                --with-sysroot="/usr/local/$ARCH/sys-root" \
89a23b
                --prefix="/usr/local/$ARCH/sys-root"
89a23b
            touch "configure.done"
89a23b
        fi
89a23b
        make -j$THREADS all-gcc || make
89a23b
        sudo make install-gcc
89a23b
        touch "gcc.done"
89a23b
    fi
89a23b
    cd ../../..
89a23b
}
89a23b
89a23b
install_crt() {
89a23b
    local ARCH="$1"
89a23b
    export PATH="/usr/local/$ARCH/sys-root/bin:$INITIAL_PATH"
89a23b
    mkdir -p "install-mingw/build/crt-$ARCH"
89a23b
    cd       "install-mingw/build/crt-$ARCH"
89a23b
    if [ ! -f "done" ]; then
89a23b
        echo && echo "install crt $ARCH" && echo
89a23b
        if [ ! -f "configure.done" ]; then
89a23b
            "../../download/$DIR_MINGW/mingw-w64-crt/configure" \
89a23b
                --host="$ARCH" \
89a23b
                --with-sysroot="/usr/local/$ARCH/sys-root" \
89a23b
                --prefix="/usr/local/$ARCH/sys-root"
89a23b
            touch "configure.done"
89a23b
        fi
89a23b
        make -j$THREADS || make
89a23b
        sudo "../../../$0" host_install "$ARCH"
89a23b
        touch "done"
89a23b
    fi
89a23b
    cd ../../..
89a23b
}
89a23b
89a23b
finish_gcc() {
89a23b
    local ARCH="$1"
89a23b
    export PATH="/usr/local/$ARCH/sys-root/bin:$INITIAL_PATH"
89a23b
    mkdir -p "install-mingw/build/gcc-$ARCH"
89a23b
    cd       "install-mingw/build/gcc-$ARCH"
89a23b
    if [ ! -f "done" ]; then
89a23b
        echo && echo "finish gcc $ARCH" && echo
89a23b
        make -j$THREADS || make
89a23b
        sudo "../../../$0" host_install "$ARCH"
89a23b
        touch "done"
89a23b
    fi
89a23b
    cd ../../..
89a23b
}
89a23b
b727d1
install_library() {
89a23b
    local ARCH="$1"
b727d1
    local NAME="$2"
89a23b
    export PATH="/usr/local/$ARCH/sys-root/bin:$INITIAL_PATH"
b727d1
    mkdir -p "install-mingw/build/mingw-$NAME-$ARCH"
b727d1
    cd       "install-mingw/build/mingw-$NAME-$ARCH"
89a23b
    if [ ! -f "done" ]; then
b727d1
        echo && echo "install library $NAME $ARCH" && echo
89a23b
        if [ ! -f "configure.done" ]; then
b727d1
            "../../download/$DIR_MINGW/mingw-w64-libraries/$NAME/configure" \
89a23b
                --host="$ARCH" \
89a23b
                --with-sysroot="/usr/local/$ARCH/sys-root" \
b727d1
                --prefix="/usr/local/$ARCH/sys-root" \
b727d1
                ${@:3}
89a23b
            touch "configure.done"
89a23b
        fi
89a23b
        make -j$THREADS || make
89a23b
        sudo "../../../$0" host_install "$ARCH"
89a23b
        touch "done"
89a23b
    fi
89a23b
    cd ../../..
89a23b
}
89a23b
b727d1
install_tool() {
89a23b
    local ARCH="$1"
b727d1
    local NAME="$2"
89a23b
    export PATH="/usr/local/$ARCH/sys-root/bin:$INITIAL_PATH"
b727d1
    mkdir -p "install-mingw/build/mingw-$NAME-$ARCH"
b727d1
    cd       "install-mingw/build/mingw-$NAME-$ARCH"
89a23b
    if [ ! -f "done" ]; then
b727d1
        echo && echo "install tool $NAME $ARCH" && echo
89a23b
        if [ ! -f "configure.done" ]; then
b727d1
            "../../download/$DIR_MINGW/mingw-w64-tools/$NAME/configure" \
b727d1
                --target="$ARCH" \
b727d1
                --prefix="/usr/local/$ARCH/sys-root" \
b727d1
                ${@:3}
89a23b
            touch "configure.done"
89a23b
        fi
89a23b
        make -j$THREADS || make
89a23b
        sudo "../../../$0" host_install "$ARCH"
89a23b
        touch "done"
89a23b
    fi
89a23b
    cd ../../..
89a23b
}
89a23b
89a23b
install_iconv() {
89a23b
    local ARCH="$1"
89a23b
    export PATH="/usr/local/$ARCH/sys-root/bin:$INITIAL_PATH"
89a23b
    mkdir -p "install-mingw/build/iconv-$ARCH"
89a23b
    cd       "install-mingw/build/iconv-$ARCH"
89a23b
    if [ ! -f "done" ]; then
89a23b
        echo && echo "install iconv $ARCH" && echo
89a23b
        if [ ! -f "configure.done" ]; then
89a23b
            "../../download/$DIR_ICONV/configure" \
89a23b
                --host="$ARCH" \
89a23b
                --enable-static \
89a23b
                --enable-shared \
89a23b
                --with-sysroot="/usr/local/$ARCH/sys-root" \
89a23b
                --prefix="/usr/local/$ARCH/sys-root"
89a23b
            touch "configure.done"
89a23b
        fi
89a23b
        make -j$THREADS || make
89a23b
        sudo "../../../$0" host_install "$ARCH"
89a23b
        touch "done"
89a23b
    fi
89a23b
    cd ../../..
89a23b
}
89a23b
89a23b
install_gettext() {
89a23b
    local ARCH="$1"
89a23b
    export PATH="/usr/local/$ARCH/sys-root/bin:$INITIAL_PATH"
89a23b
    mkdir -p "install-mingw/build/gettext-$ARCH"
89a23b
    cd       "install-mingw/build/gettext-$ARCH"
89a23b
    if [ ! -f "done" ]; then
89a23b
        echo && echo "install gettext $ARCH" && echo
89a23b
        if [ ! -f "configure.done" ]; then
89a23b
            "../../download/$DIR_GETTEXT/configure" \
89a23b
                --host="$ARCH" \
89a23b
                --disable-java \
89a23b
                --disable-native-java \
89a23b
                --disable-csharp \
89a23b
                --enable-static \
89a23b
                --enable-shared \
89a23b
                --enable-threads=win32 \
89a23b
                --without-emacs \
89a23b
                --disable-openmp \
89a23b
                --with-sysroot="/usr/local/$ARCH/sys-root" \
89a23b
                --prefix="/usr/local/$ARCH/sys-root"
89a23b
            touch "configure.done"
89a23b
        fi
89a23b
        make -j$THREADS || make
89a23b
        sudo "../../../$0" host_install "$ARCH"
89a23b
        touch "done"
89a23b
    fi
89a23b
    cd ../../..
89a23b
}
89a23b
89a23b
install_license() {
89a23b
    local NAME="$1"
89a23b
    local DIR_NAME="$2"
89a23b
    cd "install-mingw/download/$DIR_NAME"
89a23b
    if [ ! -f "../../build/$NAME.license.done" ]; then
89a23b
        echo && echo "install license $NAME" && echo
89a23b
        local TARGET="../../build/$NAME.license"
89a23b
        echo > "$TARGET"
89a23b
        for FILE in README COPYING* MAINTAINERS AUTHORS; do
89a23b
            if [ -f "$FILE" ]; then
89a23b
                echo ""                                      >> "$TARGET"
89a23b
                echo "-------------------------------------" >> "$TARGET"
89a23b
                echo "  File: $FILE"                         >> "$TARGET"
89a23b
                echo "-------------------------------------" >> "$TARGET"
89a23b
                echo ""                                      >> "$TARGET"
89a23b
                cat  "$FILE"                                 >> "$TARGET"
89a23b
            fi
89a23b
        done
89a23b
        sudo mkdir -p "/usr/local/share/doc/$NAME"
89a23b
        sudo cp "$TARGET" "/usr/local/share/doc/$NAME/copyright"
89a23b
        touch "../../build/$NAME.license.done"
89a23b
    fi
89a23b
    cd ../../..
89a23b
}
89a23b
89a23b
89a23b
install() {
89a23b
    local ARCH="$1"
89a23b
    install_binutils "$ARCH"
89a23b
    install_headers "$ARCH"
89a23b
    install_gcc "$ARCH"
89a23b
    install_crt "$ARCH"
b727d1
    install_library "$ARCH" "winpthreads"
89a23b
    finish_gcc "$ARCH"
b727d1
b727d1
    install_library "$ARCH" "libmangle"
b727d1
    install_library "$ARCH" "winstorecompat"
b727d1
    install_tool "$ARCH" "gendef"
b727d1
    install_tool "$ARCH" "genidl"
b727d1
    install_tool "$ARCH" "genlib"
b727d1
    install_tool "$ARCH" "genpeimg"
b727d1
    install_tool "$ARCH" "widl"
b727d1
89a23b
    install_iconv "$ARCH"
89a23b
    install_gettext "$ARCH"
89a23b
89a23b
    install_license gcc      "$DIR_GCC"
89a23b
    install_license g++      "$DIR_GCC"
89a23b
    install_license gfortran "$DIR_GCC"
89a23b
    install_license cc       "$DIR_GCC"
89a23b
    install_license c++      "$DIR_GCC"
89a23b
    install_license gfortran "$DIR_GCC"
89a23b
89a23b
    install_license mingw-w64 "$DIR_MINGW"
89a23b
    install_license iconv "$DIR_ICONV"
89a23b
    install_license gettext "$DIR_GETTEXT"
89a23b
}
89a23b
89a23b
clean() {
89a23b
    echo && echo "clean" && echo
89a23b
    rm -r install-mingw
89a23b
}
89a23b
89a23b
download
89a23b
install x86_64-w64-mingw32
89a23b
install i686-w64-mingw32
89a23b
clean
89a23b
89a23b
echo && echo "done" && echo