forked from OctaForge/libostd
more build cleanups
This commit is contained in:
parent
fbdcbed55e
commit
52ed8d7c08
|
@ -36,10 +36,10 @@ It also recognizes the environment variables `CXX` (the C++ compiler used
|
||||||
to build, defaults to `c++`), `AS` (the assembler used to build, defaults to
|
to build, defaults to `c++`), `AS` (the assembler used to build, defaults to
|
||||||
`c++` as well, as Clang and GCC can compile assembly files), `AR` (the tool
|
`c++` as well, as Clang and GCC can compile assembly files), `AR` (the tool
|
||||||
to create static lib archives, `ar` by default) and `STRIP` (the tool used
|
to create static lib archives, `ar` by default) and `STRIP` (the tool used
|
||||||
to strip the library in release mode).
|
to strip the library in release mode, `strip` by default).
|
||||||
|
|
||||||
Additionally, the `CXXFLAGS`, `LDFLAGS` and `ASFLAGS` environment variables
|
Additionally, the `CXXFLAGS`, `LDFLAGS` and `ASFLAGS` environment variables
|
||||||
are also used. The `CXXFLAGS` are passed when compiling C++ source files as
|
are also used. The `CXXFLAGS` are passed when compiling C++ source files as
|
||||||
well as when linking (the compiler is used to link). The `LDFLAGS` are passed
|
well as when linking (the compiler is used to link). The `LDFLAGS` are passed
|
||||||
additionally to `CXXFLAGS` only when linking. The `ASFLAGS` are passed to
|
additionally to `CXXFLAGS` only when linking. The `ASFLAGS` are passed to
|
||||||
the assembler (`CXXFLAGS` are not, even when Clang/GCC are used).
|
the assembler (`CXXFLAGS` are not, even when Clang/GCC is used).
|
||||||
|
|
65
build.cc
65
build.cc
|
@ -150,19 +150,40 @@ static fs::path path_with_ext(fs::path const &p, fs::path const &ext) {
|
||||||
return rp;
|
return rp;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void try_remove(fs::path const &path) {
|
static void try_remove(fs::path const &path, bool all = false) {
|
||||||
try {
|
try {
|
||||||
fs::remove(path);
|
if (all) {
|
||||||
|
fs::remove_all(path);
|
||||||
|
} else {
|
||||||
|
fs::remove(path);
|
||||||
|
}
|
||||||
} catch (fs::filesystem_error const &) {}
|
} catch (fs::filesystem_error const &) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool verbose = false;
|
||||||
|
|
||||||
|
template<typename ...A>
|
||||||
|
static void echo_q(A const &...args) {
|
||||||
|
if (!verbose) {
|
||||||
|
std::printf(args...);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void exec_v(
|
||||||
|
std::string const &cmd, std::vector<std::string> const &args
|
||||||
|
) {
|
||||||
|
if (verbose) {
|
||||||
|
print_command(cmd, args);
|
||||||
|
}
|
||||||
|
exec_command(cmd, args);
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
bool build_examples = true;
|
bool build_examples = true;
|
||||||
bool build_testsuite = true;
|
bool build_testsuite = true;
|
||||||
bool build_static = true;
|
bool build_static = true;
|
||||||
bool build_shared = false;
|
bool build_shared = false;
|
||||||
char const *build_cfg = "debug";
|
char const *build_cfg = "debug";
|
||||||
bool verbose = false;
|
|
||||||
bool clean = false;
|
bool clean = false;
|
||||||
|
|
||||||
std::string cxxflags = "-std=c++1z -I. -O2 -Wall -Wextra -Wshadow "
|
std::string cxxflags = "-std=c++1z -I. -O2 -Wall -Wextra -Wshadow "
|
||||||
|
@ -227,58 +248,32 @@ int main(int argc, char **argv) {
|
||||||
add_env(ldflags, "LDFLAGS");
|
add_env(ldflags, "LDFLAGS");
|
||||||
add_env(asflags, "ASFLAGS");
|
add_env(asflags, "ASFLAGS");
|
||||||
|
|
||||||
auto echo_q = [verbose](auto const &...args) {
|
|
||||||
if (!verbose) {
|
|
||||||
std::printf(args...);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
auto exec_v = [verbose](
|
|
||||||
std::string const &cmd, std::vector<std::string> const &args
|
|
||||||
) {
|
|
||||||
if (verbose) {
|
|
||||||
print_command(cmd, args);
|
|
||||||
}
|
|
||||||
exec_command(cmd, args);
|
|
||||||
};
|
|
||||||
|
|
||||||
if (clean) {
|
if (clean) {
|
||||||
std::printf("Cleaning...\n");
|
std::printf("Cleaning...\n");
|
||||||
|
|
||||||
fs::path exp = "examples";
|
|
||||||
for (auto ex: EXAMPLES) {
|
for (auto ex: EXAMPLES) {
|
||||||
auto rp = exp / ex;
|
auto rp = fs::path{"examples"} / ex;
|
||||||
try_remove(rp);
|
try_remove(rp);
|
||||||
rp.replace_extension(".o");
|
rp.replace_extension(".o");
|
||||||
try_remove(rp);
|
try_remove(rp);
|
||||||
}
|
}
|
||||||
fs::path asp = ASM_SOURCE_DIR;
|
|
||||||
for (auto aso: ASM_SOURCES) {
|
for (auto aso: ASM_SOURCES) {
|
||||||
auto rp = asp / aso;
|
auto rp = path_with_ext(fs::path{ASM_SOURCE_DIR} / aso, ".o");
|
||||||
rp.replace_extension(".o");
|
|
||||||
try_remove(rp);
|
try_remove(rp);
|
||||||
std::string fname = aso;
|
rp.replace_filename(std::string{aso} + "_dyn.o");
|
||||||
fname += "_dyn.o";
|
|
||||||
rp.replace_filename(fname);
|
|
||||||
try_remove(rp);
|
try_remove(rp);
|
||||||
}
|
}
|
||||||
fs::path csp = CXX_SOURCE_DIR;
|
|
||||||
for (auto cso: CXX_SOURCES) {
|
for (auto cso: CXX_SOURCES) {
|
||||||
auto rp = csp / cso;
|
auto rp = path_with_ext(fs::path{CXX_SOURCE_DIR} / cso, ".o");
|
||||||
rp.replace_extension(".o");
|
|
||||||
try_remove(rp);
|
try_remove(rp);
|
||||||
std::string fname = cso;
|
rp.replace_filename(std::string{cso} + "_dyn.o");
|
||||||
fname += "_dyn.o";
|
|
||||||
rp.replace_filename(fname);
|
|
||||||
try_remove(rp);
|
try_remove(rp);
|
||||||
}
|
}
|
||||||
try_remove(OSTD_STATIC_LIB);
|
try_remove(OSTD_STATIC_LIB);
|
||||||
try_remove(OSTD_SHARED_LIB);
|
try_remove(OSTD_SHARED_LIB);
|
||||||
try_remove("test_runner.o");
|
try_remove("test_runner.o");
|
||||||
try_remove("test_runner");
|
try_remove("test_runner");
|
||||||
try {
|
try_remove("tests", true);
|
||||||
fs::remove_all("tests");
|
|
||||||
} catch (fs::filesystem_error const &) {}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue