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