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