build: Support OpenWRT builds

This commit is contained in:
klzgrad 2019-11-30 22:23:52 +08:00
parent d8894ad108
commit 8072e5c86b
2 changed files with 32 additions and 4 deletions

View File

@ -128,6 +128,8 @@ declare_args() {
# By default only the binaries in official builds get build IDs. # By default only the binaries in official builds get build IDs.
force_local_build_id = false force_local_build_id = false
is_openwrt = false
} }
declare_args() { declare_args() {
@ -561,6 +563,11 @@ config("compiler") {
ldflags += [ "-stdlib=libc++" ] ldflags += [ "-stdlib=libc++" ]
} }
if (is_openwrt && current_cpu == target_cpu) {
defines += [ "_LIBCPP_HAS_MUSL_LIBC", "__UCLIBC__" ]
libs = [ "atomic" ]
}
# Add flags for link-time optimization. These flags enable # Add flags for link-time optimization. These flags enable
# optimizations/transformations that require whole-program visibility at link # optimizations/transformations that require whole-program visibility at link
# time, so they need to be applied to all translation units, and we may end up # time, so they need to be applied to all translation units, and we may end up
@ -764,6 +771,9 @@ config("compiler_cpu_abi") {
if (is_android) { if (is_android) {
cflags += [ "--target=mipsel-linux-android" ] cflags += [ "--target=mipsel-linux-android" ]
ldflags += [ "--target=mipsel-linux-android" ] ldflags += [ "--target=mipsel-linux-android" ]
} else if (is_openwrt) {
cflags += [ "--target=mipsel-openwrt-linux-musl" ]
ldflags += [ "--target=mipsel-openwrt-linux-musl" ]
} else { } else {
cflags += [ "--target=mipsel-linux-gnu" ] cflags += [ "--target=mipsel-linux-gnu" ]
ldflags += [ "--target=mipsel-linux-gnu" ] ldflags += [ "--target=mipsel-linux-gnu" ]
@ -846,8 +856,13 @@ config("compiler_cpu_abi") {
ldflags += [ "-Wl,--hash-style=sysv" ] ldflags += [ "-Wl,--hash-style=sysv" ]
if (custom_toolchain == "") { if (custom_toolchain == "") {
if (is_clang) { if (is_clang) {
if (is_openwrt) {
cflags += [ "--target=mips-openwrt-linux-musl" ]
ldflags += [ "--target=mips-openwrt-linux-musl" ]
} else {
cflags += [ "--target=mips-linux-gnu" ] cflags += [ "--target=mips-linux-gnu" ]
ldflags += [ "--target=mips-linux-gnu" ] ldflags += [ "--target=mips-linux-gnu" ]
}
} else { } else {
cflags += [ "-EB" ] cflags += [ "-EB" ]
ldflags += [ "-EB" ] ldflags += [ "-EB" ]
@ -895,6 +910,9 @@ config("compiler_cpu_abi") {
if (is_android) { if (is_android) {
cflags += [ "--target=mips64el-linux-android" ] cflags += [ "--target=mips64el-linux-android" ]
ldflags += [ "--target=mips64el-linux-android" ] ldflags += [ "--target=mips64el-linux-android" ]
} else if (is_openwrt) {
cflags += [ "--target=mips64el-openwrt-linux-musl" ]
ldflags += [ "--target=mips64el-openwrt-linux-musl" ]
} else { } else {
cflags += [ "--target=mips64el-linux-gnuabi64" ] cflags += [ "--target=mips64el-linux-gnuabi64" ]
ldflags += [ "--target=mips64el-linux-gnuabi64" ] ldflags += [ "--target=mips64el-linux-gnuabi64" ]
@ -955,8 +973,13 @@ config("compiler_cpu_abi") {
ldflags += [ "-Wl,--hash-style=sysv" ] ldflags += [ "-Wl,--hash-style=sysv" ]
if (custom_toolchain == "") { if (custom_toolchain == "") {
if (is_clang) { if (is_clang) {
if (is_openwrt) {
cflags += [ "--target=mips64-openwrt-linux-musl" ]
ldflags += [ "--target=mips64-openwrt-linux-musl" ]
} else {
cflags += [ "--target=mips64-linux-gnuabi64" ] cflags += [ "--target=mips64-linux-gnuabi64" ]
ldflags += [ "--target=mips64-linux-gnuabi64" ] ldflags += [ "--target=mips64-linux-gnuabi64" ]
}
} else { } else {
cflags += [ cflags += [
"-EB", "-EB",

View File

@ -108,6 +108,11 @@ config("executable_config") {
"-Wl,--disable-new-dtags", "-Wl,--disable-new-dtags",
] ]
} }
# Needed for non-standard ldso on OpenWRT
if (ldso_path != "" && current_cpu == target_cpu) {
ldflags += [ "-Wl,--dynamic-linker=${ldso_path}" ]
}
} }
# Settings for shared libraries. # Settings for shared libraries.