set_project("DnfProject")
set_version("1.0.0")

-- 设置 C++ 标准
set_languages("c++11")

-- 设置 32 位架构
set_arch("i386")

-- 添加 32 位编译选项
add_cxflags("-m32")
add_ldflags("-m32")
add_asflags("-m32")
add_shflags("-m32")

-- CentOS 7 兼容性选项 - 静态链接 C/C++ 运行时
add_cxflags("-static-libgcc", "-static-libstdc++")
add_ldflags("-static-libgcc", "-static-libstdc++")

-- 添加调试和发布模式
if is_mode("debug") then
    set_symbols("debug")
    set_optimize("none")
    add_cxflags("-g", "-O0")
elseif is_mode("release") then
    set_symbols("hidden")
    set_optimize("fastest")
    set_strip("all")
end

-- 定义编译选项
add_cxflags(
    "-Wno-pointer-arith",
    "-Wdeprecated-declarations",
    "-fvisibility=hidden",
    "-fno-asynchronous-unwind-tables",
    "-fpic",
    "-fexceptions",
    "-Wno-int-to-pointer-cast"
)

-- 添加宏定义
add_defines("ASMJIT_STATIC")

-- 定义目标
target("Aurora")
    set_kind("shared")
    add_ldflags("-Wl,--no-as-needed")

    -- 添加源文件
    add_files("src/*.cpp")
    add_files("src/asmjit/core/*.cpp")
    add_files("src/asmjit/arm/*.cpp")
    add_files("src/asmjit/x86/*.cpp")
    
    -- 添加头文件搜索路径
    add_includedirs("include")
    add_includedirs("src")
    add_includedirs("src/sdk")
    add_includedirs("src/sdk")
    add_includedirs("3rd/squirrel/include")
    add_includedirs("3rd/asio/include")
    add_includedirs("3rd/openssl/include")
    --系统32位路径
    add_includedirs("/usr/local/opencc-32bit/include")
    add_includedirs("/usr/local/keystone-32bit/include")
    
    -- 添加系统库链接 (注意：不包含 atomic，我们将手动静态链接)
    add_syslinks("pthread", "dl", "resolv")
    
    -- 设置输出名称
    set_basename("Aurora")
    
    -- 安装目标
    set_targetdir("/dp_s/lib")
    set_objectdir("$(builddir)/obj")
    
    -- 使用 add_shflags 添加静态库（专门用于共享库链接）
    -- 注意：这些路径是 CentOS 7 上的绝对路径
    add_shflags("/usr/lib/gcc/x86_64-redhat-linux/4.8.2/32/libstdc++.a", {force = true})
    add_shflags("3rd/squirrel/build/lib/libsqstdlib_static.a", {force = true})
    add_shflags("3rd/squirrel/build/lib/libsquirrel_static.a", {force = true})
    add_shflags("3rd/openssl/libssl.a", {force = true})
    add_shflags("3rd/openssl/libcrypto.a", {force = true})
    add_shflags("3rd/frida/libfrida-gum.a", {force = true})
    add_shflags("/usr/local/libffi-32bit/lib/libffi.a", {force = true})
    add_shflags("/usr/local/opencc-32bit/lib/libopencc.a", {force = true})
    add_shflags("/usr/local/keystone-32bit/lib/libkeystone.a", {force = true})
    add_shflags("3rd/zlib/libz.a", {force = true})
    -- 静态链接 libatomic (必须在最后)
    add_shflags("/usr/lib/gcc/x86_64-redhat-linux/4.8.2/32/libatomic.a", {force = true})

