scripts/getExtractPatch.sh
changeset 63 89b41dbffe8d
parent 62 651912c5477c
child 64 7dab8d1a2426
     1.1 --- a/scripts/getExtractPatch.sh	Sun May 06 21:47:29 2007 +0000
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,334 +0,0 @@
     1.4 -# This script will download tarballs, extract them and patch the source.
     1.5 -# Copyright 2007 Yann E. MORIN
     1.6 -# Licensed under the GPL v2. See COPYING in the root of this package
     1.7 -
     1.8 -# Download tarballs in sequence. Once we have everything, start extracting
     1.9 -# and patching the tarballs.
    1.10 -
    1.11 -#-----------------------------------------------------------------------------
    1.12 -
    1.13 -_wget=`which wget || true`
    1.14 -_curl=`which curl || true`
    1.15 -#_svn=`which svn ||true`
    1.16 -#_cvs=`which cvs || true`
    1.17 -
    1.18 -case "${_wget},${_curl}" in
    1.19 -    ,)  CT_Abort "Found neither curl nor wget. Please install one.";;
    1.20 -    ,*) CT_DoLog DEBUG "Using curl to retrieve tarballs"; CT_DoGetFile=CT_DoGetFileCurl;;
    1.21 -    *)  CT_DoLog DEBUG "Using wget to retrieve tarballs"; CT_DoGetFile=CT_DoGetFileWget;;
    1.22 -esac
    1.23 -
    1.24 -CT_DoGetFileWget() {
    1.25 -    # Need to return true because it is legitimate to not find the tarball at
    1.26 -    # some of the provided URLs (think about snapshots, different layouts for
    1.27 -    # different gcc versions, etc...)
    1.28 -    # Some (very old!) FTP server might not support the passive mode, thus
    1.29 -    # retry without
    1.30 -    # With automated download as we are doing, it can be very dangerous to use
    1.31 -    # -c to continue the downloads. It's far better to simply overwrite the
    1.32 -    # destination file
    1.33 -    wget -nc --progress=dot:binary --tries=3 --passive-ftp "$1" || wget -nc --progress=dot:binary --tries=3 "$1" || true
    1.34 -}
    1.35 -
    1.36 -CT_DoGetFileCurl() {
    1.37 -	# Note: comments about wget method are also valid here
    1.38 -	# Plus: no good progreess indicator is available with curl,
    1.39 -	#       so output is consigned to oblivion
    1.40 -	curl --ftp-pasv -O --retry 3 "$1" >/dev/null || curl -O --retry 3 "$1" >/dev/null || true
    1.41 -}
    1.42 -
    1.43 -# For those wanting bleading edge, or to retrieve old uClibc snapshots
    1.44 -# Usage: CT_GetFileSVN basename url
    1.45 -#CT_DoGetFileSVN() {
    1.46 -#    local basename="$1"
    1.47 -#    local url="`echo \"$2\" |cut -d : -f 2-`"
    1.48 -#    local tmp_dir
    1.49 -#
    1.50 -#    CT_TestOrAbort "You don't have subversion" -n "${_svn}"
    1.51 -#    CT_MktempDir tmp_dir
    1.52 -#    CT_Pushd "${tmp_dir}"
    1.53 -#    svn export --force "${url}" "${basename}"
    1.54 -#    tar cfj "${CT_TARBALLS_DIR}/${basename}.tar.bz2" "${basename}"
    1.55 -#    CT_Popd
    1.56 -#    rm -rf "${tmp_dir}"
    1.57 -#}
    1.58 -#
    1.59 -#CT_DoGetFileCVS() {
    1.60 -#    :
    1.61 -#}
    1.62 -
    1.63 -# Download the file from one of the URLs passed as argument
    1.64 -# Usage: CT_GetFile <filename> <url> [<url> ...]
    1.65 -CT_GetFile() {
    1.66 -    local got_it
    1.67 -    local ext
    1.68 -    local url
    1.69 -    local file="$1"
    1.70 -    shift
    1.71 -
    1.72 -    # Do we already have it?
    1.73 -    ext=`CT_GetFileExtension "${file}"`
    1.74 -    if [ -n "${ext}" ]; then
    1.75 -        if [ "${CT_FORCE_DOWNLOAD}" = "y" ]; then
    1.76 -            rm -f "${CT_TARBALLS_DIR}/${file}${ext}"
    1.77 -        else
    1.78 -            return 0
    1.79 -        fi
    1.80 -    fi
    1.81 -
    1.82 -    CT_DoLog EXTRA "Retrieving \"${file}\""
    1.83 -    CT_Pushd "${CT_TARBALLS_DIR}"
    1.84 -    # File not yet downloaded, try to get it
    1.85 -    got_it=0
    1.86 -    if [ "${got_it}" != "y" ]; then
    1.87 -        # We'd rather have a bzip2'ed tarball, then gzipped, and finally plain tar.
    1.88 -        for ext in .tar.bz2 .tar.gz .tgz .tar; do
    1.89 -            # Try all urls in turn
    1.90 -            for url in "$@"; do
    1.91 -                case "${url}" in
    1.92 -#                    svn://*)    CT_DoGetFileSVN "${file}" ${url}";;
    1.93 -#                    cvs://*)    CT_DoGetFileCVS "${file}" ${url}";;
    1.94 -                    *)  CT_DoLog EXTRA "Trying \"${url}/${file}${ext}\""
    1.95 -                        ${CT_DoGetFile} "${url}/${file}${ext}" 2>&1 |CT_DoLog DEBUG
    1.96 -                        ;;
    1.97 -                esac
    1.98 -                [ -f "${file}${ext}" ] && got_it=1 && break 2 || true
    1.99 -            done
   1.100 -        done
   1.101 -    fi
   1.102 -    CT_Popd
   1.103 -
   1.104 -    CT_TestAndAbort "Could not download \"${file}\", and not present in \"${CT_TARBALLS_DIR}\"" ${got_it} -eq 0
   1.105 -}
   1.106 -
   1.107 -#-----------------------------------------------------------------------------
   1.108 -
   1.109 -# Extract a tarball and patch.
   1.110 -# Some tarballs need to be extracted in specific places. Eg.: glibc addons
   1.111 -# must be extracted in the glibc directory; uCLibc locales must be extracted
   1.112 -# in the extra/locale sub-directory of uClibc.
   1.113 -CT_ExtractAndPatch() {
   1.114 -    local file="$1"
   1.115 -    local base_file=`echo "${file}" |cut -d - -f 1`
   1.116 -    local ver_file=`echo "${file}" |cut -d - -f 2-`
   1.117 -    local official_patch_dir
   1.118 -    local custom_patch_dir
   1.119 -    local libc_addon
   1.120 -    local ext=`CT_GetFileExtension "${file}"`
   1.121 -    CT_TestAndAbort "\"${file}\" not found in \"${CT_TARBALLS_DIR}\"" -z "${ext}"
   1.122 -    local full_file="${CT_TARBALLS_DIR}/${file}${ext}"
   1.123 -
   1.124 -    CT_Pushd "${CT_SRC_DIR}"
   1.125 -
   1.126 -    # Add-ons need a little love, really.
   1.127 -    case "${file}" in
   1.128 -        glibc-[a-z]*-*)
   1.129 -            CT_TestAndAbort "Trying to extract the C-library addon/locales \"${file}\" when C-library not yet extracted" ! -d "${CT_LIBC_FILE}"
   1.130 -            cd "${CT_LIBC_FILE}"
   1.131 -            libc_addon=y
   1.132 -            [ -f ".${file}.extracted" ] && return 0
   1.133 -            touch ".${file}.extracted"
   1.134 -            ;;
   1.135 -        uClibc-locale-*)
   1.136 -            CT_TestAndAbort "Trying to extract the C-library addon/locales \"${file}\" when C-library not yet extracted" ! -d "${CT_LIBC_FILE}"
   1.137 -            cd "${CT_LIBC_FILE}/extra/locale"
   1.138 -            libc_addon=y
   1.139 -            [ -f ".${file}.extracted" ] && return 0
   1.140 -            touch ".${file}.extracted"
   1.141 -            ;;
   1.142 -    esac
   1.143 -
   1.144 -    # If the directory exists, then consider extraction and patching done
   1.145 -    [ -d "${file}" ] && return 0
   1.146 -
   1.147 -    CT_DoLog EXTRA "Extracting \"${file}\""
   1.148 -    case "${ext}" in
   1.149 -        .tar.bz2)     tar xvjf "${full_file}" |CT_DoLog DEBUG;;
   1.150 -        .tar.gz|.tgz) tar xvzf "${full_file}" |CT_DoLog DEBUG;;
   1.151 -        .tar)         tar xvf  "${full_file}" |CT_DoLog DEBUG;;
   1.152 -        *)            CT_Abort "Don't know how to handle \"${file}\": unknown extension" ;;
   1.153 -    esac
   1.154 -
   1.155 -    # Snapshots might not have the version number in the extracted directory
   1.156 -    # name. This is also the case for some (old) packages, such as libfloat.
   1.157 -    # Overcome this issue by symlink'ing the directory.
   1.158 -    if [ ! -d "${file}" -a "${libc_addon}" != "y" ]; then
   1.159 -        case "${ext}" in
   1.160 -            .tar.bz2)     base=`tar tjf "${full_file}" |head -n 1 |cut -d / -f 1 || true`;;
   1.161 -            .tar.gz|.tgz) base=`tar tzf "${full_file}" |head -n 1 |cut -d / -f 1 || true`;;
   1.162 -            .tar)         base=`tar tf  "${full_file}" |head -n 1 |cut -d / -f 1 || true`;;
   1.163 -        esac
   1.164 -        CT_TestOrAbort "There was a problem when extracting \"${file}\"" -d "${base}" -o "${base}" != "${file}"
   1.165 -        ln -s "${base}" "${file}"
   1.166 -    fi
   1.167 -
   1.168 -    # Kludge: outside this function, we wouldn't know if we had just extracted
   1.169 -    # a libc addon, or a plain package. Apply patches now.
   1.170 -    CT_DoLog EXTRA "Patching \"${file}\""
   1.171 -
   1.172 -    # If libc addon, we're already in the correct place.
   1.173 -    [ -z "${libc_addon}" ] && cd "${file}"
   1.174 -
   1.175 -    [ "${CUSTOM_PATCH_ONLY}" = "y" ] || official_patch_dir="${CT_TOP_DIR}/patches/${base_file}/${ver_file}"
   1.176 -    [ "${CT_CUSTOM_PATCH}" = "y" ] && custom_patch_dir="${CT_CUSTOM_PATCH_DIR}/${base_file}/${ver_file}"
   1.177 -    for patch_dir in "${official_patch_dir}" "${custom_patch_dir}"; do
   1.178 -        if [ -n "${patch_dir}" -a -d "${patch_dir}" ]; then
   1.179 -            for p in "${patch_dir}"/*.patch; do
   1.180 -                if [ -f "${p}" ]; then
   1.181 -                    CT_DoLog DEBUG "Applying patch \"${p}\""
   1.182 -                    patch -g0 -F1 -p1 -f <"${p}" |CT_DoLog DEBUG
   1.183 -                    CT_TestAndAbort "Failed while applying patch file \"${p}\"" ${PIPESTATUS[0]} -ne 0
   1.184 -                fi
   1.185 -            done
   1.186 -        fi
   1.187 -    done
   1.188 -
   1.189 -    CT_Popd
   1.190 -}
   1.191 -
   1.192 -#-----------------------------------------------------------------------------
   1.193 -
   1.194 -# Get the file name extension of a component
   1.195 -# Usage: CT_GetFileExtension <component-version>
   1.196 -# If found, echoes the extension to stdout
   1.197 -# If not found, echoes nothing on stdout.
   1.198 -CT_GetFileExtension() {
   1.199 -    local ext
   1.200 -    local file="$1"
   1.201 -    local got_it=1
   1.202 -
   1.203 -    CT_Pushd "${CT_TARBALLS_DIR}"
   1.204 -    for ext in .tar.gz .tar.bz2 .tgz .tar; do
   1.205 -        if [ -f "${file}${ext}" ]; then
   1.206 -            echo "${ext}"
   1.207 -            got_it=0
   1.208 -            break
   1.209 -        fi
   1.210 -    done
   1.211 -    CT_Popd
   1.212 -
   1.213 -    return 0
   1.214 -}
   1.215 -
   1.216 -#-----------------------------------------------------------------------------
   1.217 -
   1.218 -# Create needed directories, remove old ones
   1.219 -mkdir -p "${CT_TARBALLS_DIR}"
   1.220 -if [ "${CT_FORCE_EXTRACT}" = "y" -a -d "${CT_SRC_DIR}" ]; then
   1.221 -    mv "${CT_SRC_DIR}" "${CT_SRC_DIR}.$$"
   1.222 -    nohup rm -rf "${CT_SRC_DIR}.$$" >/dev/null 2>&1 &
   1.223 -fi
   1.224 -mkdir -p "${CT_SRC_DIR}"
   1.225 -
   1.226 -# Make all path absolute, it so much easier!
   1.227 -# Now we have had the directories created, we even will get rid of embedded .. in paths:
   1.228 -CT_SRC_DIR="`CT_MakeAbsolutePath \"${CT_SRC_DIR}\"`"
   1.229 -CT_TARBALLS_DIR="`CT_MakeAbsolutePath \"${CT_TARBALLS_DIR}\"`"
   1.230 -
   1.231 -# Prepare the addons list to be parsable:
   1.232 -addons_list="`echo \"${CT_LIBC_ADDONS_LIST}\" |sed -r -e 's/,/ /g; s/ $//g;'`"
   1.233 -
   1.234 -if [ "${CT_NO_DOWNLOAD}" != "y" ]; then
   1.235 -    CT_DoStep INFO "Retrieving needed toolchain components' tarballs"
   1.236 -
   1.237 -    # Kernel: for now, I don't care about cygwin.
   1.238 -    if [ "${CT_KERNEL_LINUX_HEADERS_USE_CUSTOM_DIR}" != "y" ]; then
   1.239 -        CT_GetFile "${CT_KERNEL_FILE}"                                  \
   1.240 -                   ftp://ftp.kernel.org/pub/linux/kernel/v2.6           \
   1.241 -                   ftp://ftp.kernel.org/pub/linux/kernel/v2.4           \
   1.242 -                   ftp://ftp.kernel.org/pub/linux/kernel/v2.2           \
   1.243 -                   ftp://ftp.kernel.org/pub/linux/kernel/v2.6/testing   \
   1.244 -                   http://ep09.pld-linux.org/~mmazur/linux-libc-headers
   1.245 -    fi
   1.246 -
   1.247 -    # binutils
   1.248 -    CT_GetFile "${CT_BINUTILS_FILE}"                            \
   1.249 -               ftp://ftp.gnu.org/gnu/binutils                   \
   1.250 -               ftp://ftp.kernel.org/pub/linux/devel/binutils
   1.251 -
   1.252 -    # Core and final gcc
   1.253 -    # Ah! gcc folks are kind of 'different': they store the tarballs in
   1.254 -    # subdirectories of the same name! That's because gcc is such /crap/ that
   1.255 -    # it is such /big/ that it needs being splitted for distribution! Sad. :-(
   1.256 -    # Arrgghh! Some of those versions does not follow this convention:
   1.257 -    # gcc-3.3.3 lives in releases/gcc-3.3.3, while gcc-2.95.* isn't in a
   1.258 -    # subdirectory! You bastard!
   1.259 -    CT_GetFile "${CT_CC_CORE_FILE}"                                    \
   1.260 -               ftp://ftp.gnu.org/gnu/gcc/${CT_CC_CORE_FILE}            \
   1.261 -               ftp://ftp.gnu.org/gnu/gcc/releases/${CT_CC_CORE_FILE}   \
   1.262 -               ftp://ftp.gnu.org/gnu/gcc
   1.263 -    CT_GetFile "${CT_CC_FILE}"                                  \
   1.264 -               ftp://ftp.gnu.org/gnu/gcc/${CT_CC_FILE}          \
   1.265 -               ftp://ftp.gnu.org/gnu/gcc/releases/${CT_CC_FILE} \
   1.266 -               ftp://ftp.gnu.org/gnu/gcc
   1.267 -
   1.268 -    # C library
   1.269 -    case "${CT_LIBC}" in
   1.270 -        glibc)
   1.271 -            # Ah! Not all GNU folks seem stupid. All glibc releases are in the same
   1.272 -            # directory. Good. Alas, there is no snapshot there. I'll deal with them
   1.273 -            # later on... :-/
   1.274 -            libc_src="ftp://ftp.gnu.org/gnu/glibc"
   1.275 -            ;;
   1.276 -        uClibc)
   1.277 -            # For uClibc, we have almost every thing: releases, and snapshots
   1.278 -            # for the last month or so. We'll have to deal with svn revisions
   1.279 -            # later...
   1.280 -            libc_src="http://www.uclibc.org/downloads
   1.281 -                      http://www.uclibc.org/downloads/snapshots
   1.282 -                      http://www.uclibc.org/downloads/old-releases"
   1.283 -            ;;
   1.284 -    esac
   1.285 -    CT_GetFile "${CT_LIBC_FILE}" ${libc_src}
   1.286 -
   1.287 -    # C library addons
   1.288 -    addons_list=`echo "${CT_LIBC_ADDONS}" |sed -r -e 's/,/ /g; s/ $//g;'`
   1.289 -    for addon in ${addons_list}; do
   1.290 -        CT_GetFile "${CT_LIBC}-${addon}-${CT_LIBC_VERSION}" ${libc_src}
   1.291 -    done
   1.292 -    [ "${CT_LIBC_GLIBC_USE_PORTS}" = "y" ] && CT_GetFile "${CT_LIBC}-ports-${CT_LIBC_VERSION}" ${libc_src}
   1.293 -    [ "${CT_LIBC_UCLIBC_LOCALES}" = "y" ] && CT_GetFile "uClibc-locale-030818" ${libc_src}
   1.294 -
   1.295 -    # libfloat if asked for
   1.296 -    if [ "${CT_ARCH_FLOAT_SW_LIBFLOAT}" = "y" ]; then
   1.297 -        lib_float_url="ftp://ftp.de.debian.org/debian/pool/main/libf/libfloat/"
   1.298 -
   1.299 -        # Please note: because the file we download, and the file we store on the
   1.300 -        # file system don't have the same name, CT_GetFile will always try to
   1.301 -        # download the file over and over.
   1.302 -        # To avoid this, we check that the file we want already exists in the
   1.303 -        # tarball directory first. This is an ugly hack that overrides the standard
   1.304 -        # CT_GetFile behavior... Sight...
   1.305 -        ext=`CT_GetFileExtension "${CT_LIBFLOAT_FILE}"`
   1.306 -        if [ -z "${ext}" ]; then
   1.307 -            CT_GetFile libfloat_990616.orig "${lib_float_url}"
   1.308 -            ext=`CT_GetFileExtension "libfloat_990616.orig"`
   1.309 -            # Hack: remove the .orig extension, and change _ to -
   1.310 -            mv -v "${CT_TARBALLS_DIR}/libfloat_990616.orig${ext}" \
   1.311 -                  "${CT_TARBALLS_DIR}/libfloat-990616${ext}"      2>&1 |CT_DoLog DEBUG
   1.312 -        fi
   1.313 -    fi
   1.314 -    
   1.315 -    CT_EndStep
   1.316 -fi # CT_NO_DOWNLOAD
   1.317 -
   1.318 -if [ "${CT_ONLY_DOWNLOAD}" != "y" ]; then
   1.319 -    CT_DoStep INFO "Extracting and patching toolchain components"
   1.320 -
   1.321 -    if [ "${CT_KERNEL_LINUX_HEADERS_USE_CUSTOM_DIR}" != "y" ]; then
   1.322 -        CT_ExtractAndPatch "${CT_KERNEL_FILE}"
   1.323 -    fi
   1.324 -    CT_ExtractAndPatch "${CT_BINUTILS_FILE}"
   1.325 -    CT_ExtractAndPatch "${CT_CC_CORE_FILE}"
   1.326 -    CT_ExtractAndPatch "${CT_CC_FILE}"
   1.327 -    CT_ExtractAndPatch "${CT_LIBC_FILE}"
   1.328 -    for addon in ${addons_list}; do
   1.329 -        CT_ExtractAndPatch "${CT_LIBC}-${addon}-${CT_LIBC_VERSION}"
   1.330 -    done
   1.331 -    [ "${CT_LIBC_GLIBC_USE_PORTS}" = "y" ] && CT_ExtractAndPatch "${CT_LIBC}-ports-${CT_LIBC_VERSION}"
   1.332 -    [ "${CT_LIBC_UCLIBC_LOCALES}" = "y" ] && CT_ExtractAndPatch "uClibc-locale-030818"
   1.333 -
   1.334 -    [ "${CT_ARCH_FLOAT_SW_LIBFLOAT}" = "y" ] && CT_ExtractAndPatch "${CT_LIBFLOAT_FILE}"
   1.335 -
   1.336 -    CT_EndStep
   1.337 -fi