2020-05-15 10:14:04 +00:00
|
|
|
// HyperRogue: alternative build system
|
|
|
|
// This reads the file 'hyper.cpp' and compiles the cpp files it includes into separate object files, and then links them.
|
|
|
|
// Tested in Linux, should work in other systems with some changes.
|
|
|
|
|
|
|
|
// Options:
|
|
|
|
// -O2 -- optimize
|
|
|
|
// -O3 -- optimize
|
|
|
|
// -D... -- change compilation flags
|
|
|
|
// [file.cpp] -- add a module to the build (e.g. ./mymake rogueviz)
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <fstream>
|
|
|
|
#include <iostream>
|
2020-05-30 14:17:51 +00:00
|
|
|
#include <thread>
|
2020-05-15 10:14:04 +00:00
|
|
|
#include <vector>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <unistd.h>
|
2020-05-28 10:29:03 +00:00
|
|
|
#include <chrono>
|
|
|
|
#include <future>
|
2020-05-28 17:41:42 +00:00
|
|
|
#include <functional>
|
2020-05-15 10:14:04 +00:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
string opts;
|
|
|
|
|
|
|
|
string default_standard = " -std=c++11";
|
|
|
|
string standard = default_standard;
|
|
|
|
|
|
|
|
string preprocessor;
|
|
|
|
string compiler;
|
|
|
|
string linker;
|
|
|
|
string libs;
|
2021-12-19 12:07:18 +00:00
|
|
|
string default_exec_name;
|
2020-05-15 10:14:04 +00:00
|
|
|
|
2021-03-07 13:18:58 +00:00
|
|
|
bool verbose = false;
|
2021-08-22 21:42:12 +00:00
|
|
|
bool quiet = false;
|
2021-03-07 13:18:58 +00:00
|
|
|
|
2020-05-28 12:28:50 +00:00
|
|
|
int batch_size = thread::hardware_concurrency() + 1;
|
2020-09-21 23:39:04 +00:00
|
|
|
bool mingw64 = false;
|
2020-05-28 10:29:03 +00:00
|
|
|
|
2021-03-07 13:02:33 +00:00
|
|
|
int sdlver = 1;
|
2021-03-06 13:53:25 +00:00
|
|
|
|
2021-03-11 08:16:42 +00:00
|
|
|
int mysystem(string cmdline) {
|
|
|
|
if(verbose) {
|
|
|
|
printf("%s\n", cmdline.c_str());
|
|
|
|
}
|
|
|
|
if (mingw64)
|
|
|
|
cmdline = "sh -c '" + cmdline + "'"; // because system(arg) passes arg to cmd.exe on MinGW
|
|
|
|
return system(cmdline.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool file_exists(string fname) {
|
|
|
|
return access(fname.c_str(), F_OK) != -1;
|
|
|
|
}
|
|
|
|
|
2021-03-06 13:53:25 +00:00
|
|
|
#if defined(MAC)
|
|
|
|
string os = "mac";
|
|
|
|
#elif defined(WINDOWS)
|
|
|
|
string os = "mingw64";
|
|
|
|
#else
|
|
|
|
string os = "linux";
|
|
|
|
#endif
|
|
|
|
|
2021-12-19 12:07:18 +00:00
|
|
|
string exec_name = "";
|
|
|
|
|
2020-05-15 10:14:04 +00:00
|
|
|
void set_linux() {
|
|
|
|
preprocessor = "g++ -E";
|
2021-09-04 19:57:01 +00:00
|
|
|
compiler = "g++ -Wall -Wextra -Wno-maybe-uninitialized -Wno-unused-parameter -Wno-implicit-fallthrough -Wno-invalid-offsetof -rdynamic -fdiagnostics-color=always -c -march=native";
|
2021-12-19 12:07:18 +00:00
|
|
|
linker = "g++ -rdynamic";
|
|
|
|
default_exec_name = "hyper";
|
2021-03-06 13:53:25 +00:00
|
|
|
if(sdlver == 2) {
|
|
|
|
opts = "-DFHS -DLINUX -I/usr/include/SDL2";
|
2021-03-07 13:02:06 +00:00
|
|
|
libs = " -lSDL2 -lSDL2_ttf -lSDL2_mixer -lSDL2_gfx -lGLEW -lGL -lpng -rdynamic -lpthread -lz";
|
2021-03-06 13:53:25 +00:00
|
|
|
}
|
2021-09-04 19:57:17 +00:00
|
|
|
else if(sdlver == 1) {
|
2021-03-06 13:53:25 +00:00
|
|
|
opts = "-DFHS -DLINUX -I/usr/include/SDL";
|
2021-03-07 13:02:06 +00:00
|
|
|
libs = " -lSDL -lSDL_ttf -lSDL_mixer -lSDL_gfx -lGLEW -lGL -lpng -rdynamic -lpthread -lz";
|
2021-03-06 13:53:25 +00:00
|
|
|
}
|
2021-09-04 19:57:17 +00:00
|
|
|
else {
|
|
|
|
opts = "-DFHS -DLINUX";
|
|
|
|
libs = " -rdynamic -lpthread -lz";
|
|
|
|
}
|
2020-05-15 10:14:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void set_mac() {
|
|
|
|
preprocessor = "g++ -E";
|
2021-07-12 13:47:19 +00:00
|
|
|
compiler = "g++ -march=native -W -Wall -Wextra -Wsuggest-override -pedantic -Wno-unused-parameter -Wno-implicit-fallthrough -Wno-invalid-offsetof -c";
|
2021-12-19 12:07:18 +00:00
|
|
|
linker = "g++";
|
|
|
|
default_exec_name = "hyper";
|
2020-05-15 10:14:04 +00:00
|
|
|
opts = "-DMAC -I/usr/local/include";
|
2021-03-07 13:02:06 +00:00
|
|
|
libs = " -L/usr/local/lib -framework AppKit -framework OpenGL -lSDL -lSDLMain -lSDL_gfx -lSDL_mixer -lSDL_ttf -lpng -lpthread -lz";
|
2020-05-15 10:14:04 +00:00
|
|
|
}
|
|
|
|
|
2020-09-21 23:39:04 +00:00
|
|
|
void set_mingw64() {
|
|
|
|
mingw64 = true;
|
2020-05-15 10:14:04 +00:00
|
|
|
preprocessor = "g++ -E";
|
2021-07-12 10:23:48 +00:00
|
|
|
compiler = "g++ -mwindows -march=native -W -Wall -Wextra -Werror -Wno-unused-parameter -Wno-invalid-offsetof -Wno-implicit-fallthrough -Wno-maybe-uninitialized -c";
|
2021-12-19 12:07:18 +00:00
|
|
|
linker = "g++";
|
|
|
|
default_exec_name = "hyper";
|
2020-09-21 23:39:04 +00:00
|
|
|
opts = "-DWINDOWS -DCAP_GLEW=1 -DCAP_PNG=1";
|
2021-03-07 13:02:06 +00:00
|
|
|
libs = " hyper.res -lopengl32 -lSDL -lSDL_gfx -lSDL_mixer -lSDL_ttf -lpthread -lz -lglew32 -lpng";
|
2020-09-21 23:39:04 +00:00
|
|
|
setvbuf(stdout, NULL, _IONBF, 0); // MinGW is quirky with output buffering
|
2020-05-15 10:14:04 +00:00
|
|
|
}
|
|
|
|
|
2021-03-11 08:16:55 +00:00
|
|
|
/* cross-compile Linux to Windows (tested on Archlinux) */
|
|
|
|
void set_mingw64_cross() {
|
|
|
|
preprocessor = "x86_64-w64-mingw32-g++ -E";
|
2021-07-12 10:23:48 +00:00
|
|
|
compiler = "x86_64-w64-mingw32-g++ -mwindows -march=native -W -Wall -Wextra -Werror -Wno-unused-parameter -Wno-invalid-offsetof -Wno-implicit-fallthrough -Wno-maybe-uninitialized -c";
|
2021-12-19 12:07:18 +00:00
|
|
|
linker = "x86_64-w64-mingw32-g++";
|
|
|
|
default_exec_name = "hyper.exe";
|
2021-03-11 08:29:27 +00:00
|
|
|
opts = "-DWINDOWS -DGLEW_STATIC -DUSE_STDFUNCTION=1 -DCAP_PNG=1 -I /usr/x86_64-w64-mingw32/include/SDL/";
|
|
|
|
libs = " hyper64.res -static-libgcc -lopengl32 -lSDL -lSDL_gfx -lSDL_mixer -lSDL_ttf -lpthread -lz -lglew32 -lpng";
|
2021-03-11 08:16:55 +00:00
|
|
|
setvbuf(stdout, NULL, _IONBF, 0); // MinGW is quirky with output buffering
|
|
|
|
if(!file_exists("hyper64.res"))
|
|
|
|
mysystem("x86_64-w64-mingw32-windres hyper.rc -O coff -o hyper64.res");
|
|
|
|
}
|
|
|
|
|
2020-10-11 23:28:50 +00:00
|
|
|
void set_web() {
|
|
|
|
preprocessor = "/usr/lib/emscripten/em++ -E";
|
|
|
|
compiler = "/usr/lib/emscripten/em++ -c";
|
|
|
|
default_standard = standard = " -std=c++17";
|
|
|
|
opts = "-DISWEB=1";
|
|
|
|
linker =
|
|
|
|
"/usr/lib/emscripten/em++ -s USE_ZLIB=1 -s DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR=0 -s TOTAL_MEMORY=512MB "
|
|
|
|
"-s EXTRA_EXPORTED_RUNTIME_METHODS='[\"FS\",\"ccall\"]' "
|
|
|
|
"-s EXPORTED_FUNCTIONS=\"['_main', '_use_file']\" "
|
2021-12-19 12:07:18 +00:00
|
|
|
"-s DISABLE_EXCEPTION_CATCHING=0";
|
|
|
|
default_exec_name = "mhyper.html";
|
2020-10-11 23:28:50 +00:00
|
|
|
libs = "";
|
|
|
|
}
|
|
|
|
|
2021-03-06 13:53:25 +00:00
|
|
|
void set_os(string o) {
|
|
|
|
os = o;
|
|
|
|
if(os == "linux") set_linux();
|
|
|
|
else if(os == "mac") set_mac();
|
|
|
|
else if(os == "mingw64") set_mingw64();
|
2021-03-11 08:16:55 +00:00
|
|
|
else if(os == "mingw64-cross") set_mingw64_cross();
|
2021-03-06 13:53:25 +00:00
|
|
|
else if(os == "web") set_web();
|
|
|
|
else {
|
|
|
|
fprintf(stderr, "unknown OS");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-15 10:14:04 +00:00
|
|
|
vector<string> modules;
|
|
|
|
|
|
|
|
time_t get_file_time(const string s) {
|
|
|
|
struct stat attr;
|
|
|
|
if(stat(s.c_str(), &attr)) return 0;
|
|
|
|
return attr.st_mtime;
|
|
|
|
}
|
|
|
|
|
|
|
|
int optimized = 0;
|
|
|
|
|
|
|
|
string obj_dir = "mymake_files";
|
|
|
|
string setdir = "../";
|
|
|
|
|
|
|
|
int main(int argc, char **argv) {
|
2021-03-06 13:53:25 +00:00
|
|
|
set_os(os);
|
2020-09-24 18:36:47 +00:00
|
|
|
int retval = 0; // for storing return values of some function calls
|
2021-03-21 21:40:06 +00:00
|
|
|
for(string fname: {"Makefile.loc", "Makefile"})
|
2020-05-19 08:36:14 +00:00
|
|
|
if(file_exists(fname)) {
|
2021-03-11 08:16:42 +00:00
|
|
|
retval = mysystem("make -f " + fname + " language-data.cpp autohdr.h");
|
2020-09-24 18:36:47 +00:00
|
|
|
if (retval) { printf("error during preparation!\n"); exit(retval); }
|
2020-05-19 08:36:14 +00:00
|
|
|
break;
|
|
|
|
}
|
2020-05-15 10:14:04 +00:00
|
|
|
for(int i=1; i<argc; i++) {
|
|
|
|
string s = argv[i];
|
|
|
|
if(s.substr(0, 2) == "-D") {
|
|
|
|
opts += " " + s;
|
|
|
|
obj_dir += "/";
|
|
|
|
setdir += "../";
|
|
|
|
for(char c: s)
|
2020-05-19 15:44:38 +00:00
|
|
|
if(!isalnum(c)) obj_dir += "_";
|
2020-05-15 10:14:04 +00:00
|
|
|
else obj_dir += c;
|
|
|
|
}
|
2021-03-07 13:18:58 +00:00
|
|
|
else if(s == "-v") {
|
|
|
|
verbose = true;
|
|
|
|
}
|
2021-08-22 21:42:12 +00:00
|
|
|
else if(s == "-q") {
|
|
|
|
quiet = true;
|
|
|
|
}
|
2020-09-21 23:39:04 +00:00
|
|
|
else if(s == "-mingw64") {
|
2021-03-06 13:53:25 +00:00
|
|
|
set_os("mingw64");
|
2020-09-21 23:39:04 +00:00
|
|
|
obj_dir += "/mingw64";
|
2020-05-15 10:14:04 +00:00
|
|
|
setdir += "../";
|
|
|
|
}
|
2021-03-11 08:16:55 +00:00
|
|
|
else if(s == "-mingw64-cross") {
|
|
|
|
set_os("mingw64-cross");
|
|
|
|
obj_dir += "/mingw64";
|
|
|
|
setdir += "../";
|
|
|
|
}
|
2020-05-15 10:14:04 +00:00
|
|
|
else if(s == "-mac") {
|
2021-03-06 13:53:25 +00:00
|
|
|
set_os("mac");
|
2020-05-15 10:14:04 +00:00
|
|
|
obj_dir += "/mac";
|
|
|
|
setdir += "../";
|
|
|
|
}
|
|
|
|
else if(s == "-linux") {
|
2021-03-06 13:53:25 +00:00
|
|
|
set_os("linux");
|
2020-05-15 10:14:04 +00:00
|
|
|
obj_dir += "/linux";
|
|
|
|
setdir += "../";
|
|
|
|
}
|
2020-10-11 23:28:50 +00:00
|
|
|
else if(s == "-web") {
|
2021-03-06 13:53:25 +00:00
|
|
|
set_os("web");
|
2020-10-11 23:28:50 +00:00
|
|
|
modules.push_back("hyperweb");
|
|
|
|
obj_dir += "/web";
|
|
|
|
setdir += "../";
|
|
|
|
}
|
2021-03-06 13:53:25 +00:00
|
|
|
else if(s == "-sdl1") {
|
|
|
|
sdlver = 1;
|
|
|
|
set_os(os);
|
|
|
|
obj_dir += "/sdl1";
|
|
|
|
setdir += "../";
|
|
|
|
opts += " -DCAP_SDL2=0";
|
|
|
|
}
|
2021-09-04 19:57:17 +00:00
|
|
|
else if(s == "-sdl0") {
|
|
|
|
sdlver = 0;
|
|
|
|
set_os(os);
|
|
|
|
obj_dir += "/sdl0";
|
|
|
|
setdir += "../";
|
|
|
|
opts += " -DCAP_SDL=0 -DCAP_GL=0 -DCAP_PNG=0";
|
|
|
|
}
|
2021-03-06 13:53:25 +00:00
|
|
|
else if(s == "-sdl2") {
|
|
|
|
sdlver = 2;
|
|
|
|
set_os(os);
|
|
|
|
obj_dir += "/sdl2";
|
|
|
|
setdir += "../";
|
|
|
|
opts += " -DCAP_SDL2=1";
|
|
|
|
}
|
2020-05-15 10:14:04 +00:00
|
|
|
else if(s.substr(0, 2) == "-f") {
|
|
|
|
opts += " " + s;
|
|
|
|
obj_dir += "/";
|
|
|
|
setdir += "../";
|
|
|
|
for(char c: s)
|
2020-05-19 15:44:38 +00:00
|
|
|
if(!isalnum(c)) obj_dir += "_";
|
2020-05-15 10:14:04 +00:00
|
|
|
else obj_dir += c;
|
|
|
|
linker += " " + s;
|
|
|
|
}
|
2022-01-17 21:34:27 +00:00
|
|
|
else if(s == "-o") {
|
2021-12-19 12:07:18 +00:00
|
|
|
exec_name = argv[i+1];
|
|
|
|
i++;
|
|
|
|
}
|
2021-12-19 12:07:50 +00:00
|
|
|
else if(s == "-shared") {
|
|
|
|
obj_dir += "/shared";
|
|
|
|
setdir += "../";
|
|
|
|
opts += " -fPIC -DNOMAIN";
|
|
|
|
linker += " -shared -fPIC";
|
|
|
|
default_exec_name = "libhyper.so";
|
|
|
|
}
|
2020-05-15 10:14:04 +00:00
|
|
|
else if(s == "-O2")
|
|
|
|
optimized = 2, compiler += " -O2", obj_dir += "/O2", setdir += "../";
|
|
|
|
else if(s == "-O3")
|
|
|
|
optimized = 3, compiler += " -O3", obj_dir += "/O3", setdir += "../";
|
|
|
|
else if(s.substr(0, 4) == "-std")
|
|
|
|
standard = s;
|
|
|
|
else if(s.substr(0, 2) == "-l")
|
|
|
|
linker += " " + s;
|
2020-05-28 10:29:03 +00:00
|
|
|
else if(s.substr(0, 2) == "-j")
|
2020-05-28 12:28:50 +00:00
|
|
|
batch_size = stoi(s.substr(2));
|
2020-05-15 10:14:04 +00:00
|
|
|
else if(s == "-I") {
|
|
|
|
opts += " " + s + " " + argv[i+1];
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
else if(s.substr(0, 2) == "-I")
|
|
|
|
opts += " " + s;
|
2021-03-06 13:53:48 +00:00
|
|
|
else if(s == "-vr") {
|
|
|
|
obj_dir += "/vr";
|
|
|
|
setdir += "../";
|
|
|
|
linker += " -lopenvr_api";
|
|
|
|
opts += " -DCAP_VR=1 -I/usr/include/openvr/";
|
|
|
|
}
|
2020-05-15 10:14:04 +00:00
|
|
|
else if(s == "-rv") {
|
|
|
|
|
|
|
|
if(standard == default_standard) {
|
|
|
|
standard = "-std=c++17";
|
|
|
|
}
|
|
|
|
ifstream ifs("rogueviz/rogueviz-all.cpp");
|
|
|
|
string s;
|
|
|
|
while(getline(ifs, s)) {
|
|
|
|
if(s.substr(0, 10) == "#include \"") {
|
|
|
|
string t = s.substr(10);
|
|
|
|
t = t.substr(0, t.find(".cpp\""));
|
|
|
|
modules.push_back("rogueviz/" + t);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if(s.size() >= 5 && s.substr(s.size() - 4) == ".cpp")
|
|
|
|
s = s.substr(0, s.size() - 4);
|
|
|
|
modules.push_back(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!optimized)
|
|
|
|
compiler += " -g3";
|
|
|
|
preprocessor += " " + standard;
|
|
|
|
compiler += " " + standard;
|
|
|
|
ifstream fs("hyper.cpp");
|
|
|
|
|
2021-03-11 08:16:42 +00:00
|
|
|
retval = mysystem("mkdir -p " + obj_dir);
|
2020-09-24 18:36:47 +00:00
|
|
|
if (retval) { printf("unable to create output directory!\n"); exit(retval); }
|
2020-05-15 10:14:04 +00:00
|
|
|
|
|
|
|
ofstream fsm(obj_dir + "/hyper.cpp");
|
|
|
|
fsm << "#if REM\n#define INCLUDE(x)\n#endif\n";
|
|
|
|
string s;
|
|
|
|
while(getline(fs, s)) {
|
|
|
|
if(s.substr(0, 8) == "#include") {
|
|
|
|
string t;
|
|
|
|
bool in = false;
|
|
|
|
bool ext = false;
|
|
|
|
string iext = "";
|
|
|
|
for(char c: s) if(c == '"') in = !in; else if(!in) ; else if(c == '.') ext = !ext; else if(!ext) t += c; else iext += c;
|
|
|
|
if(iext == "h") { fsm << "#include \"" + setdir + "hyper.h\"\n"; continue; }
|
|
|
|
if(iext != "cpp") printf("unknown extension: %s\n", iext.c_str());
|
|
|
|
fsm << "INCLUDE(\"" << t << "\")\n";
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
fsm << s << "\n";
|
|
|
|
}
|
|
|
|
fsm.close();
|
|
|
|
|
2021-08-22 21:42:12 +00:00
|
|
|
if(!quiet) printf("preprocessing...\n");
|
2021-03-11 08:16:42 +00:00
|
|
|
if(mysystem(preprocessor + " " + opts + " "+obj_dir+"/hyper.cpp -o "+obj_dir+"/hyper.E")) { printf("preprocessing error\n"); exit(1); }
|
2020-05-15 10:14:04 +00:00
|
|
|
|
|
|
|
if(true) {
|
|
|
|
ifstream fs2(obj_dir+"/hyper.E");
|
|
|
|
while(getline(fs2, s)) {
|
|
|
|
if(s.substr(0, 7) == "INCLUDE") {
|
|
|
|
s = s.substr(9);
|
|
|
|
s = s.substr(0,s.size() - 2);
|
|
|
|
modules.push_back(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-03-07 13:02:06 +00:00
|
|
|
|
2021-09-04 19:57:17 +00:00
|
|
|
if(sdlver) modules.push_back("savepng");
|
2020-05-15 10:14:04 +00:00
|
|
|
|
|
|
|
if(get_file_time(obj_dir + "/hyper.o") < get_file_time("hyper.cpp")) {
|
2021-08-22 21:42:12 +00:00
|
|
|
if(!quiet) printf("compiling hyper...\n");
|
2021-03-11 08:16:42 +00:00
|
|
|
if(mysystem(compiler + " -DREM " + opts + " " + obj_dir + "/hyper.cpp -c -o " + obj_dir + "/hyper.o")) { printf("error\n"); exit(1); }
|
2020-05-15 10:14:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
string allobj = " " + obj_dir + "/hyper.o";
|
2020-05-28 10:29:03 +00:00
|
|
|
|
2020-05-28 15:32:29 +00:00
|
|
|
printf("compiling modules using batch size of %d:\n", batch_size);
|
|
|
|
|
2020-05-15 10:14:04 +00:00
|
|
|
int id = 0;
|
2020-05-28 17:41:42 +00:00
|
|
|
vector<pair<int, function<int(void)>>> tasks;
|
2020-05-15 10:14:04 +00:00
|
|
|
for(string m: modules) {
|
|
|
|
string src = m + ".cpp";
|
|
|
|
string m2 = m;
|
|
|
|
for(char& c: m2) if(c == '/') c = '_';
|
|
|
|
string obj = obj_dir + "/" + m2 + ".o";
|
|
|
|
time_t src_time = get_file_time(src);
|
|
|
|
if(!src_time) {
|
|
|
|
printf("file not found: %s\n", src.c_str());
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
time_t obj_time = get_file_time(obj);
|
2021-07-10 20:05:30 +00:00
|
|
|
if(src == "language.cpp") {
|
|
|
|
src_time = max(src_time, get_file_time("language-data.cpp"));
|
|
|
|
}
|
2020-05-15 10:14:04 +00:00
|
|
|
if(src_time > obj_time) {
|
2020-05-28 17:41:42 +00:00
|
|
|
string cmdline = compiler + " " + opts + " " + src + " -o " + obj;
|
2021-03-11 08:16:42 +00:00
|
|
|
pair<int, function<int(void)>> task(id, [cmdline]() { return mysystem(cmdline); });
|
2020-05-28 10:29:03 +00:00
|
|
|
tasks.push_back(task);
|
2020-05-15 10:14:04 +00:00
|
|
|
}
|
|
|
|
else {
|
2021-08-22 21:42:12 +00:00
|
|
|
if(!quiet) printf("ok: %s\n", m.c_str());
|
2020-05-15 10:14:04 +00:00
|
|
|
}
|
|
|
|
allobj += " ";
|
|
|
|
allobj += obj;
|
2020-05-28 10:29:03 +00:00
|
|
|
id++;
|
|
|
|
}
|
|
|
|
|
2020-05-30 14:17:51 +00:00
|
|
|
chrono::milliseconds quantum(40);
|
2020-05-28 10:29:03 +00:00
|
|
|
vector<future<int>> workers(batch_size);
|
|
|
|
|
|
|
|
int tasks_amt = tasks.size();
|
|
|
|
int tasks_taken = 0, tasks_done = 0;
|
|
|
|
bool finished = tasks.empty();
|
|
|
|
|
2020-05-30 14:17:51 +00:00
|
|
|
while (!finished) {
|
2020-05-28 10:29:03 +00:00
|
|
|
for (auto & worker : workers) {
|
|
|
|
if (worker.valid()) {
|
2020-05-30 14:17:51 +00:00
|
|
|
if (worker.wait_for(chrono::seconds(0)) != future_status::ready) continue;
|
2020-05-28 10:29:03 +00:00
|
|
|
else {
|
|
|
|
int res = worker.get();
|
|
|
|
if (res) { printf("compilation error!\n"); exit(1); }
|
|
|
|
++tasks_done;
|
|
|
|
}
|
|
|
|
}
|
2020-05-30 13:44:46 +00:00
|
|
|
if (tasks_taken < tasks_amt) {
|
2020-05-28 10:29:03 +00:00
|
|
|
auto task = tasks[tasks_taken];
|
|
|
|
int mid = task.first;
|
2020-05-28 17:41:42 +00:00
|
|
|
function<int(void)> do_work = task.second;
|
2021-08-22 21:42:12 +00:00
|
|
|
if(!quiet)
|
|
|
|
printf("compiling %s... [%d/%d]\n", modules[mid].c_str(), tasks_taken+1, tasks_amt);
|
2020-05-28 17:41:42 +00:00
|
|
|
worker = async(launch::async, do_work);
|
2020-05-28 10:29:03 +00:00
|
|
|
++tasks_taken;
|
|
|
|
}
|
|
|
|
else if (tasks_done == tasks_amt) { finished = true; break; }
|
2020-05-30 14:17:51 +00:00
|
|
|
} this_thread::sleep_for(quantum); }
|
2020-09-21 23:39:04 +00:00
|
|
|
|
2020-09-24 18:36:47 +00:00
|
|
|
if (mingw64) {
|
2021-03-11 08:16:42 +00:00
|
|
|
retval = mysystem("windres hyper.rc -O coff -o hyper.res");
|
2020-09-24 18:36:47 +00:00
|
|
|
if (retval) { printf("windres error!\n"); exit(retval); }
|
|
|
|
}
|
2020-09-21 23:39:04 +00:00
|
|
|
|
2020-05-15 10:14:04 +00:00
|
|
|
printf("linking...\n");
|
2021-12-19 12:07:18 +00:00
|
|
|
if(exec_name == "") exec_name = default_exec_name;
|
|
|
|
retval = mysystem(linker + " -o " + exec_name + allobj + libs);
|
2020-09-24 18:36:47 +00:00
|
|
|
if (retval) { printf("linking error!\n"); exit(retval); }
|
2020-05-15 10:14:04 +00:00
|
|
|
return 0;
|
|
|
|
}
|