Ahmad Sharif | 795ed17 | 2011-06-29 17:24:02 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | # Copyright (c) 2011 The Chromium OS Authors. All rights reserved. |
| 4 | # Use of this source code is governed by a BSD-style license that can be |
| 5 | # found in the LICENSE file. |
| 6 | |
| 7 | # TODO: Convert this to python. |
| 8 | |
| 9 | get_ctarget_from_board() |
| 10 | { |
| 11 | local board="$1" |
Ahmad Sharif | e4b7a14 | 2011-06-30 15:31:37 -0700 | [diff] [blame] | 12 | local base_board=$(echo ${board} | cut -d '_' -f 1) |
| 13 | local board_overlay=$(cros_overlay_list --board="$base_board" --primary_only) |
Ahmad Sharif | 795ed17 | 2011-06-29 17:24:02 -0700 | [diff] [blame] | 14 | cat "$board_overlay/toolchain.conf" |
| 15 | } |
| 16 | |
| 17 | get_atom_from_config() |
| 18 | { |
| 19 | local gcc_path="$(gcc-config -B "$1")" |
| 20 | equery b ${gcc_path} | head -n1 |
| 21 | } |
| 22 | |
| 23 | get_ctarget_from_atom() |
| 24 | { |
| 25 | local atom="$1" |
| 26 | echo "$atom" | sed -E 's|cross-([^/]+)/.*|\1|g' |
| 27 | } |
| 28 | |
| 29 | copy_gcc_libs_helper() |
| 30 | { |
| 31 | local target_location="$1" |
| 32 | local file_path="$2" |
| 33 | local dir_path=$(dirname "$file_path") |
| 34 | info "Copying $file_path symlink and file to $target_location/$dir_path/." |
| 35 | sudo mkdir -p "$target_location/$dir_path" |
| 36 | sudo cp -a "$file_path" "$target_location/$dir_path/" |
| 37 | sudo cp -a "$(readlink -f $file_path)" "$target_location/$dir_path/" |
| 38 | local env_d_file="$target_location/etc/env.d/05gcc" |
| 39 | info "Adding $dir_path to LDPATH in file $env_d_file" |
| 40 | sudo mkdir -p $(dirname "$env_d_file") |
| 41 | local line_to_add="LDPATH=\"$dir_path\"" |
| 42 | if ! grep -q "^$line_to_add$" "$env_d_file" &>/dev/null |
| 43 | then |
| 44 | echo "$line_to_add" | sudo_append "$env_d_file" |
| 45 | fi |
| 46 | } |
| 47 | |
| 48 | copy_gcc_libs() |
| 49 | { |
| 50 | # TODO: Figure out a better way of doing this? |
| 51 | local target_location="$1" |
| 52 | local atom="$2" |
| 53 | local libgcc_file=$(portageq contents / $atom | \ |
| 54 | grep /libgcc_s.so$) |
| 55 | local libstdcxx_file=$(portageq contents / $atom | \ |
| 56 | grep /libstdc++.so) |
| 57 | if [[ -z "$libgcc_file" || -z "$libstdcxx_file" ]] |
| 58 | then |
| 59 | error "Could not find libgcc_s.so/libstdcxx_s.so. Is\ |
| 60 | =$atom emerged properly?" |
| 61 | return 1 |
| 62 | fi |
| 63 | copy_gcc_libs_helper $target_location $libgcc_file |
| 64 | copy_gcc_libs_helper $target_location $libstdcxx_file |
| 65 | return 0 |
| 66 | } |
| 67 | |
| 68 | cros_gcc_config() |
| 69 | { |
| 70 | sudo gcc-config "$1" || return $? |
| 71 | |
| 72 | # Return if we're not switching profiles. |
| 73 | if [[ "$1" == -* ]] |
| 74 | then |
| 75 | return 0 |
| 76 | fi |
| 77 | |
| 78 | local atom=$(get_atom_from_config "$1") |
| 79 | if [[ $atom != cross* ]] |
| 80 | then |
| 81 | warn "$atom is not a cross-compiler." |
| 82 | warn "Therefore not adding its libs to the board roots." |
| 83 | return 0 |
| 84 | fi |
| 85 | |
| 86 | # Now copy the lib files into all possible boards. |
| 87 | local ctarget=$(get_ctarget_from_atom "$atom") |
| 88 | for board_root in /build/* |
| 89 | do |
Ahmad Sharif | e4b7a14 | 2011-06-30 15:31:37 -0700 | [diff] [blame] | 90 | local board=$(basename $board_root) |
Ahmad Sharif | 795ed17 | 2011-06-29 17:24:02 -0700 | [diff] [blame] | 91 | local board_tc=$(get_ctarget_from_board $board) |
| 92 | if [[ "${board_tc}" == "${ctarget}" ]] |
| 93 | then |
Ahmad Sharif | e4b7a14 | 2011-06-30 15:31:37 -0700 | [diff] [blame] | 94 | copy_gcc_libs "$board_root" $atom |
Ahmad Sharif | 795ed17 | 2011-06-29 17:24:02 -0700 | [diff] [blame] | 95 | fi |
| 96 | done |
| 97 | } |