-
-
Save iKlsR/2243119 to your computer and use it in GitHub Desktop.
c++ portable command line compiler for mingw, java and msvc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
i love compiling from the command line. the sheer raw power and speed it offers can never be rivaled by any ide. as i'm always exploring new libraries and languages i grow weary of the repetitive typing to add parameters and special flags each time i want to compile; so i wrote this small "compiler" to assist me, its fast and is easily customi(s)able to suit any build system/language. | |
//todo.. | |
- add python support | |
- xampp launcher/started | |
- msvc support | |
- ask to run after compile | |
- debug info(print to a file!) | |
(- tidier code.) | |
//to use | |
.type the location of the file(make sure to include the extension) | |
.type the new filename(not applicable to java as it inherits its filename from the class name) | |
.type the paramter to compile with(ie. -lfreeglut)(freeglut.lib when vc support is added) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Windows.h> | |
#include <iostream> | |
#include <string> | |
#include <conio.h> | |
std::string filename; | |
std::string parameters; | |
std::string new_filename; | |
std::string gcompiler = "g++"; | |
std::string mcompiler = "msvc"; //see todo | |
std::string jcompiler = "javac"; | |
#define build_point "-o" | |
#define no_name "none" | |
#define ogl "ogl" | |
#define sfml "sfml" | |
#define box "box" | |
#define sdl "sdl" | |
#define sogl "sogl" | |
#define bogl "bogl" | |
#define nor "nor" | |
#define java "java" | |
#define oglp "-lfreeglut -lopengl32 -lglew32 -lglu32" | |
#define sfmlp "-lsfml-window -lsfml-graphics -lsfml-system" | |
#define boxp "-lBox2D" | |
#define sdlp "-lSDL -lSDLmain" | |
#define soglp "-lfreeglut.h -lopengl32 -lglew32 -lglu32 -lsfml-window -lsfml-graphics -lsfml-system" | |
#define boglp "-lfreeglut.h -lopengl32 -lglew32 -lglu32 -lBox2D" | |
#define norp "" | |
#define javap "" | |
using namespace std; | |
void gbuildsystem(string mid_tmp) | |
{ | |
gcompiler.append(" "); | |
// | |
if(new_filename != no_name) | |
{ | |
gcompiler.append(build_point); | |
gcompiler.append(" "); | |
gcompiler.append(new_filename); | |
gcompiler.append(" "); | |
} | |
gcompiler.append(filename); | |
gcompiler.append(" "); | |
gcompiler.append(mid_tmp); | |
} | |
void jbuildsystem(string othertmp) | |
{ | |
jcompiler.append(" "); | |
jcompiler.append(filename); | |
} | |
void compile(string _tmp_) | |
{ | |
if(parameters == ogl) | |
{ | |
gbuildsystem(oglp); | |
string buildthis = gcompiler; | |
const char *tmp_ptr; | |
tmp_ptr = buildthis.c_str(); | |
system(tmp_ptr); | |
//todo! | |
//setup error catcher! | |
cout << "build complete!" << endl; | |
} | |
else if(parameters == nor) | |
{ | |
gbuildsystem(norp); | |
string buildthis = gcompiler; | |
const char *tmp_ptr; | |
tmp_ptr = buildthis.c_str(); | |
system(tmp_ptr); | |
cout << "build complete!" << endl; | |
} | |
else if(parameters == java) | |
{ | |
jbuildsystem(javap); | |
string buildthis = jcompiler; | |
const char *tmp_ptr; | |
tmp_ptr = buildthis.c_str(); | |
system(tmp_ptr); | |
cout << "build complete!" << endl; | |
} | |
else | |
{ | |
cout << "invalid settings found!" << endl; | |
} | |
} | |
int main(int argc, char* argv[]) | |
{ | |
cout << "Enter the filename: "; | |
cin >> filename; | |
cout << "Enter the new filename(none if left a): "; | |
cin >> new_filename; | |
cout << "Enter the parameters: "; | |
cin >> parameters; | |
compile(parameters); | |
cout << "all done"; | |
getch(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment