1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2024-11-23 13:07:16 +00:00

mymake, comments moved

This commit is contained in:
Zeno Rogue 2019-09-06 09:17:45 +02:00
parent c7f070fe76
commit ebc44af74c
6 changed files with 174 additions and 54 deletions

View File

@ -1,26 +1,11 @@
// Hyperbolic Rogue
// Copyright (C) 2011-2019 Zeno Rogue
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
// Copyright (C) 2011-2019 Zeno Rogue, see 'hyper.cpp' for details
/** \file hyper.cpp
* \brief the hyper_main function
*/
#include "hyper.h"
#if CU_HYPER
#if ISLINUX
#include <sys/resource.h>
@ -87,4 +72,3 @@ int main(int argc, char **argv) {
return hr::hyper_main(argc, argv);
}
#endif
#endif

View File

@ -1,26 +1,28 @@
// Usage:
// * compile hyper.cpp with CU == 0
// * compile init.cpp with CU == 1
// * link them.
// Only the parts defined in #if IN_CU(1) will be included in the second compiling.
// Hyperbolic Rogue
// Copyright (C) 2011-2019 Zeno Rogue
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
#ifndef CU
#define IN_CU(x) 1
#else
#define IN_CU(x) (CU == x)
#endif
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
/** \file hyper.cpp
* \brief master file which includes everything
* You can either compile this file, or use mymake to compile all the *.cpp files separately.
*/
#include "hyper.h"
#define CU_INIT IN_CU(0)
#define CU_HYPER IN_CU(0)
#if IN_CU(0)
#include "classes.cpp"
#endif
#if IN_CU(0)
#include "shaders.cpp"
#include "hprint.cpp"
#include "util.cpp"
@ -36,7 +38,6 @@
#include "sphere.cpp"
#include "quotient.cpp"
#include "crystal.cpp"
// #include "product.cpp"
#include "reg3.cpp"
#include "language.cpp"
#include "cell.cpp"
@ -47,9 +48,7 @@
#include "flags.cpp"
#include "yendor.cpp"
#include "complex.cpp"
#if CAP_COMPLEX2
#include "complex2.cpp"
#endif
#include "savemem.cpp"
#include "game.cpp"
#include "orbgen.cpp"
@ -57,11 +56,7 @@
#include "landlock.cpp"
#include "landgen.cpp"
#include "orbs.cpp"
#if CAP_INV
#include "inventory.cpp"
#else
namespace hr { namespace inv { bool on, activating; } }
#endif
#include "system.cpp"
#include "debug.cpp"
#include "geometry.cpp"
@ -72,12 +67,8 @@ namespace hr { namespace inv { bool on, activating; } }
#include "usershapes.cpp"
#include "drawing.cpp"
#include "mapeditor.cpp"
#if CAP_MODEL
#include "netgen.cpp"
#endif
#if CAP_TABFONT || CAP_CREATEFONT
#include "nofont.cpp"
#endif
#include "basegraph.cpp"
#include "screenshot.cpp"
#include "renderbuffer.cpp"
@ -91,11 +82,7 @@ namespace hr { namespace inv { bool on, activating; } }
#include "quit.cpp"
#include "multi.cpp"
#include "shmup.cpp"
#if CAP_RACING
#include "racing.cpp"
#endif
#include "models.cpp"
#include "history.cpp"
#include "rug.cpp"
@ -109,9 +96,7 @@ namespace hr { namespace inv { bool on, activating; } }
#include "achievement.cpp"
#include "barriers.cpp"
#include "surface.cpp"
#if CAP_TOUR
#include "tour.cpp"
#endif
#include "commandline.cpp"
#include "bigstuff.cpp"
#include "multigame.cpp"
@ -125,7 +110,6 @@ namespace hr { namespace inv { bool on, activating; } }
#else
namespace hr { namespace daily { bool on; } }
#endif
#endif
#include "hyper-main.cpp"

View File

@ -10,6 +10,7 @@ namespace hr {
EX namespace inv {
#if CAP_INV
EX bool on;
EX array<int, ittypes> usedup;
EX array<int, ittypes> remaining;
@ -671,4 +672,7 @@ EX namespace inv {
}
}
#else
always_false on, activating;
#endif
}}

144
mymake.cpp Normal file
View File

@ -0,0 +1,144 @@
// 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.
// 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>
#include <vector>
#include <sys/stat.h>
using namespace std;
string opts = "-DFHS -DLINUX -DWHATEVER -I/usr/include/SDL";
string preprocessor =
"g++ " + opts + " -E";
string compiler =
"g++ " + opts + " -Wall -Wextra -Wno-maybe-uninitialized -Wno-missing-field-initializers -Wno-unused-parameter -Wno-implicit-fallthrough -std=c++11 -rdynamic -fdiagnostics-color=always -c";
string linker =
"g++ -rdynamic -o hyper";
string libs = " savepng-loc.o -lSDL -lSDL_ttf -lSDL_mixer -lSDL_gfx -lGLEW -lGL -lpng -rdynamic -lpthread";
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 system(string cmdline) {
return system(cmdline.c_str());
}
int main(int argc, char **argv) {
system("make -f Makefile.loc language-data.cpp autohdr.h savepng-loc.o");
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)
if(c == '=' || c == '-' || c == '/') obj_dir += "_";
else obj_dir += c;
}
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 modules.push_back(s);
}
if(!optimized)
compiler += " -g3";
ifstream fs("hyper.cpp");
system("mkdir -p " + obj_dir);
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);
fsm << "INCLUDE(___" << t << ")\n";
continue;
}
fsm << s << "\n";
}
fsm.close();
printf("preprocessing...\n");
if(system(preprocessor + " "+obj_dir+"/hyper.cpp -o "+obj_dir+"/hyper.E")) { printf("preprocessing error\n"); exit(1); }
if(true) {
ifstream fs2(obj_dir+"/hyper.E");
while(getline(fs2, s)) {
if(s.substr(0, 7) == "INCLUDE") {
s = s.substr(11);
s = s.substr(0,s.size() - 1);
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 " + 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);
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 + " " + 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;
}
// g++ hyper.cpp -c -o hyper.o
// g++ savepng-loc.o hyper.o -o hyper -lSDL -lSDL_ttf -lSDL_mixer -lSDL_gfx -lGLEW -g3 -lGL -lpng -rdynamic

View File

@ -6,6 +6,7 @@
*/
#include "hyper.h"
#if CAP_RACING
namespace hr {
EX namespace racing {
@ -1373,3 +1374,4 @@ EX void add_debug(cell *c) {
}
}
#endif

View File

@ -7,7 +7,7 @@
#include "hyper.h"
namespace hr {
#if CAP_TOUR
EX namespace tour {
EX bool on;
@ -828,4 +828,6 @@ auto a1 = addHook(hooks_frame, 100, [] () { if(tour::on) tour::presentation(tour
auto a2 = addHook(hooks_handleKey, 100, handleKeyTour);
auto a3 = addHook(hooks_nextland, 100, [] (eLand l) { return tour::on ? getNext(l) : laNone; });
}}
EX }
#endif
}