-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzmake_helper.h
94 lines (85 loc) · 4.65 KB
/
zmake_helper.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
* zmake_helper.h
*
* Created on: 22 Feb 2024
* Author: yanbin.zhao
*/
#ifndef ZMAKE_HELPER_H_
#define ZMAKE_HELPER_H_
#include "zmake.h"
#include "zmake_util.h"
namespace zmake {
__attribute__((weak, unused))
void PrintHelpInfo() {
printf("Usage: %s [OPTION]...\n"
" Build your C++ project using the C++ rules you defined, which are implemented\n"
" in C++, so you can use std::string/std::vector/std::map these STL containers\n"
" and you can define any variable, function or class. Unbelievable, right?\n"
"\n"
" Define your building rules in 'BUILD.inc' or 'BUILD.cpp' under each dir, and\n"
" define global common vars/funcs/rules in '${project_root}/WORKSPACE.h', and put\n"
" some preparation works(import other libraries or adjust default flags/compilers)\n"
" into root BUILD.inc(normally, it's '${project_root}/BUILD.inc').\n"
"\n"
" See all available C++ APIs in '~/bin/zmake_files/zmake.h' and the demo under\n"
" '~/bin/zmake_files/demo/', which is a quite good tutorial for you;\n"
"\n"
" Firstly, use `zmake` to build your project(it'll firstly generate 'BUILD.exe'\n"
" under your project root dir and then run `./BUILD.exe` to build), and you can\n"
" use `./BUILD.exe` to rebuild if you only modify project's source/header files(no\n"
" change for the building rules, i.e.: no any change for any BUILD.inc/BUILD.cpp/\n"
" WORKSPACE.h);\n"
"\n"
" All generated files locate under '.zmade/', and if you want to clean, just\n"
" `rm -rf .zmade/`, and you can find the files that record original compile or\n"
" link commands by `find .zmade/ -name '*.cmd'`;\n"
"\n"
"Options:\n"
" -d \t set the debug level 0/1/2 to print more debug infos, -d0 by default, and\n"
" \t if you just use '-d', it means '-d1';\n"
" -v \t verbose mode to show full cmd;\n"
" -n \t not run ./BUILD.exe after generating it by `zmake`;\n"
" -j \t concurrency, -j0 by default, which will use 1/4 CPU cores;\n"
" -e \t export itself for being imported by other zmake projects, which\n"
" \t will generate the '.zmade/BUILD.libs' file;\n"
" -c \t constrain targets under a specific dir, using -c dir1/dir2/;\n"
" -t \t specify only these targets to be built, which is separated by ';'\n"
" -l \t list all target names, which can be used with '-c' flag for a sub dir;\n"
" -A \t analyze the target's dependencies and dump to stdout, using -A <target>;\n"
" -s \t simple mode(without any BUILD.inc under your project) for building, just use\n"
" \t AccessBinary(${binary_name})->AddObjs(Glob({\"**.cpp\", \"**.cc\", \"**.c\"})),\n"
" \t the ${binary_name} will be determined by the filename that contains 'main()';\n"
" -g \t add -g for all targets' compilation and link;\n"
" -O \t set optimization level for all targets' compilation and link forcedly, it\n"
" \t will replace targets' optimization level defined in BUILD.inc; it's useful\n"
" \t if you want to compile a debug version with -O0;\n"
"\n"
"Report bugs to '[email protected]'\n"
"\n", CommandArgs::Arg0());
}
struct BuilderBase {
virtual ~BuilderBase() {};
virtual void Run() {};
static auto& GlobalBuilders() {
static std::map<std::string, std::function<BuilderBase*()>> s_builders;
return s_builders;
}
};
template <typename SubType>
struct Builder : public BuilderBase {
static BuilderBase* Create() {
return new SubType();
}
};
#define BUILD() \
namespace { \
struct __sub_builder__ : public Builder<__sub_builder__> { \
virtual void Run(); \
}; \
} \
__attribute__((unused)) __attribute__((constructor)) static void __zmake_build__() { \
BuilderBase::GlobalBuilders()[__FILE__] = &__sub_builder__::Create; \
} \
void __sub_builder__::Run()
} //end of namespace zmake
#endif /* ZMAKE_HELPER_H_ */