xmake provides the grammar: $(varname)
for supporting builtin variable.
.e.g
add_cxflags("-I$(buildir)")
It will translate this variable to the real value when building.
-I$(buildir) => -I./build
We can also use these variables in the custom scripts.
target("test")
after_build(target)
print("build ok for $(plat)!")
end
And the output result is
build ok for macosx!
xmake run -d program ...
import
interfaceWe create an empty console project first:
$ xmake create -P ./hello
create hello ...
create ok!👌
And xmake will generate some files:
$ cd ./hello
$ tree .
.
├── src
│ └── main.c
└── xmake.lua
It is a simple console program only for printing hello xmake!
$ cat ./src/main.c
#include <stdio.h>
int main(int argc, char** argv)
{
printf("hello xmake!\n");
return 0;
}
The content of xmake.lua
is very simple:
$ cat xmake.lua
target("hello")
set_kind("binary")
add_files("src/*.c")
xmake provides some api, which can detect whether exist some library functions.
target("test")
-- checks some libc functions from the header files: wchar.h and stdlib.h
add_cfuncs("libc", nil, {"wchar.h", "stdlib.h"}, "wcscat",
"wcsncat",
"wcscpy",
"wcsncpy",
"wcslcpy",
"wcslen",
"wcsnlen",
"wcsstr",
"wcscasestr",
"wcscmp",
"wcscasecmp",
"wcsncmp",
"wcsncasecmp",
"wcstombs",
"mbstowcs")
-- checks the interfaces: pthread_mutex_init, pthread_create in the pthread
-- the first argument is the library alias name
add_cfuncs("posix", nil, "pthread.h", "pthread_mutex_init", "pthread_create")
-- checks the pthread interfaces and attempt to links it using flags: -lpthread
add_cfuncs("posix", "pthread", "pthread.h", "pthread_mutex_init", "pthread_create")