From daef475460ff43ef23193dde3da97d3d23dc281d Mon Sep 17 00:00:00 2001
From: Scott James Remnant <keybuk@google.com>
Date: Tue, 12 May 2015 13:58:49 -0700
Subject: [PATCH] Initial attempt at a GN/Ninja-based build system

BUG=20491586
---
 .gitignore                          |   2 +
 .gn                                 |   1 +
 BUILD.gn                            |   6 ++
 gki/BUILD.gn                        |  17 +++
 system/bta/BUILD.gn                 | 102 ++++++++++++++++++
 system/btcore/BUILD.gn              |  39 +++++++
 system/build/BUILD.gn               |  31 ++++++
 system/build/config/BUILDCONFIG.gn  |  13 +++
 system/build/toolchain/gcc/BUILD.gn |  83 +++++++++++++++
 system/device/BUILD.gn              |  37 +++++++
 system/hci/BUILD.gn                 |  73 +++++++++++++
 system/main/BUILD.gn                | 129 +++++++++++++++++++++++
 system/osi/BUILD.gn                 |  58 ++++++++++
 system/stack/BUILD.gn               | 157 ++++++++++++++++++++++++++++
 system/utils/BUILD.gn               |  13 +++
 15 files changed, 761 insertions(+)
 create mode 100644 .gitignore
 create mode 100644 .gn
 create mode 100644 BUILD.gn
 create mode 100644 gki/BUILD.gn
 create mode 100644 system/bta/BUILD.gn
 create mode 100644 system/btcore/BUILD.gn
 create mode 100644 system/build/BUILD.gn
 create mode 100644 system/build/config/BUILDCONFIG.gn
 create mode 100644 system/build/toolchain/gcc/BUILD.gn
 create mode 100644 system/device/BUILD.gn
 create mode 100644 system/hci/BUILD.gn
 create mode 100644 system/main/BUILD.gn
 create mode 100644 system/osi/BUILD.gn
 create mode 100644 system/stack/BUILD.gn
 create mode 100644 system/utils/BUILD.gn

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 00000000000..eca80ead69f
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+buildtools
+out
diff --git a/.gn b/.gn
new file mode 100644
index 00000000000..c6fefbae8d3
--- /dev/null
+++ b/.gn
@@ -0,0 +1 @@
+buildconfig = "//build/config/BUILDCONFIG.gn"
diff --git a/BUILD.gn b/BUILD.gn
new file mode 100644
index 00000000000..1af5ea4c853
--- /dev/null
+++ b/BUILD.gn
@@ -0,0 +1,6 @@
+# This pulls in main/BUILD.gn and all of its dependencies.
+group("bluetooth") {
+  deps = [
+    "//main:bluetooth.default",
+  ]
+}
diff --git a/gki/BUILD.gn b/gki/BUILD.gn
new file mode 100644
index 00000000000..0e742592753
--- /dev/null
+++ b/gki/BUILD.gn
@@ -0,0 +1,17 @@
+source_set("gki") {
+  sources = [
+    "common/gki_buffer.c",
+    "ulinux/gki_ulinux.c",
+  ]
+
+  include_dirs = [
+    "common",
+    "ulinux",
+    "//btcore/include",
+    "//include",
+    "//osi/include",
+    "//stack/include",
+    "//utils/include",
+    "//",
+  ]
+}
diff --git a/system/bta/BUILD.gn b/system/bta/BUILD.gn
new file mode 100644
index 00000000000..1869f39b9b7
--- /dev/null
+++ b/system/bta/BUILD.gn
@@ -0,0 +1,102 @@
+source_set("bta") {
+  sources = [
+    "dm/bta_dm_ci.c",
+    "dm/bta_dm_act.c",
+    "dm/bta_dm_pm.c",
+    "dm/bta_dm_main.c",
+    "dm/bta_dm_cfg.c",
+    "dm/bta_dm_api.c",
+    "dm/bta_dm_sco.c",
+    "gatt/bta_gattc_api.c",
+    "gatt/bta_gatts_act.c",
+    "gatt/bta_gatts_main.c",
+    "gatt/bta_gattc_utils.c",
+    "gatt/bta_gattc_ci.c",
+    "gatt/bta_gatts_api.c",
+    "gatt/bta_gattc_main.c",
+    "gatt/bta_gattc_act.c",
+    "gatt/bta_gattc_cache.c",
+    "gatt/bta_gatts_utils.c",
+    "ag/bta_ag_sdp.c",
+    "ag/bta_ag_sco.c",
+    "ag/bta_ag_cfg.c",
+    "ag/bta_ag_main.c",
+    "ag/bta_ag_api.c",
+    "ag/bta_ag_rfc.c",
+    "ag/bta_ag_act.c",
+    "ag/bta_ag_cmd.c",
+    "ag/bta_ag_ci.c",
+    "ag/bta_ag_at.c",
+    "hf_client/bta_hf_client_act.c",
+    "hf_client/bta_hf_client_api.c",
+    "hf_client/bta_hf_client_main.c",
+    "hf_client/bta_hf_client_rfc.c",
+    "hf_client/bta_hf_client_at.c",
+    "hf_client/bta_hf_client_sdp.c",
+    "hf_client/bta_hf_client_sco.c",
+    "hf_client/bta_hf_client_cmd.c",
+    "hh/bta_hh_cfg.c",
+    "hh/bta_hh_act.c",
+    "hh/bta_hh_api.c",
+    "hh/bta_hh_le.c",
+    "hh/bta_hh_utils.c",
+    "hh/bta_hh_main.c",
+    "pan/bta_pan_main.c",
+    "pan/bta_pan_ci.c",
+    "pan/bta_pan_act.c",
+    "pan/bta_pan_api.c",
+    "av/bta_av_act.c",
+    "av/bta_av_ci.c",
+    "av/bta_av_api.c",
+    "av/bta_av_aact.c",
+    "av/bta_av_main.c",
+    "av/bta_av_cfg.c",
+    "av/bta_av_ssm.c",
+    "av/bta_av_sbc.c",
+    "ar/bta_ar.c",
+    "hl/bta_hl_act.c",
+    "hl/bta_hl_api.c",
+    "hl/bta_hl_main.c",
+    "hl/bta_hl_utils.c",
+    "hl/bta_hl_sdp.c",
+    "hl/bta_hl_ci.c",
+    "mce/bta_mce_api.c",
+    "mce/bta_mce_main.c",
+    "mce/bta_mce_act.c",
+    "mce/bta_mce_cfg.c",
+    "sys/bta_sys_main.c",
+    "sys/bta_sys_conn.c",
+    "sys/utl.c",
+    "jv/bta_jv_act.c",
+    "jv/bta_jv_cfg.c",
+    "jv/bta_jv_main.c",
+    "jv/bta_jv_api.c",
+  ]
+
+  include_dirs = [
+    "include",
+    "sys",
+    "dm",
+    "hh",
+    "//",
+    "//btcore/include",
+    "//gki/common",
+    "//gki/ulinux",
+    "//hci/include",
+    "//include",
+    "//stack/include",
+    "//stack/btm",
+    "//osi/include",
+    "//udrv/include",
+    "//vnd/include",
+    "//utils/include",
+  ]
+
+  cflags = [
+    "-Wno-unused-variable",
+    "-Wno-unused-value",
+    "-Wno-unused-function",
+    "-Wno-pointer-to-int-cast",
+    "-Wno-int-to-pointer-cast",
+  ]
+}
diff --git a/system/btcore/BUILD.gn b/system/btcore/BUILD.gn
new file mode 100644
index 00000000000..202759a38ae
--- /dev/null
+++ b/system/btcore/BUILD.gn
@@ -0,0 +1,39 @@
+source_set("btcore") {
+  sources = [
+    "src/bdaddr.c",
+    "src/counter.c",
+    "src/device_class.c",
+    "src/module.c",
+    "src/property.c",
+    "src/uuid.c",
+  ]
+
+  include_dirs = [
+    "include",
+    "//osi/include",
+    "//",
+  ]
+}
+
+executable("net_test_btcore") {
+  sources = [
+    "test/bdaddr_test.cpp",
+    "test/counter_test.cpp",
+    "test/device_class_test.cpp",
+    "test/property_test.cpp",
+    "test/uuid_test.cpp",
+    "//osi/test/AllocationTestHarness.cpp",
+  ]
+
+  include_dirs = [
+    "include",
+    "//",
+  ]
+
+  deps = [
+    "//btcore",
+    "//osi",
+  ]
+
+  libs = [ "-lpthread", "-lrt", "-ldl" ]
+}
diff --git a/system/build/BUILD.gn b/system/build/BUILD.gn
new file mode 100644
index 00000000000..a09153409aa
--- /dev/null
+++ b/system/build/BUILD.gn
@@ -0,0 +1,31 @@
+config("linux") {
+  # TODO: include from system/core, libhardware
+  # TODO: AndroidConfig.h or equivalent
+  # TODO: gtest
+
+  cflags = [
+    "-Wall",
+    "-Werror",
+    "-g",
+    "-O0",
+  ]
+
+  cflags_c = [
+    "-std=c99"
+  ]
+
+  defines = [
+    "_FORTIFY_SOURCE=2",
+    "_GNU_SOURCE",
+    "HAS_NO_BDROID_BUILDCFG",
+    "LOG_NDEBUG=1",
+  ]
+}
+
+config("pic") {
+  cflags = [ "-fPIC" ]
+}
+
+config("gc") {
+  ldflags = [ "-Wl,--gc-sections" ]
+}
diff --git a/system/build/config/BUILDCONFIG.gn b/system/build/config/BUILDCONFIG.gn
new file mode 100644
index 00000000000..9b4d3bf325d
--- /dev/null
+++ b/system/build/config/BUILDCONFIG.gn
@@ -0,0 +1,13 @@
+set_default_toolchain("//build/toolchain/gcc")
+
+set_defaults("executable") {
+  configs = [ "//build:linux", "//build:gc" ]
+}
+
+set_defaults("shared_library") {
+  configs = [ "//build:linux", "//build:pic" ]
+}
+
+set_defaults("source_set") {
+  configs = [ "//build:linux", "//build:pic" ]
+}
diff --git a/system/build/toolchain/gcc/BUILD.gn b/system/build/toolchain/gcc/BUILD.gn
new file mode 100644
index 00000000000..e32d750f2bd
--- /dev/null
+++ b/system/build/toolchain/gcc/BUILD.gn
@@ -0,0 +1,83 @@
+# Copyright 2014 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+cc = "gcc"
+cxx = "g++"
+
+toolchain("gcc") {
+  tool("cc") {
+    depfile = "{{output}}.d"
+    command = "$cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}"
+    depsformat = "gcc"
+    description = "CC {{output}}"
+    outputs = [
+      "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
+    ]
+  }
+
+  tool("cxx") {
+    depfile = "{{output}}.d"
+    command = "$cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} -c {{source}} -o {{output}}"
+    depsformat = "gcc"
+    description = "CXX {{output}}"
+    outputs = [
+      "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
+    ]
+  }
+
+  tool("alink") {
+    rspfile = "{{output}}.rsp"
+    command = "rm -f {{output}} && ar rcs {{output}} @$rspfile"
+    description = "AR {{target_output_name}}{{output_extension}}"
+    rspfile_content = "{{inputs}}"
+    outputs = [
+      "{{target_out_dir}}/{{target_output_name}}{{output_extension}}",
+    ]
+    default_output_extension = ".a"
+    #output_prefix = "lib"
+  }
+
+  tool("solink") {
+    soname = "{{target_output_name}}{{output_extension}}"  # e.g. "libfoo.so".
+    rspfile = soname + ".rsp"
+
+    command = "$cxx -shared {{ldflags}} -o $soname -Wl,-soname=$soname @$rspfile"
+    rspfile_content = "-Wl,--whole-archive {{inputs}} {{solibs}} -Wl,--no-whole-archive {{libs}}"
+
+    description = "SOLINK $soname"
+
+    # Use this for {{output_extension}} expansions unless a target manually
+    # overrides it (in which case {{output_extension}} will be what the target
+    # specifies).
+    default_output_extension = ".so"
+
+    outputs = [
+      soname,
+    ]
+    link_output = soname
+    depend_output = soname
+    #output_prefix = "lib"
+  }
+
+  tool("link") {
+    outfile = "{{target_output_name}}{{output_extension}}"
+    rspfile = "$outfile.rsp"
+    command = "$cxx {{ldflags}} -o $outfile -Wl,--start-group @$rspfile {{solibs}} -Wl,--end-group {{libs}}"
+    description = "LINK $outfile"
+    rspfile_content = "{{inputs}}"
+    outputs = [
+      outfile,
+    ]
+  }
+
+  tool("stamp") {
+    command = "touch {{output}}"
+    description = "STAMP {{output}}"
+  }
+
+  tool("copy") {
+    command = "cp -af {{source}} {{output}}"
+    description = "COPY {{source}} {{output}}"
+  }
+}
diff --git a/system/device/BUILD.gn b/system/device/BUILD.gn
new file mode 100644
index 00000000000..41016efb68a
--- /dev/null
+++ b/system/device/BUILD.gn
@@ -0,0 +1,37 @@
+source_set("device") {
+  sources = [
+    "src/classic/peer.c",
+    "src/controller.c"
+  ]
+
+  include_dirs = [
+    "//",
+    "include",
+    "//btcore/include",
+    "//gki/common",
+    "//hci/include",
+    "//include",
+    "//osi/include",
+    "//stack/include",
+  ]
+}
+
+executable("net_test_device") {
+  sources = [
+    "//osi/test/AllocationTestHarness.cpp",
+    "test/classic/peer_test.cpp",
+  ]
+
+  include_dirs = [
+    "//",
+    "//osi/include",
+  ]
+
+  deps = [
+    "//device",
+    "//btcore",
+    "//osi",
+  ]
+
+  libs = [ "-lpthread", "-lrt", "-ldl" ]
+}
diff --git a/system/hci/BUILD.gn b/system/hci/BUILD.gn
new file mode 100644
index 00000000000..96bb12a55f6
--- /dev/null
+++ b/system/hci/BUILD.gn
@@ -0,0 +1,73 @@
+source_set("hci") {
+  sources = [
+    "src/btsnoop.c",
+    "src/btsnoop_net.c",
+    "src/buffer_allocator.c",
+    "src/hci_hal.c",
+    "src/hci_hal_h4.c",
+    "src/hci_hal_mct.c",
+    "src/hci_inject.c",
+    "src/hci_layer.c",
+    "src/hci_packet_factory.c",
+    "src/hci_packet_parser.c",
+    "src/low_power_manager.c",
+    "src/packet_fragmenter.c",
+    "src/vendor.c",
+  ]
+
+  include_dirs = [
+    "include",
+    "//",
+    "//include",
+    "//btcore/include",
+    "//gki/common",
+    "//gki/ulinux",
+    "//osi/include",
+    "//stack/include",
+    "//utils/include",
+  ]
+}
+
+executable("net_test_hci") {
+  sources = [
+    "//osi/test/AllocationTestHarness.cpp",
+    "//osi/test/AlarmTestHarness.cpp",
+    "test/hci_hal_h4_test.cpp",
+    "test/hci_hal_mct_test.cpp",
+    "test/hci_layer_test.cpp",
+    "test/low_power_manager_test.cpp",
+    "test/packet_fragmenter_test.cpp",
+  ]
+
+  sources += [ "//main/stack_config.c" ]
+
+  include_dirs = [
+    "include",
+    "//",
+    "//include",
+    "//btcore/include",
+    "//gki/common",
+    "//gki/ulinux",
+    "//osi/include",
+    "//osi/test",
+    "//stack/include",
+    "//utils/include",
+  ]
+
+  cflags = [
+    "-Wno-unused-variable",
+  ]
+
+  deps = [
+    "//hci",
+    "//osi",
+    "//btcore",
+  ]
+
+  deps += [
+    "//gki",
+    "//device",
+  ]
+
+  libs = [ "-lpthread", "-lrt", "-ldl" ]
+}
diff --git a/system/main/BUILD.gn b/system/main/BUILD.gn
new file mode 100644
index 00000000000..0c520c8856e
--- /dev/null
+++ b/system/main/BUILD.gn
@@ -0,0 +1,129 @@
+shared_library("bluetooth.default") {
+  # HAL layer
+  sources = [
+    "//btif/src/bluetooth.c",
+  ]
+
+  # platform specific
+  sources += [
+    "bte_main.c",
+    "bte_init.c",
+    "bte_logmsg.c",
+    "bte_conf.c",
+    "stack_config.c",
+  ]
+
+  # BTIF
+  sources += [
+    "//btif/src/btif_av.c",
+    "//btif/src/btif_config.c",
+    "//btif/src/btif_config_transcode.cpp",
+    "//btif/src/btif_core.c",
+    "//btif/src/btif_dm.c",
+    "//btif/src/btif_gatt.c",
+    "//btif/src/btif_gatt_client.c",
+    "//btif/src/btif_gatt_multi_adv_util.c",
+    "//btif/src/btif_gatt_server.c",
+    "//btif/src/btif_gatt_test.c",
+    "//btif/src/btif_gatt_util.c",
+    "//btif/src/btif_hf.c",
+    "//btif/src/btif_hf_client.c",
+    "//btif/src/btif_hh.c",
+    "//btif/src/btif_hl.c",
+    "//btif/src/btif_mce.c",
+    "//btif/src/btif_media_task.c",
+    "//btif/src/btif_pan.c",
+    "//btif/src/btif_profile_queue.c",
+    "//btif/src/btif_rc.c",
+    "//btif/src/btif_sm.c",
+    "//btif/src/btif_sock.c",
+    "//btif/src/btif_sock_rfc.c",
+    "//btif/src/btif_sock_sco.c",
+    "//btif/src/btif_sock_sdp.c",
+    "//btif/src/btif_sock_thread.c",
+    "//btif/src/btif_sock_util.c",
+    "//btif/src/btif_storage.c",
+    "//btif/src/btif_util.c",
+    "//btif/src/stack_manager",
+  ]
+
+  # callouts
+  sources += [
+    "//btif/co/bta_ag_co.c",
+    "//btif/co/bta_dm_co.c",
+    "//btif/co/bta_av_co.c",
+    "//btif/co/bta_hh_co.c",
+    "//btif/co/bta_hl_co.c",
+    "//btif/co/bta_pan_co.c",
+    "//btif/co/bta_gattc_co.c",
+    "//btif/co/bta_gatts_co.c",
+  ]
+
+  # sbc encoder
+  sources += [
+    "//embdrv/sbc/encoder/srce/sbc_analysis.c",
+    "//embdrv/sbc/encoder/srce/sbc_dct.c",
+    "//embdrv/sbc/encoder/srce/sbc_dct_coeffs.c",
+    "//embdrv/sbc/encoder/srce/sbc_enc_bit_alloc_mono.c",
+    "//embdrv/sbc/encoder/srce/sbc_enc_bit_alloc_ste.c",
+    "//embdrv/sbc/encoder/srce/sbc_enc_coeffs.c",
+    "//embdrv/sbc/encoder/srce/sbc_encoder.c",
+    "//embdrv/sbc/encoder/srce/sbc_packing.c",
+  ]
+
+  sources += [
+    "//udrv/ulinux/uipc.c",
+  ]
+
+  include_dirs = [
+    "//",
+    "//bta/include",
+    "//bta/sys",
+    "//bta/dm",
+    "//btcore/include",
+    "//osi/include",
+    "//gki/common",
+    "//gki/ulinux",
+    "//include",
+    "//stack/include",
+    "//stack/l2cap",
+    "//stack/a2dp",
+    "//stack/btm",
+    "//stack/avdt",
+    "//hci",
+    "//hci/include",
+    "//udrv/include",
+    "//btif/include",
+    "//btif/co",
+    "//hci/includ",
+    "//vnd/include",
+    "//brcm/include",
+    "//embdrv/sbc/encoder/include",
+    "//embdrv/sbc/decoder/include",
+    "//audio_a2dp_hw",
+    "//utils/include",
+  ]
+
+  deps = [
+    "//bta",
+    "//gki",
+    "//stack",
+    "//device",
+    "//hci",
+    "//utils",
+    "//btcore",
+    "//osi",
+    # TODO tinyxml2
+    # TODO qcom sbc decoder
+  ]
+
+  cflags = [
+    "-Wno-unused-variable",
+    "-Wno-unused-value",
+    "-Wno-unused-function",
+    "-Wno-int-to-pointer-cast",
+  ]
+  cflags_c = [
+    "-Wno-pointer-to-int-cast",
+  ]
+}
diff --git a/system/osi/BUILD.gn b/system/osi/BUILD.gn
new file mode 100644
index 00000000000..e2af09e221f
--- /dev/null
+++ b/system/osi/BUILD.gn
@@ -0,0 +1,58 @@
+source_set("osi") {
+  sources = [
+    "src/alarm.c",
+    "src/allocation_tracker.c",
+    "src/allocator.c",
+    "src/array.c",
+    "src/buffer.c",
+    "src/compat.c",
+    "src/config.c",
+    "src/data_dispatcher.c",
+    "src/eager_reader.c",
+    "src/fixed_queue.c",
+    "src/future.c",
+    "src/hash_functions.c",
+    "src/hash_map.c",
+    "src/list.c",
+    "src/non_repeating_timer.c",
+    "src/reactor.c",
+    "src/semaphore.c",
+    "src/socket.c",
+    "src/thread.c",
+  ]
+
+  include_dirs = [
+    "include",
+    "//"
+  ]
+}
+
+executable("net_test_osi") {
+  sources = [
+    "test/AlarmTestHarness.cpp",
+    "test/AllocationTestHarness.cpp",
+    "test/alarm_test.cpp",
+    "test/allocation_tracker_test.cpp",
+    "test/array_test.cpp",
+    "test/atomic_test.cpp",
+    "test/config_test.cpp",
+    "test/data_dispatcher_test.cpp",
+    "test/eager_reader_test.cpp",
+    "test/future_test.cpp",
+    "test/hash_map_test.cpp",
+    "test/list_test.cpp",
+    "test/reactor_test.cpp",
+    "test/thread_test.cpp",
+  ]
+
+  include_dirs = [
+    "include",
+    "//",
+  ]
+
+  deps = [
+    "//osi",
+  ]
+
+  libs = [ "-lpthread", "-lrt" ]
+}
diff --git a/system/stack/BUILD.gn b/system/stack/BUILD.gn
new file mode 100644
index 00000000000..5954eb85bba
--- /dev/null
+++ b/system/stack/BUILD.gn
@@ -0,0 +1,157 @@
+source_set("stack") {
+  sources = [
+    "a2dp/a2d_api.c",
+    "a2dp/a2d_sbc.c",
+    "avrc/avrc_api.c",
+    "avrc/avrc_sdp.c",
+    "avrc/avrc_opt.c",
+    "avrc/avrc_bld_tg.c",
+    "avrc/avrc_bld_ct.c",
+    "avrc/avrc_pars_tg.c",
+    "avrc/avrc_pars_ct.c",
+    "avrc/avrc_utils.c",
+    "hid/hidh_api.c",
+    "hid/hidh_conn.c",
+    "bnep/bnep_main.c",
+    "bnep/bnep_utils.c",
+    "bnep/bnep_api.c",
+    "hcic/hciblecmds.c",
+    "hcic/hcicmds.c",
+    "btm/btm_ble.c",
+    "btm/btm_sec.c",
+    "btm/btm_inq.c",
+    "btm/btm_ble_addr.c",
+    "btm/btm_ble_bgconn.c",
+    "btm/btm_main.c",
+    "btm/btm_dev.c",
+    "btm/btm_ble_gap.c",
+    "btm/btm_ble_adv_filter.c",
+    "btm/btm_ble_multi_adv.c",
+    "btm/btm_ble_batchscan.c",
+    "btm/btm_ble_cont_energy.c",
+    "btm/btm_acl.c",
+    "btm/btm_sco.c",
+    "btm/btm_pm.c",
+    "btm/btm_devctl.c",
+    "rfcomm/rfc_utils.c",
+    "rfcomm/port_rfc.c",
+    "rfcomm/rfc_l2cap_if.c",
+    "rfcomm/rfc_mx_fsm.c",
+    "rfcomm/port_utils.c",
+    "rfcomm/rfc_port_fsm.c",
+    "rfcomm/rfc_port_if.c",
+    "rfcomm/port_api.c",
+    "rfcomm/rfc_ts_frames.c",
+    "mcap/mca_dact.c",
+    "mcap/mca_dsm.c",
+    "mcap/mca_l2c.c",
+    "mcap/mca_main.c",
+    "mcap/mca_csm.c",
+    "mcap/mca_cact.c",
+    "mcap/mca_api.c",
+    "gatt/gatt_sr.c",
+    "gatt/gatt_cl.c",
+    "gatt/gatt_api.c",
+    "gatt/gatt_auth.c",
+    "gatt/gatt_utils.c",
+    "gatt/gatt_main.c",
+    "gatt/att_protocol.c",
+    "gatt/gatt_attr.c",
+    "gatt/gatt_db.c",
+    "avct/avct_api.c",
+    "avct/avct_l2c.c",
+    "avct/avct_lcb.c",
+    "avct/avct_ccb.c",
+    "avct/avct_lcb_act.c",
+    "smp/smp_main.c",
+    "smp/smp_l2c.c",
+    "smp/smp_cmac.c",
+    "smp/smp_utils.c",
+    "smp/smp_act.c",
+    "smp/smp_keys.c",
+    "smp/smp_api.c",
+    "smp/aes.c",
+    "avdt/avdt_ccb.c",
+    "avdt/avdt_scb_act.c",
+    "avdt/avdt_msg.c",
+    "avdt/avdt_ccb_act.c",
+    "avdt/avdt_api.c",
+    "avdt/avdt_scb.c",
+    "avdt/avdt_ad.c",
+    "avdt/avdt_l2c.c",
+    "sdp/sdp_server.c",
+    "sdp/sdp_main.c",
+    "sdp/sdp_db.c",
+    "sdp/sdp_utils.c",
+    "sdp/sdp_api.c",
+    "sdp/sdp_discovery.c",
+    "pan/pan_main.c",
+    "srvc/srvc_battery.c",
+    "srvc/srvc_battery_int.h",
+    "srvc/srvc_dis.c",
+    "srvc/srvc_dis_int.h",
+    "srvc/srvc_eng.c",
+    "srvc/srvc_eng_int.h",
+    "pan/pan_api.c",
+    "pan/pan_utils.c",
+    "btu/btu_hcif.c",
+    "btu/btu_init.c",
+    "btu/btu_task.c",
+    "l2cap/l2c_fcr.c",
+    "l2cap/l2c_ucd.c",
+    "l2cap/l2c_main.c",
+    "l2cap/l2c_api.c",
+    "l2cap/l2c_utils.c",
+    "l2cap/l2c_csm.c",
+    "l2cap/l2c_link.c",
+    "l2cap/l2c_ble.c",
+    "l2cap/l2cap_client.c",
+    "gap/gap_api.c",
+    "gap/gap_ble.c",
+    "//vnd/ble/vendor_ble.c",
+  ]
+
+  include_dirs = [
+    "include",
+    "avct",
+    "btm",
+    "avrc",
+    "l2cap",
+    "avdt",
+    "gatt",
+    "gap",
+    "pan",
+    "bnep",
+    "hid",
+    "sdp",
+    "smp",
+    "srvc",
+    "//btcore/include",
+    "//vnd/include",
+    "//vnd/ble",
+    "//btif/include",
+    "//hci/include",
+    "//include",
+    "//gki/common",
+    "//gki/ulinux",
+    "//osi/include",
+    "//udrv/include",
+    "//rpc/include",
+    "//hcis",
+    "//ctrlr/include",
+    "//bta/include",
+    "//bta/sys",
+    "//utils/include",
+    "//",
+  ]
+
+  deps = [ "//hci" ]
+
+  cflags = [
+    "-Wno-unused-variable",
+    "-Wno-unused-value",
+    "-Wno-unused-function",
+    "-Wno-pointer-to-int-cast",
+    "-Wno-int-to-pointer-cast",
+  ]
+}
diff --git a/system/utils/BUILD.gn b/system/utils/BUILD.gn
new file mode 100644
index 00000000000..8d74aead0e8
--- /dev/null
+++ b/system/utils/BUILD.gn
@@ -0,0 +1,13 @@
+source_set("utils") {
+  sources = [
+    "src/bt_utils.c"
+  ]
+
+  include_dirs = [
+    "include",
+    "//btcore/include",
+    "//osi/include",
+    "//stack/include",
+    "//",
+  ]
+}
-- 
GitLab