yann@1: # This script will download tarballs, extract them and patch the source. yann@1: # Copyright 2007 Yann E. MORIN yann@1: # Licensed under the GPL v2. See COPYING in the root of this package yann@1: yann@1: # Download tarballs in sequence. Once we have everything, start extracting yann@1: # and patching the tarballs. yann@1: yann@1: #----------------------------------------------------------------------------- yann@1: yann@1: _wget=`which wget || true` yann@1: _curl=`which curl || true` yann@1: #_svn=`which svn ||true` yann@1: #_cvs=`which cvs || true` yann@1: yann@1: case "${_wget},${_curl}" in yann@1: ,) CT_Abort "Found neither curl nor wget. Please install one.";; yann@1: ,*) CT_DoLog DEBUG "Using curl to retrieve tarballs"; CT_DoGetFile=CT_DoGetFileCurl;; yann@1: *) CT_DoLog DEBUG "Using wget to retrieve tarballs"; CT_DoGetFile=CT_DoGetFileWget;; yann@1: esac yann@1: yann@1: CT_DoGetFileWget() { yann@23: # Need to return true because it is legitimate to not find the tarball at yann@1: # some of the provided URLs (think about snapshots, different layouts for yann@1: # different gcc versions, etc...) yann@1: # Some (very old!) FTP server might not support the passive mode, thus yann@1: # retry without yann@1: # With automated download as we are doing, it can be very dangerous to use yann@1: # -c to continue the downloads. It's far better to simply overwrite the yann@1: # destination file yann@1: wget -nc --progress=dot:binary --tries=3 --passive-ftp "$1" || wget -nc --progress=dot:binary --tries=3 "$1" || true yann@1: } yann@1: yann@1: CT_DoGetFileCurl() { yann@1: # Note: comments about wget method are also valid here yann@1: # Plus: no good progreess indicator is available with curl, yann@1: # so output is consigned to oblivion yann@1: curl --ftp-pasv -O --retry 3 "$1" >/dev/null || curl -O --retry 3 "$1" >/dev/null || true yann@1: } yann@1: yann@1: # For those wanting bleading edge, or to retrieve old uClibc snapshots yann@1: # Usage: CT_GetFileSVN basename url yann@1: #CT_DoGetFileSVN() { yann@1: # local basename="$1" yann@1: # local url="`echo \"$2\" |cut -d : -f 2-`" yann@1: # local tmp_dir yann@1: # yann@1: # CT_TestOrAbort "You don't have subversion" -n "${_svn}" yann@1: # CT_MktempDir tmp_dir yann@1: # CT_Pushd "${tmp_dir}" yann@1: # svn export --force "${url}" "${basename}" yann@1: # tar cfj "${CT_TARBALLS_DIR}/${basename}.tar.bz2" "${basename}" yann@1: # CT_Popd yann@1: # rm -rf "${tmp_dir}" yann@1: #} yann@1: # yann@1: #CT_DoGetFileCVS() { yann@1: # : yann@1: #} yann@1: yann@1: # Download the file from one of the URLs passed as argument yann@1: # Usage: CT_GetFile [ ...] yann@1: CT_GetFile() { yann@1: local got_it yann@1: local ext yann@1: local url yann@1: local file="$1" yann@1: shift yann@1: yann@1: # Do we already have it? yann@1: ext=`CT_GetFileExtension "${file}"` yann@1: if [ -n "${ext}" ]; then yann@1: if [ "${CT_FORCE_DOWNLOAD}" = "y" ]; then yann@1: rm -f "${CT_TARBALLS_DIR}/${file}${ext}" yann@1: else yann@1: return 0 yann@1: fi yann@1: fi yann@1: yann@1: CT_DoLog EXTRA "Retrieving \"${file}\"" yann@1: CT_Pushd "${CT_TARBALLS_DIR}" yann@1: # File not yet downloaded, try to get it yann@1: got_it=0 yann@1: if [ "${got_it}" != "y" ]; then yann@1: # We'd rather have a bzip2'ed tarball, then gzipped, and finally plain tar. yann@1: for ext in .tar.bz2 .tar.gz .tgz .tar; do yann@1: # Try all urls in turn yann@1: for url in "$@"; do yann@1: case "${url}" in yann@1: # svn://*) CT_DoGetFileSVN "${file}" ${url}";; yann@1: # cvs://*) CT_DoGetFileCVS "${file}" ${url}";; yann@1: *) CT_DoLog EXTRA "Trying \"${url}/${file}${ext}\"" yann@1: ${CT_DoGetFile} "${url}/${file}${ext}" 2>&1 |CT_DoLog DEBUG yann@1: ;; yann@1: esac yann@1: [ -f "${file}${ext}" ] && got_it=1 && break 2 || true yann@1: done yann@1: done yann@1: fi yann@1: CT_Popd yann@1: yann@1: CT_TestAndAbort "Could not download \"${file}\", and not present in \"${CT_TARBALLS_DIR}\"" ${got_it} -eq 0 yann@1: } yann@1: yann@1: #----------------------------------------------------------------------------- yann@1: yann@1: # Extract a tarball and patch. yann@1: # Some tarballs need to be extracted in specific places. Eg.: glibc addons yann@1: # must be extracted in the glibc directory; uCLibc locales must be extracted yann@1: # in the extra/locale sub-directory of uClibc. yann@1: CT_ExtractAndPatch() { yann@1: local file="$1" yann@1: local base_file=`echo "${file}" |cut -d - -f 1` yann@1: local ver_file=`echo "${file}" |cut -d - -f 2-` yann@1: local official_patch_dir yann@1: local custom_patch_dir yann@1: local libc_addon yann@1: local ext=`CT_GetFileExtension "${file}"` yann@1: CT_TestAndAbort "\"${file}\" not found in \"${CT_TARBALLS_DIR}\"" -z "${ext}" yann@1: local full_file="${CT_TARBALLS_DIR}/${file}${ext}" yann@1: yann@1: CT_Pushd "${CT_SRC_DIR}" yann@1: yann@1: # Add-ons need a little love, really. yann@1: case "${file}" in yann@1: glibc-[a-z]*-*) yann@1: CT_TestAndAbort "Trying to extract the C-library addon/locales \"${file}\" when C-library not yet extracted" ! -d "${CT_LIBC_FILE}" yann@1: cd "${CT_LIBC_FILE}" yann@1: libc_addon=y yann@1: [ -f ".${file}.extracted" ] && return 0 yann@1: touch ".${file}.extracted" yann@1: ;; yann@1: uClibc-locale-*) yann@1: CT_TestAndAbort "Trying to extract the C-library addon/locales \"${file}\" when C-library not yet extracted" ! -d "${CT_LIBC_FILE}" yann@1: cd "${CT_LIBC_FILE}/extra/locale" yann@1: libc_addon=y yann@1: [ -f ".${file}.extracted" ] && return 0 yann@1: touch ".${file}.extracted" yann@1: ;; yann@1: esac yann@1: yann@1: # If the directory exists, then consider extraction and patching done yann@1: [ -d "${file}" ] && return 0 yann@1: yann@1: CT_DoLog EXTRA "Extracting \"${file}\"" yann@1: case "${ext}" in yann@1: .tar.bz2) tar xvjf "${full_file}" |CT_DoLog DEBUG;; yann@1: .tar.gz|.tgz) tar xvzf "${full_file}" |CT_DoLog DEBUG;; yann@1: .tar) tar xvf "${full_file}" |CT_DoLog DEBUG;; yann@1: *) CT_Abort "Don't know how to handle \"${file}\": unknown extension" ;; yann@1: esac yann@1: yann@1: # Snapshots might not have the version number in the extracted directory yann@1: # name. This is also the case for some (old) packages, such as libfloat. yann@1: # Overcome this issue by symlink'ing the directory. yann@1: if [ ! -d "${file}" -a "${libc_addon}" != "y" ]; then yann@1: case "${ext}" in yann@1: .tar.bz2) base=`tar tjf "${full_file}" |head -n 1 |cut -d / -f 1 || true`;; yann@1: .tar.gz|.tgz) base=`tar tzf "${full_file}" |head -n 1 |cut -d / -f 1 || true`;; yann@1: .tar) base=`tar tf "${full_file}" |head -n 1 |cut -d / -f 1 || true`;; yann@1: esac yann@1: CT_TestOrAbort "There was a problem when extracting \"${file}\"" -d "${base}" -o "${base}" != "${file}" yann@1: ln -s "${base}" "${file}" yann@1: fi yann@1: yann@1: # Kludge: outside this function, we wouldn't know if we had just extracted yann@1: # a libc addon, or a plain package. Apply patches now. yann@1: CT_DoLog EXTRA "Patching \"${file}\"" yann@1: yann@1: # If libc addon, we're already in the correct place. yann@1: [ -z "${libc_addon}" ] && cd "${file}" yann@1: yann@1: [ "${CUSTOM_PATCH_ONLY}" = "y" ] || official_patch_dir="${CT_TOP_DIR}/patches/${base_file}/${ver_file}" yann@1: [ "${CT_CUSTOM_PATCH}" = "y" ] && custom_patch_dir="${CT_CUSTOM_PATCH_DIR}/${base_file}/${ver_file}" yann@1: for patch_dir in "${official_patch_dir}" "${custom_patch_dir}"; do yann@1: if [ -n "${patch_dir}" -a -d "${patch_dir}" ]; then yann@1: for p in "${patch_dir}"/*.patch; do yann@1: if [ -f "${p}" ]; then yann@1: CT_DoLog DEBUG "Applying patch \"${p}\"" yann@1: patch -g0 -F1 -p1 -f <"${p}" |CT_DoLog DEBUG yann@1: CT_TestAndAbort "Failed while applying patch file \"${p}\"" ${PIPESTATUS[0]} -ne 0 yann@1: fi yann@1: done yann@1: fi yann@1: done yann@1: yann@1: CT_Popd yann@1: } yann@1: yann@1: #----------------------------------------------------------------------------- yann@1: yann@1: # Get the file name extension of a component yann@1: # Usage: CT_GetFileExtension yann@1: # If found, echoes the extension to stdout yann@1: # If not found, echoes nothing on stdout. yann@1: CT_GetFileExtension() { yann@1: local ext yann@1: local file="$1" yann@1: local got_it=1 yann@1: yann@1: CT_Pushd "${CT_TARBALLS_DIR}" yann@1: for ext in .tar.gz .tar.bz2 .tgz .tar; do yann@1: if [ -f "${file}${ext}" ]; then yann@1: echo "${ext}" yann@1: got_it=0 yann@1: break yann@1: fi yann@1: done yann@1: CT_Popd yann@1: yann@1: return 0 yann@1: } yann@1: yann@1: #----------------------------------------------------------------------------- yann@1: yann@1: # Create needed directories, remove old ones yann@1: mkdir -p "${CT_TARBALLS_DIR}" yann@1: if [ "${CT_FORCE_EXTRACT}" = "y" -a -d "${CT_SRC_DIR}" ]; then yann@1: mv "${CT_SRC_DIR}" "${CT_SRC_DIR}.$$" yann@1: nohup rm -rf "${CT_SRC_DIR}.$$" >/dev/null 2>&1 & yann@1: fi yann@1: mkdir -p "${CT_SRC_DIR}" yann@1: yann@1: # Make all path absolute, it so much easier! yann@1: # Now we have had the directories created, we even will get rid of embedded .. in paths: yann@1: CT_SRC_DIR="`CT_MakeAbsolutePath \"${CT_SRC_DIR}\"`" yann@1: CT_TARBALLS_DIR="`CT_MakeAbsolutePath \"${CT_TARBALLS_DIR}\"`" yann@1: yann@1: # Prepare the addons list to be parsable: yann@1: addons_list="`echo \"${CT_LIBC_ADDONS_LIST}\" |sed -r -e 's/,/ /g; s/ $//g;'`" yann@1: yann@1: if [ "${CT_NO_DOWNLOAD}" != "y" ]; then yann@1: CT_DoStep INFO "Retrieving needed toolchain components' tarballs" yann@1: yann@1: # Kernel: for now, I don't care about cygwin. yann@1: CT_GetFile "${CT_KERNEL_FILE}" \ yann@1: ftp://ftp.kernel.org/pub/linux/kernel/v2.6 \ yann@1: ftp://ftp.kernel.org/pub/linux/kernel/v2.4 \ yann@1: ftp://ftp.kernel.org/pub/linux/kernel/v2.2 \ yann@1: ftp://ftp.kernel.org/pub/linux/kernel/v2.6/testing \ yann@1: http://ep09.pld-linux.org/~mmazur/linux-libc-headers yann@1: yann@1: # binutils yann@1: CT_GetFile "${CT_BINUTILS_FILE}" \ yann@1: ftp://ftp.gnu.org/gnu/binutils \ yann@1: ftp://ftp.kernel.org/pub/linux/devel/binutils yann@1: yann@1: # Core and final gcc yann@1: # Ah! gcc folks are kind of 'different': they store the tarballs in yann@1: # subdirectories of the same name! That's because gcc is such /crap/ that yann@1: # it is such /big/ that it needs being splitted for distribution! Sad. :-( yann@1: # Arrgghh! Some of those versions does not follow this convention: yann@1: # gcc-3.3.3 lives in releases/gcc-3.3.3, while gcc-2.95.* isn't in a yann@1: # subdirectory! You bastard! yann@1: CT_GetFile "${CT_CC_CORE_FILE}" \ yann@1: ftp://ftp.gnu.org/gnu/gcc/${CT_CC_CORE_FILE} \ yann@1: ftp://ftp.gnu.org/gnu/gcc/releases/${CT_CC_CORE_FILE} \ yann@1: ftp://ftp.gnu.org/gnu/gcc yann@1: CT_GetFile "${CT_CC_FILE}" \ yann@1: ftp://ftp.gnu.org/gnu/gcc/${CT_CC_FILE} \ yann@1: ftp://ftp.gnu.org/gnu/gcc/releases/${CT_CC_FILE} \ yann@1: ftp://ftp.gnu.org/gnu/gcc yann@1: yann@1: # C library yann@1: case "${CT_LIBC}" in yann@1: glibc) yann@1: # Ah! Not all GNU folks seem stupid. All glibc releases are in the same yann@1: # directory. Good. Alas, there is no snapshot there. I'll deal with them yann@1: # later on... :-/ yann@1: libc_src="ftp://ftp.gnu.org/gnu/glibc" yann@1: ;; yann@1: uClibc) yann@1: # For uClibc, we have almost every thing: releases, and snapshots yann@1: # for the last month or so. We'll have to deal with svn revisions yann@1: # later... yann@1: libc_src="http://www.uclibc.org/downloads yann@1: http://www.uclibc.org/downloads/snapshots yann@1: http://www.uclibc.org/downloads/old-releases" yann@1: ;; yann@1: esac yann@1: CT_GetFile "${CT_LIBC_FILE}" ${libc_src} yann@1: yann@1: # C library addons yann@1: addons_list=`echo "${CT_LIBC_ADDONS}" |sed -r -e 's/,/ /g; s/ $//g;'` yann@1: for addon in ${addons_list}; do yann@16: CT_GetFile "${CT_LIBC}-${addon}-${CT_LIBC_VERSION}" ${libc_src} yann@1: done yann@16: [ "${CT_LIBC_GLIBC_USE_PORTS}" = "y" ] && CT_GetFile "${CT_LIBC}-ports-${CT_LIBC_VERSION}" ${libc_src} yann@16: [ "${CT_LIBC_UCLIBC_LOCALES}" = "y" ] && CT_GetFile "uClibc-locale-030818" ${libc_src} yann@1: yann@1: # libfloat if asked for yann@1: if [ "${CT_ARCH_FLOAT_SW_LIBFLOAT}" = "y" ]; then yann@1: lib_float_url="ftp://ftp.de.debian.org/debian/pool/main/libf/libfloat/" yann@1: yann@1: # Please note: because the file we download, and the file we store on the yann@1: # file system don't have the same name, CT_GetFile will always try to yann@1: # download the file over and over. yann@1: # To avoid this, we check that the file we want already exists in the yann@1: # tarball directory first. This is an ugly hack that overrides the standard yann@1: # CT_GetFile behavior... Sight... yann@1: ext=`CT_GetFileExtension "${CT_LIBFLOAT_FILE}"` yann@1: if [ -z "${ext}" ]; then yann@1: CT_GetFile libfloat_990616.orig "${lib_float_url}" yann@1: ext=`CT_GetFileExtension "libfloat_990616.orig"` yann@1: # Hack: remove the .orig extension, and change _ to - yann@1: mv -v "${CT_TARBALLS_DIR}/libfloat_990616.orig${ext}" \ yann@1: "${CT_TARBALLS_DIR}/libfloat-990616${ext}" 2>&1 |CT_DoLog DEBUG yann@1: fi yann@1: fi yann@1: yann@1: CT_EndStep yann@1: fi # CT_NO_DOWNLOAD yann@1: yann@1: if [ "${CT_ONLY_DOWNLOAD}" != "y" ]; then yann@1: CT_DoStep INFO "Extracting and patching toolchain components" yann@1: yann@1: CT_ExtractAndPatch "${CT_KERNEL_FILE}" yann@1: CT_ExtractAndPatch "${CT_BINUTILS_FILE}" yann@1: CT_ExtractAndPatch "${CT_CC_CORE_FILE}" yann@1: CT_ExtractAndPatch "${CT_CC_FILE}" yann@1: CT_ExtractAndPatch "${CT_LIBC_FILE}" yann@1: for addon in ${addons_list}; do yann@1: CT_ExtractAndPatch "${CT_LIBC}-${addon}-${CT_LIBC_VERSION}" yann@1: done yann@16: [ "${CT_LIBC_GLIBC_USE_PORTS}" = "y" ] && CT_ExtractAndPatch "${CT_LIBC}-ports-${CT_LIBC_VERSION}" yann@16: [ "${CT_LIBC_UCLIBC_LOCALES}" = "y" ] && CT_ExtractAndPatch "uClibc-locale-030818" yann@1: yann@1: [ "${CT_ARCH_FLOAT_SW_LIBFLOAT}" = "y" ] && CT_ExtractAndPatch "${CT_LIBFLOAT_FILE}" yann@1: yann@1: CT_EndStep yann@1: fi