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