blob: dec809a99ecaf57e1ce7803da9050738f203ff67 [file] [log] [blame]
# Copyright 2016 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.
# Define the sysroot directory.
sysroot = "$root_out_dir/sysroot"
sysroot_lib_dir = "${sysroot}/usr/lib"
sysroot_include_dir = "${sysroot}/usr/include"
config("fusl_config") {
cflags = [
# Flags from musl
"-std=c99",
"-ffreestanding",
"-nostdinc",
"-D_XOPEN_SOURCE=700",
"-Wa,--noexecstack",
"-fomit-frame-pointer",
"-fno-unwind-tables",
"-fno-asynchronous-unwind-tables",
"-ffunction-sections",
"-fdata-sections",
"-Werror=implicit-function-declaration",
"-Werror=implicit-int",
"-Werror=pointer-sign",
"-Werror=pointer-arith",
]
include_dirs = []
# Arch specific includes, these need to come before the general includes.
if (current_cpu == "x64") {
include_dirs += [ "arch/x86_64" ]
}
# General includes, these need to come after the arch specific includes.
# src/internal must come before include.
include_dirs += [
"src/internal",
"include",
]
}
config("fusl_no_stack_protector_config") {
cflags = [ "-fno-stack-protector" ]
}
static_library("libc") {
configs = []
configs += [ ":fusl_config" ]
complete_static_lib = true
deps = [
"src/aio",
"src/complex",
"src/conf",
"src/crypt",
"src/ctype",
"src/dirent",
"src/env",
"src/errno",
"src/exit",
"src/fcntl",
"src/fenv",
"src/internal",
"src/ipc",
"src/ldso",
"src/legacy",
"src/linux",
"src/locale",
"src/malloc",
"src/math",
"src/misc",
"src/mman",
"src/mq",
"src/multibyte",
"src/network",
"src/passwd",
"src/prng",
"src/process",
"src/regex",
"src/sched",
"src/search",
"src/select",
"src/setjmp",
"src/signal",
"src/stat",
"src/stdio",
"src/stdlib",
"src/string",
"src/temp",
"src/termios",
"src/thread",
"src/time",
"src/unistd",
]
}
# For simplicity, musl places all its symbols in libc. To support
# linking against e.g. libm, either implicitly or with an explicit -lm
# flag, we build empty libraries.
static_library("libm") {
complete_static_lib = true
}
copy("copy_include") {
sources = [
"include",
]
outputs = [
"${sysroot_include_dir}",
]
}
copy("copy_include_bits") {
deps = [
":copy_include",
]
if (current_cpu == "x64") {
sources = [
"arch/x86_64/bits",
]
}
outputs = [
"${sysroot_include_dir}/{{source_name_part}}",
]
}
copy("copy_libs") {
deps = [
":libc",
":libm",
]
sources = [
"${target_out_dir}/libc.a",
"${target_out_dir}/libm.a",
]
outputs = [
"${sysroot_lib_dir}/{{source_name_part}}.a",
]
}
group("copy_sysroot") {
deps = [
":copy_include",
":copy_include_bits",
":copy_libs",
"crt:copy_crt_objects",
]
}
config("sysroot_config") {
rebased_sysroot = rebase_path(sysroot)
cflags = [
"--sysroot=$rebased_sysroot",
"-fPIC",
"-static",
]
ldflags = [
"--sysroot=$rebased_sysroot",
"-static",
]
}
executable("empty_main") {
configs = []
configs += [ ":sysroot_config" ]
sources = [
"test/empty_main.c",
]
deps = [
":copy_sysroot",
]
}
group("fusl") {
deps = [
":empty_main(//build/toolchain/fusl:fusl_$current_cpu)",
":libc(//build/toolchain/fusl:fusl_$current_cpu)",
"crt(//build/toolchain/fusl:fusl_$current_cpu)",
]
}