scripts/build/libc_uClibc.sh
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Sat Jul 07 16:11:17 2007 +0000 (2007-07-07)
changeset 211 27d24ec8273a
parent 164 e78c0b2bc057
child 212 bdd97239e6b1
permissions -rw-r--r--
Parrallel compilation is broken for uClibc (I don't know if any of my patches is doing it, or if mainline is already broken).
     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 CROSS=${CT_TARGET}-            \
   124          PREFIX="${CT_SYSROOT_DIR}/"    \
   125          STRIPTOOL=true                 \
   126          all                            2>&1 |CT_DoLog ALL
   127 
   128     # YEM-FIXME: we want to install libraries in $SYSROOT/lib, but we don't want
   129     # to install headers in $SYSROOT/include, thus making only install_runtime.
   130     # Plus, the headers were previously installed earlier with install_dev, so
   131     # all should be well. Unfortunately, the install_dev target does not install
   132     # crti.o and consorts... :-( So reverting to target 'install'.
   133     # Note: PARALLELMFLAGS is not usefull for installation.
   134     # We do _not_ want to strip anything for now, in case we specifically
   135     # asked for a debug toolchain, thus the STRIPTOOL= assignment
   136     CT_DoLog EXTRA "Installing C library"
   137     make CROSS=${CT_TARGET}-            \
   138          PREFIX="${CT_SYSROOT_DIR}/"    \
   139          STRIPTOOL=true                 \
   140          install                        2>&1 |CT_DoLog ALL
   141 
   142     CT_EndStep
   143 }
   144 
   145 # This function is used to install those components needing the final C compiler
   146 do_libc_finish() {
   147     :
   148 }
   149 
   150 # Initialises the .config file to sensible values
   151 mungeuClibcConfig() {
   152     config_file="$1"
   153     munge_file="${CT_BUILD_DIR}/munge-uClibc-config.sed"
   154 
   155     # Hack our target in the config file.
   156     # Also remove stripping: its the responsibility of the
   157     # firmware builder to strip or not.
   158     cat > "${munge_file}" <<-ENDSED
   159 s/^(TARGET_.*)=y$/# \\1 is not set/
   160 s/^# TARGET_${CT_KERNEL_ARCH} is not set/TARGET_${CT_KERNEL_ARCH}=y/
   161 s/^TARGET_ARCH=".*"/TARGET_ARCH="${CT_KERNEL_ARCH}"/
   162 s/.*(DOSTRIP).*/# \\1 is not set/
   163 ENDSED
   164 
   165     # Accomodate for old and new uClibc versions, where the
   166     # way to select between big/little endian has changed
   167     case "${CT_ARCH_BE},${CT_ARCH_LE}" in
   168         y,) cat >> "${munge_file}" <<-ENDSED
   169 s/.*(ARCH_LITTLE_ENDIAN).*/# \\1 is not set/
   170 s/.*(ARCH_BIG_ENDIAN).*/\\1=y/
   171 s/.*(ARCH_WANTS_LITTLE_ENDIAN).*/# \\1 is not set/
   172 s/.*(ARCH_WANTS_BIG_ENDIAN).*/\\1=y/
   173 ENDSED
   174         ;;
   175         ,y) cat >> "${munge_file}" <<-ENDSED
   176 s/.*(ARCH_LITTLE_ENDIAN).*/\\1=y/
   177 s/.*(ARCH_BIG_ENDIAN).*/# \\1 is not set/
   178 s/.*(ARCH_WANTS_LITTLE_ENDIAN).*/\\1=y/
   179 s/.*(ARCH_WANTS_BIG_ENDIAN).*/# \\1 is not set/
   180 ENDSED
   181         ;;
   182     esac
   183 
   184     # Accomodate for old and new uClibc version, where the
   185     # way to select between hard/soft float has changed
   186     case "${CT_ARCH_FLOAT_HW},${CT_ARCH_FLOAT_SW}" in
   187         y,) cat >> "${munge_file}" <<-ENDSED
   188 s/.*(HAS_FPU).*/\\1=y/
   189 s/.*(UCLIBC_HAS_FPU).*/\\1=y/
   190 ENDSED
   191             ;;
   192         ,y) cat >> "${munge_file}" <<-ENDSED
   193 s/.*(HAS_FPU).*/\\# \\1 is not set/
   194 s/.*(UCLIBC_HAS_FPU).*/# \\1 is not set/
   195 ENDSED
   196             ;;
   197     esac
   198 
   199     # Change paths to work with crosstool
   200     # From http://www.uclibc.org/cgi-bin/viewcvs.cgi?rev=16846&view=rev
   201     #  " we just want the kernel headers, not the whole kernel source ...
   202     #  " so people may need to update their paths slightly
   203     quoted_kernel_source=`echo "${CT_HEADERS_DIR}" | sed -r -e 's,/include/?$,,; s,/,\\\\/,g;'`
   204     quoted_headers_dir=`echo ${CT_HEADERS_DIR} | sed -r -e 's,/,\\\\/,g;'`
   205     # CROSS_COMPILER_PREFIX is left as is, as the CROSS parameter is forced on the command line
   206     # DEVEL_PREFIX is left as '/usr/' because it is post-pended to $PREFIX, wich is the correct value of ${PREFIX}/${TARGET}
   207     # Some (old) versions of uClibc use KERNEL_SOURCE (which is _wrong_), and
   208     # newer versions use KERNEL_HEADERS (which is right). See:
   209     cat >> "${munge_file}" <<-ENDSED
   210 s/^DEVEL_PREFIX=".*"/DEVEL_PREFIX="\\/usr\\/"/
   211 s/^RUNTIME_PREFIX=".*"/RUNTIME_PREFIX="\\/"/
   212 s/^SHARED_LIB_LOADER_PREFIX=.*/SHARED_LIB_LOADER_PREFIX="\\/lib\\/"/
   213 s/^KERNEL_SOURCE=".*"/KERNEL_SOURCE="${quoted_kernel_source}"/
   214 s/^KERNEL_HEADERS=".*"/KERNEL_HEADERS="${quoted_headers_dir}"/
   215 s/^UCLIBC_DOWNLOAD_PREGENERATED_LOCALE=y/\\# UCLIBC_DOWNLOAD_PREGENERATED_LOCALE is not set/
   216 ENDSED
   217 
   218     if [ "${CT_USE_PIPES}" = "y" ]; then
   219         if grep UCLIBC_EXTRA_CFLAGS extra/Configs/Config.in >/dev/null 2>&1; then
   220             # Good, there is special provision for such things as -pipe!
   221             cat >> "${munge_file}" <<-ENDSED
   222 s/^(UCLIBC_EXTRA_CFLAGS=".*)"$/\\1 -pipe"/
   223 ENDSED
   224         else
   225             # Hack our -pipe into WARNINGS, which will be internally incorporated to
   226             # CFLAGS. This a dirty hack, but yet needed
   227             cat >> "${munge_file}" <<-ENDSED
   228 s/^(WARNINGS=".*)"$/\\1 -pipe"/
   229 ENDSED
   230         fi
   231     fi
   232 
   233     # Force on options needed for C++ if we'll be making a C++ compiler.
   234     # Note that the two PREGEN_LOCALE and the XLOCALE lines may be missing
   235     # entirely if LOCALE is not set.  If LOCALE was already set, we'll
   236     # assume the user has already made all the appropriate generation
   237     # arrangements.  Note that having the uClibc Makefile download the
   238     # pregenerated locales is not compatible with crosstool; besides,
   239     # crosstool downloads them as part of getandpatch.sh.
   240     if [ "${CT_CC_LANG_CXX}" = "y" ]; then
   241         cat >> "${munge_file}" <<-ENDSED
   242 s/^# DO_C99_MATH is not set/DO_C99_MATH=y/
   243 s/^# UCLIBC_CTOR_DTOR is not set/UCLIBC_CTOR_DTOR=y/
   244 # Add these three lines when doing C++?
   245 #s/^# UCLIBC_HAS_WCHAR is not set/UCLIBC_HAS_WCHAR=y/
   246 #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/
   247 #s/^# UCLIBC_HAS_GNU_GETOPT is not set/UCLIBC_HAS_GNU_GETOPT=y/
   248 ENDSED
   249     fi
   250 
   251     # Force on debug options if asked for
   252     case "${CT_LIBC_UCLIBC_DEBUG_LEVEL}" in
   253       0)
   254         cat >>"${munge_file}" <<-ENDSED
   255 s/^PTHREADS_DEBUG_SUPPORT=y/# PTHREADS_DEBUG_SUPPORT is not set/
   256 s/^DODEBUG=y/# DODEBUG is not set/
   257 s/^DODEBUG_PT=y/# DODEBUG_PT is not set/
   258 s/^DOASSERTS=y/# DOASSERTS is not set/
   259 s/^SUPPORT_LD_DEBUG=y/# SUPPORT_LD_DEBUG is not set/
   260 s/^SUPPORT_LD_DEBUG_EARLY=y/# SUPPORT_LD_DEBUG_EARLY is not set/
   261 s/^UCLIBC_MALLOC_DEBUGGING=y/# UCLIBC_MALLOC_DEBUGGING is not set/
   262 ENDSED
   263         ;;
   264       1)
   265         cat >>"${munge_file}" <<-ENDSED
   266 s/^# PTHREADS_DEBUG_SUPPORT is not set.*/PTHREADS_DEBUG_SUPPORT=y/
   267 s/^# DODEBUG is not set.*/DODEBUG=y/
   268 s/^DODEBUG_PT=y/# DODEBUG_PT is not set/
   269 s/^DOASSERTS=y/# DOASSERTS is not set/
   270 s/^SUPPORT_LD_DEBUG=y/# SUPPORT_LD_DEBUG is not set/
   271 s/^SUPPORT_LD_DEBUG_EARLY=y/# SUPPORT_LD_DEBUG_EARLY is not set/
   272 s/^UCLIBC_MALLOC_DEBUGGING=y/# UCLIBC_MALLOC_DEBUGGING is not set/
   273 ENDSED
   274         ;;
   275       2)
   276         cat >>"${munge_file}" <<-ENDSED
   277 s/^# PTHREADS_DEBUG_SUPPORT is not set.*/PTHREADS_DEBUG_SUPPORT=y/
   278 s/^# DODEBUG is not set.*/DODEBUG=y/
   279 s/^# DODEBUG_PT is not set.*/DODEBUG_PT=y/
   280 s/^# DOASSERTS is not set.*/DOASSERTS=y/
   281 s/^# SUPPORT_LD_DEBUG is not set.*/SUPPORT_LD_DEBUG=y/
   282 s/^# SUPPORT_LD_DEBUG_EARLY is not set.*/SUPPORT_LD_DEBUG_EARLY=y/
   283 s/^# UCLIBC_MALLOC_DEBUGGING is not set/UCLIBC_MALLOC_DEBUGGING=y/
   284 ENDSED
   285         ;;
   286     esac
   287     sed -r -i -f "${munge_file}" "${config_file}"
   288     rm -f "${munge_file}"
   289 }