Files
Danielkot 410b0acdb4 fix
2020-05-05 19:22:45 +00:00

318 lines
13 KiB
Bash
Executable File

#!/bin/bash
runit()
{
set -e
trap 'previous_command=$this_command; this_command=$BASH_COMMAND' DEBUG
trap 'echo FAILED COMMAND: $previous_command' EXIT
#### TU NIE ZMIENIAJ vvv
export TARGET="${1}"
export PREFIX="`pwd`/rel-bin/${TARGET}"
export PATH="${PREFIX}/bin:${PATH}"
export OUT="`pwd`/out"
export ARGS="--enable-multilib --enable-multiarch --enable-targets=all --disable-werror"
if command -v nproc >/dev/null; then
export nproc="$(( `nproc --all` * 2 ))"
elif command -v sysctl >/dev/null; then
export nproc="$(( `sysctl -n hw.ncpu` * 2 ))"
else
#domyslnie dwa rdzenie
export nproc="2"
fi
if [ "${buildnewlib}" -ne "0" ]; then
export EXTRA_ARGS="--with-newlib"
fi
if command -v gmake >/dev/null; then
export make="gmake"
else
export make="make"
fi
case "${2}" in
64)
export CC="${CROSS_COMPILE}gcc -m64"
export CXX="${CROSS_COMPILE}g++ -m64" ;;
32)
export CC="${CROSS_COMPILE}gcc -m32"
export CXX="${CROSS_COMPILE}g++ -m32" ;;
esac
mkdir -pv out logs
if echo "${glibc_version}" | grep -q "/"; then
export glibc_version_="`echo ${glibc_version} | tr '/' '-'`"
else
export glibc_version_="${glibc_version}"
fi
#### TU NIE ZMIENIAJ ^^^
download()
{
if [ ! -d gcc-dl ]; then
git clone --depth=1 -b ${gcc_version} "git://github.com/gcc-mirror/gcc" gcc-dl || return ${?}
fi
if [ ! -d glibc-dl ]; then
git clone --depth=1 -b ${glibc_version} "git://github.com/bminor/glibc" glibc-dl || return ${?}
fi
if [ ! -d linux-dl ]; then
git clone --depth=1 -b ${linux_version} "git://github.com/torvalds/linux" linux-dl || return ${?}
fi
if [ ! -d binutils-gdb-dl ]; then
git clone --depth=1 -b ${binutils_version} "git://github.com/bminor/binutils-gdb" binutils-gdb-dl || return ${?}
fi
if [ ! -d newlib-dl ]; then
git clone --depth=1 -b ${newlib_version} "git://github.com/bminor/newlib" newlib-dl || return ${?}
fi
}
build()
{
if [ "${buildnewlib}" -eq "0" ]; then
${make} -C linux-dl ARCH="`echo ${TARGET} | cut -f 1 -d '-' | sed -e s/i.86/x86/ -e s/x86_64/x86/ -e s/sun4u/sparc64/ -e s/arm.*/arm/ -e s/sa110/arm/ -e s/s390x/s390/ -e s/parisc64/parisc/ -e s/ppc.*/powerpc/ -e s/mips.*/mips/ -e s/sh[234].*/sh/ -e s/aarch64.*/arm64/ -e s/riscv.*/riscv/`" INSTALL_HDR_PATH="${PREFIX}/${TARGET}" headers_install | tee -i logs/${TARGET}-linux-headers.log || return ${?}
find ${PREFIX}/${TARGET} -name "..install.cmd" | xargs rm -rf || return ${?}
find ${PREFIX}/${TARGET} -name ".install" | xargs rm -rf || return ${?}
fi
mkdir -pv build-binutils || return ${?}
(cd build-binutils; ../binutils-gdb-dl/configure --target="${TARGET}" --prefix="${PREFIX}" --disable-nls --enable-obsolete --disable-debug ${ARGS}) | tee -i logs/${TARGET}-configure-binutils.log || return ${?}
${make} -C build-binutils -j${nproc} | tee -i logs/${TARGET}-build-binutils.log || return ${?}
${make} -C build-binutils -j${nproc} install | tee -i logs/${TARGET}-install-binutils.log || return ${?}
if [ ! -e gcc-dl/.dl_ok ]; then
(cd gcc-dl; contrib/download_prerequisites) | tee -i logs/${TARGET}-gcc-dl-prerequisites.log || return ${?}
touch gcc-dl/.dl_ok || return ${?}
fi
mkdir -pv build-gcc || return ${?}
(cd build-gcc; ../gcc-dl/configure --target="${TARGET}" --prefix="${PREFIX}" --enable-languages="c,c++" --with-pkgversion="*DANiO* GCC (`echo ${TARGET} | cut -f 1 -d '-'`)" ${ARGS} ${EXTRA_ARGS}) | tee -i logs/${TARGET}-configure-gcc.log || return ${?}
${make} -C build-gcc -j${nproc} all-gcc | tee -i logs/${TARGET}-gcc-all-gcc.log || return ${?}
${make} -C build-gcc -j${nproc} install-gcc | tee -i logs/${TARGET}-gcc-install-gcc.log || return ${?}
if [ "${buildnewlib}" -ne "0" ]; then
mkdir -pv build-newlib || return ${?}
(cd build-newlib; ../newlib-dl/configure --prefix="${PREFIX}" --target="${TARGET}" ${ARGS}) | tee -i logs/${TARGET}-configure-newlib.log || return ${?}
${make} -C build-newlib -j${nproc} | tee -i logs/${TARGET}-build-newlib.log || return ${?}
${make} -C build-newlib -j${nproc} install | tee -i logs/${TARGET}-install-newlib.log || return ${?}
#(cd gcc-dl; ln -svf ../newlib-dl/newlib newlib; ln -svf ../newlib-dl/libgloss libgloss) || return ${?}
${make} -C build-gcc -j${nproc} all-target-libgcc | tee -i logs/${TARGET}-gcc-all-target-libgcc.log || return ${?}
${make} -C build-gcc -j${nproc} install-target-libgcc | tee -i logs/${TARGET}-gcc-install-target-libgcc.log || return ${?}
else
mkdir -pv build-glibc || return ${?}
env CC="${TARGET}-gcc" CXX="${TARGET}-g++" sh -c '(cd build-glibc; ../glibc-dl/configure --prefix="${PREFIX}/${TARGET}" --host="${TARGET}" --with-headers="${PREFIX}/${TARGET}/include" --with-pkgversion="*DANiO* GLIBC (`echo ${TARGET} | cut -f 1 -d '-'`)" --enable-add-ons ${ARGS})' | tee -i logs/${TARGET}-configure-glibc.log || return ${?}
${make} -C build-glibc -j${nproc} install-bootstrap-headers=yes install-headers | tee -i logs/${TARGET}-bootstrap-headers-glibc.log || return ${?}
${make} -C build-glibc -j${nproc} csu/subdir_lib | tee -i logs/${TARGET}-build-glibc-csu.log || return ${?}
mkdir -pv ${PREFIX}/${TARGET}/lib || return ${?}
cp -ravf build-glibc/csu/crt1.o build-glibc/csu/crti.o build-glibc/csu/crtn.o ${PREFIX}/${TARGET}/lib | tee -i logs/${TARGET}-install-csu.log || return ${?}
#${TARGET}-gcc -nostdlib -nostartfiles -shared -x c /dev/null -o ${PREFIX}/${TARGET}/lib/libc.so || return ${?}
touch ${PREFIX}/${TARGET}/include/gnu/stubs.h || return ${?}
${make} -C build-gcc -j${nproc} all-target-libgcc | tee -i logs/${TARGET}-gcc-all-target-libgcc.log || return ${?}
${make} -C build-gcc -j${nproc} install-target-libgcc | tee -i logs/${TARGET}-gcc-install-target-libgcc.log || return ${?}
${make} -C build-glibc -j${nproc} | tee -i logs/${TARGET}-build-glibc.log || return ${?}
${make} -C build-glibc -j${nproc} install | tee -i logs/${TARGET}-install-glibc.log || return ${?}
fi
${make} -C build-gcc -j${nproc} all-target-libstdc++-v3 | tee -i logs/${TARGET}-gcc-all-target-libstdc++-v3.log || return ${?}
${make} -C build-gcc -j${nproc} install-target-libstdc++-v3 | tee -i logs/${TARGET}-gcc-install-target-libstdc++-v3.log || return ${?}
}
strip_n_pack()
{
#find ${PREFIX} -type f -not -path *${TARGET}/${TARGET}/* | xargs file | grep "ELF" | cut -f 1 -d ":" | xargs strip -S --strip-unneeded #for host
find ${PREFIX} -type f | xargs file | grep "ELF" | cut -f 1 -d ":" | xargs ${CROSS_COMPILE}strip -S --strip-unneeded #for host
find ${PREFIX}/${TARGET} -type f -name "*.a" | xargs ${TARGET}-strip -S --strip-unneeded #for sysroot
find ${PREFIX}/${TARGET} -type f -name "*.a" | xargs ${TARGET}-ranlib #for sysroot
find ${PREFIX}/${TARGET} -type f | xargs file | grep "ELF" | cut -f 1 -d ":" | xargs ${TARGET}-strip -S --strip-unneeded #for sysroot
if [ "${buildnewlib}" -ne "0" ]; then
if [ "${1}" = "64" ]; then
(cd rel-bin; tar -cJvf "${OUT}/${TARGET}-GCC_${gcc_version_}-newlib-`date +"%d-%m-%Y"`-`uname -s`_x86-64.txz" ${TARGET}) | tee -i logs/${TARGET}-package.log || return ${?}
else
(cd rel-bin; tar -cJvf "${OUT}/${TARGET}-GCC_${gcc_version_}-newlib-`date +"%d-%m-%Y"`-`uname -s`_x86-32.txz" ${TARGET}) | tee -i logs/${TARGET}-package.log || return ${?}
fi
else
if [ "${1}" = "64" ]; then
(cd rel-bin; tar -cJvf "${OUT}/${TARGET}-GCC_${gcc_version_}-glibc-`date +"%d-%m-%Y"`-`uname -s`_x86-64.txz" ${TARGET}) | tee -i logs/${TARGET}-package.log || return ${?}
else
(cd rel-bin; tar -cJvf "${OUT}/${TARGET}-GCC_${gcc_version_}-glibc-`date +"%d-%m-%Y"`-`uname -s`_x86-32.txz" ${TARGET}) | tee -i logs/${TARGET}-package.log || return ${?}
fi
fi
}
if [ "${clean}" -ne "0" ]; then
rm -rf build-* logs
fi
if ! download; then
trap - EXIT
echo "Error at \"download_n_extract\" section"
return 1
fi
if ! build; then
trap - EXIT
echo "Error at \"build\" section"
return 1
fi
if ! strip_n_pack ${2}; then
trap - EXIT
echo "Error at \"strip_n_pack ${2}\" section"
return 1
fi
}
ask_for_sub()
{
while :; do
clear || reset
echo "Would you like to build ${arch}-danio-linux-gnueabi{hf,} ?"
echo "[1] - yes"
echo "[2] - no"
read junk
case ${junk} in
1) return 0 ;;
2) return 1 ;;
esac
done
}
choose_sub()
{
while :; do
clear || reset
echo "Choose sub-base for ${arch}-danio-linux-"
echo "[1] is ${arch}-danio-linux-gnueabi"
echo "[2] is ${arch}-danio-linux-gnueabihf"
read junk
case ${junk} in
1) export SUBBASE="gnueabi"; break ;;
2) export SUBBASE="gnueabihf"; break ;;
*) echo "ONLY USE \"1\" OR \"2\"!"; sleep 2 ;;
esac
done
}
[ -z "${binutils_version}" ] && export binutils_version="master"
[ -z "${glibc_version}" ] && export glibc_version="master"
[ -z "${linux_version}" ] && export linux_version="master"
[ -z "${gcc_version}" ] && export gcc_version="master"
[ -z "${newlib_version}" ] && export newlib_version="master"
targets="`grep ' - t=' .travis.yml | cut -f 2 -d = | cut -f 1 -d ' ' | sort -u`"
if [ "${1}" -a "${2}" ]; then
if echo ${1} | grep -q "eabi"; then export buildnewlib="1"; fi
if echo ${1} | grep -q "elf"; then export buildnewlib="1"; fi
target="`echo ${1} | cut -d - -f1`"
mach="`echo ${1} | cut -d - -f2`"
runit "${target}-danio-${mach}" ${2}
elif [ "${AUTOBUILD}" ]; then
export clean="1"
if [ "${METHOD}" = "newlib" ]; then
export buildnewlib="1"
for i in ${targets}; do
runit ${i} 32
runit ${i} 64
done
elif [ "${METHOD}" = "glibc" ]; then
export buildnewlib="0"
for i in ${targets}; do
if echo ${i} | grep -q "eabi"; then continue; fi
if echo ${i} | grep -q "elf"; then continue; fi
runit ${i} 32
runit ${i} 64
done
else
echo "UNKNOWN OR EMPTY LIBC!"
echo "USE ONLY METHOD=\"glibc\" OR METHOD=\"newlib\" AS BASH EXVIRONMENT!"
fi
else
if ! command -v jq >/dev/null; then
echo "jq command not found, please install it before using this application!"
exit 1
fi
while :; do
clear || reset
echo "Please select architecture:"
for i in ${targets}; do
echo ${i} | cut -f 1 -d '-'
done
echo "------"
read arch
if [ "${arch}" != "" ]; then
break
fi
done
while :; do
clear || reset
echo "Would you like to build:"
echo "[1] is newlib toolchain"
echo "[2] is glibc toolchain"
echo "------"
echo "NOTE: On \"eabi\" and \"elf\" toolchains use newlib!"
read METHOD
case ${METHOD} in
1) export buildnewlib="1"; break ;;
2) export buildnewlib="0"; break ;;
*) echo "ONLY USE \"1\" or \"2\"!"; sleep 2 ;;
esac
done
while :; do
clear || reset
echo "what kind of based toolchain?"
echo "[1] is eabi"
echo "[2] is linux"
echo "[3] is elf"
read BASE
case ${BASE} in
1) export BASE="eabi"; break ;;
2) if ask_for_sub; then choose_sub; export BASE="linux-${SUBBASE}"; break; else export BASE="linux"; break; fi ;;
3) export BASE="elf"; break ;;
*) echo "ONLY USE \"1\", \"2\" or \"3\"!"; sleep 2 ;;
esac
done
while :; do
clear || reset
echo "What kind of binary format for final toolchain?"
echo "[1] is 32-bits (i686)"
echo "[2] is 64-bits (amd64)"
echo "------"
echo "NOTE: On 32-bits (i686) host machine you *CAN NOT* build 64-bits (amd64) binary format of toolchain!"
read BINARY
case ${BINARY} in
1) export BINARY="32"; break ;;
2) export BINARY="64"; break ;;
*) echo "ONLY USE \"1\" or \"2\"!"; sleep 2 ;;
esac
done
if [ "${CUSTOMBUILD}" ]; then
while :; do
clear || reset
echo "Please type gcc version or type \"master\" then press enter"
wget --no-check-cert -q -O - "http://api.github.com/repos/gcc-mirror/gcc/tags" | jq -r .[].name | sort
read gcc_version
export gcc_version="${gcc_version}"
if [ "${gcc_version}" != "" ]; then
break
fi
done
while :; do
clear || reset
echo "Please type binutils-gdb version or type \"master\" then press enter"
wget --no-check-cert -q -O - "http://api.github.com/repos/bminor/binutils-gdb/branches" | jq -r .[].name | sort
read binutils_version
export binutils_version="${binutils_version}"
if [ "${binutils_version}" != "" ]; then
break
fi
done
while :; do
clear || reset
echo "Please type linux (headers for gcc) version or type \"master\" then press enter"
wget --no-check-cert -q -O - "http://api.github.com/repos/torvalds/linux/tags" | jq -r .[].name | sort
read linux_version
export linux_version="${linux_version}"
if [ "${linux_version}" != "" ]; then
break
fi
done
while :; do
clear || reset
echo "Please type glibc (gnu-library-c) version or type \"master\" then press enter"
wget --no-check-cert -q -O - "http://api.github.com/repos/bminor/glibc/branches?page=3&per_page=100" | jq -r ".[] | select(.name | contains(\"release\")).name" | sort
read glibc_version
export glibc_version="${glibc_version}"
if [ "${glibc_version}" != "" ]; then
break
fi
done
fi
runit "${arch}-danio-${BASE}" "${BINARY}"
fi