add_rules("mode.debug", "mode.release")

set_defaultmode("debug")

-- https://xmake.io/api/scripts/extension-modules/lib/detect.html

-- Run xmake project -k cmakelists for generating CMakeLists.txt
-- Run xmake project -k make for generating a Makefile

if not is_plat("windows", "mingw") then
    -- option("SNPRINTF")
    --     add_cincludes("stdio.h")
    --     add_cfuncs("snprintf")
    --     set_configvar("HAVE_SNPRINTF", "")

    option(
        "HTML_COMPRESSION",
        function ()
            set_default(true)
            set_configvar("HTML_COMPRESSION", 1)
        end
    )

    option(
        "SNPRINTF",
        function ()
            add_cincludes("stdio.h")
            add_cfuncs("snprintf")

            set_configvar("HAVE_SNPRINTF", 1)
        end
    )

    option(
        "VSNPRINTF",
        function ()
            add_cincludes("stdio.h")
            add_cfuncs("vsnprintf")

            set_configvar("HAVE_VSNPRINTF", 1)
        end
    )

    option(
        "STRTOK_R",
        function ()
            add_cincludes("string.h")
            add_cfuncs("strtok_r")

            set_configvar("HAVE_STRTOK_R", 1)
        end
    )

    option(
        "LOCALTIME_R",
        function ()
            add_cincludes("time.h")
            add_cfuncs("localtime_r")

            set_configvar("HAVE_LOCALTIME_R", 1)
        end
    )

    -- FIXME USE sys/time.h instead of time.h???
    option(
        "GMTIME_R",
        function ()
            add_cincludes("time.h")
            add_cfuncs("gmtime_r")

            set_configvar("HAVE_GMTIME_R", 1)
        end
    )

    option(
        "MKSTEMP",
        function ()
            add_cincludes("stdlib.h")
            add_cfuncs("mkstemp")

            set_configvar("HAVE_MKSTEMP", 1)
        end
    )

    option(
        "REGEX",
        function ()
            add_cincludes("regex.h")

            set_configvar("HAVE_REGEX", 1)
        end
    )

    option(
        "PTHREADS",
        function ()
            add_cincludes("pthread.h")
            add_links("pthread")

            set_configvar("HAVE_PTHREADS", 1)
        end
    )

    option(
        "LOCKF",
        function ()
            add_cincludes("unistd.h")
            add_cfuncs("lockf")

            set_configvar("HAVE_LOCKF", 1)
        end
    )

    -- Option to build against Berkeley DB V2
    -- Should link to db, and/or db2
    option(
        "DB2",
        function ()
            add_cincludes("util/wdb.h")
            add_links(
                {
                    "db", 
                    "db2"
                }
            )

            set_configvar("HAVE_DB2", 1)
        end
    )


    -- Make sure libintl.h is always gnu gettext and not another library
    option(
        "GETTEXT",
        function ()
            add_cincludes("libintl.h")

            set_configvar("ENABLE_GETTEXT", 1)
        end
    )

    -- FIXME USE sys/time.h instead of only time.h???
    -- FIXME Check that the tzname global variable is declared in time.h HERE!!!
    -- FIXME IF FALSE DEFINE TO HAVE_DECL_TZNAME=0
    option(
        "TZNAME",
        function ()
            add_cincludes("time.h")

            set_configvar("HAVE_DECL_TZNAME", 1)
        end
    )

    -- FIXME Check that the DIR global variable is declared in dirent.h
    -- FIXME IF FALSE DEFINE TO HAVE_DIRENT_H=0
    option(
        "DIRENT_H",
        function ()
            add_cincludes("dirent.h")

            set_configvar("HAVE_DIRENT_H", 1)
        end
    )

    -- FIXME Check that the _doprnt function exists only if vprintf isn't found 
    -- FIXME IF TRUE DEFINE TO HAVE_DOPRNT=1
    option(
        "DOPRNT",
        function ()
            add_cincludes("stdio.h")
            add_cfuncs("vprintf")

            set_configvar("HAVE_DOPRNT", 0)
        end
    )

    -- FIXME IF FALSE DEFINE TO HAVE_DRAND48=0
    option(
        "DRAND48",
        function ()
            add_cincludes("stdlib.h")
            add_cfuncs("drand48")

            set_configvar("HAVE_DRAND48", 1)
        end
    )

    -- FIXME IF FALSE DEFINE TO HAVE_FCNTL_H=0
    option(
        "FCNTL_H",
        function ()
            add_cincludes("fcntl.h")

            set_configvar("HAVE_FCNTL_H", 1)
        end
    )

    -- FIXME IF FALSE DEFINE TO HAVE_FEATURES_H=0
    option(
        "FEATURES_H",
        function ()
            add_cincludes("features.h")

            set_configvar("HAVE_FEATURES_H", 1)
        end
    )

    -- FIXME USE sys/time.h instead of only time.h??? 
    -- FIXME IF FALSE DEFINE TO HAVE_GETTIMEOFDAY=0
    option(
        "GETTIMEOFDAY",
        function ()
            add_cincludes("sys/time.h")
            add_cfuncs("gettimeofday")

            set_configvar("HAVE_GETTIMEOFDAY", 1)
        end
    )

    -- FIXME USE sys/time.h instead of only time.h??? 
    -- FIXME IF FALSE DEFINE TO HAVE_GMTIME_R=0
    option(
        "GMTIME_R",
        function ()
            add_cincludes("time.h")
            add_cfuncs("gmtime_r")

            set_configvar("HAVE_GMTIME_R", 1)
        end
    )

    -- FIXME IF FALSE DEFINE TO HAVE_INTTYPES_H=0
    option(
        "INTTYPES_H",
        function ()
            add_cincludes("inttypes.h")

            set_configvar("HAVE_INTTYPES_H", 1)
        end
    )

    -- FIXME IF FALSE DEFINE TO HAVE_LIMITS_H=0
    option(
        "LIMITS_H",
        function ()
            add_cincludes("limits.h")

            set_configvar("HAVE_LIMITS_H", 1)
        end
    )

    -- FIXME USE sys/time.h instead of only time.h??? 
    -- FIXME IF FALSE DEFINE TO HAVE_LOCALTIME_R=0
    option(
        "LOCALTIME_R",
        function ()
            add_cincludes("time.h")
            add_cfuncs("localtime_r")

            set_configvar("HAVE_LOCALTIME_R", 1)
        end
    )

    -- FIXME IF FALSE DEFINE TO HAVE_MEMORY_H=0
    option(
        "MEMORY_H",
        function ()
            add_cincludes("memory.h")

            set_configvar("HAVE_MEMORY_H", 1)
        end
    )

    -- FIXME USE sys/time.h instead of only time.h??? 
    -- FIXME IF FALSE DEFINE TO HAVE_MKTIME=0
    option(
        "MKTIME",
        function ()
            add_cincludes("time.h")
            add_cfuncs("mktime")

            set_configvar("HAVE_MKTIME", 1)
        end
    )

    -- FIXME IF FALSE DEFINE TO HAVE_NDIR_H=0
    option(
        "NDIR_H",
        function ()
            add_cincludes("ndir.h")

            set_configvar("HAVE_NDIR_H", 1)
        end
    )

    option(
        "PTHREAD",
        function ()
            add_cincludes("pthread.h")
            add_links("pthread")

            set_configvar("HAVE_PTHREAD", 1)
        end
    )

    -- FIXME IF FALSE DEFINE TO HAVE_PUTENV=0
    option(
        "PUTENV",
        function ()
            add_cincludes("stdlib.h")
            add_cfuncs("putenv")

            set_configvar("HAVE_PUTENV", 1)
        end
    )

    -- FIXME IF FALSE DEFINE TO HAVE_RAND=0
    option(
        "RAND",
        function ()
            add_cincludes("stdlib.h")
            add_cfuncs("rand")

            set_configvar("HAVE_RAND", 1)
        end
    )

    -- FIXME IF FALSE DEFINE TO HAVE_RAND=0
    option(
        "RANDOM",
        function ()
            add_cincludes("stdlib.h")
            add_cfuncs("random")

            set_configvar("HAVE_RAND", 1)
        end
    )

    -- FIXME IF FALSE DEFINE TO HAVE_STDARG_H=0
    option(
        "STDARG_H",
        function ()
            add_cincludes("stdarg.h")

            set_configvar("HAVE_STDARG_H", 1)
        end
    )

    -- FIXME IF FALSE DEFINE TO HAVE_STDINT_H=0
    option(
        "STDINT_H",
        function ()
            add_cincludes("stdint.h")

            set_configvar("HAVE_STDINT_H", 1)
        end
    )

    -- FIXME IF FALSE DEFINE TO HAVE_STDLIB_H=0
    option(
        "STDLIB_H",
        function ()
            add_cincludes("stdlib.h")

            set_configvar("HAVE_STDLIB_H", 1)
        end
    )

    -- FIXME IF FALSE DEFINE TO HAVE_STRERROR=0
    option(
        "STRERROR",
        function ()
            add_cincludes("string.h")
            add_cfuncs("strerror")

            set_configvar("HAVE_STRERROR", 1)
        end
    )

    -- FIXME USE sys/time.h instead of only time.h???
    -- FIXME IF FALSE DEFINE TO HAVE_STRFTIME=0
    option(
        "STRFTIME",
        function ()
            add_cincludes("time.h")
            add_cfuncs("strftime")

            set_configvar("HAVE_STRFTIME", 1)
        end
    )

    -- FIXME IF FALSE DEFINE TO HAVE_STRINGS_H=0
    option(
        "STRINGS_H",
        function ()
            add_cincludes("strings.h")

            set_configvar("HAVE_STRINGS_H", 1)
        end
    )

    -- FIXME IF FALSE DEFINE TO HAVE_STRING_H=0
    option(
        "STRING_H",
        function ()
            add_cincludes("string.h")

            set_configvar("HAVE_STRING_H", 1)
        end
    )

    -- FIXME IF FALSE DEFINE TO HAVE_STRSPN=0
    option(
        "STRSPN",
        function ()
            add_cincludes("string.h")
            add_cfuncs("strspn")

            set_configvar("HAVE_STRSPN", 1)
        end
    )

    -- FIXME IF FALSE DEFINE TO HAVE_STRTOD=0
    option(
        "STRTOD",
        function ()
            add_cincludes("stdlib.h")
            add_cfuncs("strtod")

            set_configvar("HAVE_STRTOD", 1)
        end
    )

    -- FIXME IF FALSE DEFINE TO HAVE_STRTOK_R=0
    option(
        "STRTOK_R",
        function ()
            add_cincludes("string.h")
            add_cfuncs("strtok_r")

            set_configvar("HAVE_STRTOK_R", 1)
        end
    )

    -- FIXME IF FALSE DEFINE TO HAVE_STRTOL=0
    option(
        "STRTOL",
        function ()
            add_cincludes("stdlib.h")
            add_cfuncs("strtol")

            set_configvar("HAVE_STRTOL", 1)
        end
    )

    -- FIXME IF FALSE DEFINE TO HAVE_STRTOUL=0
    option(
        "STRTOUL",
        function ()
            add_cincludes("stdlib.h")
            add_cfuncs("strtoul")

            set_configvar("HAVE_STRTOUL", 1)
        end
    )

    -- FIXME Check if `tm_zone' is a member of `struct tm' HERE!!!
    -- FIXME IF FALSE DEFINE TO HAVE_STRUCT_TM_TM_ZONE=0
    option(
        "STRUCT_TM_TM_ZONE",
        function ()
            add_cincludes("time.h")

            set_configvar("HAVE_STRUCT_TM_TM_ZONE", 1)
        end
    )

    -- FIXME Check that the DIR global variable is declared in sys/dir.h
    -- FIXME IF FALSE DEFINE TO HAVE_SYS_DIR_H=0
    option(
        "SYS_DIR_H",
        function ()
            add_cincludes("sys/dir.h")

            set_configvar("HAVE_SYS_DIR_H", 1)
        end
    )
    
    -- FIXME IF FALSE DEFINE TO HAVE_IOCTL_H=0
    option(
        "IOCTL_H",
        function ()
            add_cincludes("sys/ioctl.h")

            set_configvar("HAVE_IOCTL_H", 1)
        end
    )

    -- FIXME Check that the DIR global variable is declared in sys/ndir.h
    -- FIXME IF FALSE DEFINE TO HAVE_SYS_NDIR_H=0
    option(
        "SYS_NDIR_H",
        function ()
            add_cincludes("sys/ndir.h")

            set_configvar("HAVE_SYS_NDIR_H", 1)
        end
    )

    -- FIXME IF FALSE DEFINE TO HAVE_SYS_STAT_H=0
    option(
        "SYS_STAT_H",
        function ()
            add_cincludes("sys/stat.h")

            set_configvar("HAVE_SYS_STAT_H", 1)
        end
    )

    -- FIXME IF FALSE DEFINE TO HAVE_SYS_TIME_H=0
    option(
        "SYS_TIME_H",
        function ()
            add_cincludes("sys/time.h")

            set_configvar("HAVE_SYS_TIME_H", 1)
        end
    )

    -- FIXME IF FALSE DEFINE TO HAVE_SYS_TYPES_H=0
    option(
        "SYS_TYPES_H",
        function ()
            add_cincludes("sys/types.h")

            set_configvar("HAVE_SYS_TIME_H", 1)
        end
    )

    -- FIXME IF FALSE DEFINE TO HAVE_SYS_WAIT_H=0
    option(
        "SYS_WAIT_H",
        function ()
            add_cincludes("sys/wait.h")

            set_configvar("HAVE_SYS_WAIT_H", 1)
        end
    )

    -- FIXME Check if `tm_zone' is a member of `struct tm' HERE!!!
    -- FIXME IF FALSE DEFINE TO HAVE_TM_ZONE=0
    option(
        "TM_ZONE",
        function ()
            add_cincludes("time.h")

            set_configvar("HAVE_TM_ZONE", 1)
        end
    )

    -- FIXME Check if you don't have `tm_zone' but do have the external array `tzname'. HERE!!!
    -- FIXME IF TRUE DEFINE TO HAVE_TZNAME=1
    option(
        "TZNAME",
        function ()
            add_cincludes("time.h")

            set_configvar("HAVE_TZNAME", 1)
        end
    )

    -- FIXME IF FALSE DEFINE TO HAVE_UNISTD_H=0
    option(
        "UNISTD_H",
        function ()
            add_cincludes("unistd.h")

            set_configvar("HAVE_UNISTD_H", 1)
        end
    )

    -- FIXME IF FALSE DEFINE TO HAVE_VARARGS_H=0
    option(
        "VARARGS_H",
        function ()
            add_cincludes("varargs.h")

            set_configvar("HAVE_VARARGS_H", 1)
        end
    )

    -- FIXME IF FALSE DEFINE TO HAVE_VPRINTF=0
    option(
        "VPRINTF",
        function ()
            add_cincludes("stdio.h")
            add_cfuncs("vprintf")

            set_configvar("HAVE_VPRINTF", 1)
        end
    )

    -- FIXME IF FALSE DEFINE TO HAVE_WAIT3=0
    option(
        "WAIT3",
        function ()
            add_cincludes("sys/wait.h")
            add_cfuncs("wait3")

            set_configvar("HAVE_WAIT3", 1)
        end
    )

    --- --- --- STREAMHTMLPARSER OPTIONS --- --- ---

    -- FIXME IF FALSE DEFINE TO HAVE_DLFCN_H=0
    option(
        "DLFCN_H",
        function ()
            add_cincludes("dlfcn.h")

            set_configvar("HAVE_DLFCN_H", 1)
        end
    )

    -- FIXME IF FALSE DEFINE TO HAVE_MALLOC=0
    option(
        "MALLOC",
        function ()
            add_cincludes("stdlib.h")
            add_cfuncs("malloc")

            set_configvar("HAVE_MALLOC", 1)
        end
    )

    -- FIXME IF FALSE DEFINE TO HAVE_MEMCHR=0
    option(
        "MEMCHR",
        function ()
            add_cincludes("string.h")
            add_cfuncs("memchr")

            set_configvar("HAVE_MEMCHR", 1)
        end
    )

    -- FIXME IF FALSE DEFINE TO HAVE_STDBOOL_H=0
    option(
        "STDBOOL_H",
        function ()
            add_cincludes("stdbool.h")

            set_configvar("HAVE_STDBOOL_H", 1)
        end
    )

    -- FIXME IF FALSE DEFINE TO HAVE_STRCASECMP=0à
    option(
        "STDBOOL_H",
        function ()
            add_cincludes("strings.h")
            add_cfuncs("strcasecmp")

            set_configvar("HAVE_STRCASECMP", 1)
        end
    )

    -- FIXME IF FALSE DEFINE TO HAVE_STRCHR=0
    option(
        "STRCHR",
        function ()
            add_cincludes("string.h")
            add_cfuncs("strchr")

            set_configvar("HAVE_STRCHR", 1)
        end
    )

    -- FIXME IF FALSE DEFINE TO HAVE_STRSTR=0
    option(
        "STRSTR",
        function ()
            add_cincludes("string.h")
            add_cfuncs("strstr")

            set_configvar("HAVE_STRSTR", 1)
        end
    )
end

-- TODO CHECK FOR IBM DB2

function configure_clearsilver (lib_name, lib_version)
    set_configdir("$(builddir)/config/clearsilver")
    add_configfiles("cs_config.h.in")

    add_includedirs("$(builddir)/config/clearsilver")

    add_includedirs(".")

    set_configvar("PACKAGE_BUGREPORT", "'http://clearsilver.net/'")

    set_configvar("PACKAGE_NAME", lib_name)

    set_configvar("PACKAGE_STRING", lib_name .. " v" .. lib_version)

    set_configvar("PACKAGE_TARNAME", lib_name .. "-" .. lib_version)

    set_configvar("PACKAGE_URL", "http://clearsilver.net/")

    set_configvar("PACKAGE_VERSION", lib_version)

    -- Check the headers of the kill and other signal handlers sys calls
    -- https://en.wikipedia.org/wiki/C_signal_handling
    set_configvar("RETSIGTYPE", "int")

    -- FIXME Should depend on the host OS !!!
    set_configvar("STDC_HEADERS", 1)

    -- FIXME Should depend on the host OS !!!
    set_configvar("TIME_WITH_SYS_TIME", 1)

    -- FIXME Should depend on the host OS !!!
    -- FIXME Check if it is really the case:
    --       Define to 1 if your <sys/time.h> declares `struct tm'.
    set_configvar("TM_IN_SYS_TIME", 1)

    --- TODO:
    --- Define to necessary symbol if this constant uses a non-standard name on your system.
    -- #undef PTHREAD_CREATE_JOINABLE

    if not is_plat("windows", "mingw") then
        add_options(
            "HTML_COMPRESSION",
            "SNPRINTF",
            "VSNPRINTF", 
            "STRTOK_R",
            "LOCALTIME_R",
            "GMTIME_R",
            "MKSTEMP",
            "REGEX",
            "PTHREADS",
            "LOCKF",
            "DB2",
            "GETTEXT",
            "TZNAME",
            "DIRENT_H",
            "DOPRNT",
            "DRAND48",
            "FCNTL_H",
            "FEATURES_H",
            "GETTIMEOFDAY",
            "GMTIME_R",
            "INTTYPES_H",
            "LIMITS_H",
            "LOCALTIME_R",
            "MEMORY_H",
            "MKTIME",
            "NDIR_H",
            "PTHREAD",
            "PUTENV",
            "RAND",
            "RANDOM",
            "STDARG_H",
            "STDINT_H",
            "STDLIB_H",
            "STRERROR",
            "STRFTIME",
            "STRINGS_H",
            "STRING_H",
            "STRSPN",
            "STRTOD",
            "STRTOK_R",
            "STRTOL",
            "STRTOUL",
            "STRUCT_TM_TM_ZONE",
            "SYS_DIR_H",
            "IOCTL_H",
            "SYS_NDIR_H",
            "SYS_STAT_H",
            "SYS_TIME_H",
            "SYS_TYPES_H",
            "SYS_WAIT_H",
            "TM_ZONE",
            "TZNAME",
            "UNISTD_H",
            "VARARGS_H",
            "VPRINTF",
            "WAIT3"
        )
    end
end

target(
    "neo_utl",
    function () 
        set_kind("shared")
        set_version("0.11.1", {soname = true})
		-- FIXME Add skiplist.c as well???
        add_files(
            {
                "util/neo_err.c",
                "util/neo_files.c",
                "util/neo_misc.c",
                "util/neo_rand.c",
                "util/ulist.c",
                "util/neo_hdf.c",
                "util/neo_str.c",
                "util/neo_date.c",
                "util/wildmat.c",
                "util/neo_hash.c",
                "util/neo_auto.c",
				"util/ulocks.c"
            }
        )
        -- FIXME Keep this or not???
        add_defines("NDEBUG", "_GNU_SOURCE=1")
        add_cflags("-Wall", "-Wextra")

        -- FIXME Only required for util/neo_misc.h so find a way to only apply it to this header.
        add_forceincludes("stdarg.h")

        add_includedirs("third_party/streamhtmlparser/src")

        -- FIXME Is it 0.11.0 or 0.11.1???
        configure_clearsilver("libneo_utl", "0.11.1")

        -- TODO add_headerfiles
        -- TODO Set the right install dir for every files
    end
)

-- For now, install streamhtmlparser as part of the clearsilver ebuild since it is only used by ClearSilver.
-- Then, streamhtmlparser might only support HTML 4 and not HTML 5.
target(
    "streamhtmlparser", 
    function () 
        set_kind("shared")
        set_version("0.1", {soname = true})
        add_files(
            {
                "third_party/streamhtmlparser/src/statemachine.c",
                "third_party/streamhtmlparser/src/jsparser.c",
                "third_party/streamhtmlparser/src/htmlparser.c",
            }
        )

        -- TODO Configure the flags of 'third_party/streamhtmlparser/src/config.h.in' with XMake options

        add_includedirs("third_party/streamhtmlparser/src/")
        -- add_includedirs("third_party/streamhtmlparser/src/streamhtmlparser")

        set_configdir("$(builddir)/config/streamhtmlparser")
        add_configfiles("third_party/streamhtmlparser/src/config.h.in")

        add_includedirs("$(builddir)/config/streamhtmlparser")

        -- All modern compilers should support this
        set_configvar("HAVE_NAMESPACES", 1)

        set_configvar("HAVE__BOOL", 1)

        -- Should be always true.
        set_configvar("STDC_HEADERS", 1)

        -- SHOULD NOT BE REQUIRED.
        -- add_files(
        --     {
        --         "third_party/streamhtmlparser/src/htmlparser_fsm.h",
        --         "third_party/streamhtmlparser/src/jsparser_fsm.h"
        --     }
        -- )
        
        -- I'm not adding htmlparser_cpp.h.in with add_configfiles since I don't want to deal with C++.
        add_headerfiles(
            {
                "third_party/streamhtmlparser/src/streamhtmlparser/statemachine.h",
                "third_party/streamhtmlparser/src/streamhtmlparser/jsparser.h",
                "third_party/streamhtmlparser/src/streamhtmlparser/htmlparser.h"
            }
        )

        -- FIXME Keep this or not???
        add_defines("NDEBUG", "_GNU_SOURCE=1")
        add_cflags("-Wall", "-Wextra")

        if not is_plat("windows", "mingw") then
            add_options(
                "DLFCN_H",
                "INTTYPES_H", 
                "MALLOC",
                "MEMCHR",
                "MEMORY_H",
                "STDBOOL_H",
                "STDINT_H",
                "STDLIB_H",
                "STRCASECMP",
                "STRCHR",
                "STRINGS_H",
                "STRING_H",
                "STRSTR",
                "STRTOL",
                "SYS_STAT_H",
                "SYS_TYPES_H",
                "UNISTD_H"
            )
        end

        -- TODO Set the right install dir for every files
    end
)

-- TODO Add all *.cs files that are provided by the autotools package

-- TODO Add doc, man pages, and other files provided by the autotools package, ...

-- TODO Link libneo_cs to libneo_utl and link libneo_utl to libstreamhtmlparser???
target(
    "neo_cs", 
    function () 
        set_kind("shared")
        set_version("0.11.1", {soname = true})
        add_files("cs/csparse.c")

        -- FIXME Keep this or not???
        add_defines("NDEBUG", "_GNU_SOURCE=1")
        add_cflags("-Wall", "-Wextra")

        -- FIXME Is it 0.11.0 or 0.11.1???
        configure_clearsilver("libneo_cs", "0.11.1")

        -- TODO add_headerfiles
        -- TODO Set the right install dir for every files
    end
)



-- TODO ADD THOSE TARGETS: /usr/bin/cs_static.cgi /usr/lib64/libneo_cgi.so

-- TODO ADD A TEST TARGET ONLY FOR PORTAGE SRC_TEST

-- TODO USE SYSTEM libstreamhtmlparser (as shared lib) and apply streamhtmlparser_python3.patch
    -- Make a xmake.lua for libstreamhtmlparser

-- target("SAMPLE_SHARED_LIBRARY")
--    set_kind("binary")
--    add_deps("foo")
--    add_files("src/main.c")

--
-- If you want to known more usage about xmake, please see https://xmake.io
--
-- ## FAQ
--
-- You can enter the project directory firstly before building project.
--
--   $ cd projectdir
--
-- 1. How to build project?
--
--   $ xmake
--
-- 2. How to configure project?
--
--   $ xmake f -p [macosx|linux|iphoneos ..] -a [x86_64|i386|arm64 ..] -m [debug|release]
--
-- 3. Where is the build output directory?
--
--   The default output directory is `./build` and you can configure the output directory.
--
--   $ xmake f -o outputdir
--   $ xmake
--
-- 4. How to run and debug target after building project?
--
--   $ xmake run [targetname]
--   $ xmake run -d [targetname]
--
-- 5. How to install target to the system directory or other output directory?
--
--   $ xmake install
--   $ xmake install -o installdir
--
-- 6. Add some frequently-used compilation flags in xmake.lua
--
-- @code
--    -- add debug and release modes
--    add_rules("mode.debug", "mode.release")
--
--    -- add macro definition
--    add_defines("NDEBUG", "_GNU_SOURCE=1")
--
--    -- set warning all as error
--    set_warnings("all", "error")
--
--    -- set language: c99, c++11
--    set_languages("c99", "c++11")
--
--    -- set optimization: none, faster, fastest, smallest
--    set_optimize("fastest")
--
--    -- add include search directories
--    add_includedirs("/usr/include", "/usr/local/include")
--
--    -- add link libraries and search directories
--    add_links("tbox")
--    add_linkdirs("/usr/local/lib", "/usr/lib")
--
--    -- add system link libraries
--    add_syslinks("z", "pthread")
--
--    -- add compilation and link flags
--    add_cxflags("-stdnolib", "-fno-strict-aliasing")
--    add_ldflags("-L/usr/local/lib", "-lpthread", {force = true})
--
-- @endcode
--

