# Copyright (C) 2021 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import("//gn/wasm.gni") declare_args() { if (target_os == "linux" || target_os == "macx") { cc = "/usr/bin/clang" cxx = "/usr/bin/clang++" pic = "-fPIC" } else if (target_os == "windows") { cc = "gcc.exe" cxx = "g++.exe" pic = "" } if (use_wasm == true) { print("make_wasm") } else if (use_wasm == false) { print("no make_wasm") } cc_wrapper = "" } toolchain("wasm") { # emsdk_dir and em_config are defined in wasm.gni. print("use gcc_like_chain wasm") if (!is_macx) { ar = "$emsdk_dir/emscripten/emar --em-config $em_config" } cc = "$emsdk_dir/emscripten/emcc --em-config $em_config" cxx = "$emsdk_dir/emscripten/em++ --em-config $em_config" lib_switch = "-l" ld_arg = "" lib_dir_switch = "-L" external_cxxflags = "" external_cflags = "" external_ldflags = "" if (defined(linker) && linker != "") { ld_arg = "-fuse-ld=$_invoker_linker" _invoker_linker = linker } if (defined(sysroot) && sysroot != "") { _invoker_sysroot = sysroot cxx = "$cxx --sysroot=$_invoker_sysroot" cc = "$cc --sysroot=$_invoker_sysroot" } if (defined(gcc_toolchain) && gcc_toolchain != "") { ld_arg = "$ld_arg --gcc-toolchain=$gcc_toolchain" } if (defined(external_cxxflags)) { print("defined external_cxxflags") external_cxxflags = external_cxxflags } if (defined(external_cflags)) { external_cflags = external_cflags } tool("cc") { depfiles = "{{output}}.d" command = "$cc_wrapper $cc -MMD -MF $depfiles {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} ${external_cflags} -c {{source}} -o {{output}}" outputfiles = "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o" outputs = [ outputfiles ] description = "step: compile {{source}}" } tool("cxx") { depfiles = "{{output}}.d" # must be defined command = "$cc_wrapper $cxx -MMD -MF $depfiles {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} ${external_cflags} ${external_cxxflags} -c {{source}} -o {{output}}" outputfiles = "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o" outputs = [ outputfiles ] description = "step: compile {{source}}" } tool("alink") { rspfile = "{{output}}.rsp" # must be defined rspfile_content = "{{inputs}}" if (is_macx) { command = "rm -f {{output}} && libtool -static {{arflags}} -o {{output}} -filelist $rspfile" } else { command = "rm -rf {{output}} && $ar rcsD {{output}} @$rspfile" } outputfiles = "{{root_out_dir}}/{{target_output_name}}{{output_extension}}" outputs = [ outputfiles ] output_prefix = "lib" default_output_extension = ".a" description = "step: link {{output}}" } tool("solink") { sonames = "{{target_output_name}}{{output_extension}}" outputfiles = "{{root_out_dir}}/$sonames" unstripped_so = outputfiles rpath = "" outputs = [ outputfiles ] command = "$cc_wrapper $cxx $ld_arg -shared {{ldflags}} ${external_ldflags} {{inputs}} {{solibs}} {{libs}} $rpath -o {{output}}" output_prefix = "lib" description = "step: link $unstripped_so" default_output_extension = ".so" } tool("link") { outputfiles = "{{root_out_dir}}/{{target_output_name}}{{output_extension}}" outputs = [ outputfiles ] command = "$cc_wrapper $cxx $ld_arg {{ldflags}} ${external_ldflags} {{inputs}} {{solibs}} {{libs}} -o {{output}}" description = "step:link {{output}}" } tool("stamp") { description = "step: stamp {{output}}" command = "touch {{output}}" } tool("copy") { description = "step: COPY files from {{source}} to {{output}}" command = "cp -arf {{source}} {{output}}" } } toolchain("gcc_like") { lib_switch = "-l" lib_dir_switch = "-L" tool("cxx") { depfile = "{{output}}.d" # must be defined command = "$cxx -o {{output}} -MMD -MF $depfile {{defines}} $pic {{include_dirs}} {{cflags}} {{cflags_cc}} -c {{source}}" outputfiles = "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o" outputs = [ outputfiles ] description = "step: compile {{source}}" } tool("cc") { depfile = "{{output}}.d" command = "$cc -o {{output}} -MMD -MF $depfile {{defines}} $pic {{include_dirs}} {{cflags}} {{cflags_c}} -c {{source}}" outputfiles = "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o" outputs = [ outputfiles ] description = "step: compile {{source}}" } tool("alink") { rspfile = "{{output}}.rsp" # this must be defined if (is_macx) { rspfile_content = "{{inputs_newline}}" command = "rm -f {{output}} && libtool -static {{arflags}} -filelist $rspfile -o {{output}}" } else { rspfile_content = "{{inputs}}" # this must be defined command = "rm -f {{output}} && $ar rcsD {{output}} @$rspfile" } outputsfiles = "{{root_out_dir}}/{{target_output_name}}{{output_extension}}" outputs = [ outputsfiles ] default_output_extension = ".a" output_prefix = "lib" description = "step: link {{output}}" } tool("link") { command = "$cxx -o {{output}} {{ldflags}} {{inputs}} {{solibs}} {{libs}}" outputsfiles = "{{root_out_dir}}/{{target_output_name}}{{output_extension}}" outputs = [ outputsfiles ] description = "step: link {{output}}" } tool("solink") { default_output_extension = ".so" command = "$cxx -o {{output}} {{ldflags}} {{inputs}} {{solibs}} {{libs}} -shared" outputsfiles = "{{root_out_dir}}/{{target_output_name}}{{output_extension}}" outputs = [ outputsfiles ] description = "step: solink {{output}}" } tool("stamp") { print("need do nothing") description = "step: touch {{output}}" command = "touch {{output}}" } tool("copy") { description = "COPY files from {{source}} to {{output}}" command = "cp -arf {{source}} {{output}}" } }