Merge "Convert to Android.bp" am: d81c8f2604
am: 5cbed885dd

Change-Id: I3e22c05a39923da8e6d5718e077327dd53a6e438
diff --git a/Android.bp b/Android.bp
new file mode 100644
index 0000000..a8e21e3
--- /dev/null
+++ b/Android.bp
@@ -0,0 +1,47 @@
+NETNS_RUN_DIR = "/mnt/run"
+
+cc_library_headers {
+    name: "iproute2_headers",
+    export_include_dirs: ["include"],
+}
+
+cc_defaults {
+    name: "iproute2_defaults",
+
+    header_libs: ["iproute2_headers"],
+
+    cflags: [
+        "-O2",
+        "-g",
+        "-W",
+        "-Wall",
+        "-Wno-pointer-arith",
+        "-Wno-sign-compare",
+        "-Wno-unused-parameter",
+        "-Werror",
+
+        "-DHAVE_ERRNO_H",
+        "-DHAVE_EXT2_IOCTLS",
+        "-DHAVE_GETPAGESIZE",
+        "-DHAVE_LINUX_FD_H",
+        "-DHAVE_LSEEK64",
+        "-DHAVE_LSEEK64_PROTOTYPE",
+        "-DHAVE_MMAP",
+        "-DHAVE_NETINET_IN_H",
+        "-DHAVE_SELINUX",
+        "-DHAVE_SETNS",
+        "-DHAVE_STDLIB_H",
+        "-DHAVE_STRDUP",
+        "-DHAVE_SYS_IOCTL_H",
+        "-DHAVE_SYS_MMAN_H",
+        "-DHAVE_SYS_MOUNT_H",
+        "-DHAVE_SYS_PRCTL_H",
+        "-DHAVE_SYS_RESOURCE_H",
+        "-DHAVE_SYS_SELECT_H",
+        "-DHAVE_SYS_STAT_H",
+        "-DHAVE_SYS_TYPES_H",
+        "-DHAVE_TYPE_SSIZE_T",
+        "-DHAVE_UNISTD_H",
+        "-DHAVE_UTIME_H",
+    ],
+}
diff --git a/Android.mk b/Android.mk
deleted file mode 100644
index 962bdce..0000000
--- a/Android.mk
+++ /dev/null
@@ -1,7 +0,0 @@
-# Explicitly list the bionic UAPI includes so we don't pick up stray
-# vendor copies of the UAPI includes that are too old for us to build.
-UAPI_INCLUDES := bionic/libc/kernel/uapi
-
-NETNS_RUN_DIR ?= /mnt/run
-
-include $(call all-subdir-makefiles)
diff --git a/ip/Android.bp b/ip/Android.bp
new file mode 100644
index 0000000..1b6ca1f
--- /dev/null
+++ b/ip/Android.bp
@@ -0,0 +1,65 @@
+cc_binary {
+    name: "ip",
+    defaults: ["iproute2_defaults"],
+
+    srcs: [
+        "ip.c",
+        "ipaddress.c",
+        "ipaddrlabel.c",
+        "iproute.c",
+        "iprule.c",
+        "ipnetns.c",
+        "rtm_map.c",
+        "iptunnel.c",
+        "ip6tunnel.c",
+        "tunnel.c",
+        "ipneigh.c",
+        "ipntable.c",
+        "iplink.c",
+        "ipmaddr.c",
+        "ipmonitor.c",
+        "ipmroute.c",
+        "ipprefix.c",
+        "iptuntap.c",
+        "ipxfrm.c",
+        "xfrm_state.c",
+        "xfrm_policy.c",
+        "xfrm_monitor.c",
+        "iplink_vlan.c",
+        "link_veth.c",
+        "link_gre.c",
+        "iplink_can.c",
+        "iplink_macvlan.c",
+        "ipl2tp.c",
+        "ipfou.c",
+        "iptoken.c",
+        "tcp_metrics.c",
+        "ipnetconf.c",
+        "iproute_lwtunnel.c",
+        "iplink_xdp.c",
+        "iplink_vrf.c",
+        "iplink_xstats.c",
+        "ipila.c",
+        "ipmacsec.c",
+        "ipseg6.c",
+        "ipvrf.c",
+    ],
+
+    shared_libs: [
+        "libiprouteutil",
+        "libnetlink",
+    ],
+
+    cflags: [
+        "-Wno-implicit-function-declaration",
+        "-Wno-int-conversion",
+        "-Wno-missing-field-initializers",
+        "-D_GNU_SOURCE",
+        "-DNETNS_RUN_DIR=\"" + NETNS_RUN_DIR + "\"",
+    ],
+
+    ldflags: [
+        "-Wl,-export-dynamic",
+        "-Wl,--no-gc-sections",
+    ],
+}
diff --git a/ip/Android.mk b/ip/Android.mk
deleted file mode 100644
index 23ffbfd..0000000
--- a/ip/Android.mk
+++ /dev/null
@@ -1,41 +0,0 @@
-LOCAL_PATH := $(call my-dir)
-
-include $(CLEAR_VARS)
-LOCAL_SRC_FILES := ip.c ipaddress.c ipaddrlabel.c iproute.c iprule.c ipnetns.c \
-        rtm_map.c iptunnel.c ip6tunnel.c tunnel.c ipneigh.c ipntable.c iplink.c \
-        ipmaddr.c ipmonitor.c ipmroute.c ipprefix.c iptuntap.c \
-        ipxfrm.c xfrm_state.c xfrm_policy.c xfrm_monitor.c \
-        iplink_vlan.c link_veth.c link_gre.c iplink_can.c \
-        iplink_macvlan.c ipl2tp.c \
-        ipfou.c iptoken.c tcp_metrics.c ipnetconf.c \
-        iproute_lwtunnel.c iplink_xdp.c iplink_vrf.c iplink_xstats.c \
-        ipila.c ipmacsec.c ipseg6.c ipvrf.c
-
-LOCAL_MODULE := ip
-
-LOCAL_MODULE_TAGS := optional
-
-LOCAL_SHARED_LIBRARIES := libc libm libdl
-
-LOCAL_SHARED_LIBRARIES += libiprouteutil libnetlink
-
-LOCAL_C_INCLUDES := $(LOCAL_PATH)/../include $(UAPI_INCLUDES)
-
-LOCAL_CFLAGS := \
-    -O2 -g \
-    -W -Wall \
-    -Wno-implicit-function-declaration \
-    -Wno-int-conversion \
-    -Wno-missing-field-initializers \
-    -Wno-pointer-arith \
-    -Wno-sign-compare \
-    -Wno-unused-parameter \
-    -Werror \
-    -D_GNU_SOURCE \
-    -DNETNS_RUN_DIR=\"$(NETNS_RUN_DIR)\" \
-    -DHAVE_SETNS \
-
-LOCAL_LDFLAGS := -Wl,-export-dynamic -Wl,--no-gc-sections
-
-include $(BUILD_EXECUTABLE)
-
diff --git a/lib/Android.bp b/lib/Android.bp
new file mode 100644
index 0000000..7b9f59c
--- /dev/null
+++ b/lib/Android.bp
@@ -0,0 +1,48 @@
+cc_library_shared {
+    name: "libiprouteutil",
+    defaults: ["iproute2_defaults"],
+
+    system_shared_libs: [
+        "libc",
+        "libdl",
+    ],
+
+    srcs: [
+        "color.c",
+        "utils.c",
+        "rt_names.c",
+        "ll_types.c",
+        "ll_proto.c",
+        "ll_addr.c",
+        "inet_proto.c",
+        "mpls_pton.c",
+        "namespace.c",
+        "names.c",
+        "libgenl.c",
+        "libnetlink.c",
+        "bpf.c",
+        "exec.c",
+        "fs.c",
+        "json_print.c",
+        "json_writer.c",
+    ],
+    cflags: [
+        "-DCONFDIR=\"/data/misc/net\"",
+        "-DNETNS_RUN_DIR=\"" + NETNS_RUN_DIR + "\"",
+        "-D_GNU_SOURCE",
+    ],
+
+    // This is a work around for b/18403920
+    ldflags: ["-Wl,--no-gc-sections"],
+}
+
+cc_library_shared {
+    name: "libnetlink",
+    defaults: ["iproute2_defaults"],
+
+    system_shared_libs: ["libc"],
+    srcs: [
+        "ll_map.c",
+        "libnetlink.c",
+    ],
+}
diff --git a/lib/Android.mk b/lib/Android.mk
deleted file mode 100644
index e1bd3fe..0000000
--- a/lib/Android.mk
+++ /dev/null
@@ -1,81 +0,0 @@
-LOCAL_PATH := $(call my-dir)
-
-include $(CLEAR_VARS)
-LOCAL_SRC_FILES := \
-    color.c utils.c rt_names.c ll_types.c ll_proto.c ll_addr.c inet_proto.c \
-    mpls_pton.c namespace.c names.c libgenl.c libnetlink.c bpf.c exec.c fs.c \
-    json_print.c json_writer.c
-LOCAL_MODULE := libiprouteutil
-LOCAL_SYSTEM_SHARED_LIBRARIES := libc
-
-LOCAL_C_INCLUDES := $(LOCAL_PATH)/../include $(UAPI_INCLUDES)
-LOCAL_CFLAGS := -O2 -g -W -Wall \
-	-DCONFDIR=\"/data/misc/net\" \
-	-DNETNS_RUN_DIR=\"$(NETNS_RUN_DIR)\" \
-	-DHAVE_UNISTD_H \
-	-DHAVE_ERRNO_H \
-	-DHAVE_NETINET_IN_H \
-	-DHAVE_SYS_IOCTL_H \
-	-DHAVE_SYS_MMAN_H \
-	-DHAVE_SYS_MOUNT_H \
-	-DHAVE_SYS_PRCTL_H \
-	-DHAVE_SYS_RESOURCE_H \
-	-DHAVE_SYS_SELECT_H \
-	-DHAVE_SYS_STAT_H \
-	-DHAVE_SYS_TYPES_H \
-	-DHAVE_STDLIB_H \
-	-DHAVE_STRDUP \
-	-DHAVE_MMAP \
-	-DHAVE_UTIME_H \
-	-DHAVE_GETPAGESIZE \
-	-DHAVE_LSEEK64 \
-	-DHAVE_LSEEK64_PROTOTYPE \
-	-DHAVE_EXT2_IOCTLS \
-	-DHAVE_LINUX_FD_H \
-	-DHAVE_TYPE_SSIZE_T \
-	-DHAVE_SETNS \
-	-D_GNU_SOURCE \
-	-Wno-pointer-arith \
-	-Wno-sign-compare \
-	-Wno-unused-parameter \
-	-Werror
-
-# This is a work around for b/18403920
-LOCAL_LDFLAGS := -Wl,--no-gc-sections
-
-include $(BUILD_SHARED_LIBRARY)
-
-include $(CLEAR_VARS)
-LOCAL_SRC_FILES := ll_map.c libnetlink.c
-LOCAL_MODULE := libnetlink
-LOCAL_SYSTEM_SHARED_LIBRARIES := libc
-
-LOCAL_C_INCLUDES := $(LOCAL_PATH)/../include $(UAPI_INCLUDES)
-LOCAL_CFLAGS := -O2 -g -W -Wall \
-	-DHAVE_UNISTD_H \
-	-DHAVE_ERRNO_H \
-	-DHAVE_NETINET_IN_H \
-	-DHAVE_SYS_IOCTL_H \
-	-DHAVE_SYS_MMAN_H \
-	-DHAVE_SYS_MOUNT_H \
-	-DHAVE_SYS_PRCTL_H \
-	-DHAVE_SYS_RESOURCE_H \
-	-DHAVE_SYS_SELECT_H \
-	-DHAVE_SYS_STAT_H \
-	-DHAVE_SYS_TYPES_H \
-	-DHAVE_STDLIB_H \
-	-DHAVE_STRDUP \
-	-DHAVE_MMAP \
-	-DHAVE_UTIME_H \
-	-DHAVE_GETPAGESIZE \
-	-DHAVE_LSEEK64 \
-	-DHAVE_LSEEK64_PROTOTYPE \
-	-DHAVE_EXT2_IOCTLS \
-	-DHAVE_LINUX_FD_H \
-	-DHAVE_TYPE_SSIZE_T \
-	-Wno-pointer-arith \
-	-Wno-sign-compare \
-	-Wno-unused-parameter \
-	-Werror
-
-include $(BUILD_SHARED_LIBRARY)
diff --git a/misc/Android.bp b/misc/Android.bp
new file mode 100644
index 0000000..8e86e72
--- /dev/null
+++ b/misc/Android.bp
@@ -0,0 +1,23 @@
+cc_binary {
+    name: "ss",
+    defaults: ["iproute2_defaults"],
+
+    srcs: [
+        "ss.c",
+        "ssfilter.y",
+    ],
+
+    shared_libs: [
+        "libiprouteutil",
+        "libnetlink",
+        "libselinux",
+    ],
+
+    cflags: [
+        "-Wno-missing-field-initializers",
+        "-Wno-tautological-pointer-compare",
+        "-Dsethostent(x)=",
+    ],
+
+    ldflags: ["-Wl,-export-dynamic"],
+}
diff --git a/misc/Android.mk b/misc/Android.mk
deleted file mode 100644
index 2fd1307..0000000
--- a/misc/Android.mk
+++ /dev/null
@@ -1,37 +0,0 @@
-LOCAL_PATH := $(call my-dir)
-
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := ss.c ssfilter.y
-
-LOCAL_MODULE := ss
-
-LOCAL_MODULE_TAGS := debug
-
-LOCAL_SHARED_LIBRARIES += libiprouteutil libnetlink libselinux
-
-LOCAL_C_INCLUDES := $(LOCAL_PATH)/../include $(UAPI_INCLUDES)
-
-##
-# "-x c" forces the lex/yacc files to be compiled as c the build system
-# otherwise forces them to be c++.
-yacc_flags := -x c
-
-LOCAL_CFLAGS := \
-    -O2 -g \
-    -W -Wall \
-    -Wno-missing-field-initializers \
-    -Wno-sign-compare \
-    -Wno-tautological-pointer-compare \
-    -Wno-unused-parameter \
-    -Werror \
-    '-Dsethostent(x)=' \
-    $(yacc_flags) \
-    -DHAVE_SETNS \
-    -DHAVE_SELINUX
-
-LOCAL_CPPFLAGS := $(yacc_flags)
-
-LOCAL_LDFLAGS := -Wl,-export-dynamic
-include $(BUILD_EXECUTABLE)
-
diff --git a/tc/Android.bp b/tc/Android.bp
new file mode 100644
index 0000000..a87da51
--- /dev/null
+++ b/tc/Android.bp
@@ -0,0 +1,36 @@
+cc_binary {
+    name: "tc",
+    defaults: ["iproute2_defaults"],
+
+    srcs: [
+        "tc.c",
+        "tc_exec.c",
+        "tc_qdisc.c",
+        "q_cbq.c",
+        "tc_util.c",
+        "tc_class.c",
+        "tc_core.c",
+        "m_action.c",
+        "m_estimator.c",
+        "tc_filter.c",
+        "tc_monitor.c",
+        "tc_stab.c",
+        "tc_cbq.c",
+        "tc_estimator.c",
+        "f_u32.c",
+        "m_police.c",
+        "q_ingress.c",
+        "m_mirred.c",
+        "q_htb.c",
+    ],
+
+    shared_libs: [
+        "libiprouteutil",
+        "libnetlink",
+    ],
+
+    cflags: ["-Wno-missing-field-initializers"],
+
+    // This is a work around for b/18403920
+    ldflags: ["-Wl,--no-gc-sections"],
+}
diff --git a/tc/Android.mk b/tc/Android.mk
deleted file mode 100644
index 78463a8..0000000
--- a/tc/Android.mk
+++ /dev/null
@@ -1,25 +0,0 @@
-LOCAL_PATH := $(call my-dir)
-
-include $(CLEAR_VARS)
-LOCAL_SRC_FILES :=  tc.c tc_exec.c tc_qdisc.c q_cbq.c tc_util.c tc_class.c tc_core.c m_action.c \
-                    m_estimator.c tc_filter.c tc_monitor.c tc_stab.c tc_cbq.c \
-                    tc_estimator.c f_u32.c m_police.c q_ingress.c m_mirred.c q_htb.c
-
-LOCAL_MODULE := tc
-
-LOCAL_SYSTEM_SHARED_LIBRARIES := \
-	libc libm libdl
-
-LOCAL_SHARED_LIBRARIES += libiprouteutil libnetlink
-
-LOCAL_C_INCLUDES := $(LOCAL_PATH)/../include $(UAPI_INCLUDES)
-
-LOCAL_CFLAGS := -O2 -g -W -Wall -Wno-pointer-arith -Wno-sign-compare -Werror \
-    -Wno-unused-parameter \
-    -Wno-missing-field-initializers
-
-# This is a work around for b/18403920
-LOCAL_LDFLAGS := -Wl,--no-gc-sections
-
-include $(BUILD_EXECUTABLE)
-