scripts/build/libc/uClibc.sh
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Sun Jan 04 14:38:41 2009 +0000 (2009-01-04)
changeset 1121 4b7ed9da5a21
parent 1112 c72aecd1a9ef
child 1123 8c5881324a79
permissions -rw-r--r--
Remove support for gcc-2.95.3, it has never ever been tested.

/trunk/config/cc/gcc.in | 6 0 6 0 ------
/trunk/scripts/build/libc/glibc.sh | 4 0 4 0 ----
/trunk/scripts/build/libc/uClibc.sh | 4 0 4 0 ----
3 files changed, 14 deletions(-)
     1 # This file declares functions to install the uClibc C library
     2 # Copyright 2007 Yann E. MORIN
     3 # Licensed under the GPL v2. See COPYING in the root of this package
     4 
     5 # Download uClibc
     6 do_libc_get() {
     7     libc_src="http://www.uclibc.org/downloads
     8               http://www.uclibc.org/downloads/snapshots
     9               http://www.uclibc.org/downloads/old-releases"
    10     # For uClibc, we have almost every thing: releases, and snapshots
    11     # for the last month or so. We'll have to deal with svn revisions
    12     # later...
    13     CT_GetFile "${CT_LIBC_FILE}" ${libc_src}
    14     # uClibc locales
    15     [ "${CT_LIBC_UCLIBC_LOCALES}" = "y" ] && CT_GetFile "uClibc-locale-030818" ${libc_src} || true
    16 
    17     return 0
    18 }
    19 
    20 # Extract uClibc
    21 do_libc_extract() {
    22     CT_ExtractAndPatch "${CT_LIBC_FILE}"
    23     # uClibc locales
    24     [ "${CT_LIBC_UCLIBC_LOCALES}" = "y" ] && CT_ExtractAndPatch "uClibc-locale-030818" || true
    25 
    26     return 0
    27 }
    28 
    29 # Check that uClibc has been previously configured
    30 do_libc_check_config() {
    31     CT_DoStep INFO "Checking C library configuration"
    32 
    33     CT_TestOrAbort "You did not provide a uClibc config file!" -n "${CT_LIBC_UCLIBC_CONFIG_FILE}" -a -f "${CT_LIBC_UCLIBC_CONFIG_FILE}"
    34 
    35     if egrep '^KERNEL_SOURCE=' "${CT_LIBC_UCLIBC_CONFIG_FILE}" >/dev/null 2>&1; then
    36         CT_DoLog WARN "Your uClibc version refers to the kernel _sources_, which is bad."
    37         CT_DoLog WARN "I can't guarantee that our little hack will work. Please try to upgrade."
    38     fi
    39 
    40     CT_DoLog EXTRA "Munging uClibc configuration"
    41     mungeuClibcConfig "${CT_LIBC_UCLIBC_CONFIG_FILE}" "${CT_BUILD_DIR}/uClibc.config"
    42 
    43     CT_EndStep
    44 }
    45 
    46 # This functions installs uClibc's headers
    47 do_libc_headers() {
    48     CT_DoStep INFO "Installing C library headers"
    49 
    50     mkdir -p "${CT_BUILD_DIR}/build-libc-headers"
    51     cd "${CT_BUILD_DIR}/build-libc-headers"
    52 
    53     # Simply copy files until uClibc has the ablity to build out-of-tree
    54     CT_DoLog EXTRA "Copying sources to build dir"
    55     { cd "${CT_SRC_DIR}/${CT_LIBC_FILE}"; tar cf - .; } |tar xf -
    56 
    57     # Retrieve the config file
    58     cp "${CT_BUILD_DIR}/uClibc.config" .config
    59 
    60     # uClibc uses the CROSS environment variable as a prefix to the
    61     # compiler tools to use.  Setting it to the empty string forces
    62     # use of the native build host tools, which we need at this
    63     # stage, as we don't have target tools yet.
    64     CT_DoLog EXTRA "Applying configuration"
    65     CT_DoYes "" |CT_DoExecLog ALL make CROSS= PREFIX="${CT_SYSROOT_DIR}/" oldconfig
    66 
    67     CT_DoLog EXTRA "Building headers"
    68     CT_DoExecLog ALL make ${CT_LIBC_UCLIBC_VERBOSITY} CROSS= PREFIX="${CT_SYSROOT_DIR}/" headers
    69 
    70     CT_DoLog EXTRA "Installing headers"
    71     CT_DoExecLog ALL make ${CT_LIBC_UCLIBC_VERBOSITY} CROSS= PREFIX="${CT_SYSROOT_DIR}/" install_headers
    72 
    73     CT_EndStep
    74 }
    75 
    76 # Build and install start files
    77 do_libc_start_files() {
    78     :
    79 }
    80 
    81 # This function build and install the full uClibc
    82 do_libc() {
    83     CT_DoStep INFO "Installing C library"
    84 
    85     mkdir -p "${CT_BUILD_DIR}/build-libc"
    86     cd "${CT_BUILD_DIR}/build-libc"
    87 
    88     # Simply copy files until uClibc has the ablity to build out-of-tree
    89     CT_DoLog EXTRA "Copying sources to build dir"
    90     { cd "${CT_SRC_DIR}/${CT_LIBC_FILE}"; tar cf - .; } |tar xf -
    91 
    92     # Retrieve the config file
    93     cp "${CT_BUILD_DIR}/uClibc.config" .config
    94 
    95     # uClibc uses the CROSS environment variable as a prefix to the compiler
    96     # tools to use.  The newly built tools should be in our path, so we need
    97     # only give the correct name for them.
    98     # Note about CFLAGS: In uClibc, CFLAGS are generated by Rules.mak,
    99     # depending  on the configuration of the library. That is, they are tailored
   100     # to best fit the target. So it is useless and seems to be a bad thing to
   101     # use LIBC_EXTRA_CFLAGS here.
   102     CT_DoLog EXTRA "Applying configuration"
   103     CT_DoYes "" |CT_DoExecLog ALL               \
   104                  make CROSS=${CT_TARGET}-       \
   105                  PREFIX="${CT_SYSROOT_DIR}/"    \
   106                  oldconfig
   107 
   108     # We do _not_ want to strip anything for now, in case we specifically
   109     # asked for a debug toolchain, thus the STRIPTOOL= assignment
   110     # /Old/ versions can not build in //
   111     CT_DoLog EXTRA "Building C library"
   112     CT_DoExecLog ALL                                    \
   113     make ${CT_LIBC_UCLIBC_PARALLEL:+${PARALLELMFLAGS}}  \
   114          CROSS=${CT_TARGET}-                            \
   115          PREFIX="${CT_SYSROOT_DIR}/"                    \
   116          STRIPTOOL=true                                 \
   117          ${CT_LIBC_UCLIBC_VERBOSITY}                    \
   118          all
   119 
   120     # YEM-FIXME: we want to install libraries in $SYSROOT/lib, but we don't want
   121     # to install headers in $SYSROOT/include, thus making only install_runtime.
   122     # Plus, the headers were previously installed earlier with install_headers,
   123     # so all should be well. Unfortunately, the install_headers target does not
   124     # install crti.o and consorts... :-( So reverting to target 'install'.
   125     # Note: PARALLELMFLAGS is not usefull for installation.
   126     # We do _not_ want to strip anything for now, in case we specifically
   127     # asked for a debug toolchain, hence the STRIPTOOL= assignment
   128     CT_DoLog EXTRA "Installing C library"
   129     CT_DoExecLog ALL                    \
   130     make CROSS=${CT_TARGET}-            \
   131          PREFIX="${CT_SYSROOT_DIR}/"    \
   132          STRIPTOOL=true                 \
   133          ${CT_LIBC_UCLIBC_VERBOSITY}    \
   134          install
   135 
   136     CT_EndStep
   137 }
   138 
   139 # This function is used to install those components needing the final C compiler
   140 do_libc_finish() {
   141     # Build and install host-side ldd
   142     CT_DoStep INFO "Finishing C library"
   143 
   144     mkdir -p "${CT_BUILD_DIR}/build-libc-finish"
   145     cd "${CT_BUILD_DIR}/build-libc-finish"
   146 
   147     # Simply copy files until uClibc has the ablity to build out-of-tree
   148     CT_DoLog EXTRA "Copying sources to build dir"
   149     { cd "${CT_SRC_DIR}/${CT_LIBC_FILE}"; tar cf - .; } |tar xf -
   150 
   151     # Retrieve the config file
   152     cp "${CT_BUILD_DIR}/uClibc.config" .config
   153 
   154     CT_DoLog EXTRA "Applying configuration"
   155     CT_DoYes "" |CT_DoExecLog ALL               \
   156                  make CROSS=${CT_TARGET}-       \
   157                  PREFIX="${CT_SYSROOT_DIR}/"    \
   158                  oldconfig
   159 
   160     CT_DoLog EXTRA "Installing C library host utils"
   161     CT_DoExecLog ALL                    \
   162     make PREFIX="${CT_SYSROOT_DIR}/"    \
   163          ${CT_LIBC_UCLIBC_VERBOSITY}    \
   164          -C utils hostutils
   165     CT_DoExecLog ALL install -m 0755 utils/ldd.host "${CT_PREFIX_DIR}/bin/${CT_TARGET}-ldd"
   166 
   167     CT_EndStep
   168 }
   169 
   170 # Initialises the .config file to sensible values
   171 # $1: original file
   172 # $2: munged file
   173 mungeuClibcConfig() {
   174     src_config_file="$1"
   175     dst_config_file="$2"
   176     munge_file="${CT_BUILD_DIR}/munge-uClibc-config.sed"
   177 
   178     # Start with a fresh file
   179     rm -f "${munge_file}"
   180     touch "${munge_file}"
   181 
   182     # Hack our target in the config file.
   183     # Also remove stripping: its the responsibility of the
   184     # firmware builder to strip or not.
   185     cat >>"${munge_file}" <<-ENDSED
   186 s/^(TARGET_.*)=y$/# \\1 is not set/
   187 s/^# TARGET_${CT_KERNEL_ARCH} is not set/TARGET_${CT_KERNEL_ARCH}=y/
   188 s/^TARGET_ARCH=".*"/TARGET_ARCH="${CT_KERNEL_ARCH}"/
   189 s/.*(DOSTRIP).*/# \\1 is not set/
   190 ENDSED
   191 
   192     # Ah. We may one day need architecture-specific handler here...
   193     # Hack the ARM {E,O}ABI into the config file
   194     if [ "${CT_ARCH_ARM_EABI}" = "y" ]; then
   195         cat >>"${munge_file}" <<-ENDSED
   196 s/.*(CONFIG_ARM_OABI).*/# \\1 is not set/
   197 s/.*(CONFIG_ARM_EABI).*/\\1=y/
   198 ENDSED
   199     else
   200         cat >>"${munge_file}" <<-ENDSED
   201 s/.*(CONFIG_ARM_OABI).*/\\1=y/
   202 s/.*(CONFIG_ARM_EABI).*/# \\1 is not set/
   203 ENDSED
   204     fi
   205 
   206     # Accomodate for old and new uClibc versions, where the
   207     # way to select between big/little endian has changed
   208     case "${CT_ARCH_BE},${CT_ARCH_LE}" in
   209         y,) cat >>"${munge_file}" <<-ENDSED
   210 s/.*(ARCH_LITTLE_ENDIAN).*/# \\1 is not set/
   211 s/.*(ARCH_BIG_ENDIAN).*/\\1=y/
   212 s/.*(ARCH_WANTS_LITTLE_ENDIAN).*/# \\1 is not set/
   213 s/.*(ARCH_WANTS_BIG_ENDIAN).*/\\1=y/
   214 ENDSED
   215         ;;
   216         ,y) cat >>"${munge_file}" <<-ENDSED
   217 s/.*(ARCH_LITTLE_ENDIAN).*/\\1=y/
   218 s/.*(ARCH_BIG_ENDIAN).*/# \\1 is not set/
   219 s/.*(ARCH_WANTS_LITTLE_ENDIAN).*/\\1=y/
   220 s/.*(ARCH_WANTS_BIG_ENDIAN).*/# \\1 is not set/
   221 ENDSED
   222         ;;
   223     esac
   224 
   225     # Accomodate for old and new uClibc version, where the
   226     # way to select between hard/soft float has changed
   227     case "${CT_ARCH_FLOAT_HW},${CT_ARCH_FLOAT_SW}" in
   228         y,) cat >>"${munge_file}" <<-ENDSED
   229 s/^[^_]*(HAS_FPU).*/\\1=y/
   230 s/.*(UCLIBC_HAS_FPU).*/\\1=y/
   231 ENDSED
   232             ;;
   233         ,y) cat >>"${munge_file}" <<-ENDSED
   234 s/^[^_]*(HAS_FPU).*/\\# \\1 is not set/
   235 s/.*(UCLIBC_HAS_FPU).*/# \\1 is not set/
   236 ENDSED
   237             ;;
   238     esac
   239 
   240     # Change paths to work with crosstool-NG
   241     # From http://www.uclibc.org/cgi-bin/viewcvs.cgi?rev=16846&view=rev
   242     #  " we just want the kernel headers, not the whole kernel source ...
   243     #  " so people may need to update their paths slightly
   244     quoted_kernel_source=$(echo "${CT_HEADERS_DIR}" | sed -r -e 's,/include/?$,,; s,/,\\/,g;')
   245     quoted_headers_dir=$(echo "${CT_HEADERS_DIR}" | sed -r -e 's,/,\\/,g;')
   246     # CROSS_COMPILER_PREFIX is left as is, as the CROSS parameter is forced on the command line
   247     # DEVEL_PREFIX is left as '/usr/' because it is post-pended to $PREFIX, wich is the correct value of ${PREFIX}/${TARGET}
   248     # Some (old) versions of uClibc use KERNEL_SOURCE (which is _wrong_), and
   249     # newer versions use KERNEL_HEADERS (which is right). See:
   250     cat >>"${munge_file}" <<-ENDSED
   251 s/^DEVEL_PREFIX=".*"/DEVEL_PREFIX="\\/usr\\/"/
   252 s/^RUNTIME_PREFIX=".*"/RUNTIME_PREFIX="\\/"/
   253 s/^SHARED_LIB_LOADER_PREFIX=.*/SHARED_LIB_LOADER_PREFIX="\\/lib\\/"/
   254 s/^KERNEL_SOURCE=".*"/KERNEL_SOURCE="${quoted_kernel_source}"/
   255 s/^KERNEL_HEADERS=".*"/KERNEL_HEADERS="${quoted_headers_dir}"/
   256 s/^UCLIBC_DOWNLOAD_PREGENERATED_LOCALE=y/\\# UCLIBC_DOWNLOAD_PREGENERATED_LOCALE is not set/
   257 ENDSED
   258 
   259     if [ "${CT_USE_PIPES}" = "y" ]; then
   260         if grep UCLIBC_EXTRA_CFLAGS extra/Configs/Config.in >/dev/null 2>&1; then
   261             # Good, there is special provision for such things as -pipe!
   262             cat >>"${munge_file}" <<-ENDSED
   263 s/^(UCLIBC_EXTRA_CFLAGS=".*)"$/\\1 -pipe"/
   264 ENDSED
   265         else
   266             # Hack our -pipe into WARNINGS, which will be internally incorporated to
   267             # CFLAGS. This a dirty hack, but yet needed
   268             cat >> "${munge_file}" <<-ENDSED
   269 s/^(WARNINGS=".*)"$/\\1 -pipe"/
   270 ENDSED
   271         fi
   272     fi
   273 
   274     # Locales support
   275     # Note that the two PREGEN_LOCALE and the XLOCALE lines may be missing
   276     # entirely if LOCALE is not set.  If LOCALE was already set, we'll
   277     # assume the user has already made all the appropriate generation
   278     # arrangements.  Note that having the uClibc Makefile download the
   279     # pregenerated locales is not compatible with crosstool; besides,
   280     # crosstool downloads them as part of getandpatch.sh.
   281     if [ "${CT_LIBC_UCLIBC_LOCALES}" = "y" ] ; then
   282        cat >>"${munge_file}" <<-ENDSED
   283 s/^# UCLIBC_HAS_LOCALE is not set/UCLIBC_HAS_LOCALE=y\\nUCLIBC_PREGENERATED_LOCALE_DATA=y\\n\\# UCLIBC_DOWNLOAD_PREGENERATED_LOCALE_DATA is not set\\n\\# UCLIBC_HAS_XLOCALE is not
   284 ENDSED
   285     fi
   286 
   287     # Force on options needed for C++ if we'll be making a C++ compiler.
   288     # I'm not sure locales are a requirement for doing C++... Are they?
   289     if [ "${CT_CC_LANG_CXX}" = "y" ]; then
   290         cat >>"${munge_file}" <<-ENDSED
   291 s/^# DO_C99_MATH is not set/DO_C99_MATH=y/
   292 s/^# UCLIBC_CTOR_DTOR is not set/UCLIBC_CTOR_DTOR=y/
   293 # Add these three lines when doing C++?
   294 s/^# UCLIBC_HAS_WCHAR is not set/UCLIBC_HAS_WCHAR=y/
   295 #s/^# UCLIBC_HAS_LOCALE is not set/UCLIBC_HAS_LOCALE=y\\nUCLIBC_PREGENERATED_LOCALE_DATA=y\\n\\# UCLIBC_DOWNLOAD_PREGENERATED_LOCALE_DATA is not set\\n\\# UCLIBC_HAS_XLOCALE is not set/
   296 s/^# UCLIBC_HAS_GNU_GETOPT is not set/UCLIBC_HAS_GNU_GETOPT=y/
   297 ENDSED
   298     fi
   299 
   300     # Always build the libpthread_db
   301     cat >>"${munge_file}" <<-ENDSED
   302 s/^# PTHREADS_DEBUG_SUPPORT is not set.*/PTHREADS_DEBUG_SUPPORT=y/
   303 ENDSED
   304 
   305     # Force on debug options if asked for
   306     case "${CT_LIBC_UCLIBC_DEBUG_LEVEL}" in
   307       0)
   308         cat >>"${munge_file}" <<-ENDSED
   309 s/^DODEBUG=y/# DODEBUG is not set/
   310 s/^DODEBUG_PT=y/# DODEBUG_PT is not set/
   311 s/^DOASSERTS=y/# DOASSERTS is not set/
   312 s/^SUPPORT_LD_DEBUG=y/# SUPPORT_LD_DEBUG is not set/
   313 s/^SUPPORT_LD_DEBUG_EARLY=y/# SUPPORT_LD_DEBUG_EARLY is not set/
   314 s/^UCLIBC_MALLOC_DEBUGGING=y/# UCLIBC_MALLOC_DEBUGGING is not set/
   315 ENDSED
   316         ;;
   317       1)
   318         cat >>"${munge_file}" <<-ENDSED
   319 s/^# DODEBUG is not set.*/DODEBUG=y/
   320 s/^DODEBUG_PT=y/# DODEBUG_PT is not set/
   321 s/^DOASSERTS=y/# DOASSERTS is not set/
   322 s/^SUPPORT_LD_DEBUG=y/# SUPPORT_LD_DEBUG is not set/
   323 s/^SUPPORT_LD_DEBUG_EARLY=y/# SUPPORT_LD_DEBUG_EARLY is not set/
   324 s/^UCLIBC_MALLOC_DEBUGGING=y/# UCLIBC_MALLOC_DEBUGGING is not set/
   325 ENDSED
   326         ;;
   327       2)
   328         cat >>"${munge_file}" <<-ENDSED
   329 s/^# DODEBUG is not set.*/DODEBUG=y/
   330 s/^# DODEBUG_PT is not set.*/DODEBUG_PT=y/
   331 s/^# DOASSERTS is not set.*/DOASSERTS=y/
   332 s/^# SUPPORT_LD_DEBUG is not set.*/SUPPORT_LD_DEBUG=y/
   333 s/^# SUPPORT_LD_DEBUG_EARLY is not set.*/SUPPORT_LD_DEBUG_EARLY=y/
   334 s/^# UCLIBC_MALLOC_DEBUGGING is not set/UCLIBC_MALLOC_DEBUGGING=y/
   335 ENDSED
   336         ;;
   337     esac
   338     sed -r -f "${munge_file}" "${src_config_file}" >"${dst_config_file}"
   339 }