diff --git a/README.md b/README.md index a4681ea2e2844f03c3ed43b189b506a4ce856961..579533d011b88d46609f65db9d630c32204a1317 100644 --- a/README.md +++ b/README.md @@ -8,47 +8,6 @@ Just build AOSP - Fluoride is there by default. Instructions for Ubuntu, tested on 14.04 with Clang 3.5.0 and 16.10 with Clang 3.8.0 -### Install required libraries - -```sh -sudo apt-get install libevent-dev libc++-dev libc++abi-dev -``` - -### Install build tools - - - Install [ninja](https://ninja-build.org/) build system - -```sh -sudo apt-get install ninja-build -``` - -or download binary from https://github.com/ninja-build/ninja/releases - - - Install [gn](https://chromium.googlesource.com/chromium/src/tools/gn/) - - meta-build system that generates NinjaBuild files. - -Get sha1 of current version from [here]( -https://chromium.googlesource.com/chromium/buildtools/+/master/linux64/gn.sha1) - and then download corresponding executable: - -```sh -wget -O gn http://storage.googleapis.com/chromium-gn/<gn.sha1> -``` - -i.e. if sha1 is "3491f6687bd9f19946035700eb84ce3eed18c5fa" (value from 24 Feb - 2016) do - -```sh -wget -O gn http://storage.googleapis.com/chromium-gn/3491f6687bd9f19946035700eb84ce3eed18c5fa -``` - -Then make binary executable and put it on your PATH, i.e.: - -```sh -chmod a+x ./gn -sudo mv ./gn /usr/bin -``` - ### Download source ```sh @@ -57,6 +16,13 @@ cd ~/fluoride git clone https://android.googlesource.com/platform/packages/modules/Bluetooth/system ``` +Install dependencies (require sudo access): + +```sh +cd ~/fluoride/bt +build/install_deps.sh +``` + Then fetch third party dependencies: ```sh diff --git a/system/build/install_deps.sh b/system/build/install_deps.sh new file mode 100755 index 0000000000000000000000000000000000000000..f1173a9ca3908ae1a7a3e3f2f04b6fff8f8aeab3 --- /dev/null +++ b/system/build/install_deps.sh @@ -0,0 +1,57 @@ +#!/bin/bash +CLANG_PACKAGE=clang +GNSHA1_URL="https://chromium.googlesource.com/chromium/buildtools/\ ++/master/linux64/gn.sha1?format=TEXT" + +# Check if clang is already installed on current system +clang_path=`which clang` +if [ -f "$clang_path" ]; then + # if clang binary is avalable, check its version + clang_version=$($clang_path --version | grep clang | sed "s/.*version\s*\([0-9]*\.[0-9]*\).*/\1/") + IFS="." read -ra clang_version_array <<< "$clang_version" + clang_version_major=${clang_version_array[0]} + clang_version_minor=${clang_version_array[1]} + # if the version is greater than 3.5 then do not install clang here + if [ $clang_version_major -ge 3 ] && [ $clang_version_minor -ge 5 ]; then + echo "Detected clang $clang_version" + CLANG_PACKAGE="" + fi +fi + +if [ ! -z "$CLANG_PACKAGE" ]; then + # Try to find clang from a known list + for clang_version in 3.9 3.8 3.7 3.6 3.5 + do + clang_path=`which clang-$clang_version` + if [ -f "$clang_path" ]; then + echo "Detected clang-$clang_version" + CLANG_PACKAGE="" + break + fi + done +fi + +if [ ! -z "$CLANG_PACKAGE" ]; then + echo "clang not found on current system, installing" + if [ -f /etc/lsb-release ]; then + # Ubuntu + ubuntu_version=$(lsb_release --release --short) + IFS="." read -ra ubuntu_version_array <<< "$ubuntu_version" + ubuntu_version_major=${ubuntu_version_array[0]} + ubuntu_version_minor=${ubuntu_version_array[1]} + if [ $ubuntu_version_major -lt 15 ]; then + echo "Choose clang-3.8 for Ubuntu 14 and below" + CLANG_PACKAGE=clang-3.8 + fi + fi +fi + +sudo apt-get -y install $CLANG_PACKAGE libevent-dev libc++-dev libc++abi-dev \ + ninja-build +gn_path=`which gn` +if [ -z $gn_path ]; then + gnsha1=$(curl $GNSHA1_URL | base64 -d) + wget -O gn http://storage.googleapis.com/chromium-gn/$gnsha1 + chmod a+x ./gn + sudo mv ./gn /usr/bin/ +fi diff --git a/system/build/toolchain/clang/BUILD.gn b/system/build/toolchain/clang/BUILD.gn index aed5c05355c1488b801dd10cb686569a35d65439..fcd6d5630bc1d466cad49dcfbd0d54c0268adbca 100644 --- a/system/build/toolchain/clang/BUILD.gn +++ b/system/build/toolchain/clang/BUILD.gn @@ -13,8 +13,15 @@ # See the License for the specific language governing permissions and # limitations under the License. # -clang = "clang" -clangxx = "clang++" +clang_suffix = exec_script("get_clang_suffix.py", [], "list lines") +clang_suffix = clang_suffix[0] +assert(clang_suffix != "None", + "Cannot find clang, please install clang 3.5 or above") +if (clang_suffix != "") { + clang_suffix = "-" + clang_suffix +} +clang = "clang$clang_suffix" +clangxx = "clang++$clang_suffix" config("clang_config") { include_dirs = [ diff --git a/system/build/toolchain/clang/get_clang_suffix.py b/system/build/toolchain/clang/get_clang_suffix.py new file mode 100644 index 0000000000000000000000000000000000000000..dedacdd51d325294994f7363b109196073150837 --- /dev/null +++ b/system/build/toolchain/clang/get_clang_suffix.py @@ -0,0 +1,43 @@ +import os +import subprocess +import re +import sys + +def which(cmd): + for p in os.environ["PATH"].split(os.pathsep): + clang_path = os.path.join(p, cmd) + if os.path.exists(clang_path): + return clang_path + return None + +CLANG_VERSION_REGEX=".*version\s*([0-9]*\.[0-9]*)\.*" +clang_path = which("clang++") +clang_version_major = 0 +clang_version_minor = 0 + +if clang_path: + clang_version_out = subprocess.Popen([clang_path, "--version"], + stdout=subprocess.PIPE).communicate()[0] + clang_version_match = re.search(CLANG_VERSION_REGEX, clang_version_out) + clang_version_str = clang_version_match.group(1) + clang_version_array = clang_version_str.split('.') + clang_version_major = int(clang_version_array[0]) + clang_version_minor = int(clang_version_array[1]) + +if clang_version_major >= 3 and clang_version_minor >= 5: + print "" +else: + # Loop in support clang version only + clang_version_major = 3 + clang_version_minor = 9 + while clang_version_major >= 3 and clang_version_minor >= 5: + clang_version_str = "%d.%d" % (clang_version_major, clang_version_minor) + clang_path = which("clang++-" + clang_version_str) + if clang_path: + print clang_version_str + sys.exit(0) + clang_version_minor -= 1 + if clang_version_minor < 0: + clang_version_minor = 9 + clang_version_major -= 1 + print "None"