1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2025-11-08 17:53:00 +00:00

Merge pull request #105 from Quuxplusone/mymake

Make "mymake" work on OSX, and add it to Travis
This commit is contained in:
Zeno Rogue
2020-05-15 12:15:48 +02:00
committed by GitHub
5 changed files with 282 additions and 200 deletions

View File

@@ -85,6 +85,41 @@ matrix:
TRAVIS_OS_NAME=linux TRAVIS_OS_NAME=linux
TRAVIS_COMPILER_NAME=emscripten TRAVIS_COMPILER_NAME=emscripten
TRAVIS_BUILD_SYSTEM=emscripten TRAVIS_BUILD_SYSTEM=emscripten
- os: osx
compiler: clang
env: >-
TRAVIS_OS_NAME=osx
TRAVIS_COMPILER_NAME=clang
TRAVIS_BUILD_SYSTEM=mymake
HYPERROGUE_USE_GLEW=1
HYPERROGUE_USE_PNG=1
- os: osx
compiler: clang
env: >-
TRAVIS_OS_NAME=osx
TRAVIS_COMPILER_NAME=clang
TRAVIS_BUILD_SYSTEM=mymake
HYPERROGUE_USE_GLEW=1
HYPERROGUE_USE_PNG=1
HYPERROGUE_USE_ROGUEVIZ=1
- os: linux
compiler: gcc
env: >-
TRAVIS_OS_NAME=linux
TRAVIS_COMPILER_NAME=gcc
TRAVIS_BUILD_SYSTEM=mymake
HYPERROGUE_USE_GLEW=1
HYPERROGUE_USE_PNG=1
- os: linux
dist: bionic
compiler: gcc
env: >-
TRAVIS_OS_NAME=linux
TRAVIS_COMPILER_NAME=gcc
TRAVIS_BUILD_SYSTEM=mymake
HYPERROGUE_USE_GLEW=1
HYPERROGUE_USE_PNG=1
HYPERROGUE_USE_ROGUEVIZ=1
before_install: before_install:
- |- - |-
@@ -143,6 +178,13 @@ script:
make make
elif [[ "$TRAVIS_BUILD_SYSTEM" == "Makefile" ]]; then elif [[ "$TRAVIS_BUILD_SYSTEM" == "Makefile" ]]; then
make -f Makefile.simple make -f Makefile.simple
elif [[ "$TRAVIS_BUILD_SYSTEM" == "mymake" ]]; then
make -f Makefile.simple mymake
if [[ "$HYPERROGUE_USE_ROGUEVIZ" == "1" ]]; then
./mymake -rv
else
./mymake
fi
elif [[ "$TRAVIS_BUILD_SYSTEM" == "emscripten" ]]; then elif [[ "$TRAVIS_BUILD_SYSTEM" == "emscripten" ]]; then
docker run --rm -v $(pwd):/src trzeci/emscripten make -f Makefile.simple emscripten docker run --rm -v $(pwd):/src trzeci/emscripten make -f Makefile.simple emscripten
else else
@@ -152,6 +194,8 @@ script:
# Test hyperrogue. # Test hyperrogue.
if [[ "$TRAVIS_BUILD_SYSTEM" == "emscripten" ]]; then if [[ "$TRAVIS_BUILD_SYSTEM" == "emscripten" ]]; then
ls -lAF hyper.html hyper.js hyper.wasm ls -lAF hyper.html hyper.js hyper.wasm
elif [[ "$TRAVIS_BUILD_SYSTEM" == "mymake" ]]; then
./hyper --help
else else
./hyperrogue --help ./hyperrogue --help
fi fi

View File

@@ -150,7 +150,7 @@ langen$(EXE_EXTENSION): langen.cpp language-??.cpp language-ptbr.cpp
$(CXX) -O0 $(CXXFLAGS) $(langen_CXXFLAGS) langen.cpp $(LDFLAGS) -o $@ $(CXX) -O0 $(CXXFLAGS) $(langen_CXXFLAGS) langen.cpp $(LDFLAGS) -o $@
makeh$(EXE_EXTENSION): makeh.cpp makeh$(EXE_EXTENSION): makeh.cpp
$(CXX) makeh.cpp -o $@ $(CXX) -O2 makeh.cpp -o $@
autohdr.h: makeh$(EXE_EXTENSION) *.cpp autohdr.h: makeh$(EXE_EXTENSION) *.cpp
./makeh classes.cpp locations.cpp hyperpoint.cpp geometry.cpp goldberg.cpp init.cpp floorshapes.cpp cell.cpp multi.cpp shmup.cpp pattern2.cpp mapeditor.cpp graph.cpp textures.cpp hprint.cpp language.cpp util.cpp complex.cpp *.cpp > autohdr.h ./makeh classes.cpp locations.cpp hyperpoint.cpp geometry.cpp goldberg.cpp init.cpp floorshapes.cpp cell.cpp multi.cpp shmup.cpp pattern2.cpp mapeditor.cpp graph.cpp textures.cpp hprint.cpp language.cpp util.cpp complex.cpp *.cpp > autohdr.h
@@ -161,6 +161,9 @@ language-data.cpp: langen$(EXE_EXTENSION)
savepng$(OBJ_EXTENSION): savepng.cpp savepng$(OBJ_EXTENSION): savepng.cpp
$(CXX) -O2 $(CXXFLAGS) -c savepng.cpp -o $@ $(CXX) -O2 $(CXXFLAGS) -c savepng.cpp -o $@
mymake$(EXE_EXTENSION): mymake.cpp
$(CXX) -O2 $(CXXFLAGS) mymake.cpp -o $@
emscripten: hyper.html emscripten: hyper.html
%.html %.js %.wasm: %.emscripten-sources %.html %.js %.wasm: %.emscripten-sources
@@ -173,5 +176,6 @@ hyper.emscripten-sources: *.cpp autohdr.h
clean: clean:
rm -f langen$(EXE_EXTENSION) language-data.cpp rm -f langen$(EXE_EXTENSION) language-data.cpp
rm -f makeh$(EXE_EXTENSION) autohdr.h rm -f makeh$(EXE_EXTENSION) autohdr.h
rm -rf mymake$(EXE_EXTENSION) mymake_files/
rm -f hyperrogue$(EXE_EXTENSION) hyper$(OBJ_EXTENSION) $(hyper_RES) savepng$(OBJ_EXTENSION) rm -f hyperrogue$(EXE_EXTENSION) hyper$(OBJ_EXTENSION) $(hyper_RES) savepng$(OBJ_EXTENSION)
rm -f hyper.html hyper.js hyper.wasm rm -f hyper.html hyper.js hyper.wasm

View File

@@ -3,6 +3,7 @@
<a href="https://travis-ci.org/zenorogue/hyperrogue/builds"> <a href="https://travis-ci.org/zenorogue/hyperrogue/builds">
<img align="right" src="https://badges.herokuapp.com/travis/zenorogue/hyperrogue?branch=master&env=TRAVIS_BUILD_SYSTEM=autotools&label=autotools" alt="TravisCI badge"> <img align="right" src="https://badges.herokuapp.com/travis/zenorogue/hyperrogue?branch=master&env=TRAVIS_BUILD_SYSTEM=autotools&label=autotools" alt="TravisCI badge">
<img align="right" src="https://badges.herokuapp.com/travis/zenorogue/hyperrogue?branch=master&env=TRAVIS_BUILD_SYSTEM=Makefile&label=make" alt="TravisCI badge"> <img align="right" src="https://badges.herokuapp.com/travis/zenorogue/hyperrogue?branch=master&env=TRAVIS_BUILD_SYSTEM=Makefile&label=make" alt="TravisCI badge">
<img align="right" src="https://badges.herokuapp.com/travis/zenorogue/hyperrogue?branch=master&env=TRAVIS_BUILD_SYSTEM=mymake&label=mymake" alt="TravisCI badge">
<img align="right" src="https://badges.herokuapp.com/travis/zenorogue/hyperrogue?branch=master&env=TRAVIS_BUILD_SYSTEM=emscripten&label=web" alt="TravisCI badge"> <img align="right" src="https://badges.herokuapp.com/travis/zenorogue/hyperrogue?branch=master&env=TRAVIS_BUILD_SYSTEM=emscripten&label=web" alt="TravisCI badge">
</a> </a>
</p> </p>

View File

@@ -572,12 +572,6 @@ void IMAGESAVE(SDL_Surface *s, const char *fname);
#endif #endif
// for some reason I need this to compile under OSX
#if ISMAC
extern "C" { void *_Unwind_Resume = 0; }
#endif
template<class T> struct dynamicval { template<class T> struct dynamicval {
T& where; T& where;
T backup; T backup;

View File

@@ -1,193 +1,232 @@
// HyperRogue: alternative build system // 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. // 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. // Tested in Linux, should work in other systems with some changes.
// Options: // Options:
// -O2 -- optimize // -O2 -- optimize
// -O3 -- optimize // -O3 -- optimize
// -D... -- change compilation flags // -D... -- change compilation flags
// [file.cpp] -- add a module to the build (e.g. ./mymake rogueviz) // [file.cpp] -- add a module to the build (e.g. ./mymake rogueviz)
#include <string> #include <string>
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
#include <vector> #include <vector>
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h> #include <unistd.h>
using namespace std; using namespace std;
string opts = "-DFHS -DLINUX -DWHATEVER -DMYMAKE -I/usr/include/SDL"; string opts;
string default_standard = " -std=c++11"; string default_standard = " -std=c++11";
string standard = default_standard; string standard = default_standard;
string preprocessor = string preprocessor;
"g++ -E"; string compiler;
string linker;
string compiler = string libs;
"g++ -Wall -Wextra -Wno-maybe-uninitialized -Wno-unused-parameter -Wno-implicit-fallthrough -rdynamic -fdiagnostics-color=always -c";
void set_linux() {
string linker = preprocessor = "g++ -E";
"g++ -rdynamic -o hyper"; compiler = "g++ -Wall -Wextra -Wno-maybe-uninitialized -Wno-unused-parameter -Wno-implicit-fallthrough -rdynamic -fdiagnostics-color=always -c";
linker = "g++ -rdynamic -o hyper";
string libs = " savepng.o -lSDL -lSDL_ttf -lSDL_mixer -lSDL_gfx -lGLEW -lGL -lpng -rdynamic -lpthread -lz"; opts = "-DFHS -DLINUX -I/usr/include/SDL";
libs = " savepng.o -lSDL -lSDL_ttf -lSDL_mixer -lSDL_gfx -lGLEW -lGL -lpng -rdynamic -lpthread -lz";
vector<string> modules; }
time_t get_file_time(const string s) { void set_mac() {
struct stat attr; preprocessor = "g++ -E";
if(stat(s.c_str(), &attr)) return 0; compiler = "g++ -march=native -W -Wall -Wextra -pedantic -Wno-unused-parameter -Wno-implicit-fallthrough -c";
return attr.st_mtime; linker = "g++ -o hyper";
} opts = "-DMAC -I/usr/local/include";
libs = " savepng.o -L/usr/local/lib -framework AppKit -framework OpenGL -lSDL -lSDLMain -lSDL_gfx -lSDL_mixer -lSDL_ttf -lpng -lpthread -lz";
int optimized = 0; }
string obj_dir = "mymake_files"; void set_win() {
string setdir = "../"; preprocessor = "g++ -E";
compiler = "runbat bwin-g.bat -c";
int system(string cmdline) { linker = "runbat bwin-linker.bat";
return system(cmdline.c_str()); opts = "-DFHS -DLINUX -I/usr/include/SDL";
} libs = "";
bool file_exists(string fname) { standard = "";
return access(fname.c_str(), F_OK) != -1; }
}
vector<string> modules;
int main(int argc, char **argv) {
for(string fname: {"Makefile.loc", "Makefile.simple", "Makefile"}) time_t get_file_time(const string s) {
if(file_exists(fname)) struct stat attr;
system("make -f " + fname + " language-data.cpp autohdr.h savepng.o"); if(stat(s.c_str(), &attr)) return 0;
for(int i=1; i<argc; i++) { return attr.st_mtime;
string s = argv[i]; }
if(s.substr(0, 2) == "-D") {
opts += " " + s; int optimized = 0;
obj_dir += "/";
setdir += "../"; string obj_dir = "mymake_files";
for(char c: s) string setdir = "../";
if(c == '=' || c == '-' || c == '/') obj_dir += "_";
else obj_dir += c; int system(string cmdline) {
} return system(cmdline.c_str());
else if(s.substr(0, 2) == "-f") { }
opts += " " + s;
obj_dir += "/"; bool file_exists(string fname) {
setdir += "../"; return access(fname.c_str(), F_OK) != -1;
for(char c: s) }
if(c == '=' || c == '-' || c == '/') obj_dir += "_";
else obj_dir += c; int main(int argc, char **argv) {
linker += " " + s; #if defined(MAC)
} set_mac();
else if(s == "-win") #elif defined(WINDOWS)
compiler = "runbat bwin-g.bat -c", obj_dir += "/win", setdir += "../", standard = "", set_win();
linker = "runbat bwin-linker.bat", libs = ""; #else
set_linux();
else if(s == "-O2") #endif
optimized = 2, compiler += " -O2", obj_dir += "/O2", setdir += "../"; for(string fname: {"Makefile.loc", "Makefile.simple", "Makefile"})
else if(s == "-O3") if(file_exists(fname))
optimized = 3, compiler += " -O3", obj_dir += "/O3", setdir += "../"; system("make -f " + fname + " language-data.cpp autohdr.h savepng.o");
else if(s.substr(0, 4) == "-std") for(int i=1; i<argc; i++) {
standard = s; string s = argv[i];
else if(s.substr(0, 2) == "-l") if(s.substr(0, 2) == "-D") {
linker += " " + s; opts += " " + s;
else if(s == "-I") { obj_dir += "/";
opts += " " + s + " " + argv[i+1]; setdir += "../";
i++; for(char c: s)
} if(c == '=' || c == '-' || c == '/') obj_dir += "_";
else if(s.substr(0, 2) == "-I") else obj_dir += c;
opts += " " + s; }
else if(s == "-rv") { else if(s == "-win") {
set_win();
if(standard == default_standard) { obj_dir += "/win";
standard = "-std=c++17"; setdir += "../";
} }
ifstream ifs("rogueviz/rogueviz-all.cpp"); else if(s == "-mac") {
string s; set_mac();
while(getline(ifs, s)) { obj_dir += "/mac";
if(s.substr(0, 10) == "#include \"") { setdir += "../";
string t = s.substr(10); }
t = t.substr(0, t.find(".cpp\"")); else if(s == "-linux") {
modules.push_back("rogueviz/" + t); set_linux();
} obj_dir += "/linux";
} setdir += "../";
} }
else { else if(s.substr(0, 2) == "-f") {
if(s.size() >= 5 && s.substr(s.size() - 4) == ".cpp") opts += " " + s;
s = s.substr(0, s.size() - 4); obj_dir += "/";
modules.push_back(s); setdir += "../";
} for(char c: s)
} if(c == '=' || c == '-' || c == '/') obj_dir += "_";
if(!optimized) else obj_dir += c;
compiler += " -g3"; linker += " " + s;
compiler += " " + standard; }
ifstream fs("hyper.cpp"); else if(s == "-O2")
optimized = 2, compiler += " -O2", obj_dir += "/O2", setdir += "../";
system("mkdir -p " + obj_dir); else if(s == "-O3")
optimized = 3, compiler += " -O3", obj_dir += "/O3", setdir += "../";
ofstream fsm(obj_dir + "/hyper.cpp"); else if(s.substr(0, 4) == "-std")
fsm << "#if REM\n#define INCLUDE(x)\n#endif\n"; standard = s;
string s; else if(s.substr(0, 2) == "-l")
while(getline(fs, s)) { linker += " " + s;
if(s.substr(0, 8) == "#include") { else if(s == "-I") {
string t; opts += " " + s + " " + argv[i+1];
bool in = false; i++;
bool ext = false; }
string iext = ""; else if(s.substr(0, 2) == "-I")
for(char c: s) if(c == '"') in = !in; else if(!in) ; else if(c == '.') ext = !ext; else if(!ext) t += c; else iext += c; opts += " " + s;
if(iext == "h") { fsm << "#include \"" + setdir + "hyper.h\"\n"; continue; } else if(s == "-rv") {
if(iext != "cpp") printf("unknown extension: %s\n", iext);
fsm << "INCLUDE(___" << t << ")\n"; if(standard == default_standard) {
continue; standard = "-std=c++17";
} }
fsm << s << "\n"; ifstream ifs("rogueviz/rogueviz-all.cpp");
} string s;
fsm.close(); while(getline(ifs, s)) {
if(s.substr(0, 10) == "#include \"") {
printf("preprocessing...\n"); string t = s.substr(10);
if(system(preprocessor + " " + opts + " "+obj_dir+"/hyper.cpp -o "+obj_dir+"/hyper.E")) { printf("preprocessing error\n"); exit(1); } t = t.substr(0, t.find(".cpp\""));
modules.push_back("rogueviz/" + t);
if(true) { }
ifstream fs2(obj_dir+"/hyper.E"); }
while(getline(fs2, s)) { }
if(s.substr(0, 7) == "INCLUDE") { else {
s = s.substr(11); if(s.size() >= 5 && s.substr(s.size() - 4) == ".cpp")
s = s.substr(0,s.size() - 1); s = s.substr(0, s.size() - 4);
modules.push_back(s); modules.push_back(s);
} }
} }
} if(!optimized)
compiler += " -g3";
if(get_file_time(obj_dir + "/hyper.o") < get_file_time("hyper.cpp")) { preprocessor += " " + standard;
printf("compiling hyper...\n"); compiler += " " + standard;
if(system(compiler + " -DREM " + opts + " " + obj_dir + "/hyper.cpp -c -o " + obj_dir + "/hyper.o")) { printf("error\n"); exit(1); } ifstream fs("hyper.cpp");
}
system("mkdir -p " + obj_dir);
string allobj = " " + obj_dir + "/hyper.o";
ofstream fsm(obj_dir + "/hyper.cpp");
int id = 0; fsm << "#if REM\n#define INCLUDE(x)\n#endif\n";
for(string m: modules) { string s;
id++; while(getline(fs, s)) {
string src = m + ".cpp"; if(s.substr(0, 8) == "#include") {
string m2 = m; string t;
for(char& c: m2) if(c == '/') c = '_'; bool in = false;
string obj = obj_dir + "/" + m2 + ".o"; bool ext = false;
time_t src_time = get_file_time(src); string iext = "";
if(!src_time) { for(char c: s) if(c == '"') in = !in; else if(!in) ; else if(c == '.') ext = !ext; else if(!ext) t += c; else iext += c;
printf("file not found: %s\n", src.c_str()); if(iext == "h") { fsm << "#include \"" + setdir + "hyper.h\"\n"; continue; }
exit(1); if(iext != "cpp") printf("unknown extension: %s\n", iext.c_str());
} fsm << "INCLUDE(\"" << t << "\")\n";
time_t obj_time = get_file_time(obj); continue;
if(src_time > obj_time) { }
printf("compiling %s... [%d/%d]\n", m.c_str(), id, int(modules.size())); fsm << s << "\n";
if(system(compiler + " " + opts + " " + src + " -o " + obj)) { printf("error\n"); exit(1); } }
} fsm.close();
else {
printf("ok: %s\n", m.c_str()); printf("preprocessing...\n");
} if(system(preprocessor + " " + opts + " "+obj_dir+"/hyper.cpp -o "+obj_dir+"/hyper.E")) { printf("preprocessing error\n"); exit(1); }
allobj += " ";
allobj += obj; if(true) {
} ifstream fs2(obj_dir+"/hyper.E");
while(getline(fs2, s)) {
printf("linking...\n"); if(s.substr(0, 7) == "INCLUDE") {
system(linker + allobj + libs); s = s.substr(9);
return 0; s = s.substr(0,s.size() - 2);
} modules.push_back(s);
}
}
}
if(get_file_time(obj_dir + "/hyper.o") < get_file_time("hyper.cpp")) {
printf("compiling hyper...\n");
if(system(compiler + " -DREM " + opts + " " + obj_dir + "/hyper.cpp -c -o " + obj_dir + "/hyper.o")) { printf("error\n"); exit(1); }
}
string allobj = " " + obj_dir + "/hyper.o";
int id = 0;
for(string m: modules) {
id++;
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);
if(src_time > obj_time) {
printf("compiling %s... [%d/%d]\n", m.c_str(), id, int(modules.size()));
if(system(compiler + " " + opts + " " + src + " -o " + obj)) { printf("error\n"); exit(1); }
}
else {
printf("ok: %s\n", m.c_str());
}
allobj += " ";
allobj += obj;
}
printf("linking...\n");
system(linker + allobj + libs);
return 0;
}