# Copyright (C) 2023-2025 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("//build/ohos.gni")

libfuse_source = [
  "//third_party/libfuse/lib/buffer.c",
  "//third_party/libfuse/lib/compat.c",
  "//third_party/libfuse/lib/cuse_lowlevel.c",
  "//third_party/libfuse/lib/fuse_log.c",
  "//third_party/libfuse/lib/fuse_loop_mt.c",
  "//third_party/libfuse/lib/fuse_loop.c",
  "//third_party/libfuse/lib/fuse_lowlevel.c",
  "//third_party/libfuse/lib/fuse_opt.c",
  "//third_party/libfuse/lib/fuse_signals.c",
  "//third_party/libfuse/lib/fuse.c",
  "//third_party/libfuse/lib/helper.c",
  "//third_party/libfuse/lib/mount_util.c",
  "//third_party/libfuse/lib/mount.c",
  "//third_party/libfuse/lib/util.c",
  "//third_party/libfuse/lib/modules/iconv.c",
  "//third_party/libfuse/lib/modules/subdir.c",
]

import("//build/ohos.gni")

config("libfuse_public_config") {
  visibility = [ ":*" ]

  include_dirs = [
    "//third_party/libfuse/include",
    "//third_party/libfuse/lib",
    "//third_party/libfuse/util",
  ]
}

config("libfuse_config") {
  visibility = [ ":*" ]

  include_dirs = [
    "//third_party/libfuse/include",
    "//third_party/libfuse/lib",
    "//third_party/libfuse",
  ]

  cflags = [
    "-fdiagnostics-color=always",
    "-pipe",
    "-D_FILE_OFFSET_BITS=64",
    "-Winvalid-pch",
    "-Wextra",
    "-O2",
    "-g",
    "-D_REENTRANT",
    "-Wno-sign-compare",
    "-Wmissing-declarations",
    "-Wwrite-strings",
    "-Wno-unused-result",
    "-DFUSE_USE_VERSION=317",
    "-DFUSERMOUNT_DIR=\"/usr/local/bin\"",
    "-U_GNU_SOURCE",
    "-pthread",
  ]
}

ohos_shared_library("libfuse") {
  configs = [ "//third_party/libfuse:libfuse_config" ]
  public_configs = [ ":libfuse_public_config" ]
  sources = libfuse_source
  license_file = "./LGPL2.txt"
  ldflags = [
    "-ldl",
    "-Wl,--version-script",
    rebase_path("//third_party/libfuse/lib/fuse_versionscript", root_build_dir),
    "-Wl,-soname,libfuse3.so.4",
    "-Wl,--no-undefined",
    "-Wl,--as-needed",
    "-shared",
    "-fPIC",
    "-Wl,-mllvm,-import-instr-limit=0",
  ]
  innerapi_tags = [ "platformsdk" ]
  external_deps = [ "c_utils:utils" ]
  subsystem_name = "thirdparty"
  part_name = "libfuse"
  output_name = "libfuse"
  install_enable = true
  install_images = [
    "system",
    "updater",
  ]
}